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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
use Piwik\Access;
use Piwik\Plugins\Goals\API;
use Piwik\WidgetsList;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
/**
* Class Core_WidgetsListTest
*
* @group Core
*/
class Core_WidgetsListTest extends IntegrationTestCase
{
/**
* @group Core
*/
public function testGet()
{
// setup the access layer
$pseudoMockAccess = new FakeAccess;
FakeAccess::$superUser = true;
Access::setSingletonInstance($pseudoMockAccess);
Fixture::createWebsite('2009-01-04 00:11:42');
$_GET['idSite'] = 1;
WidgetsList::_reset();
$widgets = WidgetsList::get();
WidgetsList::_reset();
// check if each category has the right number of widgets
$numberOfWidgets = array(
'VisitsSummary_VisitsSummary' => 6,
'Live!' => 4,
'General_Visitors' => 12,
'UserSettings_VisitorSettings' => 6,
'General_Actions' => 10,
'Events_Events' => 3,
'Actions_SubmenuSitesearch' => 5,
'Referrers_Referrers' => 7,
'Goals_Goals' => 1,
'SEO' => 2,
'Example Widgets' => 4,
'DevicesDetection_DevicesDetection' => 8,
'Insights_WidgetCategory' => 2
);
// number of main categories
$this->assertEquals(count($numberOfWidgets), count($widgets));
foreach ($numberOfWidgets as $category => $widgetCount) {
$this->assertEquals($widgetCount, count($widgets[$category]), sprintf("Widget: %s", $category));
}
}
/**
* @group Core
*/
public function testGetWithGoals()
{
// setup the access layer
$pseudoMockAccess = new FakeAccess;
FakeAccess::$superUser = true;
Access::setSingletonInstance($pseudoMockAccess);
Fixture::createWebsite('2009-01-04 00:11:42');
API::getInstance()->addGoal(1, 'Goal 1 - Thank you', 'title', 'Thank you', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = 1);
$_GET['idSite'] = 1;
WidgetsList::_reset();
$widgets = WidgetsList::get();
WidgetsList::_reset();
// number of main categories
$this->assertEquals(13, count($widgets));
// check that the goal widget was added
$numberOfWidgets = array(
'Goals_Goals' => 2,
);
foreach ($numberOfWidgets as $category => $widgetCount) {
$this->assertEquals($widgetCount, count($widgets[$category]));
}
}
/**
* @group Core
*/
public function testGetWithGoalsAndEcommerce()
{
// setup the access layer
$pseudoMockAccess = new FakeAccess;
FakeAccess::$superUser = true;
Access::setSingletonInstance($pseudoMockAccess);
Fixture::createWebsite('2009-01-04 00:11:42', true);
API::getInstance()->addGoal(1, 'Goal 1 - Thank you', 'title', 'Thank you', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = 1);
$_GET['idSite'] = 1;
WidgetsList::_reset();
$widgets = WidgetsList::get();
WidgetsList::_reset();
// number of main categories
$this->assertEquals(14, count($widgets));
// check if each category has the right number of widgets
$numberOfWidgets = array(
'Goals_Goals' => 2,
'Goals_Ecommerce' => 5,
);
foreach ($numberOfWidgets as $category => $widgetCount) {
$this->assertEquals($widgetCount, count($widgets[$category]));
}
}
/**
* @group Core
*/
public function testRemove()
{
// setup the access layer
$pseudoMockAccess = new FakeAccess;
FakeAccess::$superUser = true;
Access::setSingletonInstance($pseudoMockAccess);
Fixture::createWebsite('2009-01-04 00:11:42', true);
API::getInstance()->addGoal(1, 'Goal 1 - Thank you', 'title', 'Thank you', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = 1);
$_GET['idSite'] = 1;
WidgetsList::_reset();
$widgets = WidgetsList::get();
$this->assertCount(14, $widgets);
WidgetsList::remove('SEO', 'NoTeXiStInG');
$widgets = WidgetsList::get();
$this->assertCount(14, $widgets);
$this->assertArrayHasKey('SEO', $widgets);
$this->assertCount(2, $widgets['SEO']);
WidgetsList::remove('SEO', 'SEO_SeoRankings');
$widgets = WidgetsList::get();
$this->assertCount(1, $widgets['SEO']);
WidgetsList::remove('SEO');
$widgets = WidgetsList::get();
$this->assertArrayNotHasKey('SEO', $widgets);
WidgetsList::_reset();
}
/**
* @group Core
*/
public function testIsDefined()
{
// setup the access layer
$pseudoMockAccess = new FakeAccess;
FakeAccess::$superUser = true;
Access::setSingletonInstance($pseudoMockAccess);
\Piwik\Translate::loadEnglishTranslation();
Fixture::createWebsite('2009-01-04 00:11:42', true);
$_GET['idSite'] = 1;
WidgetsList::_reset();
WidgetsList::add('Actions', 'Pages', 'Actions', 'getPageUrls');
$this->assertTrue(WidgetsList::isDefined('Actions', 'getPageUrls'));
$this->assertFalse(WidgetsList::isDefined('Actions', 'inValiD'));
}
}
|