Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattpiwik <matthieu.aubry@gmail.com>2010-07-06 04:04:35 +0400
committermattpiwik <matthieu.aubry@gmail.com>2010-07-06 04:04:35 +0400
commit52ce332c866505448a73cf836282faa4e8b9b620 (patch)
tree988ac08696a12a63ad9bd0d1065845845866ffbd /plugins/ExampleAPI
parenta725cfd4eb3d7476017960f6ed1c75477a68b378 (diff)
Introducing documented piwik.php PHP Tracking client.
Also adding integration test suite in place. * Adding new mechanism to trigger known tracking requests, then call all API methods get* and compare XML to the previous 'expected' XML. * make sure overwritten config files are not read during tests. Use defaults from global.ini.php. * piwik.php Tracker allow calling script to force Datetime and user IP for a specific request. * Wrote 3 main tests * wrong tracking requests should not return error and should not record anything * standard one visitor, 2 visits, with page view, download, outlink and goal tracked * Added integration test as an example in the ExampleAPI plugin (pretty simple to add testing code) TODO * Finish PiwikTracker and show it in UI * Show how to use image based tracker in UI * Add more tests (multi periods and multi sites) in Main.test.php * Fix failing Config.test.php test (when ran via all_tests.php doesn't fail otherwise) git-svn-id: http://dev.piwik.org/svn/trunk@2429 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'plugins/ExampleAPI')
-rw-r--r--plugins/ExampleAPI/tests/Integration.test.php37
-rw-r--r--plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getAnswerToLife.xml2
-rw-r--r--plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getCompetitionDatatable.xml11
-rw-r--r--plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getDescriptionArray.xml7
-rw-r--r--plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getGoldenRatio.xml2
-rw-r--r--plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getMoreInformationAnswerToLife.xml2
-rw-r--r--plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getNull.xml4
-rw-r--r--plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getObject.xml4
-rw-r--r--plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.xml2
9 files changed, 71 insertions, 0 deletions
diff --git a/plugins/ExampleAPI/tests/Integration.test.php b/plugins/ExampleAPI/tests/Integration.test.php
new file mode 100644
index 0000000000..ba71996848
--- /dev/null
+++ b/plugins/ExampleAPI/tests/Integration.test.php
@@ -0,0 +1,37 @@
+<?php
+if(!defined("PIWIK_PATH_TEST_TO_ROOT")) {
+ define('PIWIK_PATH_TEST_TO_ROOT', getcwd().'/../../..');
+}
+if(!defined('PIWIK_CONFIG_TEST_INCLUDED'))
+{
+ require_once PIWIK_PATH_TEST_TO_ROOT . "/tests/config_test.php";
+}
+
+require_once PIWIK_INCLUDE_PATH . '/tests/integration/Integration.php';
+
+/**
+ * This test is a simple example of how to use the Integration test Base class
+ * in order to easily build an integration test of a given plugin.
+ *
+ * You can for example easily generate Tracking pages and visits, and then query all API
+ * to compare the output XML.
+ *
+ * Check out this example and more in tests/integration/*
+ */
+class Test_Piwik_Integration_ExampleAPI extends Test_Integration
+{
+ public function getPathToTestDirectory()
+ {
+ return PIWIK_INCLUDE_PATH . '/plugins/ExampleAPI/tests';
+ }
+
+ function test_allGetMethods()
+ {
+ // Executes all API methods get* and check for output
+ // In this plugin, output is static and manually set in the API.php, but in other scripts,
+ // one could generate fake inputs, and check that ouputs are processed as expected
+ // @see tests/integration/ for more info
+ $this->setApiToCall( 'ExampleAPI' );
+ $this->callGetApiCompareOutput(__FUNCTION__);
+ }
+} \ No newline at end of file
diff --git a/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getAnswerToLife.xml b/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getAnswerToLife.xml
new file mode 100644
index 0000000000..36a787c47a
--- /dev/null
+++ b/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getAnswerToLife.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>42</result> \ No newline at end of file
diff --git a/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getCompetitionDatatable.xml b/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getCompetitionDatatable.xml
new file mode 100644
index 0000000000..b3f152f190
--- /dev/null
+++ b/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getCompetitionDatatable.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>
+ <row>
+ <name>piwik</name>
+ <license>GPL</license>
+ </row>
+ <row>
+ <name>google analytics</name>
+ <license>commercial</license>
+ </row>
+</result> \ No newline at end of file
diff --git a/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getDescriptionArray.xml b/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getDescriptionArray.xml
new file mode 100644
index 0000000000..1714bdf97a
--- /dev/null
+++ b/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getDescriptionArray.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>
+ <row>piwik</row>
+ <row>open source</row>
+ <row>web analytics</row>
+ <row>free</row>
+</result> \ No newline at end of file
diff --git a/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getGoldenRatio.xml b/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getGoldenRatio.xml
new file mode 100644
index 0000000000..f74b9ec866
--- /dev/null
+++ b/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getGoldenRatio.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>1.61803398875</result> \ No newline at end of file
diff --git a/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getMoreInformationAnswerToLife.xml b/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getMoreInformationAnswerToLife.xml
new file mode 100644
index 0000000000..a8ddf5e69d
--- /dev/null
+++ b/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getMoreInformationAnswerToLife.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>Check http://en.wikipedia.org/wiki/The_Answer_to_Life,_the_Universe,_and_Everything</result> \ No newline at end of file
diff --git a/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getNull.xml b/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getNull.xml
new file mode 100644
index 0000000000..ef26c9f568
--- /dev/null
+++ b/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getNull.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>
+ <success message="ok" />
+</result> \ No newline at end of file
diff --git a/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getObject.xml b/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getObject.xml
new file mode 100644
index 0000000000..2b669038e1
--- /dev/null
+++ b/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getObject.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>
+ <error message="The API cannot handle this data structure." />
+</result> \ No newline at end of file
diff --git a/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.xml b/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.xml
new file mode 100644
index 0000000000..85e137e912
--- /dev/null
+++ b/plugins/ExampleAPI/tests/expected/test_allGetMethods__ExampleAPI.getPiwikVersion.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>0.6.3</result> \ No newline at end of file