Chris@17: /** Chris@17: * Creates role with given permissions. Chris@17: * Chris@17: * @param {object} settings Chris@17: * Settings object Chris@17: * @param {array} settings.permissions Chris@17: * The list of roles granted for the user. Chris@17: * @param {string} [settings.name=null] Chris@17: * The role name. Chris@17: * @param {function} callback Chris@17: * A callback which will be called, when creating the role is finished. Chris@17: * @return {object} Chris@17: * The drupalCreateRole command. Chris@17: */ Chris@17: exports.command = function drupalCreateRole( Chris@17: { permissions, name = null }, Chris@17: callback, Chris@17: ) { Chris@17: const self = this; Chris@17: const roleName = Chris@17: name || Chris@17: Math.random() Chris@17: .toString(36) Chris@17: .substring(2, 15); Chris@17: Chris@17: let machineName; Chris@17: this.drupalLoginAsAdmin(() => { Chris@17: this.drupalRelativeURL('/admin/people/roles/add') Chris@17: .setValue('input[name="label"]', roleName) Chris@17: // Wait for the machine name to appear so that it can be used later to Chris@17: // select the permissions from the permission page. Chris@17: .expect.element('.user-role-form .machine-name-value') Chris@17: .to.be.visible.before(2000); Chris@17: Chris@17: this.perform(done => { Chris@17: this.getText('.user-role-form .machine-name-value', element => { Chris@17: machineName = element.value; Chris@17: done(); Chris@17: }); Chris@17: }) Chris@17: .submitForm('#user-role-form') Chris@17: .drupalRelativeURL('/admin/people/permissions') Chris@17: .perform((client, done) => { Chris@17: Promise.all( Chris@17: permissions.map( Chris@17: permission => Chris@17: new Promise(resolve => { Chris@17: client.click( Chris@17: `input[name="${machineName}[${permission}]"]`, Chris@17: () => { Chris@17: resolve(); Chris@17: }, Chris@17: ); Chris@17: }), Chris@17: ), Chris@17: ).then(() => { Chris@17: done(); Chris@17: }); Chris@17: }) Chris@17: .submitForm('#user-admin-permissions'); Chris@17: }).perform(() => { Chris@17: if (typeof callback === 'function') { Chris@17: callback.call(self, machineName); Chris@17: } Chris@17: }); Chris@17: Chris@17: return this; Chris@17: };