function NodeAccessUnpublishedCacheabilityTest::testNodeAccessCacheabilityBubbleUpOnUnpublishedContent

Tests correct cacheability information bubbles up from node access.

File

core/modules/node/tests/src/Functional/NodeAccessUnpublishedCacheabilityTest.php, line 32

Class

NodeAccessUnpublishedCacheabilityTest
Tests cacheability on unpublished nodes inherited from node access.

Namespace

Drupal\Tests\node\Functional

Code

public function testNodeAccessCacheabilityBubbleUpOnUnpublishedContent() : void {
  $rid = $this->drupalCreateRole([
    'access content',
    'view own unpublished content',
  ]);
  $test_user1 = $this->drupalCreateUser(values: [
    'roles' => [
      $rid,
    ],
  ]);
  $test_user2 = $this->drupalCreateUser(values: [
    'roles' => [
      $rid,
    ],
  ]);
  $unpublished_node_by_test_user1 = $this->createNode([
    'type' => 'page',
    'uid' => $test_user1->id(),
    'status' => NodeInterface::NOT_PUBLISHED,
  ]);
  $this->drupalLogin($test_user2);
  $this->drupalGet('node_access_test_auto_bubbling_node_access/' . $unpublished_node_by_test_user1->id());
  $this->assertSession()
    ->pageTextNotContains($unpublished_node_by_test_user1->label());
  // The author of the unpublished node must have access.
  $this->drupalLogin($test_user1);
  $this->drupalGet('node_access_test_auto_bubbling_node_access/' . $unpublished_node_by_test_user1->id());
  $this->assertSession()
    ->pageTextContains($unpublished_node_by_test_user1->label());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.