From a496005c7e79637daa379b61c2f03c1d1c99a18c Mon Sep 17 00:00:00 2001
From: Stefan Giehl <stefan@piwik.org>
Date: Fri, 22 Sep 2017 14:51:07 +0200
Subject: [PATCH] Make visitor profile wellformed XML (#12100)

* Make visitor profile wellformed XML

* update test files
---
 plugins/Actions/VisitorDetails.php            |  9 ++++++++-
 .../test___Live.getVisitorProfile.xml         | 20 +++++++++++++++----
 ...st_higherLimit__Live.getVisitorProfile.xml | 20 +++++++++++++++----
 ...taAndNormalAPI__Live.getVisitorProfile.xml |  5 ++++-
 ...PI_pagesegment__Live.getVisitorProfile.xml |  5 ++++-
 5 files changed, 48 insertions(+), 11 deletions(-)

diff --git a/plugins/Actions/VisitorDetails.php b/plugins/Actions/VisitorDetails.php
index becb6cdaf7..1781593451 100644
--- a/plugins/Actions/VisitorDetails.php
+++ b/plugins/Actions/VisitorDetails.php
@@ -265,7 +265,14 @@ class VisitorDetails extends VisitorDetailsAbstract
     public function finalizeProfile($visits, &$profile)
     {
         arsort($this->visitedPageUrls);
-        $profile['visitedPages'] = $this->visitedPageUrls;
+        $profile['visitedPages'] = [];
+
+        foreach ($this->visitedPageUrls as $visitedPageUrl => $count) {
+            $profile['visitedPages'][] = [
+                'url' => $visitedPageUrl,
+                'count' => $count
+            ];
+        }
 
         $this->handleSiteSearches($profile);
         $this->handleAveragePageGenerationTime($profile);
diff --git a/plugins/Live/tests/System/expected/test___Live.getVisitorProfile.xml b/plugins/Live/tests/System/expected/test___Live.getVisitorProfile.xml
index 94b05f931a..878232f0c4 100644
--- a/plugins/Live/tests/System/expected/test___Live.getVisitorProfile.xml
+++ b/plugins/Live/tests/System/expected/test___Live.getVisitorProfile.xml
@@ -1192,10 +1192,22 @@
 	</lastVisit>
 	<visitsAggregated>10</visitsAggregated>
 	<visitedPages>
-		<row key="http://example.org/my/dir/page0">8</row>
-		<row key="http://example.org/my/dir/page1">8</row>
-		<row key="http://example.org/my/dir/page2">8</row>
-		<row key="http://example.org/my/dir/page3">7</row>
+		<row>
+			<url>http://example.org/my/dir/page0</url>
+			<count>8</count>
+		</row>
+		<row>
+			<url>http://example.org/my/dir/page1</url>
+			<count>8</count>
+		</row>
+		<row>
+			<url>http://example.org/my/dir/page2</url>
+			<count>8</count>
+		</row>
+		<row>
+			<url>http://example.org/my/dir/page3</url>
+			<count>7</count>
+		</row>
 	</visitedPages>
 	<devices>
 		<Unknown>
diff --git a/plugins/Live/tests/System/expected/test_higherLimit__Live.getVisitorProfile.xml b/plugins/Live/tests/System/expected/test_higherLimit__Live.getVisitorProfile.xml
index 481470e978..4071574fdc 100644
--- a/plugins/Live/tests/System/expected/test_higherLimit__Live.getVisitorProfile.xml
+++ b/plugins/Live/tests/System/expected/test_higherLimit__Live.getVisitorProfile.xml
@@ -2342,10 +2342,22 @@
 	</lastVisit>
 	<visitsAggregated>20</visitsAggregated>
 	<visitedPages>
-		<row key="http://example.org/my/dir/page0">8</row>
-		<row key="http://example.org/my/dir/page1">8</row>
-		<row key="http://example.org/my/dir/page2">8</row>
-		<row key="http://example.org/my/dir/page3">7</row>
+		<row>
+			<url>http://example.org/my/dir/page0</url>
+			<count>8</count>
+		</row>
+		<row>
+			<url>http://example.org/my/dir/page1</url>
+			<count>8</count>
+		</row>
+		<row>
+			<url>http://example.org/my/dir/page2</url>
+			<count>8</count>
+		</row>
+		<row>
+			<url>http://example.org/my/dir/page3</url>
+			<count>7</count>
+		</row>
 	</visitedPages>
 	<devices>
 		<Unknown>
diff --git a/tests/PHPUnit/System/expected/test_periodIsRange_dateIsLastN_MetadataAndNormalAPI__Live.getVisitorProfile.xml b/tests/PHPUnit/System/expected/test_periodIsRange_dateIsLastN_MetadataAndNormalAPI__Live.getVisitorProfile.xml
index 6f59d16f8f..7d19d39bce 100644
--- a/tests/PHPUnit/System/expected/test_periodIsRange_dateIsLastN_MetadataAndNormalAPI__Live.getVisitorProfile.xml
+++ b/tests/PHPUnit/System/expected/test_periodIsRange_dateIsLastN_MetadataAndNormalAPI__Live.getVisitorProfile.xml
@@ -303,7 +303,10 @@
 	</lastVisit>
 	<visitsAggregated>2</visitsAggregated>
 	<visitedPages>
-		<row key="http://example.org/homepage">1</row>
+		<row>
+			<url>http://example.org/homepage</url>
+			<count>1</count>
+		</row>
 	</visitedPages>
 	<devices>
 		<Desktop>
diff --git a/tests/PHPUnit/System/expected/test_periodIsRange_dateIsLastN_MetadataAndNormalAPI_pagesegment__Live.getVisitorProfile.xml b/tests/PHPUnit/System/expected/test_periodIsRange_dateIsLastN_MetadataAndNormalAPI_pagesegment__Live.getVisitorProfile.xml
index 6f59d16f8f..7d19d39bce 100644
--- a/tests/PHPUnit/System/expected/test_periodIsRange_dateIsLastN_MetadataAndNormalAPI_pagesegment__Live.getVisitorProfile.xml
+++ b/tests/PHPUnit/System/expected/test_periodIsRange_dateIsLastN_MetadataAndNormalAPI_pagesegment__Live.getVisitorProfile.xml
@@ -303,7 +303,10 @@
 	</lastVisit>
 	<visitsAggregated>2</visitsAggregated>
 	<visitedPages>
-		<row key="http://example.org/homepage">1</row>
+		<row>
+			<url>http://example.org/homepage</url>
+			<count>1</count>
+		</row>
 	</visitedPages>
 	<devices>
 		<Desktop>
-- 
GitLab