You are here

public function BulkFormEntityListBuilderTest::testDeleteAction in Entity API 8

Test the delete action on the bulk form.

File

tests/src/Functional/BulkFormEntityListBuilderTest.php, line 99

Class

BulkFormEntityListBuilderTest
Tests the bulk-form list builder.

Namespace

Drupal\Tests\entity\Functional

Code

public function testDeleteAction() {
  $entity = $this->storage
    ->create([
    'name' => 'Entity 1',
    'type' => 'default',
    'user_id' => $this->loggedInUser
      ->id(),
  ]);
  $entity
    ->save();
  $id = $entity
    ->id();
  $this
    ->drupalGet($entity
    ->toUrl('collection'));
  $this
    ->assertSession()
    ->fieldValueEquals('Action', 'entity_test_enhanced_with_owner_delete_action');
  $edit = [
    "entities[{$id}]" => $id,
  ];
  $this
    ->submitForm($edit, 'Apply to selected items');
  $this
    ->assertSession()
    ->elementTextContains('css', '.messages--error', 'No access to execute Delete enhanced entities with owner on the enhanced entity with owner Entity 1.');
  $this
    ->assertInstanceOf(EnhancedEntityWithOwner::class, $this->storage
    ->load($id));
  $account = $this
    ->drupalCreateUser(array_merge($this->basePermissions, [
    'delete any default entity_test_enhanced_with_owner',
  ]));
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet($entity
    ->toUrl('collection'));
  $this
    ->submitForm($edit, 'Apply to selected items');
  $this
    ->assertSession()
    ->elementTextContains('css', 'h1', 'Are you sure you want to delete this enhanced entity with owner?');
  $this
    ->submitForm([], 'Delete');

  // The entity is deleted in the web process, but will still be in the static
  // cache of the test process, so we need to clear it manually.
  $this->storage
    ->resetCache([
    $id,
  ]);
  $this
    ->assertSession()
    ->elementTextContains('css', 'h1', 'Enhanced entities with owner');
  $this
    ->assertSession()
    ->elementTextContains('css', '.messages--status', 'Deleted 1 item.');
  $this
    ->assertNull($this->storage
    ->load($id));
}