DeleteMultipleFormTest.php in Entity API 8.0
File
tests/src/Functional/DeleteMultipleFormTest.php
View source
<?php
namespace Drupal\Tests\entity\Functional;
use Drupal\entity_module_test\Entity\EnhancedEntity;
use Drupal\entity_module_test\Entity\EnhancedEntityBundle;
use Drupal\simpletest\BrowserTestBase;
class DeleteMultipleFormTest extends BrowserTestBase {
protected $account;
public static $modules = [
'entity_module_test',
'user',
'entity',
];
protected function setUp() {
parent::setUp();
EnhancedEntityBundle::create([
'id' => 'default',
'label' => 'Default',
])
->save();
$this->account = $this
->drupalCreateUser([
'administer entity_test_enhanced',
]);
$this
->drupalLogin($this->account);
}
public function testForm() {
$entities = [];
$selection = [];
for ($i = 0; $i < 2; $i++) {
$entity = EnhancedEntity::create([
'type' => 'default',
]);
$entity
->save();
$entities[$entity
->id()] = $entity;
$langcode = $entity
->language()
->getId();
$selection[$entity
->id()][$langcode] = $langcode;
}
$tempstore = \Drupal::service('user.private_tempstore')
->get('entity_delete_multiple_confirm');
$tempstore
->set($this->account
->id(), $selection);
$this
->drupalGet('/entity_test_enhanced/delete');
$assert = $this
->assertSession();
$assert
->statusCodeEquals(200);
$assert
->elementTextContains('css', '.page-title', 'Are you sure you want to delete these items?');
$delete_button = $this
->getSession()
->getPage()
->findButton('Delete');
$delete_button
->click();
$assert = $this
->assertSession();
$assert
->addressEquals('/entity_test_enhanced');
$assert
->responseContains('Deleted 2 items.');
\Drupal::entityTypeManager()
->getStorage('entity_test_enhanced')
->resetCache();
$remaining_entities = EnhancedEntity::loadMultiple(array_keys($selection));
$this
->assertEmpty($remaining_entities);
}
}