drupalextension icon indicating copy to clipboard operation
drupalextension copied to clipboard

Given :name create(s) a/an :type (content ) with the title :title

Open jonathanjfshaw opened this issue 8 years ago • 1 comments

The lovely new UserManager service enables the following step. Is it worth including in DrupalContext?

/**
   * Creates content of the given type.
   *
   * @Given :name create(s) a/an :type (content ) with the title :title
   * @Given I am viewing a/an :type (content )(created )by :name with the title :title
   * @Given a/an :type (content )(created )by :name with the title :title
   */
  public function userCreatesNode($type, $title, $name) {
    if ($name === 'me' || $name === 'I') {
      $uid = $this->getUserManager()->getCurrentUser()->uid;
    }
    else {
      $uid = $this->getUserManager()->getUser($name)->uid;
    }
    $node = (object) array(
      'title' => $title,
      'type' => $type,
      'uid' => $uid,
    );
    $saved = $this->nodeCreate($node);
    // Set internal page on the new node.
    $this->getSession()->visit($this->locatePath('/node/' . $saved->nid));
  }

I haven't tried, but I think this could be combined with the existing createNode step definition, so it doesn't bloat the number of step definitions being maintained.

jonathanjfshaw avatar Feb 12 '17 14:02 jonathanjfshaw

Makes sense to me!

jhedstrom avatar Dec 05 '17 19:12 jhedstrom