You are here

public function BulkFormEntityListBuilderTest::testBulkForm in Entity API 8

Tests that the bulk form is displayed correctly.

File

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

Class

BulkFormEntityListBuilderTest
Tests the bulk-form list builder.

Namespace

Drupal\Tests\entity\Functional

Code

public function testBulkForm() {
  $entity = $this->storage
    ->create([
    'name' => 'Entity 1',
    'type' => 'default',
  ]);
  $collection_url = $entity
    ->getEntityType()
    ->getLinkTemplate('collection');

  // Without any entities the bulk form should not be shown.
  $this
    ->drupalGet($collection_url);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->fieldNotExists('Action');
  $this
    ->assertSession()
    ->buttonNotExists('Apply to selected items');

  // Create an entity and make sure that the bulk form is shown.
  $entity
    ->save();
  $this
    ->drupalGet($collection_url);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->fieldExists('Action');
  $this
    ->assertSession()
    ->buttonExists('Apply to selected items');
  $this
    ->submitForm([], 'Apply to selected items');
  $this
    ->assertSession()
    ->elementTextContains('css', '.messages--error', 'No items selected.');
}