Skip to content
Snippets Groups Projects
Commit c9252d07 authored by catch's avatar catch
Browse files

Issue #2688535 by amateescu, alexpott, xjm, cilefen, olegiv: User deletion -...

Issue #2688535 by amateescu, alexpott, xjm, cilefen, olegiv: User deletion - unexpected nodes deletion in batch mode
parent 4b265669
No related branches found
No related tags found
No related merge requests found
......@@ -102,6 +102,9 @@ function _node_mass_update_helper(NodeInterface $node, array $updates, $langcode
* An array of node IDs.
* @param array $updates
* Associative array of updates.
* @param string $langcode
* The language updates should be applied to. If none is specified all
* available languages are processed.
* @param bool $load
* TRUE if $nodes contains an array of node IDs to be loaded, FALSE if it
* contains fully loaded nodes.
......@@ -111,7 +114,7 @@ function _node_mass_update_helper(NodeInterface $node, array $updates, $langcode
* @param array|\ArrayAccess $context.
* An array of contextual key/values.
*/
function _node_mass_update_batch_process(array $nodes, array $updates, $load, $revisions, &$context) {
function _node_mass_update_batch_process(array $nodes, array $updates, $langcode, $load, $revisions, &$context) {
if (!isset($context['sandbox']['progress'])) {
$context['sandbox']['progress'] = 0;
$context['sandbox']['max'] = count($nodes);
......@@ -127,7 +130,7 @@ function _node_mass_update_batch_process(array $nodes, array $updates, $load, $r
$node = $revisions ?
entity_revision_load('node', $node) : Node::load($node);
}
$node = _node_mass_update_helper($node, $updates);
$node = _node_mass_update_helper($node, $updates, $langcode);
// Store result for post-processing in the finished callback.
$context['results'][] = \Drupal::l($node->label(), $node->urlInfo());
......
......@@ -373,6 +373,53 @@ function testUserAnonymize() {
$this->assertRaw(t('%name has been deleted.', array('%name' => $account->getUsername())), "Confirmation message displayed to user.");
}
/**
* Delete account and anonymize all content using a batch process.
*/
public function testUserAnonymizeBatch() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
$user_storage = $this->container->get('entity.manager')->getStorage('user');
// Create a user.
$account = $this->drupalCreateUser(array('cancel account'));
$this->drupalLogin($account);
// Load a real user object.
$user_storage->resetCache([$account->id()]);
$account = $user_storage->load($account->id());
// Create 11 nodes in order to trigger batch processing in
// node_mass_update().
$nodes = [];
for ($i = 0; $i < 11; $i++) {
$node = $this->drupalCreateNode(['uid' => $account->id()]);
$nodes[$node->id()] = $node;
}
// Attempt to cancel account.
$this->drupalGet('user/' . $account->id() . '/edit');
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
$this->assertText(t('Are you sure you want to cancel your account?'), 'Confirmation form to cancel account displayed.');
$this->assertRaw(t('Your account will be removed and all account information deleted. All of your content will be assigned to the %anonymous-name user.', array('%anonymous-name' => $this->config('user.settings')->get('anonymous'))), 'Informs that all content will be attributed to anonymous account.');
// Confirm account cancellation.
$timestamp = time();
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
$this->assertText(t('A confirmation request to cancel your account has been sent to your email address.'), 'Account cancellation request mailed message displayed.');
// Confirm account cancellation request.
$this->drupalGet("user/" . $account->id() . "/cancel/confirm/$timestamp/" . user_pass_rehash($account, $timestamp));
$user_storage->resetCache([$account->id()]);
$this->assertFalse($user_storage->load($account->id()), 'User is not found in the database.');
// Confirm that user's content has been attributed to anonymous user.
$node_storage->resetCache(array_keys($nodes));
$test_nodes = $node_storage->loadMultiple(array_keys($nodes));
foreach ($test_nodes as $test_node) {
$this->assertTrue(($test_node->getOwnerId() == 0 && $test_node->isPublished()), 'Node ' . $test_node->id() . ' of the user has been attributed to anonymous user.');
}
}
/**
* Delete account and remove all content.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment