From 420d45463eb2c0ff38c96fb3b4e8611bb5ba8fdb Mon Sep 17 00:00:00 2001
From: mattab <matthieu.aubry@gmail.com>
Date: Mon, 11 Nov 2013 17:14:04 +1300
Subject: [PATCH] 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.

---
 ...eTest__Live.getLastVisitsDetails_month.xml |   4 +-
 ...dReports.generateReport_month.original.pdf | Bin 506168 -> 505834 bytes
 ...edReports.generateReport_week.original.pdf | Bin 528615 -> 528437 bytes
 tests/PHPUnit/IntegrationTestCase.php         |  38 +++++++++++++-----
 tests/PHPUnit/UI                              |   2 +-
 5 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/tests/PHPUnit/Integration/expected/test_ManyVisitorsOneWebsiteTest__Live.getLastVisitsDetails_month.xml b/tests/PHPUnit/Integration/expected/test_ManyVisitorsOneWebsiteTest__Live.getLastVisitsDetails_month.xml
index 612e65abe7..01e588217f 100644
--- a/tests/PHPUnit/Integration/expected/test_ManyVisitorsOneWebsiteTest__Live.getLastVisitsDetails_month.xml
+++ b/tests/PHPUnit/Integration/expected/test_ManyVisitorsOneWebsiteTest__Live.getLastVisitsDetails_month.xml
@@ -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>
diff --git a/tests/PHPUnit/Integration/expected/test_TwoVisitors_twoWebsites_differentDays_scheduled_report_in_pdf_tables_only__ScheduledReports.generateReport_month.original.pdf b/tests/PHPUnit/Integration/expected/test_TwoVisitors_twoWebsites_differentDays_scheduled_report_in_pdf_tables_only__ScheduledReports.generateReport_month.original.pdf
index d9183ab6116e898d21277761b7434ca98f8bed82..050f24e8e51a843e9090cf413a746dab5843e3b0 100644
GIT binary patch
delta 69
zcmdn-N$%BqxrP?T7N!>F7M2#)7Pc+yxpSv4pUbYz!o|tSIlW*NyZCgi`RuCGyXLWf
NL=)Q{zJUFq1ORJ=7pwpP

delta 407
zcmaF$UT()HxrP?T7N!>F7M2#)7Pc+yxpS>-Dsl^~oQqNuOHy5c*v`nn&{)^d5Qsty
zjI9iftxV0d4GgRd3~cn#R8G&G%dTAy*6*92l9^UXjD94QT%4So5Z$RIi7AOCiA3o~
zRtq#?y6Q@Hk?9rl*j1<Bn9KeV>>OWTE0_G_(%jU%5>FSq($dTnE8~>J6f+acR9*8F
zV?$jt(?l~}BQsMIT}u;V6GMZ<RI`*+Gq49y^}?J86!pw2E=kNwPQ`Dc0(K)2nx`wS
PWS0QDcRS~N_J<MxU}1eQ

diff --git a/tests/PHPUnit/Integration/expected/test_ecommerceOrderWithItems_scheduled_report_in_pdf_tables_only__ScheduledReports.generateReport_week.original.pdf b/tests/PHPUnit/Integration/expected/test_ecommerceOrderWithItems_scheduled_report_in_pdf_tables_only__ScheduledReports.generateReport_week.original.pdf
index 5f39e966b902710a20f5e1cc78e3d50bbae2bdda..1079c561b82ff7251fbca3dd3108f06d572ca0c5 100644
GIT binary patch
delta 133
zcmaF9P+{u=g@zW!7N!>F7M2#)7Pc+yJ)fr^`^>J*!o|tSIklfde7eJDcGc}Gzp!&K
zs+gM@7@H@jr0J%bnV9M(ni!?%rdb-B>84sHStgnrrJ5ThnoYm@m0gc0mD|<7u^*5E
E0Cd4A?f?J)

delta 311
zcmdnGK;ij9g@zW!7N!>F7M2#)7Pc+yJ)f;?Dsl^~oQqNuOHy5c*v`nn&{)^d5Qsty
zjI9h!txU|c4GgRd3~cn#R8H^t%&uJz*6*92l9^UXjD94QT%4So5Z$RIi7AOCiA3o~
zRtq#?dh-`{%kAGkvvV-2m?oztnI)SU>Y5oP8R{A(CR^xQ7^SA_8mAZ<n<tv2StJ@-
TOjrKOu1A#0?WJGY4@dz3pfFx9

diff --git a/tests/PHPUnit/IntegrationTestCase.php b/tests/PHPUnit/IntegrationTestCase.php
index 6ccb1c5db5..75c899cbc8 100755
--- a/tests/PHPUnit/IntegrationTestCase.php
+++ b/tests/PHPUnit/IntegrationTestCase.php
@@ -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;
+    }
+
 }
diff --git a/tests/PHPUnit/UI b/tests/PHPUnit/UI
index 0de660f2d7..176806335c 160000
--- a/tests/PHPUnit/UI
+++ b/tests/PHPUnit/UI
@@ -1 +1 @@
-Subproject commit 0de660f2d75b9f2013a480e45106e1496f645e96
+Subproject commit 176806335cc19d12d933f10b8e915650eb7c6fb1
-- 
GitLab