3

I am doing some work that requires customization of a breadcrumb for only one content type. I'm trying to write a behat test to verify it.

My Given is successfully creating the nodes, and I can verify that they are there if I tell behat to look at them in the admin content view:

Scenario:
  Given "partner_accomodation" content:
    |title            | body         | status|
    |Accomodation Foo | Test content | 1     |
  And I am logged in as a user with the "administrator" role
  When I go to "admin/content"
  Then I should see "Accomodation Foo"

What I can't figure out though is how to tell it visit that specific page. I would assume if I have pathauto configured correctly, that I should be able to go something like

When I go to "accomodation-foo"

Is there a way to know the node id or the URL alias of the content it created?

4

You can do two things in this scenario:

You can instruct it to click on "Accomodation Foo" (which should be the linked node title) on this page, to go to the node when the path is unknown.

If you have pathauto installed and configured, you can assume the path, so if it is [node:title], the path in this case is likely 'accomodation-foo'.

I use both in different cases, depending on the scenario. I keep the test node titles small and predictable so I know what the path (should) be. If the path isn't found, it is also a good way to test if Pathauto is creating the URLs you expect.

Here is an example one I wrote not too long ago:

Feature: Page Content Type (Anonymous)
  When I view the website
  As an anonymous user
  I should be able to view basic page content and its fields

  Background:
    Given "page" content:
      | title                     | status  | body             |  field_subtitle       |  field_summary            |
      | Published page            |       1 | PLACEHOLDER BODY |  This is the subtitle |  This is the page summary |
      | Unpublished page          |       0 | PLACEHOLDER BODY |  This is the subtitle |  This is the page summary |
    And I am on "published-page"

  Scenario: An anonymous user should be able access published basic page content
    Then I should not see "You are not authorized to access this page."

  Scenario: An anonymous user should be able to view the title
    Then I should see "Published page" in the summary region

  Scenario: An anonymous user should be able to view the subtitle
    Then I should see "This is the subtitle" in the summary region

  Scenario: An anonymous user should be able to view the page summary
    Then I should see "This is the page summary" in the summary region

  Scenario: An anonymous user should not be able access unpublished basic page content
    When I go to "unpublished-page"
    Then I should see "You are not authorized to access this page."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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