function LayoutBuilderFieldBlockEntityReferenceCacheTagsTest::testEntityReferenceFieldBlockCaching
Same name in other branches
- 8.9.x core/modules/layout_builder/tests/src/Functional/LayoutBuilderFieldBlockEntityReferenceCacheTagsTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderFieldBlockEntityReferenceCacheTagsTest::testEntityReferenceFieldBlockCaching()
- 10 core/modules/layout_builder/tests/src/Functional/LayoutBuilderFieldBlockEntityReferenceCacheTagsTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderFieldBlockEntityReferenceCacheTagsTest::testEntityReferenceFieldBlockCaching()
- 11.x core/modules/layout_builder/tests/src/Functional/LayoutBuilderFieldBlockEntityReferenceCacheTagsTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderFieldBlockEntityReferenceCacheTagsTest::testEntityReferenceFieldBlockCaching()
Tests cache tags on field block for entity reference field.
File
-
core/
modules/ layout_builder/ tests/ src/ Functional/ LayoutBuilderFieldBlockEntityReferenceCacheTagsTest.php, line 73
Class
- LayoutBuilderFieldBlockEntityReferenceCacheTagsTest
- Tests cache tags on entity reference field blocks in Layout Builder.
Namespace
Drupal\Tests\layout_builder\FunctionalCode
public function testEntityReferenceFieldBlockCaching() {
$assert_session = $this->assertSession();
// Create two nodes, one of the referenced content type and one of the
// referencing content type, with the first node being referenced by the
// second. Set the referenced node to be unpublished so anonymous user will
// not have view access.
$referenced_node = $this->createNode([
'type' => 'bundle_referenced',
'title' => 'The referenced node title',
'status' => 0,
]);
$referencing_node = $this->createNode([
'type' => 'bundle_with_reference_field',
'title' => 'The referencing node title',
'field_reference' => [
'entity' => $referenced_node,
],
]);
// When user does not have view access to referenced entities in entity
// reference field blocks, test that the cache tags of the referenced entity
// are still bubbled to page cache.
$referencing_node_url = $referencing_node->toUrl();
$this->verifyPageCacheContainsTags($referencing_node_url, 'MISS');
$this->verifyPageCacheContainsTags($referencing_node_url, 'HIT', $referenced_node->getCacheTags());
// Since the referenced node is inaccessible, it should not appear on the
// referencing node.
$this->drupalGet($referencing_node_url);
$assert_session->linkNotExists('The referenced node title');
// Publish the referenced entity.
$referenced_node->setPublished()
->save();
// Revisit the node with the reference field without clearing cache. Now
// that the referenced node is published, it should appear.
$this->verifyPageCacheContainsTags($referencing_node_url, 'MISS');
$this->verifyPageCacheContainsTags($referencing_node_url, 'HIT', $referenced_node->getCacheTags());
$this->drupalGet($referencing_node_url);
$assert_session->linkExists('The referenced node title');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.