drupalGet('pages'); $this->assertSession()->statusCodeEquals(200); } /** * Ensure that only the correct nodes are returned. * * Ensure that only published pages are returned by the view. Unpublished * pages or content of different types should not be shown. */ public function testOnlyPublishedPagesAreShown() { $this->drupalCreateContentType(['type' => 'article']); // This is a published page, so it should be visible. $this->drupalCreateNode(['type' => 'page', 'status' => TRUE]); // This is an article, so it should not be visible. $this->drupalCreateNode(['type' => 'article']); // This page is not published, so it should not be visible. $this->drupalCreateNode(['type' => 'page', 'status' => FALSE]); // Rather than testing the rendered HTML, we are going to load the view // results programmatically and run assertions against the data it returns. // This makes it easier to test certain scenarios, and ensures that the // test is future-proofed and won't fail at a later date due to a change in // the presentation code. $result = views_get_view_result('pages'); // $result contains an array of Drupal\views\ResultRow objects. We can use // a Collection here to pluck the nid from each node and return them as an // array. $nids = collect($result)->pluck('nid')->all(); // Then I should only see the published pages. } }