diff --git a/core/modules/views/src/Tests/NodeAccessTest.php b/core/modules/views/src/Tests/NodeAccessTest.php index dc5296a..1a9204f 100644 --- a/core/modules/views/src/Tests/NodeAccessTest.php +++ b/core/modules/views/src/Tests/NodeAccessTest.php @@ -50,12 +50,11 @@ protected function setUp() { parent::setUp(FALSE); // User to add and remove language. - $this->adminUser = $this->drupalCreateUser(['access administration pages']); + $this->adminUser = $this->drupalCreateUser(['bypass node access']); // User to check non-admin access. - $this->regularUser = $this->drupalCreateUser(); + $this->regularUser = $this->drupalCreateUser(['access content']); // Create Basic page and Article node types. - //$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']); $field_names = $this->setUpFieldStorages(1); @@ -91,15 +90,15 @@ protected function setUp() { ]); $field->save(); - // Now create some example nodes/users for the view result. + // Now create some example nodes for the view result. for ($i = 0; $i < 2; $i++) { $edit = [ $field_names[0] => [ ['value' => $this->randomMachineName()], ], ]; - if ($i > 1) { - // Set the entity reference field values. + if ($i > 0) { + // For 2nd node, set the entity reference field value to the 1st node. $edit['field_related_pages'][0]['target_id'] = 1; } $nodes[] = $this->drupalCreateNode($edit); @@ -115,53 +114,31 @@ protected function setUp() { * */ function testViewsData() { - $view = Views::getView('test_articles'); - $view->setDisplay(); + $this->drupalLogin($this->regularUser); + $this->drupalGet('test-articles'); + $rows = count($this->xpath("//div[@class='views-row']")); + $this->assertTrue($rows == 2, "View has right amount of rows."); - // Execute the view as anonymous user. - $view->execute(); - - // Assert the row count of the view. - $count = count($view->result); - debug($count); - $this->assertEqual(2, $count, 'The number of returned rows match.'); $this->drupalLogin($this->adminUser); - $view->execute(); - - // Assert the row count of the view. - $count = count($view->result); - debug($count); - $this->assertEqual(2, $count, 'The number of returned rows match.'); + $this->drupalGet('test-articles'); + $rows = count($this->xpath("//div[@class='views-row']")); + $this->assertTrue($rows == 2, "View has right amount of rows."); + // Rebuild permissions. // Enable the mynodeaccess module. \Drupal::service('module_installer')->install(['views_test_mynodeaccess']); - - - // Rebuild permissions. - /*$this->drupalGet('admin/reports/status/rebuild'); - $this->drupalPostForm(NULL, array(), t('Rebuild permissions')); - $this->assertText(t('The content access permissions have been rebuilt.'));*/ node_access_rebuild(); - // Execute the view: admin and anonymous users will again see the same thing. - $this->drupalLogin($this->adminUser); - $view->execute(); - - // Assert the row count of the view. - $count = count($view->result); - debug($count); - $this->assertEqual(2, $count, 'The number of returned rows match.'); - // Execute the view as anonymous user. - - $this->drupalLogout(); - $view->execute(); - - // Assert the row count of the view. - $count = count($view->result); - debug($count); - $this->assertEqual(2, $count, 'The number of returned rows match.'); + $this->drupalLogin($this->regularUser); + $this->drupalGet('test-articles'); + $rows = count($this->xpath("//div[@class='views-row']")); + $this->assertTrue($rows == 2, "View has right amount of rows."); + $this->drupalLogin($this->adminUser); + $this->drupalGet('test-articles'); + $rows = count($this->xpath("//div[@class='views-row']")); + $this->assertTrue($rows == 2, "View has right amount of rows."); } }