1

I'm trying to write Behat tests to verify my Drupal Commerce store.

My test creates some users, so I know the usernames but not the UIDs (the UIDs are assigned by Drupal in the test, so they will be different each time).

So, I want to get the UID based on the username, and then redirect to the payment method page for that user with a step like When I go to the payment method page for username ABC.

Here's my code:

  /**
   * @Then I go to the payment method page for username :username
   */
  public function iGoToThePaymentMethodPageForUsername($username) {
    $user_object = $this->userManager->getUser($username);
    $uid = $user_object->id;
    if (!(is_int($uid))) {
      throw new Exception("UID is not a number ('$uid')");
    }
    $this->visitPath("user/$uid/payment-methods");
  }

However, this code fails with the following error message:

  No user with ABC name is registered with the driver.

When I checked this->userManager->getUsers(), I found that it only has the users generated by the Drupal extension in the current scenario; I cannot access the users who have been registered in other scenarios or users who have already registered outside of Behat.

What's the correct way to get the user object for such a user?

1 Answer 1

1

You could use Sub-pathauto which will allow you to use /user/username/somewhere instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.