public function NodeAccessCacheabilityWithNodeGrants::testAccessCacheabilityWithNodeGrants in Drupal 9
Same name and namespace in other branches
- 8 core/modules/node/tests/src/Functional/NodeAccessCacheabilityWithNodeGrants.php \Drupal\Tests\node\Functional\NodeAccessCacheabilityWithNodeGrants::testAccessCacheabilityWithNodeGrants()
- 10 core/modules/node/tests/src/Functional/NodeAccessCacheabilityWithNodeGrants.php \Drupal\Tests\node\Functional\NodeAccessCacheabilityWithNodeGrants::testAccessCacheabilityWithNodeGrants()
Tests node view access cacheability with node grants.
File
- core/
modules/ node/ tests/ src/ Functional/ NodeAccessCacheabilityWithNodeGrants.php, line 32
Class
- NodeAccessCacheabilityWithNodeGrants
- Tests node view access cacheability with node grants.
Namespace
Drupal\Tests\node\FunctionalCode
public function testAccessCacheabilityWithNodeGrants() {
NodeType::create([
'type' => 'page',
])
->save();
$this
->createEntityReferenceField('node', 'page', 'ref', 'Ref', 'node');
EntityViewDisplay::create([
'targetEntityType' => 'node',
'bundle' => 'page',
'mode' => 'default',
'status' => TRUE,
])
->setComponent('ref', [
'type' => 'entity_reference_label',
])
->save();
// Check that at least one module implements hook_node_grants() as this test
// only tests this case.
// @see \node_test_node_grants()
$node_grants_implementations = \Drupal::moduleHandler()
->getImplementations('node_grants');
$this
->assertNotEmpty($node_grants_implementations);
// Create an unpublished node.
$referenced = $this
->createNode([
'status' => FALSE,
]);
// Create a node referencing $referenced.
$node = $this
->createNode([
'ref' => $referenced,
]);
// Check that the referenced entity link doesn't show on the host entity.
$this
->drupalGet($node
->toUrl());
$this
->assertSession()
->linkNotExists($referenced
->label());
// Publish the referenced node.
$referenced
->setPublished()
->save();
// Check that the referenced entity link shows on the host entity.
$this
->getSession()
->reload();
$this
->assertSession()
->linkExists($referenced
->label());
}