-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #2946073 by claudiu.cristea, mpp, neclimdul, Berdir, idimopoulo…
…s, remkoklein: Node grant access check missing cacheable dependency on node (cherry picked from commit 6685ea27ee977078bf83323e3ab3cd4f6b13685b)
- Loading branch information
catch
committed
May 11, 2020
1 parent
7efa3ab
commit febfb1a
Showing
3 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
modules/node/tests/src/Functional/NodeAccessCacheabilityWithNodeGrants.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?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; | ||
|
||
/** | ||
* Tests node view access cacheability with node grants. | ||
* | ||
* @group node | ||
*/ | ||
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() | ||
$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()); | ||
} | ||
|
||
} |