You are here

public function UITest::testAddEntityActions in Entity Construction Kit (ECK) 8

Tests that the entity listing contains the correct local actions.

File

tests/src/Functional/UITest.php, line 130

Class

UITest
Tests if eck's UI elements are working properly.

Namespace

Drupal\Tests\eck\Functional

Code

public function testAddEntityActions() {
  $entityType = $this
    ->createEntityType();

  // No content can be added without the bundle, the link should therefor not
  // be present if there are no bundles.
  $this
    ->drupalGet(Url::fromRoute("eck.entity.{$entityType['id']}.list"));
  $this
    ->assertSession()
    ->responseNotContains("Add {$entityType['label']}");
  $bundles[] = $this
    ->createEntityBundle($entityType['id']);

  // The action link should link directly to the add entity form if there is
  // only one bundle present.
  $this
    ->drupalGet(Url::fromRoute("eck.entity.{$entityType['id']}.list"));
  $this
    ->clickLink("Add {$entityType['label']}");
  $this
    ->assertSession()
    ->fieldExists('title[0][value]');
  $bundles[] = $this
    ->createEntityBundle($entityType['id']);

  // When there are multiple bundles available. The user should be able to
  // choose which bundle to use.
  $this
    ->drupalGet(Url::fromRoute("eck.entity.{$entityType['id']}.list"));
  $this
    ->clickLink("Add {$entityType['label']}");
  foreach ($bundles as $bundle) {
    $this
      ->assertSession()
      ->responseContains($bundle['name']);
  }

  // After deleting the bundle, the user should once again end up on the add
  // entity form when clicking the action link.
  $route = "entity.{$entityType['id']}_type.delete_form";
  $routeArguments = [
    "{$entityType['id']}_type" => $bundles[1]['type'],
  ];
  $this
    ->drupalGet(Url::fromRoute($route, $routeArguments));
  $this
    ->submitForm([], 'Delete');
  $this
    ->drupalGet(Url::fromRoute("eck.entity.{$entityType['id']}.list"));
  $this
    ->clickLink("Add {$entityType['label']}");
  $this
    ->assertSession()
    ->fieldExists('title[0][value]');
}