From f8529971234edf4c2e92f6297bea8a6684c01519 Mon Sep 17 00:00:00 2001
From: mattpiwik <matthieu.aubry@gmail.com>
Date: Mon, 12 Jul 2010 07:00:19 +0000
Subject: [PATCH] Refs #1446 Refs #818  * Fixing unit tests on local box by
 ignoring ExampleAPI.getPiwikVersion which would fail at every new version

Note: on my box, when I run all_tests.php, I don't see the green bar at the bottom of the page anymore. It simply displays the Time and Memory delta. I didn't see any commit that coudl have broken this so I'm a bit confused as to why the green/red bar doesn't display anymore?

git-svn-id: http://dev.piwik.org/svn/trunk@2472 59fd770c-687e-43c8-a1e3-f5a4ff64c105
---
 plugins/ExampleAPI/tests/Integration.test.php |   2 +
 ...GetMethods__ExampleAPI.getPiwikVersion.csv | Bin 24 -> 0 bytes
 ...etMethods__ExampleAPI.getPiwikVersion.html |  12 ----
 ...etMethods__ExampleAPI.getPiwikVersion.json |   1 -
 ...thods__ExampleAPI.getPiwikVersion.original |   1 -
 ...GetMethods__ExampleAPI.getPiwikVersion.php |   1 -
 ...GetMethods__ExampleAPI.getPiwikVersion.tsv | Bin 24 -> 0 bytes
 ...GetMethods__ExampleAPI.getPiwikVersion.xml |   2 -
 tests/README.txt                              |  43 +++++++-----
 tests/integration/Integration.php             |  62 +++++++++++-------
 10 files changed, 66 insertions(+), 58 deletions(-)
 delete mode 100644 plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.csv
 delete mode 100644 plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.html
 delete mode 100644 plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.json
 delete mode 100644 plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.original
 delete mode 100644 plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.php
 delete mode 100644 plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.tsv
 delete mode 100644 plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.xml

diff --git a/plugins/ExampleAPI/tests/Integration.test.php b/plugins/ExampleAPI/tests/Integration.test.php
index 2fa76ffaab..ca84de2562 100644
--- a/plugins/ExampleAPI/tests/Integration.test.php
+++ b/plugins/ExampleAPI/tests/Integration.test.php
@@ -32,6 +32,8 @@ class Test_Piwik_Integration_ExampleAPI extends Test_Integration
 		// one could generate fake inputs, and check that ouputs are processed as expected
 		// @see tests/integration/ for more info
 		$this->setApiToCall( 'ExampleAPI' );
+		// Ignore the getPiwikVersion call which would otherwise fail at every new release
+		$this->setApiNotToCall( 'ExampleAPI.getPiwikVersion');
 		$renderers = Piwik_DataTable_Renderer::getRenderers();
         $this->callGetApiCompareOutput(__FUNCTION__, $renderers);
 	}
