Chris@17: /** Chris@17: * Logs into Drupal as the given user. Chris@17: * Chris@17: * @param {object} settings Chris@17: * Settings object Chris@17: * @param {string} settings.name Chris@17: * The user name. Chris@17: * @param {string} settings.password Chris@17: * The user password. Chris@17: * @param {array} [settings.permissions=[]] Chris@17: * The list of permissions granted for the user. Chris@17: * @param {function} callback Chris@17: * A callback which will be called, when the creating the use is finished. Chris@17: * @return {object} Chris@17: * The drupalCreateUser command. Chris@17: */ Chris@17: exports.command = function drupalCreateUser( Chris@17: { name, password, permissions = [] }, Chris@17: callback, Chris@17: ) { Chris@17: const self = this; Chris@17: Chris@17: let role; Chris@17: this.perform((client, done) => { Chris@17: if (permissions) { Chris@17: client.drupalCreateRole({ permissions, name: null }, newRole => { Chris@17: role = newRole; Chris@17: done(); Chris@17: }); Chris@17: } else { Chris@17: done(); Chris@17: } Chris@17: }).drupalLoginAsAdmin(() => { Chris@17: this.drupalRelativeURL('/admin/people/create') Chris@17: .setValue('input[name="name"]', name) Chris@17: .setValue('input[name="pass[pass1]"]', password) Chris@17: .setValue('input[name="pass[pass2]"]', password) Chris@17: .perform((client, done) => { Chris@17: if (role) { Chris@17: client.click(`input[name="roles[${role}]`, () => { Chris@17: done(); Chris@17: }); Chris@17: } else { Chris@17: done(); Chris@17: } Chris@17: }) Chris@17: .submitForm('#user-register-form') Chris@17: .assert.containsText( Chris@17: '.messages', Chris@17: 'Created a new user account', Chris@17: `User "${name}" was created succesfully.`, Chris@17: ); Chris@17: }); Chris@17: Chris@17: if (typeof callback === 'function') { Chris@17: callback.call(self); Chris@17: } Chris@17: Chris@17: return this; Chris@17: };