diff --git a/core/inlineimage.class.inc.php b/core/inlineimage.class.inc.php
index 552ba2e4f2..37232fdeda 100644
--- a/core/inlineimage.class.inc.php
+++ b/core/inlineimage.class.inc.php
@@ -266,6 +266,9 @@ class InlineImage extends DBObject
*/
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/sources/Core/AttributeDefinition/AttributeText.php b/sources/Core/AttributeDefinition/AttributeText.php
index 07d4b4ee2a..c5727f2881 100644
--- a/sources/Core/AttributeDefinition/AttributeText.php
+++ b/sources/Core/AttributeDefinition/AttributeText.php
@@ -97,6 +97,9 @@ class AttributeText extends AttributeString
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/tests/ci_description.ini b/tests/ci_description.ini
index ea76b363f4..f96ce6755c 100644
--- a/tests/ci_description.ini
+++ b/tests/ci_description.ini
@@ -1,8 +1,8 @@
[infra]
; STS version : testing greatest PHP version possible
-php_version=8.2-apache
+php_version=8.3-apache
; N°6629 perf bug on some tests on mariadb for now, so specifying MySQL
-db_version=5.7
+db_version=latest-mariadb
[itop]
itop_setup=tests/setup_params/default-params.xml
diff --git a/tests/php-code-style/.php-cs-fixer.dist.php b/tests/php-code-style/.php-cs-fixer.dist.php
index ecaa66f716..2b9e349b32 100644
--- a/tests/php-code-style/.php-cs-fixer.dist.php
+++ b/tests/php-code-style/.php-cs-fixer.dist.php
@@ -13,13 +13,12 @@ $config = new PhpCsFixer\Config();
return $config->setRiskyAllowed(true)
->setRules([
'@PSR12' => true,
- 'indentation_type' => true,
- 'no_extra_blank_lines' => true,
- 'array_syntax' => ['syntax' => 'short'],
- 'concat_space' => true,
- 'trailing_comma_in_multiline' => true,
+ 'no_extra_blank_lines' => true, // default value ['tokens' => ['extra']]
+ 'array_syntax' => true, // default value ['syntax' => 'short']
+ 'concat_space' => true, // default value ['spacing' => 'none']
+ 'trailing_comma_in_multiline' => true, // default value ['after_heredoc' => false, 'elements' => ['arrays']]
])
->setIndent("\t")
->setLineEnding("\n")
->setFinder($finder)
-;
\ No newline at end of file
+;
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..40a7a1f676
--- /dev/null
+++ b/tests/php-unit-tests/unitary-tests/core/AttributeTextTest.php
@@ -0,0 +1,79 @@
+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 @@ 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 = '';
+ $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);
+ }
}