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

Action.test.php « Tracker « core « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2cc1fba21616006f73244ea87c49684532a10602 (plain)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?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 'Tracker/Action.php';
require_once 'Tracker/Config.php';
class Test_Piwik_TrackerAction extends UnitTestCase
{
	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(
			// outlinks
			array(
				'request' => array( 'link' => 'http://example.org'),
				'expected' => array(	'name' => null,
										'url' => 'http://example.org',
										'type' => Piwik_Tracker_Action::TYPE_OUTLINK),
			),
			// outlinks with custom name
			array(
				'request' => array( 'link' => 'http://example.org', 'action_name' => 'Example.org'),
				'expected' => array(	'name' => 'Example.org',
										'url' => 'http://example.org',
										'type' => Piwik_Tracker_Action::TYPE_OUTLINK),
			),
			// keep the case in urls, but trim
			array(
				'request' => array( 'link' => '	http://example.org/Category/Test/  	'),
				'expected' => array(	'name' => null,
										'url' => 'http://example.org/Category/Test/',
										'type' => Piwik_Tracker_Action::TYPE_OUTLINK),
			),

			// trim the custom name
			array(
				'request' => array( 'link' => '	http://example.org/Category/Test/  	', 'action_name' => '  Example dot org '),
				'expected' => array(	'name' => 'Example dot org',
										'url' => 'http://example.org/Category/Test/',
										'type' => Piwik_Tracker_Action::TYPE_OUTLINK),
			),

			// downloads
			array(
				'request' => array( 'download' => 'http://example.org/*$test.zip'),
				'expected' => array(	'name' => null,
										'url' => 'http://example.org/*$test.zip',
										'type' => Piwik_Tracker_Action::TYPE_DOWNLOAD),
			),

			// downloads with custom name
			array(
				'request' => array( 'download' => 'http://example.org/*$test.zip', 'action_name' => 'Download test.zip'),
				'expected' => array(	'name' => 'Download test.zip',
										'url' => 'http://example.org/*$test.zip',
										'type' => Piwik_Tracker_Action::TYPE_DOWNLOAD),
			),
			
			// keep the case and multiple / in urls
			array(
				'request' => array( 'download' => 'http://example.org/CATEGORY/test///test.pdf'),
				'expected' => array(	'name' => null,
										'url' => 'http://example.org/CATEGORY/test///test.pdf',
										'type' => Piwik_Tracker_Action::TYPE_DOWNLOAD),
			),
			
			// page view
			array(
				'request' => array( 'url' => 'http://example.org/'),
				'expected' => array(	'name' => null,
										'url' => 'http://example.org/',
										'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
			),
			array(
				'request' => array( 'url' => 'http://example.org/', 'action_name' => 'Example.org Website'),
				'expected' => array(	'name' => 'Example.org Website',
										'url' => 'http://example.org/',
										'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
			),
			array(
				'request' => array( 'url' => 'http://example.org/CATEGORY/'),
				'expected' => array(	'name' => null,
										'url' => 'http://example.org/CATEGORY/',
										'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
			),
			array(
				'request' => array( 'url' => 'http://example.org/CATEGORY/TEST', 'action_name' => 'Example.org / Category / test /'),
				'expected' => array(	'name' => 'Example.org/Category/test',
										'url' => 'http://example.org/CATEGORY/TEST',
										'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
			),

			// empty request
			array(
				'request' => array(),
				'expected' => array(	'name' => null,	'url' => '/',
										'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
			),
			array(
				'request' => array( 'url' => 'http://example.org/category/',
									'action_name' => 'custom name with/one delimiter/two delimiters/'),
				'expected' => array(	'name' => 'custom name with/one delimiter/two delimiters',
										'url' => 'http://example.org/category/',
										'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
			),
			array(
				'request' => array( 'url' => 'http://example.org/category/',
									'action_name' => 'http://custom action name look like url/'),
				'expected' => array(	'name' => 'http:/custom action name look like url',
										'url' => 'http://example.org/category/',
										'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
			),
			// testing: delete tab, trimmed, not strtolowered
			array( 
				'request' => array( 'url' => "http://example.org/category/test///test  wOw  	"),
				'expected' => array(	'name' => null,
										'url' => 'http://example.org/category/test///test  wOw',
										'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
			),
			// testing: inclusion of zero values in action name
			array(
				'request' => array( 'url' => "http://example.org/category/1/0/t/test"),
				'expected' => array(	'name' => null,
										'url' => 'http://example.org/category/1/0/t/test',
										'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
			),
		);
		foreach($tests as $test) {
			$request = $test['request'];
			$expected = $test['expected'];
			$action->setRequest($request);
			$this->assertEqual($action->public_extractUrlAndActionNameFromRequest(), $expected);
		}
	}
}

class Test_Piwik_TrackerAction_extractUrlAndActionNameFromRequest extends Piwik_Tracker_Action{
	public function public_extractUrlAndActionNameFromRequest()
	{
		return $this->extractUrlAndActionNameFromRequest();
	}
}