From a0fcb3f88f361d19032c4cf9ef9861198b482351 Mon Sep 17 00:00:00 2001
From: Anne-Cath
Date: Fri, 22 Mar 2024 11:32:50 +0100
Subject: [PATCH 1/5] =?UTF-8?q?N=C2=B07385=20-=20Trigger=20on=20mention=20?=
=?UTF-8?q?executed=20even=20if=20it's=20not=20a=20mention=20with=20@?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
application/utils.inc.php | 135 ++++++++++++++++++++------------------
1 file changed, 70 insertions(+), 65 deletions(-)
diff --git a/application/utils.inc.php b/application/utils.inc.php
index 340913bf84..9b05b675cb 100644
--- a/application/utils.inc.php
+++ b/application/utils.inc.php
@@ -522,7 +522,7 @@ protected static function Sanitize_Internal($value, $sSanitizationFilter)
// For URL
case static::ENUM_SANITIZATION_FILTER_URL:
- // NĀ°6350 - returns only valid URLs
+ // NĀ°6350 - returns only valid URLs
$retValue = filter_var($value, FILTER_VALIDATE_URL);
break;
@@ -555,44 +555,44 @@ public static function ReadPostedDocument($sName, $sIndex = null)
switch($sError)
{
case UPLOAD_ERR_OK:
- $sTmpName = is_null($sIndex) ? $aFileInfo['tmp_name'] : $aFileInfo['tmp_name'][$sIndex];
- $sMimeType = is_null($sIndex) ? $aFileInfo['type'] : $aFileInfo['type'][$sIndex];
- $sName = is_null($sIndex) ? $aFileInfo['name'] : $aFileInfo['name'][$sIndex];
+ $sTmpName = is_null($sIndex) ? $aFileInfo['tmp_name'] : $aFileInfo['tmp_name'][$sIndex];
+ $sMimeType = is_null($sIndex) ? $aFileInfo['type'] : $aFileInfo['type'][$sIndex];
+ $sName = is_null($sIndex) ? $aFileInfo['name'] : $aFileInfo['name'][$sIndex];
- $doc_content = file_get_contents($sTmpName);
+ $doc_content = file_get_contents($sTmpName);
$sMimeType = self::GetFileMimeType($sTmpName);
$oDocument = new ormDocument($doc_content, $sMimeType, $sName);
- break;
+ break;
case UPLOAD_ERR_NO_FILE:
- // no file to load, it's a normal case, just return an empty document
- break;
+ // no file to load, it's a normal case, just return an empty document
+ break;
case UPLOAD_ERR_FORM_SIZE:
case UPLOAD_ERR_INI_SIZE:
- throw new FileUploadException(Dict::Format('UI:Error:UploadedFileTooBig', ini_get('upload_max_filesize')));
- break;
+ throw new FileUploadException(Dict::Format('UI:Error:UploadedFileTooBig', ini_get('upload_max_filesize')));
+ break;
case UPLOAD_ERR_PARTIAL:
- throw new FileUploadException(Dict::S('UI:Error:UploadedFileTruncated.'));
- break;
+ throw new FileUploadException(Dict::S('UI:Error:UploadedFileTruncated.'));
+ break;
case UPLOAD_ERR_NO_TMP_DIR:
- throw new FileUploadException(Dict::S('UI:Error:NoTmpDir'));
- break;
+ throw new FileUploadException(Dict::S('UI:Error:NoTmpDir'));
+ break;
case UPLOAD_ERR_CANT_WRITE:
- throw new FileUploadException(Dict::Format('UI:Error:CannotWriteToTmp_Dir', ini_get('upload_tmp_dir')));
- break;
+ throw new FileUploadException(Dict::Format('UI:Error:CannotWriteToTmp_Dir', ini_get('upload_tmp_dir')));
+ break;
case UPLOAD_ERR_EXTENSION:
- $sName = is_null($sIndex) ? $aFileInfo['name'] : $aFileInfo['name'][$sIndex];
- throw new FileUploadException(Dict::Format('UI:Error:UploadStoppedByExtension_FileName', $sName));
- break;
+ $sName = is_null($sIndex) ? $aFileInfo['name'] : $aFileInfo['name'][$sIndex];
+ throw new FileUploadException(Dict::Format('UI:Error:UploadStoppedByExtension_FileName', $sName));
+ break;
default:
- throw new FileUploadException(Dict::Format('UI:Error:UploadFailedUnknownCause_Code', $sError));
- break;
+ throw new FileUploadException(Dict::Format('UI:Error:UploadFailedUnknownCause_Code', $sError));
+ break;
}
}
@@ -890,10 +890,10 @@ public static function StringToTime($sDate, $sFormat)
$aDateRegexps = array_values($aSpec);
}
- $sDateRegexp = str_replace($aDateTokens, $aDateRegexps, $sFormat);
+ $sDateRegexp = str_replace($aDateTokens, $aDateRegexps, $sFormat);
- if (preg_match('!^(?)'.$sDateRegexp.'(?)$!', $sDate, $aMatches))
- {
+ if (preg_match('!^(?)'.$sDateRegexp.'(?)$!', $sDate, $aMatches))
+ {
$sYear = isset($aMatches['year']) ? $aMatches['year'] : 0;
$sMonth = isset($aMatches['month']) ? $aMatches['month'] : 1;
$sDay = isset($aMatches['day']) ? $aMatches['day'] : 1;
@@ -902,11 +902,11 @@ public static function StringToTime($sDate, $sFormat)
$sSecond = isset($aMatches['second']) ? $aMatches['second'] : 0;
return strtotime("$sYear-$sMonth-$sDay $sHour:$sMinute:$sSecond");
}
- else
- {
- return false;
- }
- // http://www.spaweditor.com/scripts/regex/index.php
+ else
+ {
+ return false;
+ }
+ // http://www.spaweditor.com/scripts/regex/index.php
}
/**
@@ -1335,8 +1335,8 @@ public static function GetSessionLog()
return Session::GetLog();
}
- static function DebugBacktrace($iLimit = 5)
- {
+ static function DebugBacktrace($iLimit = 5)
+ {
$aFullTrace = debug_backtrace();
$aLightTrace = array();
for($i=1; ($i<=$iLimit && $i < count($aFullTrace)); $i++) // Skip the last function call... which is the call to this function !
@@ -1344,7 +1344,7 @@ static function DebugBacktrace($iLimit = 5)
$aLightTrace[$i] = $aFullTrace[$i]['function'].'(), called from line '.$aFullTrace[$i]['line'].' in '.$aFullTrace[$i]['file'];
}
echo "".print_r($aLightTrace, true)."
\n";
- }
+ }
/**
* Execute the given iTop PHP script, passing it the current credentials
@@ -1540,7 +1540,7 @@ public static function GetPopupMenuItemsBlock(iUIBlock &$oContainerBlock, $iMenu
if (strlen($sUrl) < SERVER_MAX_URL_LENGTH) {
// Static menus: Email this page, CSV Export & Add to Dashboard
$aResult[] = new URLPopupMenuItem('UI:Menu:EMail', Dict::S('UI:Menu:EMail'),
- "mailto:?body=".urlencode($sUrl).' ' // Add an extra space to make it work in Outlook
+ "mailto:?body=".urlencode($sUrl).' ' // Add an extra space to make it work in Outlook
);
}
@@ -1987,7 +1987,7 @@ public static function DoPostRequest($sUrl, $aData, $sOptionnalHeaders = null, &
/**
* Get a standard list of character sets
*
- * @param array $aAdditionalEncodings Additional values
+ * @param array $aAdditionalEncodings Additional values
* @return array of iconv code => english label, sorted by label
*/
public static function GetPossibleEncodings($aAdditionalEncodings = array())
@@ -2222,13 +2222,13 @@ public static function ResizeImageToFit(ormDocument $oImage, $iWidth, $iHeight,
case 'image/gif':
case 'image/jpeg':
case 'image/png':
- $img = @imagecreatefromstring($oImage->GetData());
- break;
+ $img = @imagecreatefromstring($oImage->GetData());
+ break;
default:
- // Unsupported image type, return the image as-is
- //throw new Exception("Unsupported image type: '".$oImage->GetMimeType()."'. Cannot resize the image, original image will be used.");
- return $oImage;
+ // Unsupported image type, return the image as-is
+ //throw new Exception("Unsupported image type: '".$oImage->GetMimeType()."'. Cannot resize the image, original image will be used.");
+ return $oImage;
}
if ($img === false)
{
@@ -2260,16 +2260,16 @@ public static function ResizeImageToFit(ormDocument $oImage, $iWidth, $iHeight,
switch ($oImage->GetMimeType())
{
case 'image/gif':
- imagegif($new); // send image to output buffer
- break;
+ imagegif($new); // send image to output buffer
+ break;
case 'image/jpeg':
- imagejpeg($new, null, 80); // null = send image to output buffer, 80 = good quality
- break;
+ imagejpeg($new, null, 80); // null = send image to output buffer, 80 = good quality
+ break;
case 'image/png':
- imagepng($new, null, 5); // null = send image to output buffer, 5 = medium compression
- break;
+ imagepng($new, null, 5); // null = send image to output buffer, 5 = medium compression
+ break;
}
$oResampledImage = new ormDocument(ob_get_contents(), $oImage->GetMimeType(), $oImage->GetFileName());
@ob_end_clean();
@@ -2299,16 +2299,16 @@ public static function CreateUUID($sPrefix = '')
$data .= mt_rand();
$hash = strtoupper(hash('ripemd128', $uid . md5($data)));
$sUUID = '{' .
- substr($hash, 0, 8) .
- '-' .
- substr($hash, 8, 4) .
- '-' .
- substr($hash, 12, 4) .
- '-' .
- substr($hash, 16, 4) .
- '-' .
- substr($hash, 20, 12) .
- '}';
+ substr($hash, 0, 8) .
+ '-' .
+ substr($hash, 8, 4) .
+ '-' .
+ substr($hash, 12, 4) .
+ '-' .
+ substr($hash, 16, 4) .
+ '-' .
+ substr($hash, 20, 12) .
+ '}';
return $sUUID;
}
@@ -2320,7 +2320,7 @@ public static function CreateUUID($sPrefix = '')
*/
public static function GetCurrentModuleName($iCallDepth = 0)
{
- return ModuleService::GetInstance()->GetCurrentModuleName($iCallDepth + 1);
+ return ModuleService::GetInstance()->GetCurrentModuleName($iCallDepth + 1);
}
/**
@@ -2367,7 +2367,7 @@ public static function GetCurrentModuleUrl()
*/
public static function GetCurrentModuleSetting($sProperty, $defaultvalue = null)
{
- return ModuleService::GetInstance()->GetCurrentModuleSetting($sProperty, $defaultvalue);
+ return ModuleService::GetInstance()->GetCurrentModuleSetting($sProperty, $defaultvalue);
}
/**
@@ -2376,7 +2376,7 @@ public static function GetCurrentModuleSetting($sProperty, $defaultvalue = null)
*/
public static function GetCompiledModuleVersion($sModuleName)
{
- return ModuleService::GetInstance()->GetCompiledModuleVersion($sModuleName);
+ return ModuleService::GetInstance()->GetCompiledModuleVersion($sModuleName);
}
/**
@@ -3114,14 +3114,19 @@ public static function GetMentionedObjectsFromText(string $sText): array
foreach ($aMentionMatches[0] as $iMatchIdx => $sCompleteMatch) {
$sMatchedClass = $aMentionMatches[2][$iMatchIdx];
$sMatchedId = $aMentionMatches[3][$iMatchIdx];
+ $sMatchedName = $aMentionMatches[1][$iMatchIdx];
- // Prepare array for matched class if not already present
- if (!array_key_exists($sMatchedClass, $aMentionedObjects)) {
- $aMentionedObjects[$sMatchedClass] = array();
- }
- // Add matched ID if not already there
- if (!in_array($sMatchedId, $aMentionedObjects[$sMatchedClass])) {
- $aMentionedObjects[$sMatchedClass][] = $sMatchedId;
+ //tests if the name starts with @
+ if(str_starts_with($sMatchedName,'@')) {
+
+ // Prepare array for matched class if not already present
+ if (!array_key_exists($sMatchedClass, $aMentionedObjects)) {
+ $aMentionedObjects[$sMatchedClass] = array();
+ }
+ // Add matched ID if not already there
+ if (!in_array($sMatchedId, $aMentionedObjects[$sMatchedClass])) {
+ $aMentionedObjects[$sMatchedClass][] = $sMatchedId;
+ }
}
}
From 43c163345928df718442f112c1c17dc9b5ce2469 Mon Sep 17 00:00:00 2001
From: Anne-Cath
Date: Thu, 30 Jan 2025 09:18:32 +0100
Subject: [PATCH 2/5] WIP - just for save - does not work
---
application/utils.inc.php | 31 ++++++++++--------
.../unitary-tests/application/utilsTest.php | 32 +++++++++++++------
2 files changed, 40 insertions(+), 23 deletions(-)
diff --git a/application/utils.inc.php b/application/utils.inc.php
index 9b05b675cb..5fd3b721a7 100644
--- a/application/utils.inc.php
+++ b/application/utils.inc.php
@@ -3110,24 +3110,29 @@ public static function GetMentionedObjectsFromText(string $sText): array
$aMentionMatches = [];
$sText = html_entity_decode($sText);
- preg_match_all('/]*)data-object-class="([^"]*)"\s.*data-object-key="([^"]*)"/Ui', $sText, $aMentionMatches);
+ $aMentionAllowedClasses = MetaModel::GetConfig()->Get('mentions.allowed_classes');
+ preg_match_all('/]*)data-object-class="([^"]*)"\s.*data-object-key="([^"]*)"/Ui', $sText, $aMentionMatches);
foreach ($aMentionMatches[0] as $iMatchIdx => $sCompleteMatch) {
$sMatchedClass = $aMentionMatches[2][$iMatchIdx];
$sMatchedId = $aMentionMatches[3][$iMatchIdx];
$sMatchedName = $aMentionMatches[1][$iMatchIdx];
- //tests if the name starts with @
- if(str_starts_with($sMatchedName,'@')) {
-
- // Prepare array for matched class if not already present
- if (!array_key_exists($sMatchedClass, $aMentionedObjects)) {
- $aMentionedObjects[$sMatchedClass] = array();
- }
- // Add matched ID if not already there
- if (!in_array($sMatchedId, $aMentionedObjects[$sMatchedClass])) {
- $aMentionedObjects[$sMatchedClass][] = $sMatchedId;
- }
- }
+ $sMentionPrefix = array_search($sMatchedClass, $aMentionAllowedClasses);
+ if ($sMentionPrefix === false) {
+ continue;
+ }
+ //tests if the name starts with $sMentionPrefix (@)
+ if (str_starts_with($sMatchedName,$sMentionPrefix) === false) {
+ continue;
+ }
+ // Prepare array for matched class if not already present
+ if (!array_key_exists($sMatchedClass, $aMentionedObjects)) {
+ $aMentionedObjects[$sMatchedClass] = array();
+ }
+ // Add matched ID if not already there
+ if (!in_array($sMatchedId, $aMentionedObjects[$sMatchedClass])) {
+ $aMentionedObjects[$sMatchedClass][] = $sMatchedId;
+ }
}
return $aMentionedObjects;
diff --git a/tests/php-unit-tests/unitary-tests/application/utilsTest.php b/tests/php-unit-tests/unitary-tests/application/utilsTest.php
index 410f15efe7..93f4fa25c0 100644
--- a/tests/php-unit-tests/unitary-tests/application/utilsTest.php
+++ b/tests/php-unit-tests/unitary-tests/application/utilsTest.php
@@ -22,6 +22,7 @@
namespace Combodo\iTop\Test\UnitTest\Application;
use Combodo\iTop\Test\UnitTest\ItopTestCase;
+use MetaModel;
use ormDocument;
use utils;
@@ -653,6 +654,7 @@ public function ToAcronymProvider()
*/
public function testGetMentionedObjectsFromText($sInput, $aExceptedMentionedObjects)
{
+ MetaModel::GetConfig()->Set('mentions.allowed_classes', ['@' => 'Person','š#' => 'Team']);
// Emulate the "Case provider mechanism" (reason: the data provider requires utils constants not available before the application startup)
echo "testGetMentionedObjectsFromText: input = $sInput\n";
$aTestedMentionedObjects = utils::GetMentionedObjectsFromText($sInput);
@@ -677,28 +679,38 @@ public function GetMentionedObjectsFromTextProvider(): array
End",
[],
],
- '1 UserRequest' => [
+ '1 Object' => [
<<BeginningBefore link #Test TicketAfter link
End
+Beginning
Before link #Test PersonAfter link
End
HTML,
[
- 'UserRequest' => ['12345'],
+ 'Person' => ['12345'],
],
],
- '2 UserRequests' => [
+ 'Should not match 1 Object if the mention prefix is missing' => [
<<Beginning
Before link #Test Ticket After link
And #Test Ticket
End
+
HTML,
[
- 'UserRequest' => ['12345', '987654'],
- ],
+ [],
+ ],
],
- '1 UserRequest, 1 Person' => [
+ 'Should return 2 Objects' => [
<<
+
HTML,
[
- 'UserRequest' => ['12345'],
+ 'Person' => ['12345', '987654'],
+ ],
+ ],
+ 'Should process objects of different classes' => [
+ "Begining
+ Before link š#R-012345 After link
+ And @Claude Monet
+ End",
+ utils::ENUM_TEXT_FORMAT_HTML,
+ [
+ 'Team' => ['12345'],
'Person' => ['3'],
],
],
From de30dd9742559d4465eec6d85cf4b9b22c375482 Mon Sep 17 00:00:00 2001
From: Anne-Cath
Date: Thu, 30 Jan 2025 11:32:05 +0100
Subject: [PATCH 3/5] Final fix after rebase
---
application/utils.inc.php | 2 +-
.../unitary-tests/application/utilsTest.php | 29 ++++++++++---------
2 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/application/utils.inc.php b/application/utils.inc.php
index 5fd3b721a7..8bc4337e46 100644
--- a/application/utils.inc.php
+++ b/application/utils.inc.php
@@ -3111,7 +3111,7 @@ public static function GetMentionedObjectsFromText(string $sText): array
$sText = html_entity_decode($sText);
$aMentionAllowedClasses = MetaModel::GetConfig()->Get('mentions.allowed_classes');
- preg_match_all('/]*)data-object-class="([^"]*)"\s.*data-object-key="([^"]*)"/Ui', $sText, $aMentionMatches);
+ preg_match_all('/]*)data-object-class="([^"]*)"\s.*data-object-key="([^"]*)"\s*([^>]*)>(.*)<\/a>/Ui', $sText, $aMentionMatches);
foreach ($aMentionMatches[0] as $iMatchIdx => $sCompleteMatch) {
$sMatchedClass = $aMentionMatches[2][$iMatchIdx];
$sMatchedId = $aMentionMatches[3][$iMatchIdx];
diff --git a/tests/php-unit-tests/unitary-tests/application/utilsTest.php b/tests/php-unit-tests/unitary-tests/application/utilsTest.php
index 93f4fa25c0..1817d65b0a 100644
--- a/tests/php-unit-tests/unitary-tests/application/utilsTest.php
+++ b/tests/php-unit-tests/unitary-tests/application/utilsTest.php
@@ -21,6 +21,7 @@
namespace Combodo\iTop\Test\UnitTest\Application;
+use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
use Combodo\iTop\Test\UnitTest\ItopTestCase;
use MetaModel;
use ormDocument;
@@ -29,8 +30,10 @@
/**
* @covers utils
*/
-class utilsTest extends ItopTestCase
+class utilsTest extends ItopDataTestCase
{
+ const USE_TRANSACTION = false;
+
protected function setUp(): void
{
parent::setUp();
@@ -47,6 +50,7 @@ protected function tearDown(): void
public function testEndsWith()
{
$this->assertFalse(utils::EndsWith('a', 'bbbb'));
+ $this->assertTrue(utils::EndsWith('bbba', 'a'));
}
/**
@@ -681,7 +685,7 @@ public function GetMentionedObjectsFromTextProvider(): array
],
'1 Object' => [
<<BeginningBefore link #Test PersonAfter link
End
+Beginning
Before link @Test PersonAfter link
End
HTML,
[
'Person' => ['12345'],
@@ -689,26 +693,25 @@ public function GetMentionedObjectsFromTextProvider(): array
],
'Should not match 1 Object if the mention prefix is missing' => [
<<Beginning
Before link #Test Ticket After link
And #Test Ticket
End
+
HTML,
- [
- [],
- ],
+ [],
],
'Should return 2 Objects' => [
<<
+
HTML,
[
- 'Person' => ['12345', '987654'],
+ 'Person' => ['12345', '3'],
],
],
'Should process objects of different classes' => [
- "Begining
- Before link š#R-012345 After link
- And @Claude Monet
- End",
- utils::ENUM_TEXT_FORMAT_HTML,
+ <<š#R-012345 After link
+ And @Claude Monet
+ End
+HTML,
[
'Team' => ['12345'],
'Person' => ['3'],
From a32002aa7b739784349776104e87fc487fcea143 Mon Sep 17 00:00:00 2001
From: Anne-Catherine <57360138+accognet@users.noreply.github.com>
Date: Mon, 3 Feb 2025 13:40:09 +0100
Subject: [PATCH 4/5] Update application/utils.inc.php
Co-authored-by: Molkobain
---
application/utils.inc.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/application/utils.inc.php b/application/utils.inc.php
index 8bc4337e46..777a614207 100644
--- a/application/utils.inc.php
+++ b/application/utils.inc.php
@@ -3121,7 +3121,7 @@ public static function GetMentionedObjectsFromText(string $sText): array
if ($sMentionPrefix === false) {
continue;
}
- //tests if the name starts with $sMentionPrefix (@)
+ //tests if the name starts with $sMentionPrefix (e.g. '@' for 'Contact' class)
if (str_starts_with($sMatchedName,$sMentionPrefix) === false) {
continue;
}
From 9a726c631620832b4f3c880b7e490d2f63512019 Mon Sep 17 00:00:00 2001
From: Anne-Cath
Date: Mon, 10 Feb 2025 14:48:52 +0100
Subject: [PATCH 5/5] WIP
---
application/utils.inc.php | 6 +-
.../src/BaseTestCase/ItopTestCase.php | 5 +-
.../unitary-tests/application/utilsTest.php | 77 +----------------
.../application/utilsTestWithDataModel.php | 85 +++++++++++++++++++
4 files changed, 91 insertions(+), 82 deletions(-)
create mode 100644 tests/php-unit-tests/unitary-tests/application/utilsTestWithDataModel.php
diff --git a/application/utils.inc.php b/application/utils.inc.php
index 777a614207..e8792e5a07 100644
--- a/application/utils.inc.php
+++ b/application/utils.inc.php
@@ -1962,7 +1962,7 @@ public static function DoPostRequest($sUrl, $aData, $sOptionnalHeaders = null, &
CURLOPT_HTTPHEADER => $aHTTPHeaders,
);
- $aAllOptions = $aCurlOptions + $aOptions;
+ $aAllOptions = $aCurlOptions + $aOptions;
$ch = curl_init($sUrl);
curl_setopt_array($ch, $aAllOptions);
$response = curl_exec($ch);
@@ -3115,14 +3115,14 @@ public static function GetMentionedObjectsFromText(string $sText): array
foreach ($aMentionMatches[0] as $iMatchIdx => $sCompleteMatch) {
$sMatchedClass = $aMentionMatches[2][$iMatchIdx];
$sMatchedId = $aMentionMatches[3][$iMatchIdx];
- $sMatchedName = $aMentionMatches[1][$iMatchIdx];
+ $sMatchedName = $aMentionMatches[5][$iMatchIdx];
$sMentionPrefix = array_search($sMatchedClass, $aMentionAllowedClasses);
if ($sMentionPrefix === false) {
continue;
}
//tests if the name starts with $sMentionPrefix (e.g. '@' for 'Contact' class)
- if (str_starts_with($sMatchedName,$sMentionPrefix) === false) {
+ if (str_starts_with($sMatchedName, $sMentionPrefix) === false) {
continue;
}
// Prepare array for matched class if not already present
diff --git a/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php b/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php
index 52cbe3436c..8e2b6dc52f 100644
--- a/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php
+++ b/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php
@@ -520,14 +520,13 @@ protected function AssertArraysHaveSameItems(array $aExpected, array $aActual, s
sort($aActual);
sort($aExpected);
- $sExpected = implode("\n", $aExpected);
- $sActual = implode("\n", $aActual);
+ $sExpected = var_export($aExpected, true);
+ $sActual = var_export($aActual, true);
if ($sExpected === $sActual) {
$this->assertTrue(true);
return;
}
$sMessage .= "\nExpected:\n$sExpected\nActual:\n$sActual";
- var_export($aActual);
$this->fail($sMessage);
}
diff --git a/tests/php-unit-tests/unitary-tests/application/utilsTest.php b/tests/php-unit-tests/unitary-tests/application/utilsTest.php
index 1817d65b0a..7b78f2298c 100644
--- a/tests/php-unit-tests/unitary-tests/application/utilsTest.php
+++ b/tests/php-unit-tests/unitary-tests/application/utilsTest.php
@@ -21,19 +21,15 @@
namespace Combodo\iTop\Test\UnitTest\Application;
-use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
use Combodo\iTop\Test\UnitTest\ItopTestCase;
-use MetaModel;
use ormDocument;
use utils;
/**
* @covers utils
*/
-class utilsTest extends ItopDataTestCase
+class utilsTest extends ItopTestCase
{
- const USE_TRANSACTION = false;
-
protected function setUp(): void
{
parent::setUp();
@@ -50,7 +46,6 @@ protected function tearDown(): void
public function testEndsWith()
{
$this->assertFalse(utils::EndsWith('a', 'bbbb'));
- $this->assertTrue(utils::EndsWith('bbba', 'a'));
}
/**
@@ -650,76 +645,6 @@ public function ToAcronymProvider()
];
}
- /**
- * @dataProvider GetMentionedObjectsFromTextProvider
- * @covers utils::GetMentionedObjectsFromText
- *
- * @throws \Exception
- */
- public function testGetMentionedObjectsFromText($sInput, $aExceptedMentionedObjects)
- {
- MetaModel::GetConfig()->Set('mentions.allowed_classes', ['@' => 'Person','š#' => 'Team']);
- // Emulate the "Case provider mechanism" (reason: the data provider requires utils constants not available before the application startup)
- echo "testGetMentionedObjectsFromText: input = $sInput\n";
- $aTestedMentionedObjects = utils::GetMentionedObjectsFromText($sInput);
-
- $sExpectedAsString = print_r($aExceptedMentionedObjects, true);
- $sTestedAsString = print_r($aTestedMentionedObjects, true);
-
- $this->assertEquals($sExpectedAsString, $sTestedAsString, "Found mentioned objects don't match. Got: $sTestedAsString, expected $sExpectedAsString");
- }
-
- /**
- * @since 3.0.0
- */
- public function GetMentionedObjectsFromTextProvider(): array
- {
- $sAbsUrlAppRoot = utils::GetAbsoluteUrlAppRoot();
-
- return [
- 'No object' => [
- "Begining
- Second line
- End",
- [],
- ],
- '1 Object' => [
- <<BeginningBefore link @Test PersonAfter link
End
-HTML,
- [
- 'Person' => ['12345'],
- ],
- ],
- 'Should not match 1 Object if the mention prefix is missing' => [
- <<Beginning
Before link #Test Ticket After link
-HTML,
- [],
- ],
- 'Should return 2 Objects' => [
- <<
-HTML,
- [
- 'Person' => ['12345', '3'],
- ],
- ],
- 'Should process objects of different classes' => [
- <<š#R-012345 After link
- And @Claude Monet
- End
-HTML,
- [
- 'Team' => ['12345'],
- 'Person' => ['3'],
- ],
- ],
- ];
- }
-
/**
* @dataProvider FormatInitialsForMedallionProvider
* @covers utils::FormatInitialsForMedallion
diff --git a/tests/php-unit-tests/unitary-tests/application/utilsTestWithDataModel.php b/tests/php-unit-tests/unitary-tests/application/utilsTestWithDataModel.php
new file mode 100644
index 0000000000..5fd4068d86
--- /dev/null
+++ b/tests/php-unit-tests/unitary-tests/application/utilsTestWithDataModel.php
@@ -0,0 +1,85 @@
+Set('mentions.allowed_classes', ['@' => 'Person', 'š#' => 'Team']);
+ // Emulate the "Case provider mechanism" (reason: the data provider requires utils constants not available before the application startup)
+ $aTestedMentionedObjects = utils::GetMentionedObjectsFromText($sInput);
+
+ $this->AssertArraysHaveSameItems($aExceptedMentionedObjects, $aTestedMentionedObjects);
+ }
+
+ /**
+ * @since 3.0.0
+ */
+ public function GetMentionedObjectsFromTextProvider(): array
+ {
+ $sAbsUrlAppRoot = 'https://myitop.com/itop/';
+
+ return [
+ 'No object' => [
+ "Begining
+ Second line
+ End",
+ [],
+ ],
+ '1 Object' => [
+ <<BeginningBefore link @Test PersonAfter link
End
+HTML,
+ [
+ 'Person' => ['12345'],
+ ],
+ ],
+ 'Should not match 1 Object if the mention prefix is missing' => [
+ <<Beginning
Before link #Test Ticket After link
+HTML,
+ [],
+ ],
+ 'Should return 2 Objects' => [
+ <<
+HTML,
+ [
+ 'Person' => ['12345', '3'],
+ ],
+ ],
+ 'Should process objects of different classes' => [
+ <<š#R-012345 After link
+ And @Claude Monet
+ End
+HTML,
+ [
+ 'Team' => ['12345'],
+ 'Person' => ['3'],
+ ],
+ ],
+ ];
+ }
+}