Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / tests / Drupal / Nightwatch / Commands / drupalCreateUser.js
1 /**
2  * Logs into Drupal as the given user.
3  *
4  * @param {object} settings
5  *   Settings object
6  * @param {string} settings.name
7  *   The user name.
8  * @param {string} settings.password
9  *   The user password.
10  * @param {array} [settings.permissions=[]]
11  *   The list of permissions granted for the user.
12  * @param {function} callback
13  *   A callback which will be called, when the creating the use is finished.
14  * @return {object}
15  *   The drupalCreateUser command.
16  */
17 exports.command = function drupalCreateUser(
18   { name, password, permissions = [] },
19   callback,
20 ) {
21   const self = this;
22
23   let role;
24   this.perform((client, done) => {
25     if (permissions) {
26       client.drupalCreateRole({ permissions, name: null }, newRole => {
27         role = newRole;
28         done();
29       });
30     } else {
31       done();
32     }
33   }).drupalLoginAsAdmin(() => {
34     this.drupalRelativeURL('/admin/people/create')
35       .setValue('input[name="name"]', name)
36       .setValue('input[name="pass[pass1]"]', password)
37       .setValue('input[name="pass[pass2]"]', password)
38       .perform((client, done) => {
39         if (role) {
40           client.click(`input[name="roles[${role}]`, () => {
41             done();
42           });
43         } else {
44           done();
45         }
46       })
47       .submitForm('#user-register-form')
48       .assert.containsText(
49         '.messages',
50         'Created a new user account',
51         `User "${name}" was created succesfully.`,
52       );
53   });
54
55   if (typeof callback === 'function') {
56     callback.call(self);
57   }
58
59   return this;
60 };