diff options
author | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2010-06-23 07:45:36 +0400 |
---|---|---|
committer | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2010-06-23 07:45:36 +0400 |
commit | 7e1b5d6b762340cbff1bb928d15815980c7649a7 (patch) | |
tree | e07da179b9e1372866d2349777bd1cc6b4c9e8cf /tests/core/Tracker/Action.test.php | |
parent | 999f46479294713104c962bfe7469e9b6e7a4bbf (diff) | |
parent | c98ea06f2cccec81c6ccce49162a583494e44d91 (diff) |
Diffstat (limited to 'tests/core/Tracker/Action.test.php')
-rw-r--r-- | tests/core/Tracker/Action.test.php | 131 |
1 files changed, 125 insertions, 6 deletions
diff --git a/tests/core/Tracker/Action.test.php b/tests/core/Tracker/Action.test.php index 2cc1fba216..bc2492d6b3 100644 --- a/tests/core/Tracker/Action.test.php +++ b/tests/core/Tracker/Action.test.php @@ -9,14 +9,133 @@ if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) require_once 'Tracker/Action.php'; require_once 'Tracker/Config.php'; -class Test_Piwik_TrackerAction extends UnitTestCase +require_once "Database.test.php"; + +class Test_Piwik_TrackerAction extends Test_Database { + function setUp() + { + $GLOBALS['PIWIK_TRACKER_MODE'] = true; + parent::setUp(); + $userFile = PIWIK_PATH_TEST_TO_ROOT . '/tests/resources/Tracker/Action.config.ini.php'; + $config = Piwik_Tracker_Config::getInstance(); + $config->init($userFile); + } + + function tearDown() + { + $GLOBALS['PIWIK_TRACKER_MODE'] = false; + } + + protected function setUpRootAccess() + { + $pseudoMockAccess = new FakeAccess; + FakeAccess::$superUser = true; + Zend_Registry::set('access', $pseudoMockAccess); + } + + protected function getTestUrls() + { + $urls = array( + // a wrongly formatted url (parse_url returns false) + 'http:////wrongurl', + + // a URL with all components + 'http://username:password@hostname:80/path?phpSESSID=value#anchor', + + // a standard url + 'http://a.com/index?p1=v1', + + // testing with capital parameter + 'http://a.com/index?p1=v1&P2=v2&p3=v3', + + // testing with extra && + 'http://a.com/index?p1=v1&&p2=v2&p3=v3&p4=v4&&', + ); + + return $urls; + } + + /* + * No excluded query parameters specified, appart from the standard "session" parameters, always excluded + */ + function test_excludeQueryParameters_none() + { + $excludedQueryParameters = ''; + $this->setUpRootAccess(); + $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1",array('http://example.org'), $excludedIps = '', $excludedQueryParameters); + $urls = $this->getTestUrls(); + foreach($urls as $url) + { + $expectedUrl = $url; + if($url=='http://username:password@hostname:80/path?phpSESSID=value#anchor') + { + $expectedUrl = 'http://username:password@hostname:80/path#anchor'; + } + + // the extra & are automatically cleaned up + if($url=='http://a.com/index?p1=v1&&p2=v2&p3=v3&p4=v4&&') + { + $expectedUrl = 'http://a.com/index?p1=v1&p2=v2&p3=v3&p4=v4'; + } + $this->assertEqual($expectedUrl, Piwik_Tracker_Action::excludeQueryParametersFromUrl($url, $idsite)); + } + } + + /* + * Testing with some website specific parameters excluded + */ + function test_excludeQueryParameters_siteExcluded() + { + $excludedQueryParameters = 'p4, p2'; + $expectedUrls = array( + 'http:////wrongurl', + 'http://username:password@hostname:80/path#anchor', + 'http://a.com/index?p1=v1', + 'http://a.com/index?p1=v1&p3=v3', + 'http://a.com/index?p1=v1&p3=v3', + ); + $this->setUpRootAccess(); + $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1",array('http://example.org'), $excludedIps = '', $excludedQueryParameters); + $urls = $this->getTestUrls(); + $filteredUrls = array(); + foreach($urls as $url) + { + $filteredUrls[] = Piwik_Tracker_Action::excludeQueryParametersFromUrl($url, $idsite); + } + $this->assertEqual($expectedUrls, $filteredUrls); + } + + /* + * Testing with some website specific and some global excluded query parameters + */ + function test_excludeQueryParameters_siteAndGlobalExcluded() + { + // testing also that query parameters are case insensitive + $excludedQueryParameters = 'P2'; + $excludedGlobalParameters = 'blabla, P4'; + $expectedUrls = array( + 'http:////wrongurl', + 'http://username:password@hostname:80/path#anchor', + 'http://a.com/index?p1=v1', + 'http://a.com/index?p1=v1&p3=v3', + 'http://a.com/index?p1=v1&p3=v3', + ); + $this->setUpRootAccess(); + $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1",array('http://example.org'), $excludedIps = '', $excludedQueryParameters); + Piwik_SitesManager_API::getInstance()->setGlobalExcludedQueryParameters($excludedGlobalParameters); + $urls = $this->getTestUrls(); + $filteredUrls = array(); + foreach($urls as $url) + { + $filteredUrls[] = Piwik_Tracker_Action::excludeQueryParametersFromUrl($url, $idsite); + } + $this->assertEqual($expectedUrls, $filteredUrls); + } + + function test_extractUrlAndActionNameFromRequest() { - $userFile = PIWIK_PATH_TEST_TO_ROOT . '/tests/resources/Tracker/Action.config.ini.php'; - $config = Piwik_Tracker_Config::getInstance(); - $config->init($userFile); - $action = new Test_Piwik_TrackerAction_extractUrlAndActionNameFromRequest(); $tests = array( @@ -103,7 +222,7 @@ class Test_Piwik_TrackerAction extends UnitTestCase // empty request array( 'request' => array(), - 'expected' => array( 'name' => null, 'url' => '/', + 'expected' => array( 'name' => null, 'url' => '', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL), ), array( |