-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathOneClickUpdate_spec.js
More file actions
164 lines (131 loc) · 6.4 KB
/
OneClickUpdate_spec.js
File metadata and controls
164 lines (131 loc) · 6.4 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
/*!
* Matomo - free/libre analytics platform
*
* OneClickUpdate screenshot tests.
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
var fs = require('fs'),
path = require('../../lib/screenshot-testing/support/path');
const request = require('request-promise');
const exec = require('child_process').exec;
describe("OneClickUpdate", function () {
this.fixture = "Piwik\\Tests\\Fixtures\\LatestStableInstall";
const latestStableUrl = config.piwikUrl + '/latestStableInstall/index.php';
const settingsUrl = latestStableUrl + '?module=CoreAdminHome&action=home&idSite=1&period=day&date=yesterday';
function readUpdateDetailsTokenFromConfig() {
const pathConfigIni = path.join(PIWIK_INCLUDE_PATH, '/latestStableInstall/config/config.ini.php');
const configFile = fs.readFileSync(pathConfigIni);
const match = ('' + configFile).match(/update_details_token\s?=\s?"(.*)"/);
return match && match[1] ? match[1] : null;
}
it('should show the new version available button in the admin screen', async function () {
await page.goto(latestStableUrl);
await page.waitForNetworkIdle();
await page.waitForSelector('#login_form_login', { visible: true });
await page.type('#login_form_login', superUserLogin);
await page.type('#login_form_password', superUserPassword);
await page.evaluate(function(){
$('#login_form_submit').click();
});
await page.waitForNetworkIdle();
await page.waitForSelector('.pageWrap');
await page.goto(settingsUrl);
await page.waitForNetworkIdle();
const element = await page.waitForSelector('#header_message', { visible: true });
expect(await element.screenshot()).to.matchImage('latest_version_available');
});
it('should show the one click update screen when the update button is clicked', async function () {
await page.click('#header_message');
await page.waitForNetworkIdle();
await page.waitForSelector('.content');
expect(await page.screenshot({ fullPage: true })).to.matchImage('update_screen');
});
it('should fail to automatically update when trying to update over https fails', async function () {
await page.click('#updateAutomatically');
await page.waitForNetworkIdle();
await page.waitForSelector('.content');
expect(await page.screenshot({ fullPage: true })).to.matchImage('update_fail');
});
it('should fail when a directory is not writable', async function () {
fs.chmodSync(path.join(PIWIK_INCLUDE_PATH, '/latestStableInstall/core'), 0o555);
await page.waitForTimeout(100);
await page.click('#updateUsingHttp');
await page.waitForNetworkIdle();
await page.evaluate(function(directory) {
$('.alert-danger').html($('.alert-danger').html().replace(directory, '/hiddenpath/latestStableInstall/core'));
}, path.join(PIWIK_INCLUDE_PATH, '/latestStableInstall/core'));
expect(await page.screenshot({ fullPage: true })).to.matchImage('update_fail_permission');
});
it('should update successfully and show the finished update screen', async function () {
fs.chmodSync(path.join(PIWIK_INCLUDE_PATH, '/latestStableInstall/core'), 0o777);
await page.waitForTimeout(100);
await page.goBack();
await page.click('#updateUsingHttp');
await page.waitForNetworkIdle();
await page.waitForSelector('.content');
expect(await page.screenshot({ fullPage: true })).to.matchImage('update_success');
// check update details token has been created
const updateDetailsToken = readUpdateDetailsTokenFromConfig();
const runUpdaterLink = await page.$eval('.footer a', link => link.getAttribute('href'));
if (updateDetailsToken) {
expect(runUpdaterLink).to.match(new RegExp(`[?&]updateDetailsToken=${updateDetailsToken}(?:&|$)`));
} else {
expect(runUpdaterLink).to.not.match(/[?&]updateDetailsToken=/);
}
});
it('should login successfully after the update', async function () {
await page.click('.footer a');
await page.waitForNetworkIdle();
// in case a db upgrade is required
while (true) {
const submitButton = await page.$('.content input[type=submit]');
if (submitButton) {
await submitButton.click();
await page.waitForNetworkIdle();
await page.waitForTimeout(250);
const continueButton = await page.$('.footer a');
if (continueButton) { // finish page might not be displayed if only one query is executed
await continueButton.click();
await page.waitForNetworkIdle();
}
} else {
break;
}
}
// avoid taking an unnecessary screenshot, as knowing we land on #site-without-data is enough
await page.waitForSelector('#site-without-data', { visible: true });
await page.evaluate(() => window.stop()); // stop ongoing requests
// check update details token has been removed
const updateDetailsToken = readUpdateDetailsTokenFromConfig();
expect(updateDetailsToken).to.be.not.ok;
});
it('should have a working cron archiving process', async function () {
// track one action
const trackerUrl = config.piwikUrl + "latestStableInstall/piwik.php?";
await request({
method: 'POST',
uri: trackerUrl,
form: {
idsite: 1,
url: 'http://piwik.net/test/url',
action_name: 'test page',
},
});
// run cron archiving
const output = await new Promise((resolve, reject) => {
exec(`${config.php} ${PIWIK_INCLUDE_PATH}/latestStableInstall/console --matomo-domain=${config.phpServer.HTTP_HOST} core:archive`, (error, stdout, stderr) => {
const output = stdout.toString() + "\n" + stderr.toString();
if (error) {
console.log(`core:archive failed, output: ${output}`);
reject(error);
return;
}
resolve(output);
});
});
// check output has no errors
expect(output).to.not.match(/ERROR|WARN/g);
});
});