View source
<?php
namespace Drupal\node\Tests;
class NodeAccessRebuildNodeGrantsTest extends NodeTestBase {
protected $webUser;
protected function setUp() {
parent::setUp();
$admin_user = $this
->drupalCreateUser(array(
'administer site configuration',
'access administration pages',
'access site reports',
'bypass node access',
));
$this
->drupalLogin($admin_user);
$this->webUser = $this
->drupalCreateUser();
}
public function testNodeAccessRebuildNodeGrants() {
\Drupal::service('module_installer')
->install([
'node_access_test',
]);
$this
->resetAll();
$node = $this
->drupalCreateNode(array(
'uid' => $this->webUser
->id(),
));
$this
->assertTrue(\Drupal::service('node.grant_storage')
->access($node, 'view', $this->webUser), 'The expected node access records are present');
$this
->assertEqual(1, \Drupal::service('node.grant_storage')
->checkAll($this->webUser), 'There is an all realm access record');
$this
->assertTrue(\Drupal::state()
->get('node.node_access_needs_rebuild'), 'Node access permissions need to be rebuilt');
$this
->drupalGet('admin/reports/status/rebuild');
$this
->drupalPostForm(NULL, array(), t('Rebuild permissions'));
$this
->assertText(t('The content access permissions have been rebuilt.'));
$this
->assertNull(\Drupal::state()
->get('node.node_access_needs_rebuild'), 'Node access permissions have been rebuilt');
$this
->assertTrue(\Drupal::service('node.grant_storage')
->access($node, 'view', $this->webUser), 'The expected node access records are present');
$this
->assertFalse(\Drupal::service('node.grant_storage')
->checkAll($this->webUser), 'There is no all realm access record');
}
public function testNodeAccessRebuildNoAccessModules() {
$this
->assertEqual(1, \Drupal::service('node.grant_storage')
->count(), 'There is an all realm access record');
$this
->assertFalse(\Drupal::state()
->get('node.node_access_needs_rebuild'), 'Node access permissions need to be rebuilt');
$this
->drupalGet('admin/reports/status');
$this
->clickLink(t('Rebuild permissions'));
$this
->drupalPostForm(NULL, array(), t('Rebuild permissions'));
$this
->assertText(t('Content permissions have been rebuilt.'));
$this
->assertNull(\Drupal::state()
->get('node.node_access_needs_rebuild'), 'Node access permissions have been rebuilt');
$this
->assertEqual(1, \Drupal::service('node.grant_storage')
->count(), 'There is an all realm access record');
}
}