diff --git a/core/modules/node/src/Tests/AssertButtonsTrait.php b/core/modules/node/src/Tests/AssertButtonsTrait.php index 58d484d9e4..512ea2a1d8 100644 --- a/core/modules/node/src/Tests/AssertButtonsTrait.php +++ b/core/modules/node/src/Tests/AssertButtonsTrait.php @@ -2,8 +2,13 @@ namespace Drupal\node\Tests; +@trigger_error('\Drupal\Tests\node\Functional\AssertButtonsTrait is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\node\Functional\AssertButtonsTrait', E_USER_DEPRECATED); + /** * Asserts that buttons are present on a page. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use \Drupal\Tests\node\Functional\AssertButtonsTrait instead. */ trait AssertButtonsTrait { diff --git a/core/modules/node/src/Tests/AssertButtonsTrait.php b/core/modules/node/tests/src/Functional/AssertButtonsTrait.php similarity index 84% copy from core/modules/node/src/Tests/AssertButtonsTrait.php copy to core/modules/node/tests/src/Functional/AssertButtonsTrait.php index 58d484d9e4..bc2ef9078b 100644 --- a/core/modules/node/src/Tests/AssertButtonsTrait.php +++ b/core/modules/node/tests/src/Functional/AssertButtonsTrait.php @@ -1,6 +1,6 @@ xpath('//input[@type="submit"][@value="Save"]'); @@ -30,10 +30,11 @@ public function assertButtons($buttons, $dropbutton = TRUE) { $this->assertTrue(empty($save_button)); // Dropbutton elements. + /** @var \Behat\Mink\Element\NodeElement[] $elements */ $elements = $this->xpath('//div[@class="dropbutton-wrapper"]//input[@type="submit"]'); $this->assertEqual($count, count($elements)); foreach ($elements as $element) { - $value = isset($element['value']) ? (string) $element['value'] : ''; + $value = $element->getValue() ?: ''; $this->assertEqual($buttons[$i], $value); $i++; } diff --git a/core/modules/node/src/Tests/NodeAccessAutoBubblingTest.php b/core/modules/node/tests/src/Functional/NodeAccessAutoBubblingTest.php similarity index 92% rename from core/modules/node/src/Tests/NodeAccessAutoBubblingTest.php rename to core/modules/node/tests/src/Functional/NodeAccessAutoBubblingTest.php index 789818b408..6af8d8de66 100644 --- a/core/modules/node/src/Tests/NodeAccessAutoBubblingTest.php +++ b/core/modules/node/tests/src/Functional/NodeAccessAutoBubblingTest.php @@ -1,8 +1,9 @@ nidsVisible = []; foreach ($this->xpath("//a[text()='Read more']") as $link) { // See also testTranslationRendering() in NodeTranslationUITest. - $this->assertTrue(preg_match('|node/(\d+)$|', (string) $link['href'], $matches), 'Read more points to a node'); + $this->assertTrue(preg_match('|node/(\d+)$|', $link->getAttribute('href'), $matches), 'Read more points to a node'); $this->nidsVisible[$matches[1]] = TRUE; } foreach ($this->nodesByUser as $uid => $data) { diff --git a/core/modules/node/src/Tests/NodeAccessPagerTest.php b/core/modules/node/tests/src/Functional/NodeAccessPagerTest.php similarity index 95% rename from core/modules/node/src/Tests/NodeAccessPagerTest.php rename to core/modules/node/tests/src/Functional/NodeAccessPagerTest.php index b4fe8302e9..ad6cc54944 100644 --- a/core/modules/node/src/Tests/NodeAccessPagerTest.php +++ b/core/modules/node/tests/src/Functional/NodeAccessPagerTest.php @@ -1,18 +1,18 @@ adminUser = $this->drupalCreateUser(['administer site configuration', 'access administration pages', 'access site reports']); + $this->drupalLogin($this->adminUser); + + $this->webUser = $this->drupalCreateUser(); + } + + /** + * Tests rebuilding the node access permissions table with content. + */ + public function testNodeAccessRebuildNodeGrants() { + \Drupal::service('module_installer')->install(['node_access_test']); + \Drupal::state()->set('node_access_test.private', TRUE); + node_access_test_add_field(NodeType::load('page')); + $this->resetAll(); + + // Create 30 nodes so that _node_access_rebuild_batch_operation() has to run + // more than once. + for ($i = 0; $i < 30; $i++) { + $nodes[] = $this->drupalCreateNode([ + 'uid' => $this->webUser->id(), + 'private' => [['value' => 1]] + ]); + } + + /** @var \Drupal\node\NodeGrantDatabaseStorageInterface $grant_storage */ + $grant_storage = \Drupal::service('node.grant_storage'); + // Default realm access and node records are present. + foreach ($nodes as $node) { + $this->assertTrue($node->private->value); + $this->assertTrue($grant_storage->access($node, 'view', $this->webUser)->isAllowed(), 'Prior to rebuilding node access the grant storage returns allowed for the node author.'); + $this->assertTrue($grant_storage->access($node, 'view', $this->adminUser)->isAllowed(), 'Prior to rebuilding node access the grant storage returns allowed for the admin user.'); + } + + $this->assertEqual(1, \Drupal::service('node.grant_storage')->checkAll($this->webUser), 'There is an all realm access record'); + $this->assertTrue(\Drupal::state()->get('node.node_access_needs_rebuild'), 'Node access permissions need to be rebuilt'); + + // Rebuild permissions. + node_access_rebuild(FALSE); + + // Test if the rebuild by user that cannot bypass node access and does not + // have access to the nodes has been successful. + $this->assertFalse($this->adminUser->hasPermission('bypass node access')); + $this->assertNull(\Drupal::state()->get('node.node_access_needs_rebuild'), 'Node access permissions have been rebuilt'); + foreach ($nodes as $node) { + $this->assertTrue($grant_storage->access($node, 'view', $this->webUser)->isAllowed(), 'After rebuilding node access the grant storage returns allowed for the node author.'); + $this->assertFalse($grant_storage->access($node, 'view', $this->adminUser)->isForbidden(), 'After rebuilding node access the grant storage returns forbidden for the admin user.'); + } + $this->assertFalse(\Drupal::service('node.grant_storage')->checkAll($this->webUser), 'There is no all realm access record'); + + // Test an anonymous node access rebuild from code. + $this->drupalLogout(); + node_access_rebuild(); + foreach ($nodes as $node) { + $this->assertTrue($grant_storage->access($node, 'view', $this->webUser)->isAllowed(), 'After rebuilding node access the grant storage returns allowed for the node author.'); + $this->assertFalse($grant_storage->access($node, 'view', $this->adminUser)->isForbidden(), 'After rebuilding node access the grant storage returns forbidden for the admin user.'); + } + $this->assertFalse(\Drupal::service('node.grant_storage')->checkAll($this->webUser), 'There is no all realm access record'); + } + + /** + * Tests rebuilding the node access permissions table with no content. + */ + public function testNodeAccessRebuildNoAccessModules() { + // Default realm access is present. + $this->assertEqual(1, \Drupal::service('node.grant_storage')->count(), 'There is an all realm access record'); + + // No need to rebuild permissions. + $this->assertFalse(\Drupal::state()->get('node.node_access_needs_rebuild'), 'Node access permissions need to be rebuilt'); + + // Rebuild permissions. + node_access_rebuild(FALSE); + $this->assertNull(\Drupal::state()->get('node.node_access_needs_rebuild'), 'Node access permissions have been rebuilt'); + + // Default realm access is still present. + $this->assertEqual(1, \Drupal::service('node.grant_storage')->count(), 'There is an all realm access record'); + } + +} diff --git a/core/modules/node/src/Tests/NodeAdminTest.php b/core/modules/node/tests/src/Functional/NodeAdminTest.php similarity index 98% rename from core/modules/node/src/Tests/NodeAdminTest.php rename to core/modules/node/tests/src/Functional/NodeAdminTest.php index 8bf54cc294..24a50cf51a 100644 --- a/core/modules/node/src/Tests/NodeAdminTest.php +++ b/core/modules/node/tests/src/Functional/NodeAdminTest.php @@ -1,6 +1,6 @@ assertLinkByHref('node/' . $node->id() . '/edit'); $this->assertLinkByHref('node/' . $node->id() . '/delete'); // Verify that we can see the content type label. - $this->assertEqual(trim((string) $node_type_labels[$delta]), $node->type->entity->label()); + $this->assertEqual(trim($node_type_labels[$delta]->getText()), $node->type->entity->label()); $delta++; } diff --git a/core/modules/node/src/Tests/NodeBlockFunctionalTest.php b/core/modules/node/tests/src/Functional/NodeBlockFunctionalTest.php similarity index 99% rename from core/modules/node/src/Tests/NodeBlockFunctionalTest.php rename to core/modules/node/tests/src/Functional/NodeBlockFunctionalTest.php index 5a2e40a30d..ad3613d74f 100644 --- a/core/modules/node/src/Tests/NodeBlockFunctionalTest.php +++ b/core/modules/node/tests/src/Functional/NodeBlockFunctionalTest.php @@ -1,6 +1,6 @@ assertNoText('Data that should appear only in the body for the node.', 'Body text not present'); // Test that the correct build mode has been set. - $build = $this->drupalBuildEntityView($node); + $build = $this->buildEntityView($node); $this->assertEqual($build['#view_mode'], 'teaser', 'The view mode has correctly been set to teaser.'); } diff --git a/core/modules/node/src/Tests/NodeFieldMultilingualTest.php b/core/modules/node/tests/src/Functional/NodeFieldMultilingualTest.php similarity index 95% rename from core/modules/node/src/Tests/NodeFieldMultilingualTest.php rename to core/modules/node/tests/src/Functional/NodeFieldMultilingualTest.php index edd01b2d00..771426d025 100644 --- a/core/modules/node/src/Tests/NodeFieldMultilingualTest.php +++ b/core/modules/node/tests/src/Functional/NodeFieldMultilingualTest.php @@ -1,19 +1,19 @@ ' node ', ':content-class' => 'node__content', ]); - $this->assertEqual(current($body), $node->body->value, 'Node body found.'); + $this->assertEqual($body[0]->getText(), $node->body->value, 'Node body found.'); } } diff --git a/core/modules/node/src/Tests/NodeFormButtonsTest.php b/core/modules/node/tests/src/Functional/NodeFormButtonsTest.php similarity index 99% rename from core/modules/node/src/Tests/NodeFormButtonsTest.php rename to core/modules/node/tests/src/Functional/NodeFormButtonsTest.php index ed2bb8f7a4..546a6334ad 100644 --- a/core/modules/node/src/Tests/NodeFormButtonsTest.php +++ b/core/modules/node/tests/src/Functional/NodeFormButtonsTest.php @@ -1,6 +1,6 @@ tag. $this->drupalGet('node/' . $node->id()); $xpath = '//title'; - $this->assertEqual(current($this->xpath($xpath)), $node->label() . ' | Drupal', 'Page title is equal to node title.', 'Node'); + $this->assertEqual($this->xpath($xpath)[0]->getText(), $node->label() . ' | Drupal', 'Page title is equal to node title.', 'Node'); // Test breadcrumb in comment preview. $this->drupalGet('comment/reply/node/' . $node->id() . '/comment'); $xpath = '//nav[@class="breadcrumb"]/ol/li[last()]/a'; - $this->assertEqual(current($this->xpath($xpath)), $node->label(), 'Node breadcrumb is equal to node title.', 'Node'); + $this->assertEqual($this->xpath($xpath)[0]->getText(), $node->label(), 'Node breadcrumb is equal to node title.', 'Node'); // Test node title in comment preview. - $this->assertEqual(current($this->xpath('//article[contains(concat(" ", normalize-space(@class), " "), :node-class)]/h2/a/span', [':node-class' => ' node--type-' . $node->bundle() . ' '])), $node->label(), 'Node preview title is equal to node title.', 'Node'); + $this->assertEqual($this->xpath('//article[contains(concat(" ", normalize-space(@class), " "), :node-class)]/h2/a/span', [':node-class' => ' node--type-' . $node->bundle() . ' '])[0]->getText(), $node->label(), 'Node preview title is equal to node title.', 'Node'); // Test node title is clickable on teaser list (/node). $this->drupalGet('node'); @@ -92,11 +92,11 @@ public function testNodeTitle() { // the page. $edge_case_title_escaped = Html::escape($edge_case_title); $this->drupalGet('node/' . $node->id()); - $this->assertTitle($edge_case_title_escaped . ' | Drupal', 'Page title is equal to article\'s "title".', 'Node'); + $this->assertRaw($edge_case_title_escaped . ' | Drupal', 'Page title is equal to article\'s "title".', 'Node'); // Test that the title appears as