2

I would like to create a Behat test that confirms a user can only see content they own or are referenced in. The struggle is that I can't figure out how to assign the content to created user.

Starting with something like:

Given users:
| name | status |
| test | 1      |
Given "Page" content:
| title | uid |
| A title | ?? |

I need to create several nodes to test, and it seems...odd... that I would need to do the entire steps (e.g. Then I go to register, then I go to node/add/page, ....).

How do I know the uid of the user created in the Given?

2
  • 1
    Are you trying to add content as a fixture/mock to test something else? What driver are you using?
    – mradcliffe
    Commented Oct 24, 2017 at 20:24
  • @mradcliffe I'm testing that a user sees a list of content that a) they own or b) they have been referenced in. I just found nuvole.org/blog/2015/mar/24/… which seems to be what I need (user "author") Commented Oct 24, 2017 at 20:34

1 Answer 1

2

In the example in features/api.feature you'll find how to do this:

  Scenario: Create nodes with specific authorship
    Given users:
    | name     | mail            | status |
    | Joe User | [email protected] | 1      |
    And "article" nodes:
    | title          | author   | body             | promote |
    | Article by Joe | Joe User | PLACEHOLDER BODY | 1       |
    When I am logged in as a user with the "administrator" role
    And I am on the homepage
    And I follow "Article by Joe"
    Then I should see the link "Joe User"

Your Answer

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

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