class NodeAccessCacheabilityWithNodeGrants
Same name and namespace in other branches
- 10 core/modules/node/tests/src/Functional/NodeAccessCacheabilityWithNodeGrants.php \Drupal\Tests\node\Functional\NodeAccessCacheabilityWithNodeGrants
- 8.9.x core/modules/node/tests/src/Functional/NodeAccessCacheabilityWithNodeGrants.php \Drupal\Tests\node\Functional\NodeAccessCacheabilityWithNodeGrants
Tests node view access cacheability with node grants.
@group node
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\node\Functional\NodeAccessCacheabilityWithNodeGrants uses \Drupal\Tests\field\Traits\EntityReferenceTestTrait extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of NodeAccessCacheabilityWithNodeGrants
File
-
core/
modules/ node/ tests/ src/ Functional/ NodeAccessCacheabilityWithNodeGrants.php, line 15
Namespace
Drupal\Tests\node\FunctionalView source
class NodeAccessCacheabilityWithNodeGrants extends BrowserTestBase {
use EntityReferenceTestTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'node',
'node_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests node view access cacheability with node grants.
*/
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()
$this->assertTrue(\Drupal::moduleHandler()->hasImplementations('node_grants'));
// 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());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.