From 6d2ec4c3542b97866160bee6e4998a21a93ddfbf Mon Sep 17 00:00:00 2001
From: BeezyT <timo@ezdesign.de>
Date: Sat, 4 Feb 2012 19:58:19 +0000
Subject: [PATCH] refs #534 integration tests for label filter

git-svn-id: http://dev.piwik.org/svn/trunk@5759 59fd770c-687e-43c8-a1e3-f5a4ff64c105
---
 core/API/DocumentationGenerator.php           |  1 +
 tests/integration/Integration.php             |  2 +-
 tests/integration/LabelFilter.test.php        | 87 +++++++++++++++++++
 ...ir2subfilephp__Actions.getPageUrls_day.xml | 16 ++++
 ...belFilter_dir__Actions.getPageUrls_day.xml | 12 +++
 ...foobarfoo2bar__Actions.getPageUrls_day.xml | 14 +++
 ...irnonExistent__Actions.getPageUrls_day.xml |  2 +
 ...r_nonExistent__Actions.getPageUrls_day.xml |  2 +
 ...er_thisiscool__Actions.getPageUrls_day.xml | 19 ++++
 9 files changed, 154 insertions(+), 1 deletion(-)
 create mode 100644 tests/integration/LabelFilter.test.php
 create mode 100644 tests/integration/expected/test_LabelFilter_dir2subfilephp__Actions.getPageUrls_day.xml
 create mode 100644 tests/integration/expected/test_LabelFilter_dir__Actions.getPageUrls_day.xml
 create mode 100644 tests/integration/expected/test_LabelFilter_dirfilephpfoobarfoo2bar__Actions.getPageUrls_day.xml
 create mode 100644 tests/integration/expected/test_LabelFilter_dirnonExistent__Actions.getPageUrls_day.xml
 create mode 100644 tests/integration/expected/test_LabelFilter_nonExistent__Actions.getPageUrls_day.xml
 create mode 100644 tests/integration/expected/test_LabelFilter_thisiscool__Actions.getPageUrls_day.xml

diff --git a/core/API/DocumentationGenerator.php b/core/API/DocumentationGenerator.php
index f9b17bde6e..e15ecb1899 100644
--- a/core/API/DocumentationGenerator.php
+++ b/core/API/DocumentationGenerator.php
@@ -182,6 +182,7 @@ class Piwik_API_DocumentationGenerator
 		$aParameters['language'] = false;
 		$aParameters['includeInnerNodes'] = false;
 		$aParameters['translateColumnNames'] = false;
+        $aParameters['label'] = false;
 		
 		$moduleName = Piwik_API_Proxy::getInstance()->getModuleNameFromClassName($class);
 		$urlExample = '?module=API&method='.$moduleName.'.'.$methodName.'&';
