You are here

public function BulkFormEntityListBuilderTest::testPublishAction in Entity API 8

Test the publish action on the bulk form.

File

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

Class

BulkFormEntityListBuilderTest
Tests the bulk-form list builder.

Namespace

Drupal\Tests\entity\Functional

Code

public function testPublishAction() {

  /* @var \Drupal\entity_module_test\Entity\EnhancedEntityWithOwner $entity */
  $entity = $this->storage
    ->create([
    'name' => 'Entity 1',
    'type' => 'default',
    'user_id' => $this->loggedInUser
      ->id(),
    'status' => 0,
  ]);
  $entity
    ->save();
  $id = $entity
    ->id();
  $this
    ->drupalGet($entity
    ->toUrl('collection'));
  $edit = [
    'action' => 'entity_test_enhanced_with_owner_publish_action',
    "entities[{$id}]" => $id,
  ];
  $this
    ->submitForm($edit, 'Apply to selected items');
  $this
    ->assertSession()
    ->elementTextContains('css', '.messages--error', 'No access to execute Publish enhanced entities with owner on the enhanced entity with owner Entity 1.');
  $entity = $this->storage
    ->load($id);
  $this
    ->assertFalse($entity
    ->isPublished());
  $account = $this
    ->drupalCreateUser(array_merge($this->basePermissions, [
    'update any default entity_test_enhanced_with_owner',
  ]));
  $entity
    ->setOwner($account)
    ->save();
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet($entity
    ->toUrl('collection'));
  $this
    ->submitForm($edit, 'Apply to selected items');

  // 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', 'Publish enhanced entities with owner was applied to 1 item.');
  $entity = $this->storage
    ->load($id);
  $this
    ->assertTrue($entity
    ->isPublished());
}