public function BulkFormEntityListBuilderTest::testUnpublishAction in Entity API 8
Test the unpublish action on the bulk form.
File
- tests/
src/ Functional/ BulkFormEntityListBuilderTest.php, line 181
Class
- BulkFormEntityListBuilderTest
- Tests the bulk-form list builder.
Namespace
Drupal\Tests\entity\FunctionalCode
public function testUnpublishAction() {
/* @var \Drupal\entity_module_test\Entity\EnhancedEntityWithOwner $entity */
$entity = $this->storage
->create([
'name' => 'Entity 1',
'type' => 'default',
'user_id' => $this->loggedInUser
->id(),
]);
$entity
->save();
$id = $entity
->id();
$this
->drupalGet($entity
->toUrl('collection'));
$edit = [
'action' => 'entity_test_enhanced_with_owner_unpublish_action',
"entities[{$id}]" => $id,
];
$this
->submitForm($edit, 'Apply to selected items');
$this
->assertSession()
->elementTextContains('css', '.messages--error', 'No access to execute Unpublish enhanced entities with owner on the enhanced entity with owner Entity 1.');
$entity = $this->storage
->load($id);
$this
->assertTrue($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', 'Unpublish enhanced entities with owner was applied to 1 item.');
$entity = $this->storage
->load($id);
$this
->assertFalse($entity
->isPublished());
}