function UserCancelTest::testUserBlockUnpublishNodeAccess
Same name in other branches
- 10 core/modules/user/tests/src/Functional/UserCancelTest.php \Drupal\Tests\user\Functional\UserCancelTest::testUserBlockUnpublishNodeAccess()
- 11.x core/modules/user/tests/src/Functional/UserCancelTest.php \Drupal\Tests\user\Functional\UserCancelTest::testUserBlockUnpublishNodeAccess()
Tests nodes are unpublished even if inaccessible to cancelling user.
File
-
core/
modules/ user/ tests/ src/ Functional/ UserCancelTest.php, line 289
Class
- UserCancelTest
- Ensure that account cancellation methods work as expected.
Namespace
Drupal\Tests\user\FunctionalCode
public function testUserBlockUnpublishNodeAccess() {
\Drupal::service('module_installer')->install([
'node_access_test',
'user_form_test',
]);
// Setup node access
node_access_rebuild();
node_access_test_add_field(NodeType::load('page'));
\Drupal::state()->set('node_access_test.private', TRUE);
$this->config('user.settings')
->set('cancel_method', 'user_cancel_block_unpublish')
->save();
// Create a user.
$user_storage = $this->container
->get('entity_type.manager')
->getStorage('user');
$account = $this->drupalCreateUser([
'cancel account',
]);
// Load a real user object.
$user_storage->resetCache([
$account->id(),
]);
$account = $user_storage->load($account->id());
// Create a published private node.
$node = $this->drupalCreateNode([
'uid' => $account->id(),
'type' => 'page',
'status' => 1,
'private' => TRUE,
]);
// Cancel node author.
$admin_user = $this->drupalCreateUser([
'cancel other accounts',
]);
$this->drupalLogin($admin_user);
$this->drupalGet('user_form_test_cancel/' . $account->id());
$this->submitForm([], 'Confirm');
// Confirm node has been unpublished, even though the admin user
// does not have permission to access it.
$node_storage = $this->container
->get('entity_type.manager')
->getStorage('node');
$node_storage->resetCache([
$node->id(),
]);
$test_node = $node_storage->load($node->id());
$this->assertFalse($test_node->isPublished(), 'Node of the user has been unpublished.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.