diff --git a/tests/integration/Integration.php b/tests/integration/Integration.php
index 69f61750e0..91e05be75d 100644
--- a/tests/integration/Integration.php
+++ b/tests/integration/Integration.php
@@ -1059,7 +1059,7 @@ abstract class Test_Integration_Facade extends Test_Integration
 	abstract public function getApiToTest();
 	
 	/**
-	 * Returns an array descriging the Controller actions to call & compare
+	 * Returns an array describing the Controller actions to call & compare
 	 * with expected output.
 	 * 
 	 * The returned array must be of the following format:
diff --git a/tests/integration/LabelFilter.test.php b/tests/integration/LabelFilter.test.php
new file mode 100644
index 0000000000..18431aac13
--- /dev/null
+++ b/tests/integration/LabelFilter.test.php
@@ -0,0 +1,87 @@
+<?php
+if(!defined('PIWIK_CONFIG_TEST_INCLUDED'))
+{
+	require_once dirname(__FILE__)."/../../tests/config_test.php";
+}
+
+require_once PIWIK_INCLUDE_PATH . '/tests/integration/Integration.php';
+
+/**
+ * Tests the class Piwik_API_DataTableLabelFilter.
+ * This is not possible as unit test, since it loads data from the API.
+ */
+class Test_Piwik_Integration_LabelFilter extends Test_Integration_Facade
+{
+	protected $dateTime = '2010-03-06 11:22:33';
+	protected $idSite = null;
+
+	public function getApiToTest()
+	{
+        $labelsToTest = array(
+            // first level
+            'nonExistent', 'dir', '/this is cool!',
+            // second level
+            'dir->>-nonExistent', 'dir->>-/file.php?foo=bar&foo2=bar',
+            // third level
+            'dir2->>-sub->>-/file.php'
+        );
+        
+        $return = array();
+        foreach ($labelsToTest as $label) {
+            $return[] = array('Actions.getPageUrls', array(
+                'testSuffix' => '_'.preg_replace('/[^a-z0-9]*/mi', '', $label),
+                'idSite' => $this->idSite,
+                'date' => $this->dateTime,
+                'otherRequestParameters' => array(
+                    'label' => urlencode($label),
+                    'expanded' => 0
+                )
+            ));
+        }
+        
+		return $return;
+	}
+    
+	public function getControllerActionsToTest()
+	{
+		return array();
+	}
+	
+	public function getOutputPrefix()
+	{
+		return 'LabelFilter';
+	}
+	
+	public function setUp()
+	{
+		parent::setUp();
+		$this->idSite = $this->createWebsite($this->dateTime);
+	}
+
+	protected function trackVisits()
+	{
+		$dateTime = $this->dateTime;
+    	$idSite = $this->idSite;
+        $t = $this->getTracker($idSite, $dateTime, $defaultInit = true, $useThirdPartyCookie = 1);
+        
+        $t->setUrl('http://example.org/this%20is%20cool!');
+        $this->checkResponse($t->doTrackPageView('incredible title!'));
+        
+        $t->setUrl('http://example.org/dir/file.php?foo=bar&foo2=bar');
+        $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.2)->getDatetime());
+        $this->checkResponse($t->doTrackPageView('incredible title!'));
+        
+        $t->setUrl('http://example.org/dir/file.php?foo=bar&foo2=bar2');
+        $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime());
+        $this->checkResponse($t->doTrackPageView('incredible title!'));
+        
+        $t->setUrl('http://example.org/dir2/file.php?foo=bar&foo2=bar');
+        $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.4)->getDatetime());
+        $this->checkResponse($t->doTrackPageView('incredible title!'));
+        
+        $t->setUrl('http://example.org/dir2/sub/file.php');
+        $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.4)->getDatetime());
+        $this->checkResponse($t->doTrackPageView('incredible title!'));
+	}
+}
+
diff --git a/tests/integration/expected/test_LabelFilter_dir2subfilephp__Actions.getPageUrls_day.xml b/tests/integration/expected/test_LabelFilter_dir2subfilephp__Actions.getPageUrls_day.xml
new file mode 100644
index 0000000000..2e0cf6314d
--- /dev/null
+++ b/tests/integration/expected/test_LabelFilter_dir2subfilephp__Actions.getPageUrls_day.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>
+	<row>
+		<label>/file.php</label>
+		<nb_visits>1</nb_visits>
+		<nb_uniq_visitors>1</nb_uniq_visitors>
+		<nb_hits>1</nb_hits>
+		<sum_time_spent>0</sum_time_spent>
+		<exit_nb_uniq_visitors>1</exit_nb_uniq_visitors>
+		<exit_nb_visits>1</exit_nb_visits>
+		<avg_time_on_page>0</avg_time_on_page>
+		<bounce_rate>0%</bounce_rate>
+		<exit_rate>100%</exit_rate>
+		<url>http://example.org/dir2/sub/file.php</url>
+	</row>
+</result>
\ No newline at end of file
diff --git a/tests/integration/expected/test_LabelFilter_dir__Actions.getPageUrls_day.xml b/tests/integration/expected/test_LabelFilter_dir__Actions.getPageUrls_day.xml
new file mode 100644
index 0000000000..422a0bbd16
--- /dev/null
+++ b/tests/integration/expected/test_LabelFilter_dir__Actions.getPageUrls_day.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>
+	<row>
+		<label>dir</label>
+		<nb_visits>2</nb_visits>
+		<nb_hits>2</nb_hits>
+		<sum_time_spent>720</sum_time_spent>
+		<avg_time_on_page>360</avg_time_on_page>
+		<bounce_rate>0%</bounce_rate>
+		<exit_rate>0%</exit_rate>
+	</row>
+</result>
\ No newline at end of file
diff --git a/tests/integration/expected/test_LabelFilter_dirfilephpfoobarfoo2bar__Actions.getPageUrls_day.xml b/tests/integration/expected/test_LabelFilter_dirfilephpfoobarfoo2bar__Actions.getPageUrls_day.xml
new file mode 100644
index 0000000000..2a1a262fa1
--- /dev/null
+++ b/tests/integration/expected/test_LabelFilter_dirfilephpfoobarfoo2bar__Actions.getPageUrls_day.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>
+	<row>
+		<label>/file.php?foo=bar&amp;foo2=bar</label>
+		<nb_visits>1</nb_visits>
+		<nb_uniq_visitors>1</nb_uniq_visitors>
+		<nb_hits>1</nb_hits>
+		<sum_time_spent>360</sum_time_spent>
+		<avg_time_on_page>360</avg_time_on_page>
+		<bounce_rate>0%</bounce_rate>
+		<exit_rate>0%</exit_rate>
+		<url>http://example.org/dir/file.php?foo=bar&amp;foo2=bar</url>
+	</row>
+</result>
\ No newline at end of file
diff --git a/tests/integration/expected/test_LabelFilter_dirnonExistent__Actions.getPageUrls_day.xml b/tests/integration/expected/test_LabelFilter_dirnonExistent__Actions.getPageUrls_day.xml
new file mode 100644
index 0000000000..c234bed59e
--- /dev/null
+++ b/tests/integration/expected/test_LabelFilter_dirnonExistent__Actions.getPageUrls_day.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result />
\ No newline at end of file
diff --git a/tests/integration/expected/test_LabelFilter_nonExistent__Actions.getPageUrls_day.xml b/tests/integration/expected/test_LabelFilter_nonExistent__Actions.getPageUrls_day.xml
new file mode 100644
index 0000000000..c234bed59e
--- /dev/null
+++ b/tests/integration/expected/test_LabelFilter_nonExistent__Actions.getPageUrls_day.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result />
\ No newline at end of file
diff --git a/tests/integration/expected/test_LabelFilter_thisiscool__Actions.getPageUrls_day.xml b/tests/integration/expected/test_LabelFilter_thisiscool__Actions.getPageUrls_day.xml
new file mode 100644
index 0000000000..de3f93dcc9
--- /dev/null
+++ b/tests/integration/expected/test_LabelFilter_thisiscool__Actions.getPageUrls_day.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>
+	<row>
+		<label>/this is cool!</label>
+		<nb_visits>1</nb_visits>
+		<nb_uniq_visitors>1</nb_uniq_visitors>
+		<nb_hits>1</nb_hits>
+		<sum_time_spent>720</sum_time_spent>
+		<entry_nb_uniq_visitors>1</entry_nb_uniq_visitors>
+		<entry_nb_visits>1</entry_nb_visits>
+		<entry_nb_actions>5</entry_nb_actions>
+		<entry_sum_visit_length>1441</entry_sum_visit_length>
+		<entry_bounce_count>0</entry_bounce_count>
+		<avg_time_on_page>720</avg_time_on_page>
+		<bounce_rate>0%</bounce_rate>
+		<exit_rate>0%</exit_rate>
+		<url>http://example.org/this%20is%20cool!</url>
+	</row>
+</result>
\ No newline at end of file
-- 
GitLab