You are here

public function DeleteMultipleFormTest::testForm in Entity API 8.0

Tests the add page.

File

tests/src/Functional/DeleteMultipleFormTest.php, line 54
Contains \Drupal\Tests\entity\Functional\DeleteMultipleFormTest.

Class

DeleteMultipleFormTest
Tests the delete multiple confirmation form.

Namespace

Drupal\Tests\entity\Functional

Code

public function testForm() {
  $entities = [];
  $selection = [];
  for ($i = 0; $i < 2; $i++) {
    $entity = EnhancedEntity::create([
      'type' => 'default',
    ]);
    $entity
      ->save();
    $entities[$entity
      ->id()] = $entity;
    $langcode = $entity
      ->language()
      ->getId();
    $selection[$entity
      ->id()][$langcode] = $langcode;
  }

  // Add the selection to the tempstore just like DeleteAction would.
  $tempstore = \Drupal::service('user.private_tempstore')
    ->get('entity_delete_multiple_confirm');
  $tempstore
    ->set($this->account
    ->id(), $selection);
  $this
    ->drupalGet('/entity_test_enhanced/delete');
  $assert = $this
    ->assertSession();
  $assert
    ->statusCodeEquals(200);
  $assert
    ->elementTextContains('css', '.page-title', 'Are you sure you want to delete these items?');
  $delete_button = $this
    ->getSession()
    ->getPage()
    ->findButton('Delete');
  $delete_button
    ->click();
  $assert = $this
    ->assertSession();
  $assert
    ->addressEquals('/entity_test_enhanced');
  $assert
    ->responseContains('Deleted 2 items.');
  \Drupal::entityTypeManager()
    ->getStorage('entity_test_enhanced')
    ->resetCache();
  $remaining_entities = EnhancedEntity::loadMultiple(array_keys($selection));
  $this
    ->assertEmpty($remaining_entities);
}