diff --git a/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.csv b/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.csv
deleted file mode 100644
index f538888e84ba4f20ec1416e9f4bd40780b361ce2..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 24
fcmezWuZ$s)A%~%qA(erP!GJ-J!HhwV!I%L6TOtJ-

diff --git a/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.html b/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.html
deleted file mode 100644
index d0a9a2e252..0000000000
--- a/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.html
+++ /dev/null
@@ -1,12 +0,0 @@
-<table id="ExampleAPI_getPiwikVersion" border="1">
-<thead>
-	<tr>
-		<th>value</th>
-	</tr>
-</thead>
-<tbody>
-	<tr>
-		<td>0.6.3</td>
-	</tr>
-</tbody>
-</table>
diff --git a/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.json b/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.json
deleted file mode 100644
index cb1de4ec3a..0000000000
--- a/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.json
+++ /dev/null
@@ -1 +0,0 @@
-{"value":"0.6.3"}
\ No newline at end of file
diff --git a/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.original b/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.original
deleted file mode 100644
index a0a15177f3..0000000000
--- a/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.original
+++ /dev/null
@@ -1 +0,0 @@
-0.6.3
\ No newline at end of file
diff --git a/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.php b/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.php
deleted file mode 100644
index 384d7c1b0e..0000000000
--- a/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.php
+++ /dev/null
@@ -1 +0,0 @@
-s:5:"0.6.3";
\ No newline at end of file
diff --git a/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.tsv b/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.tsv
deleted file mode 100644
index f538888e84ba4f20ec1416e9f4bd40780b361ce2..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 24
fcmezWuZ$s)A%~%qA(erP!GJ-J!HhwV!I%L6TOtJ-

diff --git a/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.xml b/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.xml
deleted file mode 100644
index 85e137e912..0000000000
--- a/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.xml
+++ /dev/null
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<result>0.6.3</result>
\ No newline at end of file
diff --git a/tests/README.txt b/tests/README.txt
index b14e0dd3e1..b16c1a5403 100644
--- a/tests/README.txt
+++ b/tests/README.txt
@@ -1,29 +1,33 @@
- RUN TESTS
-==========
-You can run all tests 
-http://dev.piwik.org/svn/trunk/tests/all_tests.php
-
-You can run one test file at a time by going to the test file directly 
+Piwik comes with unit tests, integration tests, Javascript tests and Webtests.
+This document briefly describes how to use and modify Piwik tests. 
+ 
+ HOW TO RUN PIWIK TESTS
+=======================
+You can run all tests by calling the file tests/all_tests.php
+The file will run all unit tests and integration tests.
+
+You can also run one test file at a time by executing the test file directly eg. 
 http://dev.piwik.org/svn/trunk/tests/core/DataTable.test.php
 
- CONTINOUS INTEGRATION
-======================
-We currently use continuous integration build server, located at:
-http://bamboo.openx.org:8085/browse/PIWIK-TRUNK/
-
  UNIT TESTs
 ===========
 Piwik tests use the Simpletest Unit Testing framework.
-
 Piwik unit tests suite can be found in the Piwik SVN: 
 http://dev.piwik.org/svn/trunk/tests/
 
+Plugins can also integrate unit tests, in a tests/ directory inside the plugin folder.
+Check for example plugins/SitesManager/tests/ or plugins/UserCountry/tests/
+
  INTEGRATION TESTS
 ==================
-Located in tests/integration/. They generate hits to the Tracker (record visits and page views)
-and then test all API responses and for each API output, check that they match expected XML.
+Integration tests allow to test how major Piwik components interact together.
+A test will typically generate hits to the Tracker (record visits and page views)
+and then test all API responses and for each API output. It then checks that they match expected XML.
 You can then use Text Compare softwares (eg. WinMerge on Win) to easily view changes.
 
+The main test is located tests/integration/Main.test.php
+See also http://dev.piwik.org/trac/ticket/1465   
+
  JAVASCRIPT TESTS
 =================
 piwik.js is unit tested and you can run tests in piwik/tests/javascript/
@@ -33,6 +37,13 @@ piwik.js is unit tested and you can run tests in piwik/tests/javascript/
 The Installation process is also webtested. They are ran by the continuous integration server.
 http://dev.piwik.org/svn/trunk/tests/webtest/testcases/level0/
 
-If you want to help, we are always looking to improve the Piwik code coverage!  
+ CONTINOUS INTEGRATION
+======================
+We currently use continuous integration build server, located at:
+http://bamboo.openx.org:8085/browse/PIWIK-TRUNK/
+
+ PARTICIPATE
+============
+You can help by improving existing tests, or identify some missing tests and implement them.
+See http://dev.piwik.org/trac/wiki/PiwikDevelopmentProcess#Howtosubmitapatch
 Please contact us at hello@piwik.org
- 
\ No newline at end of file
diff --git a/tests/integration/Integration.php b/tests/integration/Integration.php
index 794784a60d..8ea25b5bbb 100644
--- a/tests/integration/Integration.php
+++ b/tests/integration/Integration.php
@@ -94,14 +94,41 @@ abstract class Test_Integration extends Test_Database
 		{
 			$apiToCall = array($apiToCall);
 		}
-		$this->apiToCall= $apiToCall;
+		$this->apiToCall = $apiToCall;
+	}
+	
+	/**
+	 * Sets a list of API methods to not call during the test
+	 * @param $apiNotToCall eg. 'ExampleAPI.getPiwikVersion'
+	 * @return void
+	 */
+	protected function setApiNotToCall( $apiNotToCall )
+	{
+		if(!is_array($apiNotToCall))
+		{
+			$apiNotToCall = array($apiNotToCall);
+		}
+		$this->apiNotToCall = $apiNotToCall;
 	}
 	
 	protected $apiToCall = array();
 	
-	/*
+	// List of Modules, or Module.Method that should not be called as part of the XML output compare
+	// Usually these modules either return random changing data, or are already tested in specific unit tests. 
+	protected $apiNotToCall = array(
+			'LanguagesManager',
+			'DBStats',
+			'UsersManager',
+			'SitesManager',
+			'ExampleUI',
+			'Live',
+			'SEO',
+			'ExampleAPI',
+		);
+	
+	/**
 	 * Checks that the response is a GIF image as expected.
-	 * 
+	 * @return Will fail the test if the response is not the expected GIF
 	 */
 	protected function checkResponse($response)
 	{
@@ -183,19 +210,6 @@ abstract class Test_Integration extends Test_Database
 	 */ 
 	protected function generateUrlsApi( $parametersToSet, $formats, $periods, $setDateLastN = false )
 	{
-		// List of Modules, or Module.Method that should not be called as part of the XML output compare
-		// Usually these modules either return random changing data, or are already tester in specific unit tests. 
-		// Live! should also be tested and its API finalized. 
-		$apiNotToTest = array(
-			'LanguagesManager',
-			'DBStats',
-			'UsersManager',
-			'SitesManager',
-			'ExampleUI',
-			'Live',
-			'SEO',
-			'ExampleAPI',
-		);
 		
 		// Get the URLs to query against the API for all functions starting with get*
 		$skipped = $requestUrls = array();
@@ -208,19 +222,17 @@ abstract class Test_Integration extends Test_Database
     			$apiId = $moduleName.'.'.$methodName;
     			
     			// If Api to test were set, we only test these
-    			if(!empty($this->apiToCall))
+    			if(!empty($this->apiToCall)
+    				&& in_array($moduleName, $this->apiToCall) === false
+    				&& in_array($apiId, $this->apiToCall) === false)
     			{
-        			if(in_array($moduleName, $this->apiToCall) === false
-        				&& in_array($apiId, $this->apiToCall) === false)
-        			{
-        				$skipped[] = $apiId;
-        				continue;
-    				}
+    				$skipped[] = $apiId;
+    				continue;
     			}
     			// Excluded modules from test
     			elseif(strpos($methodName, 'get') !== 0
-    				|| in_array($moduleName, $apiNotToTest) === true
-    				|| in_array($apiId, $apiNotToTest) === true)
+    				|| in_array($moduleName, $this->apiNotToCall) === true
+    				|| in_array($apiId, $this->apiNotToCall) === true)
     			{
     				$skipped[] = $apiId;
     				continue;
-- 
GitLab