From 88a0399f39e21d8d584159ddea3634a1a1e0600d Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sat, 21 Oct 2017 20:35:37 +0100 Subject: [PATCH] Get the result of the view --- .gitignore | 1 + tests/src/Functional/PageListTest.php | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2659611 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +composer.lock diff --git a/tests/src/Functional/PageListTest.php b/tests/src/Functional/PageListTest.php index 3ea80a5..42030c0 100644 --- a/tests/src/Functional/PageListTest.php +++ b/tests/src/Functional/PageListTest.php @@ -39,7 +39,17 @@ class PageListTest extends BrowserTestBase { // This page is not published, so it should not be visible. $this->drupalCreateNode(['type' => 'page', 'status' => FALSE]); - // When I view the page. + // 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. }