diff options
author | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2009-10-23 02:40:18 +0400 |
---|---|---|
committer | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2009-10-23 02:40:18 +0400 |
commit | 851b2e22b2fc004c4e006abfb84d267d9bfe0b29 (patch) | |
tree | 989989fe4794e0162410fe7d1c933bad41f83f09 /plugins/Actions | |
parent | 013711875021fb0b585c86e4b1404132f34cf437 (diff) |
- Fixes #708 kudos to Maciej for his work on this one, and Anthon & Matt for the review.
Changes from Maciej's patch:
-- the old Actions stats are displayed in the Page titles section, ensure BC when users were specifying page titles, they would appear in the same report. The api Actions.getActions (now deprecated) is a proxy to Actions.getPageTitles)
-- applied schema change to log_conversion
-- empty action names and empty URLs are now accepted at tracking time. They will be replaced at archiving time by the strings defined in the config file.
- API: if a method has a comment @deprecated, it won't be shown in the API listing page (used for the now deprecated Actions.getActions() API call)
- Fixes #693 Visits generator now asks for user confirmation before inserting fake data in the DB
TODO:
- apply small modifs to the JS tracker (setCustomUrl() and action_name defaulting to document.title)
- improve/fix unit tests around the expected behavior of Action naming
Diffstat (limited to 'plugins/Actions')
-rw-r--r-- | plugins/Actions/API.php | 19 | ||||
-rw-r--r-- | plugins/Actions/Actions.php | 167 | ||||
-rw-r--r-- | plugins/Actions/Controller.php | 54 | ||||
-rw-r--r-- | plugins/Actions/tests/Actions.test.php | 92 |
4 files changed, 275 insertions, 57 deletions
diff --git a/plugins/Actions/API.php b/plugins/Actions/API.php index 8a9851cf30..658d5da13f 100644 --- a/plugins/Actions/API.php +++ b/plugins/Actions/API.php @@ -50,10 +50,25 @@ class Piwik_Actions_API $dataTable->queueFilter('ReplaceSummaryRowLabel'); return $dataTable; } - + + /** + * Backward compatibility. Fallsback to getPageTitles() instead. + * @deprecated Deprecated since Piwik 0.5 + */ public function getActions( $idSite, $period, $date, $expanded = false, $idSubtable = false ) { - return $this->getDataTable('Actions_actions', $idSite, $period, $date, $expanded, $idSubtable ); + return $this->getPageTitles( $idSite, $period, $date, $expanded, $idSubtable ); + } + + public function getPageUrls( $idSite, $period, $date, $expanded = false, $idSubtable = false ) + { + return $this->getDataTable('Actions_actions_url', $idSite, $period, $date, $expanded, $idSubtable ); + } + + public function getPageTitles( $idSite, $period, $date, $expanded = false, $idSubtable = false) + { + $dataTable = $this->getDataTable('Actions_actions', $idSite, $period, $date, $expanded, $idSubtable); + return $dataTable; } public function getDownloads( $idSite, $period, $date, $expanded = false, $idSubtable = false ) diff --git a/plugins/Actions/Actions.php b/plugins/Actions/Actions.php index 1fc9d2c19e..199726675a 100644 --- a/plugins/Actions/Actions.php +++ b/plugins/Actions/Actions.php @@ -20,6 +20,9 @@ class Piwik_Actions extends Piwik_Plugin { static protected $actionCategoryDelimiter = null; + static protected $defaultActionName = null; + static protected $defaultActionNameWhenNotDefined = null; + static protected $defaultActionUrlWhenNotDefined = null; static protected $limitLevelSubCategory = 10; // must be less than Piwik_DataTable::MAXIMUM_DEPTH_LEVEL_ALLOWED protected $maximumRowsInDataTableLevelZero; protected $maximumRowsInSubDataTable; @@ -47,9 +50,13 @@ class Piwik_Actions extends Piwik_Plugin ); return $hooks; } + public function __construct() { self::$actionCategoryDelimiter = Zend_Registry::get('config')->General->action_category_delimiter; + self::$defaultActionName = Zend_Registry::get('config')->General->action_default_name; + self::$defaultActionNameWhenNotDefined = Zend_Registry::get('config')->General->action_default_name_when_not_defined; + self::$defaultActionUrlWhenNotDefined = Zend_Registry::get('config')->General->action_default_url_when_not_defined; $this->columnToSortByBeforeTruncation = 'nb_visits'; $this->maximumRowsInDataTableLevelZero = Zend_Registry::get('config')->General->datatable_archiving_maximum_rows_actions; $this->maximumRowsInSubDataTable = Zend_Registry::get('config')->General->datatable_archiving_maximum_rows_subtable_actions; @@ -57,16 +64,18 @@ class Piwik_Actions extends Piwik_Plugin function addWidgets() { - Piwik_AddWidget( 'Actions_Actions', 'Actions_SubmenuPages', 'Actions', 'getActions'); + Piwik_AddWidget( 'Actions_Actions', 'Actions_SubmenuPages', 'Actions', 'getPageUrls'); + Piwik_AddWidget( 'Actions_Actions', 'Actions_SubmenuPageTitles', 'Actions', 'getPageTitles'); Piwik_AddWidget( 'Actions_Actions', 'Actions_SubmenuOutlinks', 'Actions', 'getOutlinks'); Piwik_AddWidget( 'Actions_Actions', 'Actions_SubmenuDownloads', 'Actions', 'getDownloads'); } function addMenus() { - Piwik_AddMenu('Actions_Actions', 'Actions_SubmenuPages', array('module' => 'Actions', 'action' => 'getActions')); + Piwik_AddMenu('Actions_Actions', 'Actions_SubmenuPages', array('module' => 'Actions', 'action' => 'getPageUrls')); + Piwik_AddMenu('Actions_Actions', 'Actions_SubmenuPageTitles', array('module' => 'Actions', 'action' => 'getPageTitles')); Piwik_AddMenu('Actions_Actions', 'Actions_SubmenuOutlinks', array('module' => 'Actions', 'action' => 'getOutlinks')); - Piwik_AddMenu('Actions_Actions', 'Actions_SubmenuDownloads', array('module' => 'Actions', 'action' => 'getDownloads')); + Piwik_AddMenu('Actions_Actions', 'Actions_SubmenuDownloads', array('module' => 'Actions', 'action' => 'getDownloads')); } static protected $invalidSummedColumnNameToRenamedNameForPeriodArchive = array( @@ -88,6 +97,7 @@ class Piwik_Actions extends Piwik_Plugin 'Actions_actions', 'Actions_downloads', 'Actions_outlink', + 'Actions_actions_url', ); $archiveProcessing->archiveDataTable($dataTableToSum, self::$invalidSummedColumnNameToRenamedNameForPeriodArchive, $this->maximumRowsInDataTableLevelZero, $this->maximumRowsInSubDataTable, $this->columnToSortByBeforeTruncation); } @@ -106,9 +116,10 @@ class Piwik_Actions extends Piwik_Plugin $archiveProcessing = $notification->getNotificationObject(); $this->actionsTablesByType = array( - Piwik_Tracker_Action::TYPE_ACTION => array(), + Piwik_Tracker_Action::TYPE_ACTION_URL => array(), Piwik_Tracker_Action::TYPE_DOWNLOAD => array(), Piwik_Tracker_Action::TYPE_OUTLINK => array(), + Piwik_Tracker_Action::TYPE_ACTION_NAME => array(), ); // This row is used in the case where an action is know as an exit_action @@ -122,7 +133,7 @@ class Piwik_Actions extends Piwik_Plugin ))); /* - * Actions global information + * Actions urls global information */ $query = "SELECT name, type, @@ -131,7 +142,25 @@ class Piwik_Actions extends Piwik_Plugin count(*) as nb_hits FROM (".$archiveProcessing->logTable." as t1 LEFT JOIN ".$archiveProcessing->logVisitActionTable." as t2 USING (idvisit)) - LEFT JOIN ".$archiveProcessing->logActionTable." as t3 USING (idaction) + LEFT JOIN ".$archiveProcessing->logActionTable." as t3 ON (t2.idaction_url = t3.idaction) + WHERE visit_server_date = ? + AND idsite = ? + GROUP BY t3.idaction + ORDER BY nb_hits DESC"; + $query = $archiveProcessing->db->query($query, array( $archiveProcessing->strDateStart, $archiveProcessing->idsite )); + $modified = $this->updateActionsTableWithRowQuery($query); + + /* + * Actions names global information + */ + $query = "SELECT name, + type, + count(distinct t1.idvisit) as nb_visits, + count(distinct visitor_idcookie) as nb_uniq_visitors, + count(*) as nb_hits + FROM (".$archiveProcessing->logTable." as t1 + LEFT JOIN ".$archiveProcessing->logVisitActionTable." as t2 USING (idvisit)) + LEFT JOIN ".$archiveProcessing->logActionTable." as t3 ON (t2.idaction_name = t3.idaction) WHERE visit_server_date = ? AND idsite = ? GROUP BY t3.idaction @@ -139,7 +168,6 @@ class Piwik_Actions extends Piwik_Plugin $query = $archiveProcessing->db->query($query, array( $archiveProcessing->strDateStart, $archiveProcessing->idsite )); $modified = $this->updateActionsTableWithRowQuery($query); - /* * Entry actions */ @@ -151,10 +179,10 @@ class Piwik_Actions extends Piwik_Plugin sum(visit_total_time) as entry_sum_visit_length, sum(case visit_total_actions when 1 then 1 else 0 end) as entry_bounce_count FROM ".$archiveProcessing->logTable." - JOIN ".$archiveProcessing->logActionTable." ON (visit_entry_idaction = idaction) + JOIN ".$archiveProcessing->logActionTable." ON (visit_entry_idaction_url = idaction) WHERE visit_server_date = ? AND idsite = ? - GROUP BY visit_entry_idaction + GROUP BY visit_entry_idaction_url "; $query = $archiveProcessing->db->query($query, array( $archiveProcessing->strDateStart, $archiveProcessing->idsite )); $modified = $this->updateActionsTableWithRowQuery($query); @@ -169,10 +197,10 @@ class Piwik_Actions extends Piwik_Plugin count(*) as exit_nb_visits, sum(case visit_total_actions when 1 then 1 else 0 end) as exit_bounce_count FROM ".$archiveProcessing->logTable." - JOIN ".$archiveProcessing->logActionTable." ON (visit_exit_idaction = idaction) + JOIN ".$archiveProcessing->logActionTable." ON (visit_exit_idaction_url = idaction) WHERE visit_server_date = ? AND idsite = ? - GROUP BY visit_exit_idaction + GROUP BY visit_exit_idaction_url "; $query = $archiveProcessing->db->query($query, array( $archiveProcessing->strDateStart, $archiveProcessing->idsite )); $modified = $this->updateActionsTableWithRowQuery($query); @@ -185,10 +213,10 @@ class Piwik_Actions extends Piwik_Plugin sum(time_spent_ref_action) as sum_time_spent FROM (".$archiveProcessing->logTable." log_visit JOIN ".$archiveProcessing->logVisitActionTable." log_link_visit_action USING (idvisit)) - JOIN ".$archiveProcessing->logActionTable." log_action ON (log_action.idaction = log_link_visit_action.idaction_ref) + JOIN ".$archiveProcessing->logActionTable." log_action ON (log_action.idaction = log_link_visit_action.idaction_url_ref) WHERE visit_server_date = ? AND idsite = ? - GROUP BY idaction_ref + GROUP BY idaction_url_ref "; $query = $archiveProcessing->db->query($query, array( $archiveProcessing->strDateStart, $archiveProcessing->idsite )); $modified = $this->updateActionsTableWithRowQuery($query); @@ -197,10 +225,10 @@ class Piwik_Actions extends Piwik_Plugin protected function archiveDayRecordInDatabase($archiveProcessing) { - $dataTable = Piwik_ArchiveProcessing_Day::generateDataTable($this->actionsTablesByType[Piwik_Tracker_Action::TYPE_ACTION]); + $dataTable = Piwik_ArchiveProcessing_Day::generateDataTable($this->actionsTablesByType[Piwik_Tracker_Action::TYPE_ACTION_URL]); $this->deleteInvalidSummedColumnsFromDataTable($dataTable); $s = $dataTable->getSerialized( $this->maximumRowsInDataTableLevelZero, $this->maximumRowsInSubDataTable, $this->columnToSortByBeforeTruncation ); - $archiveProcessing->insertBlobRecord('Actions_actions', $s); + $archiveProcessing->insertBlobRecord('Actions_actions_url', $s); destroy($dataTable); $dataTable = Piwik_ArchiveProcessing_Day::generateDataTable($this->actionsTablesByType[Piwik_Tracker_Action::TYPE_DOWNLOAD]); @@ -215,6 +243,12 @@ class Piwik_Actions extends Piwik_Plugin $archiveProcessing->insertBlobRecord('Actions_outlink', $s); destroy($dataTable); + $dataTable = Piwik_ArchiveProcessing_Day::generateDataTable($this->actionsTablesByType[Piwik_Tracker_Action::TYPE_ACTION_NAME]); + $this->deleteInvalidSummedColumnsFromDataTable($dataTable); + $s = $dataTable->getSerialized( $this->maximumRowsInDataTableLevelZero, $this->maximumRowsInSubDataTable, $this->columnToSortByBeforeTruncation ); + $archiveProcessing->insertBlobRecord('Actions_actions', $s); + destroy($dataTable); + unset($this->actionsTablesByType); } @@ -232,30 +266,84 @@ class Piwik_Actions extends Piwik_Plugin } } } + + /** + * Explodes action name into an array of elements. + * + * for downloads: + * we explode link http://piwik.org/some/path/piwik.zip into an array( 'piwik.org', '/some/path/piwik.zip' ); + * + * for outlinks: + * we explode link http://dev.piwik.org/some/path into an array( 'dev.piwik.org', '/some/path' ); + * + * for action urls: + * we explode link http://piwik.org/some/path into an array( 'some', 'path' ); + * + * for action names: + * we explode name 'Piwik / Category 1 / Category 2' into an array('Piwik', 'Category 1', 'Category 2'); + * + * @param string action name + * @param int action type + * @return array of exploded elements from $name + */ static public function getActionExplodedNames($name, $type) { + $matches = array(); + $isUrl = false; + + preg_match('@^http[s]?://([^/]+)[/]?([^#]*)[#]?(.*)$@i', $name, $matches); + + if( count($matches) ) + { + $isUrl = true; + $urlHost = $matches[1]; + $urlPath = $matches[2]; + $urlAnchor = $matches[3]; + } + if($type == Piwik_Tracker_Action::TYPE_DOWNLOAD || $type == Piwik_Tracker_Action::TYPE_OUTLINK) { - $matches = $split_arr = array(); - //TODO optimize with substring count rather than preg_match - if(preg_match("#://[^/]+(/)#", $name, $matches, PREG_OFFSET_CAPTURE)) + if( $isUrl ) + { + return array($urlHost, '/' . $urlPath); + } + } + + if( $isUrl ) + { + $name = $urlPath; + + if( empty($name) || substr($name, -1) == '/' ) { - $host = substr($name, 0, $matches[1][1]); - return array($host, substr($name, strlen($host))); + $name .= self::$defaultActionName; } - return array($name, "/"); } + if(empty(self::$actionCategoryDelimiter)) { - return array($name); + return array( trim($name) ); + } + + $split = explode(self::$actionCategoryDelimiter, $name, self::$limitLevelSubCategory); + + // trim every category and remove empty categories + $split = array_map('trim', $split); + $split = array_filter($split, 'strlen'); + + if( empty($split) ) + { + if($type == Piwik_Tracker_Action::TYPE_ACTION_NAME) { + $defaultName = self::$defaultActionNameWhenNotDefined; + } else { + $defaultName = self::$defaultActionUrlWhenNotDefined; + } + return array( $defaultName ); } - return explode( self::$actionCategoryDelimiter, - $name, - self::$limitLevelSubCategory); + + return array_values( $split ); } - protected function updateActionsTableWithRowQuery($query) { $rowsProcessed = 0; @@ -265,7 +353,7 @@ class Piwik_Actions extends Piwik_Plugin // we work on the root table of the given TYPE (either ACTION or DOWNLOAD or OUTLINK etc.) $currentTable =& $this->actionsTablesByType[$row['type']]; - + // go to the level of the subcategory $end = count($actionExplodedNames)-1; for($level = 0 ; $level < $end; $level++) @@ -274,15 +362,19 @@ class Piwik_Actions extends Piwik_Plugin $currentTable =& $currentTable[$actionCategory]; } $actionName = $actionExplodedNames[$end]; - - // we are careful to prefix the pageName with some value + + // we are careful to prefix the page URL / name with some value // so that if a page has the same name as a category // we don't merge both entries - if($row['type'] == Piwik_Tracker_Action::TYPE_ACTION) + if($row['type'] == Piwik_Tracker_Action::TYPE_ACTION_URL ) { $actionName = '/' . $actionName; } - + else if( $row['type'] == Piwik_Tracker_Action::TYPE_ACTION_NAME ) + { + $actionName = ' ' . $actionName; + } + // currentTable is now the array element corresponding the the action // at this point we may be for example at the 4th level of depth in the hierarchy $currentTable =& $currentTable[$actionName]; @@ -290,10 +382,19 @@ class Piwik_Actions extends Piwik_Plugin // add the row to the matching sub category subtable if(!($currentTable instanceof Piwik_DataTable_Row)) { - $currentTable = new Piwik_DataTable_Row(array( + if( $row['type'] == Piwik_Tracker_Action::TYPE_ACTION_NAME ) + { + $currentTable = new Piwik_DataTable_Row(array( + Piwik_DataTable_Row::COLUMNS => array('label' => (string)$actionName), + )); + } + else + { + $currentTable = new Piwik_DataTable_Row(array( Piwik_DataTable_Row::COLUMNS => array('label' => (string)$actionName), Piwik_DataTable_Row::METADATA => array('url' => (string)$row['name']), )); + } } foreach($row as $name => $value) @@ -325,7 +426,7 @@ class Piwik_Actions extends Piwik_Plugin if($currentTable->getColumn('nb_hits') === false) { // to test this code: delete the entries in log_link_action_visit for - // a given exit_idaction + // a given exit_idaction_url foreach($this->defaultRow->getColumns() as $name => $value) { $currentTable->addColumn($name, $value); diff --git a/plugins/Actions/Controller.php b/plugins/Actions/Controller.php index 6943e3d531..64974199b4 100644 --- a/plugins/Actions/Controller.php +++ b/plugins/Actions/Controller.php @@ -17,41 +17,52 @@ */ class Piwik_Actions_Controller extends Piwik_Controller { - public function index() + public function getPageUrls($fetch = false) { - $view = Piwik_View::factory('index'); - - /* Actions, Downloads, Outlinks */ - $view->dataTableActions = $this->getActions( true ); - $view->dataTableDownloads = $this->getDownloads( true ); - $view->dataTableOutlinks = $this->getOutlinks( true ); - - echo $view->render(); + $view = Piwik_ViewDataTable::factory(); + $view->init( $this->pluginName, + __FUNCTION__, + 'Actions.getPageUrls', + 'getPageUrlsSubDataTable' ); + $view->setColumnTranslation('label', Piwik_Translate('Actions_ColumnPageURL')); + $this->configureViewActions($view); + return $this->renderView($view, $fetch); } - public function getActions($fetch = false) + public function getPageUrlsSubDataTable($fetch = false) { $view = Piwik_ViewDataTable::factory(); $view->init( $this->pluginName, __FUNCTION__, - 'Actions.getActions', - 'getActionsSubDataTable' ); + 'Actions.getPageUrls', + 'getActionsSubDataTable' ); $this->configureViewActions($view); + return $this->renderView($view, $fetch); + } + + public function getPageTitles($fetch = false) + { + $view = Piwik_ViewDataTable::factory(); + $view->init( $this->pluginName, + __FUNCTION__, + 'Actions.getPageTitles', + 'getPageTitlesSubDataTable' ); $view->setColumnTranslation('label', Piwik_Translate('Actions_ColumnPageName')); + $this->configureViewActions($view); return $this->renderView($view, $fetch); } - - public function getActionsSubDataTable($fetch = false) + + public function getPageTitlesSubDataTable($fetch = false) { $view = Piwik_ViewDataTable::factory(); - $view->init( $this->pluginName, + $view->init( $this->pluginName, __FUNCTION__, - 'Actions.getActions', - 'getActionsSubDataTable' ); + 'Actions.getPageTitles', + 'getPageTitlesSubDataTable' ); $this->configureViewActions($view); return $this->renderView($view, $fetch); } - + public function getDownloads($fetch = false) { $view = Piwik_ViewDataTable::factory(); @@ -76,7 +87,7 @@ class Piwik_Actions_Controller extends Piwik_Controller $view->disableSearchBox(); return $this->renderView($view, $fetch); } - + public function getOutlinks($fetch = false) { $view = Piwik_ViewDataTable::factory(); @@ -101,7 +112,7 @@ class Piwik_Actions_Controller extends Piwik_Controller $view->disableSearchBox(); return $this->renderView($view, $fetch); } - + protected function configureViewActions($view) { $view->setTemplate('CoreHome/templates/datatable_actions.tpl'); @@ -123,7 +134,6 @@ class Piwik_Actions_Controller extends Piwik_Controller $view->setLimit( 100 ); $view->setColumnsToDisplay( array('label','nb_hits','nb_visits') ); - $view->setColumnTranslation('label', Piwik_Translate('Actions_ColumnPageName')); $view->setColumnTranslation('nb_hits', Piwik_Translate('General_ColumnPageviews')); $view->setColumnTranslation('nb_visits', Piwik_Translate('General_ColumnUniquePageviews')); @@ -171,7 +181,7 @@ class Piwik_Actions_Controller extends Piwik_Controller $view->disableExcludeLowPopulation(); $view->setLimit( 15 ); } - + protected function getArrayFromRecursiveDataTable( $dataTable, $depth = 0 ) { $table = array(); diff --git a/plugins/Actions/tests/Actions.test.php b/plugins/Actions/tests/Actions.test.php new file mode 100644 index 0000000000..08f11e81ef --- /dev/null +++ b/plugins/Actions/tests/Actions.test.php @@ -0,0 +1,92 @@ +<?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 'Actions/Actions.php'; +require_once 'Tracker/Action.php'; +require_once 'Tracker/Config.php'; + +class Test_Piwik_Actions extends UnitTestCase +{ + function test_getActionExplodedNames() + { + $userFile = PIWIK_INCLUDE_PATH . '/tests/resources/plugins/Actions/Actions.config.ini.php'; + + Piwik::createConfigObject($userFile); + + $action = new Test_Piwik_Actions_getActionExplodedNames(); + + $tests = array( + array( + 'params' => array( 'name' => 'http://example.org/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL), + 'expected' => array('index' ), + ), + array( + 'params' => array( 'name' => 'http://example.org/path/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL), + 'expected' => array( 'path', 'index' ), + ), + array( + 'params' => array( 'name' => 'http://example.org/test/path', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL), + 'expected' => array( 'test', 'path' ), + ), + array( + 'params' => array( 'name' => 'Test / Path', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL), + 'expected' => array( 'Test', 'Path' ), + ), + array( + 'params' => array( 'name' => ' Test trim ', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL), + 'expected' => array( 'Test trim' ), + ), + array( + 'params' => array( 'name' => 'Category / Subcategory', 'type' => Piwik_Tracker_Action::TYPE_ACTION_NAME), + 'expected' => array( 'Category', 'Subcategory' ), + ), + array( + 'params' => array( 'name' => '/path/index.php?var=test', 'type' => Piwik_Tracker_Action::TYPE_ACTION_NAME), + 'expected' => array( 'path', 'index.php?var=test' ), + ), + array( + 'params' => array( 'name' => 'http://example.org/path/Default.aspx#anchor', 'type' => Piwik_Tracker_Action::TYPE_ACTION_NAME), + 'expected' => array( 'path', 'Default.aspx' ), + ), + array( + 'params' => array( 'name' => '', 'type' => Piwik_Tracker_Action::TYPE_ACTION_NAME), + 'expected' => array( 'index' ), + ), + array( + 'params' => array( 'name' => 'http://example.org/download.zip', 'type' => Piwik_Tracker_Action::TYPE_DOWNLOAD), + 'expected' => array( 'example.org', '/download.zip' ), + ), + array( + 'params' => array( 'name' => 'http://example.org/download/1/', 'type' => Piwik_Tracker_Action::TYPE_DOWNLOAD), + 'expected' => array( 'example.org', '/download/1/' ), + ), + array( + 'params' => array( 'name' => 'http://example.org/link', 'type' => Piwik_Tracker_Action::TYPE_OUTLINK), + 'expected' => array( 'example.org', '/link' ), + ), + array( + 'params' => array( 'name' => 'http://example.org/some/path/', 'type' => Piwik_Tracker_Action::TYPE_OUTLINK), + 'expected' => array( 'example.org', '/some/path/' ), + ), + + ); + foreach($tests as $test) { + $params = $test['params']; + $expected = $test['expected']; + $this->assertEqual($action->public_getActionExplodedNames($params['name'],$params['type']), $expected); + } + } +} + +class Test_Piwik_Actions_getActionExplodedNames extends Piwik_Actions { + public function public_getActionExplodedNames($name, $type) + { + return self::getActionExplodedNames($name, $type); + } +}
\ No newline at end of file |