1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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);
}
}
|