X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Ftests%2FDrupal%2FNightwatch%2FCommands%2FdrupalLogout.js;fp=web%2Fcore%2Ftests%2FDrupal%2FNightwatch%2FCommands%2FdrupalLogout.js;h=6ab29e6d40ad23610900e5de0cd6fa0aad7ebff8;hp=0000000000000000000000000000000000000000;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/tests/Drupal/Nightwatch/Commands/drupalLogout.js b/web/core/tests/Drupal/Nightwatch/Commands/drupalLogout.js new file mode 100644 index 000000000..6ab29e6d4 --- /dev/null +++ b/web/core/tests/Drupal/Nightwatch/Commands/drupalLogout.js @@ -0,0 +1,36 @@ +import { execSync } from 'child_process'; +import { URL } from 'url'; + +/** + * Logs out from a Drupal site. + * + * @param {object} [settings={}] + * The settings object. + * @param {boolean} [settings.silent=false] + * If the command should be run silently. + * @param {function} callback + * A callback which will be called, when the logout is finished. + * @return {object} + * The drupalLogout command. + */ +exports.command = function drupalLogout({ silent = false } = {}, callback) { + const self = this; + + this.drupalRelativeURL('/user/logout'); + + this.drupalUserIsLoggedIn(sessionExists => { + if (silent) { + if (sessionExists) { + throw new Error('Logging out failed.'); + } + } else { + this.assert.equal(sessionExists, false, 'The user was logged out.'); + } + }); + + if (typeof callback === 'function') { + callback.call(self); + } + + return this; +};