Skip to content
Extraits de code Groupes Projets
Valider 420d4546 rédigé par mattab's avatar mattab
Parcourir les fichiers

Fixes #4288 Remove from the PDF the metadata that changes with datetime, or...

Fixes #4288 Remove from the PDF the metadata that changes with datetime, or that is random.This ensures that when we compare two binary PDF files together, the comparison does not take into account these random bits in the pdf files.
parent 52875adf
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -62,8 +62,8 @@
<regionCode>CA</regionCode>
<city>not a city</city>
<location>not a city, California, United States</location>
<latitude>1.000000</latitude>
<longitude>2.000000</longitude>
<latitude>1</latitude>
<longitude>2</longitude>
<provider>Unknown</provider>
<providerName>Unknown</providerName>
<providerUrl>http://piwik.org/faq/general/#faq_52</providerUrl>
......
......@@ -717,21 +717,15 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
if ($isLiveMustDeleteDates) {
$response = $this->removeAllLiveDatesFromXml($response);
}
// normalize date markups and document ID in pdf files :
// - /LastModified (D:20120820204023+00'00')
// - /CreationDate (D:20120820202226+00'00')
// - /ModDate (D:20120820202226+00'00')
// - /M (D:20120820202226+00'00')
// - /ID [ <0f5cc387dc28c0e13e682197f485fe65> <0f5cc387dc28c0e13e682197f485fe65> ]
$response = preg_replace('/\(D:[0-9]{14}/', '(D:19700101000000', $response);
$response = preg_replace('/\/ID \[ <.*> ]/', '', $response);
$response = $this->normalizePdfContent($response);
if (empty($compareAgainst)) {
file_put_contents($processedFilePath, $response);
}
$expected = $this->loadExpectedFile($expectedFilePath);
$expected = $this->normalizePdfContent($expected);
if (empty($expected)) {
print("The expected file is not found at '$expectedFilePath'. The Processed response was:");
print("\n----------------------------\n\n");
......@@ -854,9 +848,11 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
// Only raise error if there was some data before
$testNotSmallAfter = strlen($input > 100) && $testNotSmallAfter;
$oldInput = $input;
$input = preg_replace('/(<' . $xmlElement . '>.+?<\/' . $xmlElement . '>)/', '', $input);
//check we didn't delete the whole string
if ($testNotSmallAfter) {
if ($testNotSmallAfter && $input != $oldInput) {
$this->assertTrue(strlen($input) > 100);
}
return $input;
......@@ -1155,4 +1151,26 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
ArchiveTableCreator::refreshTableList($forceReload = true);
}
/**
* Removes content from PDF binary the content that changes with the datetime or other random Ids
*/
protected function normalizePdfContent($response)
{
// normalize date markups and document ID in pdf files :
// - /LastModified (D:20120820204023+00'00')
// - /CreationDate (D:20120820202226+00'00')
// - /ModDate (D:20120820202226+00'00')
// - /M (D:20120820202226+00'00')
// - /ID [ <0f5cc387dc28c0e13e682197f485fe65> <0f5cc387dc28c0e13e682197f485fe65> ]
$response = preg_replace('/\(D:[0-9]{14}/', '(D:19700101000000', $response);
$response = preg_replace('/\/ID \[ <.*> ]/', '', $response);
$response = preg_replace('/\/id:\[ <.*> ]/', '', $response);
$response = $this->removeXmlElement($response, "xmp:CreateDate");
$response = $this->removeXmlElement($response, "xmp:ModifyDate");
$response = $this->removeXmlElement($response, "xmp:MetadataDate");
$response = $this->removeXmlElement($response, "xmpMM:DocumentID");
$response = $this->removeXmlElement($response, "xmpMM:InstanceID");
return $response;
}
}
Subproject commit 0de660f2d75b9f2013a480e45106e1496f645e96
Subproject commit 176806335cc19d12d933f10b8e915650eb7c6fb1
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter