diff --git a/plugins/ExampleAPI/tests/Integration.test.php b/plugins/ExampleAPI/tests/Integration.test.php index 2fa76ffaabc2c45a8df6aea1b5131830e107ca67..ca84de256236d6bdece535d622013c9d737bc89a 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 Binary files a/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.csv and /dev/null differ 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 d0a9a2e2522bfe6bd2c416c7a7a50d208554bdf1..0000000000000000000000000000000000000000 --- 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 cb1de4ec3a10a86f8dbc1f07c0df42c86da8e31e..0000000000000000000000000000000000000000 --- 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 a0a15177f39314e2c4a95e4982f4dc0bf2f757a8..0000000000000000000000000000000000000000 --- 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 384d7c1b0eb25970fd49844f162fb905217cd2d8..0000000000000000000000000000000000000000 --- 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 Binary files a/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.tsv and /dev/null differ 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 85e137e9124e0f56f1431d8220a9e954960be78b..0000000000000000000000000000000000000000 --- 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 b14e0dd3e135ee9e763a36ff542cab273fbcc8b9..b16c1a54033d60f2e3987e60e52884e6e676f1df 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 794784a60dbd3cd28673564ec48f7cc93cf1b1e4..8ea25b5bbb77c657a6d6e071f8f732c0b49abe67 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;