diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php
index 150a28cdc4..63830d8e41 100644
--- a/core/attributedef.class.inc.php
+++ b/core/attributedef.class.inc.php
@@ -4259,6 +4259,9 @@ public function GetMaxSize()
public static function RenderWikiHtml($sText, $bWikiOnly = false)
{
+ // N°8681 - Ensure to have a string value
+ $sText = $sText ?? '';
+
if (!$bWikiOnly) {
$sPattern = '/'.str_replace('/', '\/', utils::GetConfig()->Get('url_validation_pattern')).'/i';
if (preg_match_all(
diff --git a/core/inlineimage.class.inc.php b/core/inlineimage.class.inc.php
index 50242ff36b..fe4d4a7294 100644
--- a/core/inlineimage.class.inc.php
+++ b/core/inlineimage.class.inc.php
@@ -266,6 +266,9 @@ public static function OnFormCancel($sTempId): bool
*/
public static function FixUrls($sHtml)
{
+ // N°8681 - Ensure to have a string value
+ $sHtml = $sHtml ?? '';
+
$aNeedles = [];
$aReplacements = [];
// Find img tags with an attribute data-img-id
diff --git a/tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php b/tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php
index 739cf3b652..5c4e620a41 100644
--- a/tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php
@@ -13,13 +13,6 @@ class AttributeDefinitionTest extends ItopDataTestCase
{
public const CREATE_TEST_ORG = true;
- protected function setUp(): void
- {
- parent::setUp();
- require_once(APPROOT.'core/attributedef.class.inc.php');
-
- }
-
public function testGetImportColumns()
{
$oAttributeDefinition = MetaModel::GetAttributeDef("ApplicationSolution", "status");
diff --git a/tests/php-unit-tests/unitary-tests/core/AttributeTextTest.php b/tests/php-unit-tests/unitary-tests/core/AttributeTextTest.php
new file mode 100644
index 0000000000..a84d5b897f
--- /dev/null
+++ b/tests/php-unit-tests/unitary-tests/core/AttributeTextTest.php
@@ -0,0 +1,78 @@
+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 https://combodo.com 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('', $sResult);
+ $this->assertStringContainsString('class="object-ref-link"', $sResult);
+
+ // bWikiOnly = false
+ $sResult = AttributeText::RenderWikiHtml($sInput, false);
+ $this->assertStringContainsString('', $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('', $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);
+ }
+}
diff --git a/tests/php-unit-tests/unitary-tests/core/InlineImageTest.php b/tests/php-unit-tests/unitary-tests/core/InlineImageTest.php
index 68196a0439..1818c97e8c 100644
--- a/tests/php-unit-tests/unitary-tests/core/InlineImageTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/InlineImageTest.php
@@ -59,4 +59,43 @@ public function OnFormCancelInvalidTempIdProvider()
],
];
}
+
+ /**
+ * @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 = '';
+ $sResult = InlineImage::FixUrls($sHtml);
+ $this->assertEquals($sHtml, $sResult);
+ }
+
+ /**
+ * @covers InlineImage::FixUrls
+ */
+ public function testFixUrls_shouldReplaceImagesSrcWithCurrentAppRootUrlAndSecret()
+ {
+ $sHtml = <<
+
+
+
+HTML;
+ $sResult = InlineImage::FixUrls($sHtml);
+ $this->assertStringContainsString('
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);
+ }
}