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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Tests\Integration\ViewDataTable;
use Piwik\Option;
use Piwik\ViewDataTable\Manager as ViewDataTableManager;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
/**
* @group Core
* @group ViewDataTable
*/
class ManagerTest extends IntegrationTestCase
{
public function test_getViewDataTableParameters_shouldReturnEmptyArray_IfNothingPersisted()
{
$login = 'mylogin';
$method = 'API.get';
$storedParams = ViewDataTableManager::getViewDataTableParameters($login, $method);
$this->assertEquals(array(), $storedParams);
}
public function test_getViewDataTableParameters_shouldOnlyReturnParams_IfLoginAndActionMatches()
{
$params = $this->addParameters();
$storedParams = ViewDataTableManager::getViewDataTableParameters('WroNgLogIn', $params['method']);
$this->assertEquals(array(), $storedParams);
$storedParams = ViewDataTableManager::getViewDataTableParameters($params['login'], 'API.wRoNg');
$this->assertEquals(array(), $storedParams);
$storedParams = ViewDataTableManager::getViewDataTableParameters($params['login'], $params['method']);
$this->assertEquals($params['params'], $storedParams);
}
public function test_setViewDataTableParameters_inConfigProperty_shouldOnlyAllowOverridableParams()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Setting parameters translations is not allowed. Please report this bug to the Matomo team.');
$login = 'mylogin';
$method = 'API.get';
$params = array(
'flat' => '0',
'translations' => 'this is not overridable param and should fail',
'viewDataTable' => 'tableAllColumns'
);
ViewDataTableManager::saveViewDataTableParameters($login, $method, $params);
}
public function test_setViewDataTableParameters_inConfigProperty_shouldOnlyAllowOverridableParams_bis()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Setting parameters filters is not allowed. Please report this bug to the Matomo team.');
$login = 'mylogin';
$method = 'API.get';
$params = array(
'flat' => '0',
'filters' => 'this is not overridable param and should fail',
'viewDataTable' => 'tableAllColumns'
);
ViewDataTableManager::saveViewDataTableParameters($login, $method, $params);
}
public function test_setViewDataTableParameters_inRequestConfigProperty_shouldOnlyAllowOverridableParams()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Setting parameters apiMethodToRequestDataTable is not allowed. Please report this bug to the Matomo team.');
$login = 'mylogin';
$method = 'API.get';
$params = array(
'flat' => '0',
'apiMethodToRequestDataTable' => 'this is not overridable in RequestConfig param and should fail',
'viewDataTable' => 'tableAllColumns'
);
ViewDataTableManager::saveViewDataTableParameters($login, $method, $params);
}
public function test_getViewDataTableParameters_removesNonOverridableParameter()
{
$params = array(
'flat' => '0',
'filters' => 'this is not overridable param and should fail',
'viewDataTable' => 'tableAllColumns'
);
// 'filters' was removed
$paramsExpectedWhenFetched = array(
'flat' => '0',
'viewDataTable' => 'tableAllColumns'
);
$login = 'mylogin';
$controllerAction = 'API.get';
// simulate an invalid list of parameters (contains 'filters')
$paramsKey = sprintf('viewDataTableParameters_%s_%s', $login, $controllerAction);
Option::set($paramsKey, json_encode($params));
// check the invalid list is fetched without the overridable parameter
$processed = ViewDataTableManager::getViewDataTableParameters($login, $controllerAction);
$this->assertEquals($paramsExpectedWhenFetched, $processed);
}
public function test_clearAllViewDataTableParameters_shouldRemoveAllPersistedParameters()
{
ViewDataTableManager::saveViewDataTableParameters('mylogin1', 'API.get1', array('flat' => 1));
ViewDataTableManager::saveViewDataTableParameters('mylogin1', 'API.get2', array('flat' => 1));
ViewDataTableManager::saveViewDataTableParameters('mylogin2', 'API.get3', array('flat' => 1));
ViewDataTableManager::saveViewDataTableParameters('mylogin1', 'API.get4', array('flat' => 1));
ViewDataTableManager::saveViewDataTableParameters('mylogin3', 'API.get5', array('flat' => 1));
$this->assertNotEmpty(ViewDataTableManager::getViewDataTableParameters('mylogin1', 'API.get1'));
$this->assertNotEmpty(ViewDataTableManager::getViewDataTableParameters('mylogin1', 'API.get2'));
$this->assertNotEmpty(ViewDataTableManager::getViewDataTableParameters('mylogin2', 'API.get3'));
$this->assertNotEmpty(ViewDataTableManager::getViewDataTableParameters('mylogin1', 'API.get4'));
$this->assertNotEmpty(ViewDataTableManager::getViewDataTableParameters('mylogin3', 'API.get5'));
ViewDataTableManager::clearAllViewDataTableParameters();
$this->assertEmpty(ViewDataTableManager::getViewDataTableParameters('mylogin1', 'API.get1'));
$this->assertEmpty(ViewDataTableManager::getViewDataTableParameters('mylogin1', 'API.get2'));
$this->assertEmpty(ViewDataTableManager::getViewDataTableParameters('mylogin2', 'API.get3'));
$this->assertEmpty(ViewDataTableManager::getViewDataTableParameters('mylogin1', 'API.get4'));
$this->assertEmpty(ViewDataTableManager::getViewDataTableParameters('mylogin3', 'API.get5'));
}
public function test_clearUserViewDataTableParameters_shouldOnlyRemoveAUsersParameters()
{
ViewDataTableManager::saveViewDataTableParameters('mylogin1', 'API.get1', array('flat' => 1));
ViewDataTableManager::saveViewDataTableParameters('mylogin1', 'API.get2', array('flat' => 1));
ViewDataTableManager::saveViewDataTableParameters('mylogin2', 'API.get3', array('flat' => 1));
ViewDataTableManager::saveViewDataTableParameters('mylogin1', 'API.get4', array('flat' => 1));
ViewDataTableManager::saveViewDataTableParameters('mylogin3', 'API.get5', array('flat' => 1));
$this->assertNotEmpty(ViewDataTableManager::getViewDataTableParameters('mylogin1', 'API.get1'));
$this->assertNotEmpty(ViewDataTableManager::getViewDataTableParameters('mylogin1', 'API.get2'));
$this->assertNotEmpty(ViewDataTableManager::getViewDataTableParameters('mylogin2', 'API.get3'));
$this->assertNotEmpty(ViewDataTableManager::getViewDataTableParameters('mylogin1', 'API.get4'));
$this->assertNotEmpty(ViewDataTableManager::getViewDataTableParameters('mylogin3', 'API.get5'));
ViewDataTableManager::clearUserViewDataTableParameters('mylogin1');
$this->assertEmpty(ViewDataTableManager::getViewDataTableParameters('mylogin1', 'API.get1'));
$this->assertEmpty(ViewDataTableManager::getViewDataTableParameters('mylogin1', 'API.get2'));
$this->assertEmpty(ViewDataTableManager::getViewDataTableParameters('mylogin1', 'API.get4'));
$this->assertNotEmpty(ViewDataTableManager::getViewDataTableParameters('mylogin2', 'API.get3'));
$this->assertNotEmpty(ViewDataTableManager::getViewDataTableParameters('mylogin3', 'API.get5'));
}
private function addParameters()
{
$login = 'mylogin';
$method = 'API.get';
$params = array('flat' => '0', 'expanded' => 1, 'viewDataTable' => 'tableAllColumns');
ViewDataTableManager::saveViewDataTableParameters($login, $method, $params);
return array('login' => $login, 'method' => $method, 'params' => $params);
}
}
|