3 namespace Drupal\Tests\entity\Functional;
5 use Drupal\entity_module_test\Entity\EnhancedEntity;
6 use Drupal\entity_module_test\Entity\EnhancedEntityBundle;
7 use Drupal\Tests\BrowserTestBase;
10 * Tests the delete multiple confirmation form.
13 * @runTestsInSeparateProcesses
14 * @preserveGlobalState disabled
16 class DeleteMultipleFormTest extends BrowserTestBase {
21 * @var \Drupal\Core\Session\AccountInterface
30 public static $modules = ['entity_module_test', 'user', 'entity'];
35 protected function setUp() {
38 EnhancedEntityBundle::create([
42 $this->account = $this->drupalCreateUser(['administer entity_test_enhanced']);
43 $this->drupalLogin($this->account);
49 public function testForm() {
52 for ($i = 0; $i < 2; $i++) {
53 $entity = EnhancedEntity::create([
57 $entities[$entity->id()] = $entity;
59 $langcode = $entity->language()->getId();
60 $selection[$entity->id()][$langcode] = $langcode;
62 // Add the selection to the tempstore just like DeleteAction would.
63 $tempstore = \Drupal::service('tempstore.private')->get('entity_delete_multiple_confirm');
64 $tempstore->set($this->account->id() . ':entity_test_enhanced', $selection);
66 $this->drupalGet('/entity_test_enhanced/delete');
67 $assert = $this->assertSession();
68 $assert->statusCodeEquals(200);
69 $assert->elementTextContains('css', '.page-title', 'Are you sure you want to delete these enhanced entities?');
70 $delete_button = $this->getSession()->getPage()->findButton('Delete');
71 $delete_button->click();
72 $assert = $this->assertSession();
73 $assert->addressEquals('/entity_test_enhanced');
74 $assert->responseContains('Deleted 2 items.');
76 \Drupal::entityTypeManager()->getStorage('entity_test_enhanced')->resetCache();
77 $remaining_entities = EnhancedEntity::loadMultiple(array_keys($selection));
78 $this->assertEmpty($remaining_entities);