You are here

public function BulkFormTest::testBulkDeletion in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/node/tests/src/Functional/Views/BulkFormTest.php \Drupal\Tests\node\Functional\Views\BulkFormTest::testBulkDeletion()
  2. 9 core/modules/node/tests/src/Functional/Views/BulkFormTest.php \Drupal\Tests\node\Functional\Views\BulkFormTest::testBulkDeletion()

Tests multiple deletion.

File

core/modules/node/tests/src/Functional/Views/BulkFormTest.php, line 224

Class

BulkFormTest
Tests a node bulk form.

Namespace

Drupal\Tests\node\Functional\Views

Code

public function testBulkDeletion() {

  // Select a bunch of translated and untranslated nodes and check that
  // nodes and individual translations are properly deleted.
  $edit = [
    // Original and all translations.
    // Node 1, English, original.
    'node_bulk_form[0]' => TRUE,
    // Node 1, British English.
    'node_bulk_form[1]' => TRUE,
    // Node 1, Italian.
    'node_bulk_form[2]' => TRUE,
    // Original and only one translation.
    // Node 2, English.
    'node_bulk_form[3]' => TRUE,
    // Node 2, British English, original.
    'node_bulk_form[4]' => TRUE,
    // Node 2, Italian.
    'node_bulk_form[5]' => FALSE,
    // Only a single translation.
    // Node 3, English.
    'node_bulk_form[6]' => TRUE,
    // Node 3, Italian, original.
    'node_bulk_form[7]' => FALSE,
    // Only a single untranslated node.
    // Node 4, English, untranslated.
    'node_bulk_form[8]' => TRUE,
    // Node 5, British English, untranslated.
    'node_bulk_form[9]' => FALSE,
    'action' => 'node_delete_action',
  ];
  $this
    ->submitForm($edit, 'Apply to selected items');
  $label = $this
    ->loadNode(1)
    ->label();
  $this
    ->assertSession()
    ->pageTextContains("{$label} (Original translation) - The following content item translations will be deleted:");
  $label = $this
    ->loadNode(2)
    ->label();
  $this
    ->assertSession()
    ->pageTextContains("{$label} (Original translation) - The following content item translations will be deleted:");
  $label = $this
    ->loadNode(3)
    ->getTranslation('en')
    ->label();
  $this
    ->assertSession()
    ->pageTextContains($label);
  $this
    ->assertSession()
    ->pageTextNotContains("{$label} (Original translation) - The following content item translations will be deleted:");
  $label = $this
    ->loadNode(4)
    ->label();
  $this
    ->assertSession()
    ->pageTextContains($label);
  $this
    ->assertSession()
    ->pageTextNotContains("{$label} (Original translation) - The following content item translations will be deleted:");
  $this
    ->submitForm([], 'Delete');
  $node = $this
    ->loadNode(1);
  $this
    ->assertNull($node, '1: Node has been deleted');
  $node = $this
    ->loadNode(2);
  $this
    ->assertNull($node, '2: Node has been deleted');
  $node = $this
    ->loadNode(3);
  $result = count($node
    ->getTranslationLanguages()) && $node
    ->language()
    ->getId() == 'it';
  $this
    ->assertTrue($result, '3: English translation has been deleted');
  $node = $this
    ->loadNode(4);
  $this
    ->assertNull($node, '4: Node has been deleted');
  $node = $this
    ->loadNode(5);
  $this
    ->assertNotEmpty($node, '5: Node has not been deleted');
  $this
    ->assertSession()
    ->pageTextContains('Deleted 8 content items.');
}