-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathAttributeTextTest.php
More file actions
78 lines (66 loc) · 3.12 KB
/
AttributeTextTest.php
File metadata and controls
78 lines (66 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/*
* @copyright Copyright (C) 2010-2026 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Test\UnitTest\Core;
use AttributeText;
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
class AttributeTextTest extends ItopDataTestCase
{
protected \Organization $oTestOrganizationForAttributeText;
public function setUp(): void
{
parent::setUp();
$this->oTestOrganizationForAttributeText = $this->CreateOrganization('Test for AttributeTextTest');
}
/**
* @covers AttributeText::RenderWikiHtml
*/
public function testRenderWikiHtml_nonWikiUrlVariants()
{
// String value
$sInput = 'This hyperlink https://combodo.com should be in an anchor tag.';
$sExpected = 'This hyperlink <a href="https://combodo.com">https://combodo.com</a> should be in an anchor tag.';
$this->assertEquals($sExpected, AttributeText::RenderWikiHtml($sInput));
// Empty string value
$this->assertEquals('', AttributeText::RenderWikiHtml(''));
// Null value
$this->assertEquals('', AttributeText::RenderWikiHtml(null));
}
/**
* @covers AttributeText::RenderWikiHtml
*/
public function testRenderWikiHtml_bWikiOnlyAbsentOrFalse_shouldTransformBothRegularAndWikiHyperlinks()
{
$sInput = 'A regular hyperlink https://combodo.com and a wiki hyperlink to an existing object [[Organization:'.$this->oTestOrganizationForAttributeText->GetKey().']]';
// bWikiOnly default value
$sResult = AttributeText::RenderWikiHtml($sInput);
$this->assertStringContainsString('<a href="https://combodo.com">', $sResult);
$this->assertStringContainsString('class="object-ref-link"', $sResult);
// bWikiOnly = false
$sResult = AttributeText::RenderWikiHtml($sInput, false);
$this->assertStringContainsString('<a href="https://combodo.com">', $sResult);
$this->assertStringContainsString('class="object-ref-link"', $sResult);
}
/**
* @covers AttributeText::RenderWikiHtml
*/
public function testRenderWikiHtml_bWikiOnlyToTrue_shouldNotTransformRegularHyperlinkButTransformWikiHyperlink()
{
$sInput = 'A regular hyperlink https://combodo.com and a wiki hyperlink to an existing object [[Organization:'.$this->oTestOrganizationForAttributeText->GetKey().']]';
$sResult = AttributeText::RenderWikiHtml($sInput, true);
$this->assertStringNotContainsString('<a href="https://combodo.com">', $sResult);
$this->assertStringContainsString('class="object-ref-link"', $sResult);
}
/**
* @covers AttributeText::RenderWikiHtml
*/
public function testRenderWikiHtml_shouldTransformWikiHyperlinkForExistingObjectsOnly()
{
$sInput = 'A wiki hyperlink to a non existing object [[Organization:123456789]] and a wiki hyperlink to an existing object [[Organization:'.$this->oTestOrganizationForAttributeText->GetKey().']]';
$sResult = AttributeText::RenderWikiHtml($sInput);
$this->assertStringContainsString('wiki_broken_link', $sResult);
$this->assertStringContainsString('class="object-ref-link"', $sResult);
}
}