Added Entity and Entity Reference Revisions which got dropped somewhere along the...
[yaffs-website] / web / modules / contrib / entity / tests / src / Functional / DeleteMultipleFormTest.php
1 <?php
2
3 namespace Drupal\Tests\entity\Functional;
4
5 use Drupal\entity_module_test\Entity\EnhancedEntity;
6 use Drupal\Tests\BrowserTestBase;
7
8 /**
9  * Tests the delete multiple confirmation form.
10  *
11  * @group entity
12  * @runTestsInSeparateProcesses
13  * @preserveGlobalState disabled
14  */
15 class DeleteMultipleFormTest extends BrowserTestBase {
16
17   /**
18    * The current user.
19    *
20    * @var \Drupal\Core\Session\AccountInterface
21    */
22   protected $account;
23
24   /**
25    * Modules to enable.
26    *
27    * @var array
28    */
29   public static $modules = ['entity_module_test', 'user', 'entity'];
30
31   /**
32    * {@inheritdoc}
33    */
34   protected function setUp() {
35     parent::setUp();
36
37     $this->account = $this->drupalCreateUser(['administer entity_test_enhanced']);
38     $this->drupalLogin($this->account);
39   }
40
41   /**
42    * Tests the add page.
43    */
44   public function testForm() {
45     $entities = [];
46     $selection = [];
47     for ($i = 0; $i < 2; $i++) {
48       $entity = EnhancedEntity::create([
49         'type' => 'default',
50       ]);
51       $entity->save();
52       $entities[$entity->id()] = $entity;
53
54       $langcode = $entity->language()->getId();
55       $selection[$entity->id()][$langcode] = $langcode;
56     }
57     // Add the selection to the tempstore just like DeleteAction would.
58     $tempstore = \Drupal::service('tempstore.private')->get('entity_delete_multiple_confirm');
59     $tempstore->set($this->account->id() . ':entity_test_enhanced', $selection);
60
61     $this->drupalGet('/entity_test_enhanced/delete');
62     $assert = $this->assertSession();
63     $assert->statusCodeEquals(200);
64     $assert->elementTextContains('css', '.page-title', 'Are you sure you want to delete these enhanced entities?');
65     $delete_button = $this->getSession()->getPage()->findButton('Delete');
66     $delete_button->click();
67     $assert = $this->assertSession();
68     $assert->addressEquals('/entity_test_enhanced');
69     $assert->responseContains('Deleted 2 items.');
70
71     \Drupal::entityTypeManager()->getStorage('entity_test_enhanced')->resetCache();
72     $remaining_entities = EnhancedEntity::loadMultiple(array_keys($selection));
73     $this->assertEmpty($remaining_entities);
74   }
75
76 }