-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathWidgetsListTest.php
More file actions
217 lines (163 loc) · 6.89 KB
/
WidgetsListTest.php
File metadata and controls
217 lines (163 loc) · 6.89 KB
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Tests\Integration;
use Piwik\Plugin\Manager;
use Piwik\Widget\WidgetConfig;
use Piwik\Plugins\Goals\API;
use Piwik\Tests\Framework\Mock\FakeAccess;
use Piwik\Widget\WidgetsList;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
/**
* @group Core
*/
class WidgetsListTest extends IntegrationTestCase
{
public function setUp(): void
{
parent::setUp();
FakeAccess::$superUser = true;
}
public function testGet()
{
Fixture::createWebsite('2009-01-04 00:11:42');
$_GET['idSite'] = 1;
$widgets = WidgetsList::get();
$widgetsPerCategory = $this->getWidgetsPerCategory($widgets);
// check if each category has the right number of widgets
$numberOfWidgets = array(
'Dashboard_Dashboard' => 1,
'General_Actions' => 26,
'General_KpiMetric' => 1,
'General_Visitors' => 30,
'SEO' => 1,
'Goals_Goals' => 3,
'Insights_WidgetCategory' => 2,
'ExampleUI_UiFramework' => 8,
'Referrers_Referrers' => 11,
'About Matomo' => 11,
'Marketplace_Marketplace' => 3,
'General_AIAssistants' => 2,
// widgets provided by Professional Services plugin for plugin promos
'ProfessionalServices_PromoAbTesting' => 1,
'ProfessionalServices_PromoCrashAnalytics' => 1,
'ProfessionalServices_PromoCustomReports' => 1,
'ProfessionalServices_PromoFormAnalytics' => 1,
'ProfessionalServices_PromoFunnels' => 1,
'ProfessionalServices_PromoHeatmaps' => 1,
'ProfessionalServices_PromoMediaAnalytics' => 1,
'ProfessionalServices_PromoSessionRecording' => 1,
);
if (Manager::getInstance()->isPluginActivated('CustomVariables')) {
$numberOfWidgets['General_Visitors']++;
}
// number of main categories
$this->assertEquals(count($numberOfWidgets), count($widgetsPerCategory));
foreach ($numberOfWidgets as $category => $widgetCount) {
$this->assertEquals($widgetCount, count($widgetsPerCategory[$category]), sprintf("Widget: %s", $category));
}
}
private function getWidgetsPerCategory(WidgetsList $list)
{
$widgetsPerCategory = array();
foreach ($list->getWidgetConfigs() as $widgetConfig) {
$category = $widgetConfig->getCategoryId();
if (!isset($widgetsPerCategory[$category])) {
$widgetsPerCategory[$category] = array();
}
$widgetsPerCategory[$category][] = $widgetConfig;
}
return $widgetsPerCategory;
}
public function testGetWithGoals()
{
Fixture::createWebsite('2009-01-04 00:11:42');
$initialGoalsWidgets = 3;
$_GET['idSite'] = 1;
$perCategory = $this->getWidgetsPerCategory(WidgetsList::get());
$this->assertEquals($initialGoalsWidgets, count($perCategory['Goals_Goals']));
API::getInstance()->addGoal(1, 'Goal 1 - Thank you', 'title', 'Thank you', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = 1);
$perCategory = $this->getWidgetsPerCategory(WidgetsList::get());
// number of main categories
$this->assertEquals(20, count($perCategory));
$this->assertEquals($initialGoalsWidgets + 2, count($perCategory['Goals_Goals'])); // make sure widgets for that goal were added
}
public function testGetWithGoalsAndEcommerce()
{
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;
$perCategory = $this->getWidgetsPerCategory(WidgetsList::get());
// number of main categories
$this->assertEquals(21, count($perCategory));
// check if each category has the right number of widgets
$numberOfWidgets = array(
'Goals_Goals' => 5,
'Goals_Ecommerce' => 4,
);
foreach ($numberOfWidgets as $category => $widgetCount) {
$this->assertEquals($widgetCount, count($perCategory[$category]));
}
}
public function testGetWithoutProfessionalServicesPromos()
{
Fixture::createWebsite('2009-01-04 00:11:42');
Manager::getInstance()->deactivatePlugin('ProfessionalServices');
$_GET['idSite'] = 1;
$widgets = WidgetsList::get();
// number of main categories
$widgetsPerCategory = $this->getWidgetsPerCategory($widgets);
$this->assertCount(12, $widgetsPerCategory);
// no professional services promos
foreach ($widgetsPerCategory as $category => $categoryWidgets) {
$this->assertStringStartsNotWith($category, 'ProfessionalServices_Promo');
}
}
public function testRemove()
{
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;
$list = WidgetsList::get();
$this->assertCount(21, $this->getWidgetsPerCategory($list));
$list->remove('SEO', 'NoTeXiStInG');
$perCategory = $this->getWidgetsPerCategory($list);
$this->assertCount(21, $perCategory);
$this->assertArrayHasKey('SEO', $perCategory);
$this->assertCount(1, $perCategory['SEO']);
$list->remove('SEO', 'SEO_SeoRankings');
$perCategory = $this->getWidgetsPerCategory($list);
$this->assertArrayNotHasKey('SEO', $perCategory);
$this->assertArrayHasKey('About Matomo', $perCategory);
$list->remove('About Matomo');
$perCategory = $this->getWidgetsPerCategory($list);
$this->assertArrayNotHasKey('About Matomo', $perCategory);
}
public function testIsDefined()
{
Fixture::loadAllTranslations();
Fixture::createWebsite('2009-01-04 00:11:42', true);
$_GET['idSite'] = 1;
$config = new WidgetConfig();
$config->setCategoryId('Actions');
$config->setName('Pages');
$config->setModule('Actions');
$config->setAction('getPageUrls');
$list = WidgetsList::get();
$list->addWidgetConfig($config);
$this->assertTrue($list->isDefined('Actions', 'getPageUrls'));
$this->assertFalse($list->isDefined('Actions', 'inValiD'));
Fixture::resetTranslations();
}
public function provideContainerConfig()
{
return array(
'Piwik\Access' => new FakeAccess(),
);
}
}