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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
/*!
* Matomo - free/libre analytics platform
*
* Screenshot tests for Marketplace.
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
describe("Marketplace", function () {
this.timeout(0);
this.fixture = "Piwik\\Plugins\\Marketplace\\tests\\Fixtures\\SimpleFixtureTrackFewVisits";
var urlBase = '?module=Marketplace&action=overview';
var paidPluginsUrl = urlBase + '&show=premium';
var themesUrl = urlBase + '&show=themes';
var pluginsUrl = urlBase;
var noLicense = 'noLicense';
var expiredLicense = 'expiredLicense';
var exceededLicense = 'exceededLicense';
var validLicense = 'validLicense';
async function loadPluginDetailPage(pluginName, isFreePlugin)
{
await page.goto(isFreePlugin ? pluginsUrl : paidPluginsUrl);
const elem = await page.waitForSelector('.card-title [piwik-plugin-name="' + pluginName + '"]');
await elem.click();
await page.waitForNetworkIdle();
await page.waitForSelector('.ui-dialog .pluginDetails');
}
async function captureSelector(screenshotName, selector)
{
await page.waitForFunction("$('" + selector + "').length > 0");
await page.waitForNetworkIdle();
expect(await page.screenshotSelector(selector)).to.matchImage(screenshotName);
}
async function captureModal(screenshotName, selector)
{
await page.waitForFunction("$('" + selector + "').length > 0");
await page.waitForNetworkIdle();
const elem = await page.$(selector);
expect(await elem.screenshot()).to.matchImage(screenshotName);
}
async function captureMarketplace(screenshotName, selector)
{
if (!selector) {
await page.waitForNetworkIdle();
const element = await page.$('.marketplace');
expect(await element.screenshot()).to.matchImage(screenshotName);
return;
}
await captureSelector(screenshotName, '.marketplace' + selector);
}
async function captureWithNotification(screenshotName)
{
await captureMarketplace(screenshotName, ',#notificationContainer');
}
async function captureWithDialog(screenshotName)
{
await captureSelector(screenshotName, '.ui-dialog');
}
function assumePaidPluginsActivated()
{
testEnvironment.mockMarketplaceAssumePluginNamesActivated = ['CustomPlugin1','CustomPlugin2','PaidPlugin1','PaidPlugin2'];
testEnvironment.save();
}
function setEnvironment(mode, consumer)
{
if (mode === 'user') {
testEnvironment.idSitesViewAccess = [1];
} else {
// superuser
testEnvironment.idSitesViewAccess = [];
}
if (mode === 'multiUserEnvironment') {
testEnvironment.overrideConfig('General', 'multi_server_environment', '1');
} else {
testEnvironment.overrideConfig('General', 'multi_server_environment', '0');
}
testEnvironment.overrideConfig('General', 'enable_plugins_admin', '1');
delete testEnvironment.mockMarketplaceAssumePluginNamesActivated;
testEnvironment.consumer = consumer;
testEnvironment.mockMarketplaceApiService = 1;
testEnvironment.save();
}
['superuser', 'user', 'multiUserEnvironment'].forEach(function (mode) {
if (mode !== 'user') {
it('should show available updates in plugins page', async function() {
setEnvironment(mode, noLicense);
await page.goto('?module=CorePluginsAdmin&action=plugins&idSite=1&period=day&date=yesterday&activated=');
await captureSelector('updates_' + mode, '#content .card:first');
});
}
it(mode + ' for a user without license key should be able to open paid plugins', async function() {
setEnvironment(mode, noLicense);
await page.goto(paidPluginsUrl);
await captureMarketplace('paid_plugins_no_license_' + mode);
});
it(mode + ' for a user with license key should be able to open paid plugins', async function() {
setEnvironment(mode, validLicense);
await page.goto(paidPluginsUrl);
await captureMarketplace('paid_plugins_with_license_' + mode);
});
it(mode + ' for a user with exceeded license key should be able to open paid plugins', async function() {
setEnvironment(mode, exceededLicense);
assumePaidPluginsActivated();
await page.goto(paidPluginsUrl);
await captureMarketplace('paid_plugins_with_exceeded_license_' + mode);
});
it('should show themes page', async function() {
setEnvironment(mode, validLicense);
await page.goto(themesUrl);
await captureMarketplace('themes_with_valid_license_' + mode);
});
it('should show free plugin details', async function() {
setEnvironment(mode, noLicense);
var isFree = true;
await loadPluginDetailPage('TreemapVisualization', isFree);
await captureWithDialog('free_plugin_details_' + mode);
});
it('should show paid plugin details when having no license', async function() {
setEnvironment(mode, noLicense);
assumePaidPluginsActivated();
var isFree = false;
await loadPluginDetailPage('PaidPlugin1', isFree);
await captureWithDialog('paid_plugin_details_no_license_' + mode);
});
it('should show paid plugin details when having valid license', async function() {
setEnvironment(mode, validLicense);
assumePaidPluginsActivated();
var isFree = false;
await loadPluginDetailPage('PaidPlugin1', isFree);
await captureWithDialog('paid_plugin_details_valid_license_' + mode + '_installed');
});
it('should show paid plugin details when having valid license', async function() {
setEnvironment(mode, exceededLicense);
assumePaidPluginsActivated();
var isFree = false;
await loadPluginDetailPage('PaidPlugin1', isFree);
await captureWithDialog('paid_plugin_details_exceeded_license_' + mode);
});
});
var mode = 'superuser';
it('should show a dialog showing a list of all possible plugins to install', async function() {
setEnvironment(mode, validLicense);
await page.goto(pluginsUrl);
await page.click('.installAllPaidPlugins');
await page.mouse.move(-10, -10);
await captureModal(mode + '_install_all_paid_plugins_at_once', '.modal.open');
});
it('should show an error message when invalid license key entered', async function() {
setEnvironment(mode, noLicense);
await page.goto(pluginsUrl);
await page.type('#license_key', 'invalid');
await page.click('.marketplace-paid-intro'); // click outside so change event is triggered
await page.click('#submit_license_key input');
await page.waitForNetworkIdle();
await page.waitForTimeout(200);
await captureWithNotification(mode + '_invalid_license_key_entered');
});
it('should show a confirmation before removing a license key', async function() {
setEnvironment(mode, validLicense);
await page.goto(pluginsUrl);
await page.click('#remove_license_key input');
await captureModal(mode + '_remove_license_key_confirmation', '.modal.open');
});
it('should show a confirmation before removing a license key', async function() {
setEnvironment(mode, noLicense);
elem = await page.jQuery('.modal.open .modal-footer a:contains(Yes)');
await elem.click();
await captureMarketplace(mode + '_remove_license_key_confirmed');
});
it('should show a success message when valid license key entered', async function() {
setEnvironment(mode, noLicense);
await page.goto(pluginsUrl);
await page.type('#license_key', 'valid');
setEnvironment(mode, validLicense);
await page.click('#submit_license_key input');
await captureMarketplace(mode + '_valid_license_key_entered');
});
it('should hide activate / deactivate buttons if plugins admin is disabled', async function() {
setEnvironment(mode, noLicense);
testEnvironment.overrideConfig('General', 'enable_plugins_admin', '0');
testEnvironment.save();
await page.goto(pluginsUrl);
await captureMarketplace( mode + '_enable_plugins_admin');
});
it('should hide activate / deactivate buttons if plugins admin is disabled when also multi server environment is enabled', async function() {
setEnvironment('multiUserEnvironment', noLicense);
testEnvironment.overrideConfig('General', 'enable_plugins_admin', '0');
testEnvironment.save();
await page.goto(pluginsUrl);
await captureMarketplace(mode + '_enable_plugins_admin_with_multiserver_enabled');
});
[expiredLicense, exceededLicense, validLicense, noLicense].forEach(function (consumer) {
it('should show a subscription overview for ' + consumer, async function() {
setEnvironment('superuser', consumer);
await page.goto('?module=Marketplace&action=subscriptionOverview');
await captureSelector('subscription_overview_' + consumer, '#content');
});
});
[noLicense, expiredLicense, exceededLicense].forEach(function (consumer) {
// when there is no license it should not show a warning! as it could be due to network problems etc
it('should show a warning if license is ' + consumer, async function() {
setEnvironment('superuser', consumer);
assumePaidPluginsActivated();
await page.goto('?module=UsersManager&action=index');
await captureSelector('notification_plugincheck_' + consumer, '#notificationContainer');
});
});
});
|