Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't throw an exception when attempting to delete role that doesn't exist #210

Open
bkosborne opened this issue Oct 8, 2019 · 0 comments · May be fixed by #211
Open

Don't throw an exception when attempting to delete role that doesn't exist #210

bkosborne opened this issue Oct 8, 2019 · 0 comments · May be fixed by #211

Comments

@bkosborne
Copy link

In RawDrupalContext, there is an AfterScenario that deletes roles that were programmatically created by other step definitions that were executed:

  /**
   * Remove any created roles.
   *
   * @AfterScenario
   */
  public function cleanRoles() {
    // Remove any roles that were created.
    foreach ($this->roles as $rid) {
      $this->getDriver()->roleDelete($rid);
    }
    $this->roles = array();
  }

For the Drupal8 core, this code gets run:

  /**
   * {@inheritdoc}
   */
  public function roleDelete($role_name) {
    $role = user_role_load($role_name);

    if (!$role) {
      throw new \RuntimeException(sprintf('No role "%s" exists.', $role_name));
    }

    $role->delete();
  }

The problem is that the role may no longer exist, since actions taken during the step may have deleted the role. This exception causes the test to fail even though everything is fine.

I noticed that the other "delete" methods on the Drupal8 core first check that the entity being deleted exists before deleting it. I think we should do the same here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant