Reputation: 1693
I am testing a controller method and I am accessing a route in a test.
Then I would like to make sure that the correct model was returned in the view and was loaded with all of the correct relationships.
I know that I can do this:
$this->assertViewHas("content");
But can how can I verify that the content model that was returned into the view has the correct, for example, category? i.e. how can I get the content model object and then do something like
$this->assertEquals($content->category->name, "category 1");
?
Upvotes: 5
Views: 7073
Reputation: 141
You can use
$your_desired_data = $response->assertSee('var_tag');
and if it's an array of data you can access its data by:
$first_name = $your_desired_data['first_name'];
Upvotes: 1
Reputation: 132
You can get your content from the response like this:
$content = $response->getOriginalContent()->getData()['content'];
getData()
returns the data sent to the view as an array.
Upvotes: 5
Reputation: 18833
You can use the following to get the array that's passed to the view:
$response->original->getData()
This comes from Illuminate/Http/ResponseTrait (link to docs).
Upvotes: 3