diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index 823cfa93cb..40797d2706 100644 --- a/core/attributedef.class.inc.php +++ b/core/attributedef.class.inc.php @@ -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; } diff --git a/tests/php-unit-tests/unitary-tests/core/ormDocumentTest.php b/tests/php-unit-tests/unitary-tests/core/ormDocumentTest.php new file mode 100644 index 0000000000..e9d33871c3 --- /dev/null +++ b/tests/php-unit-tests/unitary-tests/core/ormDocumentTest.php @@ -0,0 +1,142 @@ +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, + ], + ]; + } +}