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
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Tests\Integration;
use Piwik\Widget\WidgetConfig;
use Piwik\Plugins\Goals\API;
use Piwik\Tests\Framework\Mock\FakeAccess;
use Piwik\Translate;
use Piwik\Widget\WidgetsList;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
/**
* @group Core
*/
class WidgetsListTest extends IntegrationTestCase
{
public function setIp()
{
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' => 15,
'General_Visitors' => 34,
'SEO' => 2,
'Goals_Goals' => 3,
'Live!' => 2,
'Insights_WidgetCategory' => 2,
'ExampleUI_UiFramework' => 8,
'Referrers_Referrers' => 9,
'About Piwik' => 7,
);
// 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(10, 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(11, 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 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(11, $this->getWidgetsPerCategory($list));
$list->remove('SEO', 'NoTeXiStInG');
$perCategory = $this->getWidgetsPerCategory($list);
$this->assertCount(11, $perCategory);
$this->assertArrayHasKey('SEO', $perCategory);
$this->assertCount(2, $perCategory['SEO']);
$list->remove('SEO', 'SEO_SeoRankings');
$perCategory = $this->getWidgetsPerCategory($list);
$this->assertCount(1, $perCategory['SEO']);
$list->remove('SEO');
$perCategory = $this->getWidgetsPerCategory($list);
$this->assertArrayNotHasKey('SEO', $perCategory);
}
public function testIsDefined()
{
Translate::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'));
Translate::reset();
}
public function provideContainerConfig()
{
return array(
'Piwik\Access' => new FakeAccess()
);
}
}
|