Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / tests / Drupal / Nightwatch / Commands / drupalLogin.js
diff --git a/web/core/tests/Drupal/Nightwatch/Commands/drupalLogin.js b/web/core/tests/Drupal/Nightwatch/Commands/drupalLogin.js
new file mode 100644 (file)
index 0000000..5fccdfc
--- /dev/null
@@ -0,0 +1,33 @@
+/**
+ * Logs into Drupal as the given user.
+ *
+ * @param {string} name
+ *   The user name.
+ * @param {string} password
+ *   The user password.
+ * @return {object}
+ *   The drupalUserIsLoggedIn command.
+ */
+exports.command = function drupalLogin({ name, password }) {
+  this.drupalUserIsLoggedIn(sessionExists => {
+    // Log the current user out if necessary.
+    if (sessionExists) {
+      this.drupalLogout();
+    }
+    // Log in with the given credentials.
+    this.drupalRelativeURL('/user/login')
+      .setValue('input[name="name"]', name)
+      .setValue('input[name="pass"]', password)
+      .submitForm('#user-login-form');
+    // Assert that a user is logged in.
+    this.drupalUserIsLoggedIn(sessionExists => {
+      this.assert.equal(
+        sessionExists,
+        true,
+        `The user "${name}" was logged in.`,
+      );
+    });
+  });
+
+  return this;
+};