NodeAccessCacheabilityWithNodeGrants.php in Drupal 10
File
core/modules/node/tests/src/Functional/NodeAccessCacheabilityWithNodeGrants.php
View source
<?php
namespace Drupal\Tests\node\Functional;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
class NodeAccessCacheabilityWithNodeGrants extends BrowserTestBase {
use EntityReferenceTestTrait;
protected static $modules = [
'node',
'node_test',
];
protected $defaultTheme = 'stark';
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();
$this
->assertTrue(\Drupal::moduleHandler()
->hasImplementations('node_grants'));
$referenced = $this
->createNode([
'status' => FALSE,
]);
$node = $this
->createNode([
'ref' => $referenced,
]);
$this
->drupalGet($node
->toUrl());
$this
->assertSession()
->linkNotExists($referenced
->label());
$referenced
->setPublished()
->save();
$this
->getSession()
->reload();
$this
->assertSession()
->linkExists($referenced
->label());
}
}