mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-18 06:48:50 +02:00
Merge remote-tracking branch 'origin/support/3.1' into develop
This commit is contained in:
@@ -8599,7 +8599,7 @@ class AttributeBlob extends AttributeDefinition
|
||||
public function RecordAttChange(DBObject $oObject, $original, $value): void
|
||||
{
|
||||
// N°6502 Don't record history if only the download count has changed
|
||||
if ($original->EqualsExceptDownloadsCount($value)) {
|
||||
if ((null !== $original) && (null !== $value) && $original->EqualsExceptDownloadsCount($value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ class ObjectRepository
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
static public function Search(string $sObjectClass, array $aFieldsToLoad, string $sSearch): ?array
|
||||
public static function Search(string $sObjectClass, array $aFieldsToLoad, string $sSearch): ?array
|
||||
{
|
||||
try {
|
||||
|
||||
@@ -82,7 +82,7 @@ class ObjectRepository
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
static public function SearchFromOql(string $sObjectClass, array $aFieldsToLoad, string $sOql, string $sSearch, DBObject $oThisObject = null): ?array
|
||||
public static function SearchFromOql(string $sObjectClass, array $aFieldsToLoad, string $sOql, string $sSearch, DBObject $oThisObject = null): ?array
|
||||
{
|
||||
try {
|
||||
|
||||
@@ -117,7 +117,7 @@ class ObjectRepository
|
||||
* @throws \CoreException
|
||||
* @throws \DictExceptionMissingString
|
||||
*/
|
||||
static private function DBSetToObjectArray(iDBObjectSetIterator $oDbObjectSet, string $sObjectClass, array $aFieldsToLoad): array
|
||||
private static function DBSetToObjectArray(iDBObjectSetIterator $oDbObjectSet, string $sObjectClass, array $aFieldsToLoad): array
|
||||
{
|
||||
// Retrieve friendly name complementary specification
|
||||
$aComplementAttributeSpec = MetaModel::GetNameSpec($sObjectClass, FriendlyNameType::COMPLEMENTARY);
|
||||
@@ -158,7 +158,7 @@ class ObjectRepository
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
static public function GetDefaultFieldsToLoad(array $aComplementAttributeSpec, string $sObjectImageAttCode)
|
||||
public static function GetDefaultFieldsToLoad(array $aComplementAttributeSpec, string $sObjectImageAttCode)
|
||||
{
|
||||
// Friendly name complementary fields
|
||||
$aFieldsToLoad = $aComplementAttributeSpec[1];
|
||||
@@ -185,7 +185,7 @@ class ObjectRepository
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static public function ComputeOthersData(DBObject $oDbObject, string $sClass, array $aData, array $aComplementAttributeSpec, string $sObjectImageAttCode): array
|
||||
public static function ComputeOthersData(DBObject $oDbObject, string $sClass, array $aData, array $aComplementAttributeSpec, string $sObjectImageAttCode): array
|
||||
{
|
||||
try {
|
||||
|
||||
@@ -196,6 +196,7 @@ class ObjectRepository
|
||||
$aData['obsolescence_flag'] = $oDbObject->IsObsolete();
|
||||
|
||||
// Additional fields
|
||||
$sFriendlynameForHtml = utils::EscapeHtml($aData['friendlyname']);
|
||||
if (count($aComplementAttributeSpec[1]) > 0) {
|
||||
$aData['has_additional_field'] = true;
|
||||
$aArguments = [];
|
||||
@@ -203,9 +204,10 @@ class ObjectRepository
|
||||
$aArguments[] = $oDbObject->Get($sAdditionalField);
|
||||
}
|
||||
$aData['additional_field'] = vsprintf($aComplementAttributeSpec[0], $aArguments);
|
||||
$aData['full_description'] = "{$aData['friendlyname']}<br><i><small>{$aData['additional_field']}</small></i>";
|
||||
$sAdditionalFieldForHtml = utils::EscapeHtml($aData['additional_field']);
|
||||
$aData['full_description'] = "{$sFriendlynameForHtml}<br><i><small>{$sAdditionalFieldForHtml}</small></i>";
|
||||
} else {
|
||||
$aData['full_description'] = $aData['friendlyname'];
|
||||
$aData['full_description'] = $sFriendlynameForHtml;
|
||||
}
|
||||
|
||||
// Image
|
||||
@@ -308,7 +310,7 @@ class ObjectRepository
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
static public function DeleteFromOql(string $sOql): bool
|
||||
public static function DeleteFromOql(string $sOql): bool
|
||||
{
|
||||
try {
|
||||
|
||||
|
||||
142
tests/php-unit-tests/unitary-tests/core/ormDocumentTest.php
Normal file
142
tests/php-unit-tests/unitary-tests/core/ormDocumentTest.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
/*!
|
||||
* @copyright Copyright (C) 2010-2023 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use ormDocument;
|
||||
|
||||
/**
|
||||
* Tests of the ormDocument class
|
||||
*/
|
||||
class ormDocumentTest extends ItopDataTestCase
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function LoadRequiredItopFiles(): void
|
||||
{
|
||||
parent::LoadRequiredItopFiles();
|
||||
|
||||
$this->RequireOnceItopFile('core/ormdocument.class.inc.php');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $aDocAData
|
||||
* @param array $aDocBData
|
||||
* @param bool $bExpectedResult
|
||||
*
|
||||
* @dataProvider EqualsExceptDownloadsCountProvider
|
||||
*/
|
||||
public function testEqualsExceptDownloadsCount(array $aDocAData, array $aDocBData, bool $bExpectedResult)
|
||||
{
|
||||
$oDocA = new ormDocument(base64_decode($aDocAData[0]), $aDocAData[1], $aDocAData[2], $aDocAData[3]);
|
||||
$oDocB = new ormDocument(base64_decode($aDocBData[0]), $aDocBData[1], $aDocBData[2], $aDocBData[3]);
|
||||
|
||||
$bTestedResult = $oDocA->EqualsExceptDownloadsCount($oDocB);
|
||||
$this->assertSame($bExpectedResult, $bTestedResult);
|
||||
}
|
||||
|
||||
public function EqualsExceptDownloadsCountProvider(): array
|
||||
{
|
||||
$sFirstDummyTextFileContentBase64 = "Rmlyc3Q=";
|
||||
$sSecondDummyTextFileContentBase64 = "U2Vjb25k";
|
||||
|
||||
return [
|
||||
'Total different files' => [
|
||||
[
|
||||
$sFirstDummyTextFileContentBase64,
|
||||
"text/plain",
|
||||
"a.txt",
|
||||
0
|
||||
],
|
||||
[
|
||||
$sSecondDummyTextFileContentBase64,
|
||||
"image/png",
|
||||
"b.png",
|
||||
1
|
||||
],
|
||||
false,
|
||||
],
|
||||
'Different data only' => [
|
||||
[
|
||||
$sFirstDummyTextFileContentBase64,
|
||||
"text/plain",
|
||||
"a.txt",
|
||||
0
|
||||
],
|
||||
[
|
||||
$sSecondDummyTextFileContentBase64,
|
||||
"text/plain",
|
||||
"a.txt",
|
||||
0
|
||||
],
|
||||
false,
|
||||
],
|
||||
'Different mime types only' => [
|
||||
[
|
||||
$sFirstDummyTextFileContentBase64,
|
||||
"text/plain",
|
||||
"a.txt",
|
||||
0
|
||||
],
|
||||
[
|
||||
$sFirstDummyTextFileContentBase64,
|
||||
"image/png",
|
||||
"a.txt",
|
||||
0
|
||||
],
|
||||
false,
|
||||
],
|
||||
'Different file names only' => [
|
||||
[
|
||||
$sFirstDummyTextFileContentBase64,
|
||||
"text/plain",
|
||||
"a.txt",
|
||||
0
|
||||
],
|
||||
[
|
||||
$sFirstDummyTextFileContentBase64,
|
||||
"text/plain",
|
||||
"b.txt",
|
||||
0
|
||||
],
|
||||
false,
|
||||
],
|
||||
'Different download counts only' => [
|
||||
[
|
||||
$sFirstDummyTextFileContentBase64,
|
||||
"text/plain",
|
||||
"a.txt",
|
||||
0
|
||||
],
|
||||
[
|
||||
$sFirstDummyTextFileContentBase64,
|
||||
"text/plain",
|
||||
"a.txt",
|
||||
1
|
||||
],
|
||||
true,
|
||||
],
|
||||
'Identical files, different object instances' => [
|
||||
[
|
||||
$sFirstDummyTextFileContentBase64,
|
||||
"text/plain",
|
||||
"a.txt",
|
||||
0
|
||||
],
|
||||
[
|
||||
$sFirstDummyTextFileContentBase64,
|
||||
"text/plain",
|
||||
"a.txt",
|
||||
0
|
||||
],
|
||||
false,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user