Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / tests / Drupal / Nightwatch / Commands / drupalLoginAsAdmin.js
1 import { execSync } from 'child_process';
2 import { URL } from 'url';
3 import { commandAsWebserver } from '../globals';
4
5 /**
6  * Logs in as the admin user.
7  *
8  * @param {function} callback
9  *   A callback which will allow running commands as an administrator.
10  * @return {object}
11  *   The drupalLoginAsAdmin command.
12  */
13 exports.command = function drupalLoginAsAdmin(callback) {
14   const self = this;
15   this.drupalUserIsLoggedIn(sessionExists => {
16     if (sessionExists) {
17       this.drupalLogout();
18     }
19     const userLink = execSync(
20       commandAsWebserver(
21         `php ./scripts/test-site.php user-login 1 --site-path ${
22           this.drupalSitePath
23         }`,
24       ),
25     );
26
27     this.drupalRelativeURL(userLink.toString());
28
29     this.drupalUserIsLoggedIn(sessionExists => {
30       if (!sessionExists) {
31         throw new Error('Logging in as an admin user failed.');
32       }
33     });
34   });
35
36   if (typeof callback === 'function') {
37     callback.call(self);
38   }
39
40   this.drupalLogout({ silent: true });
41
42   return this;
43 };