mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 18:48:51 +02:00
N°8681 - Add unit tests
This commit is contained in:
@@ -25,9 +25,9 @@ class AttributeTextTest extends ItopDataTestCase
|
||||
public function testRenderWikiHtml_nonWikiUrlVariants()
|
||||
{
|
||||
// String value
|
||||
$input = 'This hyperlink https://combodo.com should be in an anchor tag.';
|
||||
$expected = 'This hyperlink <a href="https://combodo.com">https://combodo.com</a> should be in an anchor tag.';
|
||||
$this->assertEquals($expected, AttributeText::RenderWikiHtml($input));
|
||||
$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(''));
|
||||
@@ -41,17 +41,17 @@ class AttributeTextTest extends ItopDataTestCase
|
||||
*/
|
||||
public function testRenderWikiHtml_bWikiOnlyAbsentOrFalse_shouldTransformBothRegularAndWikiHyperlinks()
|
||||
{
|
||||
$input = 'A regular hyperlink https://combodo.com and a wiki hyperlink to an existing object [[Organization:'.$this->oTestOrganizationForAttributeText->GetKey().']]';
|
||||
$sInput = 'A regular hyperlink https://combodo.com and a wiki hyperlink to an existing object [[Organization:'.$this->oTestOrganizationForAttributeText->GetKey().']]';
|
||||
|
||||
// bWikiOnly default value
|
||||
$result = AttributeText::RenderWikiHtml($input);
|
||||
$this->assertStringContainsString('<a href="https://combodo.com">', $result);
|
||||
$this->assertStringContainsString('class="object-ref-link"', $result);
|
||||
$sResult = AttributeText::RenderWikiHtml($sInput);
|
||||
$this->assertStringContainsString('<a href="https://combodo.com">', $sResult);
|
||||
$this->assertStringContainsString('class="object-ref-link"', $sResult);
|
||||
|
||||
// bWikiOnly = false
|
||||
$result = AttributeText::RenderWikiHtml($input, false);
|
||||
$this->assertStringContainsString('<a href="https://combodo.com">', $result);
|
||||
$this->assertStringContainsString('class="object-ref-link"', $result);
|
||||
$sResult = AttributeText::RenderWikiHtml($sInput, false);
|
||||
$this->assertStringContainsString('<a href="https://combodo.com">', $sResult);
|
||||
$this->assertStringContainsString('class="object-ref-link"', $sResult);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,10 +59,10 @@ class AttributeTextTest extends ItopDataTestCase
|
||||
*/
|
||||
public function testRenderWikiHtml_bWikiOnlyToTrue_shouldNotTransformRegularHyperlinkButTransformWikiHyperlink()
|
||||
{
|
||||
$input = 'A regular hyperlink https://combodo.com and a wiki hyperlink to an existing object [[Organization:'.$this->oTestOrganizationForAttributeText->GetKey().']]';
|
||||
$result = AttributeText::RenderWikiHtml($input, true);
|
||||
$this->assertStringNotContainsString('<a href="https://combodo.com">', $result);
|
||||
$this->assertStringContainsString('class="object-ref-link"', $result);
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,9 +70,9 @@ class AttributeTextTest extends ItopDataTestCase
|
||||
*/
|
||||
public function testRenderWikiHtml_shouldTransformWikiHyperlinkForExistingObjectsOnly()
|
||||
{
|
||||
$input = 'A wiki hyperlink to a non existing object [[Organization:123456789]] and a wiki hyperlink to an existing object [[Organization:'.$this->oTestOrganizationForAttributeText->GetKey().']]';
|
||||
$result = AttributeText::RenderWikiHtml($input);
|
||||
$this->assertStringContainsString('wiki_broken_link', $result);
|
||||
$this->assertStringContainsString('class="object-ref-link"', $result);
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,4 +59,43 @@ class InlineImageTest extends ItopDataTestCase
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers InlineImage::FixUrls
|
||||
*/
|
||||
public function testFixUrls_shouldReturnAnEmptyStringIfNullOrEmptyStringPassed()
|
||||
{
|
||||
$sResult = InlineImage::FixUrls(null);
|
||||
$this->assertEquals('', $sResult);
|
||||
|
||||
$sResult = InlineImage::FixUrls('');
|
||||
$this->assertEquals('', $sResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers InlineImage::FixUrls
|
||||
*/
|
||||
public function testFixUrls_shouldReturnUnchangedValueIfValueContainsNoImage()
|
||||
{
|
||||
$sHtml = '<div><p>Texte sans image</p></div>';
|
||||
$sResult = InlineImage::FixUrls($sHtml);
|
||||
$this->assertEquals($sHtml, $sResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers InlineImage::FixUrls
|
||||
*/
|
||||
public function testFixUrls_shouldReplaceImagesSrcWithCurrentAppRootUrlAndSecret()
|
||||
{
|
||||
$sHtml = <<<HTML
|
||||
<div>
|
||||
<img src="/images/test1.png" data-img-id="123" data-img-secret="abc" />
|
||||
<img src="/images/test2.png" data-img-id="456" data-img-secret="def" />
|
||||
</div>
|
||||
HTML;
|
||||
$sResult = InlineImage::FixUrls($sHtml);
|
||||
$this->assertStringContainsString('<img', $sResult);
|
||||
$this->assertStringContainsString(\utils::EscapeHtml(\utils::GetAbsoluteUrlAppRoot().INLINEIMAGE_DOWNLOAD_URL.'123&s=abc'), $sResult);
|
||||
$this->assertStringContainsString(\utils::EscapeHtml(\utils::GetAbsoluteUrlAppRoot().INLINEIMAGE_DOWNLOAD_URL.'456&s=def'), $sResult);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user