Chris@17
|
1 <?php
|
Chris@17
|
2
|
Chris@17
|
3 namespace Drupal\FunctionalTests\Entity;
|
Chris@17
|
4
|
Chris@17
|
5 use Drupal\entity_test\Entity\EntityTestBundle;
|
Chris@17
|
6 use Drupal\entity_test\Entity\EntityTestMulRevPub;
|
Chris@17
|
7 use Drupal\entity_test\Entity\EntityTestRev;
|
Chris@17
|
8 use Drupal\language\Entity\ConfigurableLanguage;
|
Chris@17
|
9 use Drupal\Tests\BrowserTestBase;
|
Chris@17
|
10
|
Chris@17
|
11 /**
|
Chris@17
|
12 * Tests the delete multiple confirmation form.
|
Chris@17
|
13 *
|
Chris@17
|
14 * @group Entity
|
Chris@17
|
15 * @runTestsInSeparateProcesses
|
Chris@17
|
16 * @preserveGlobalState disabled
|
Chris@17
|
17 */
|
Chris@17
|
18 class DeleteMultipleFormTest extends BrowserTestBase {
|
Chris@17
|
19
|
Chris@17
|
20 /**
|
Chris@17
|
21 * The current user.
|
Chris@17
|
22 *
|
Chris@17
|
23 * @var \Drupal\Core\Session\AccountInterface
|
Chris@17
|
24 */
|
Chris@17
|
25 protected $account;
|
Chris@17
|
26
|
Chris@17
|
27 /**
|
Chris@17
|
28 * Modules to enable.
|
Chris@17
|
29 *
|
Chris@17
|
30 * @var array
|
Chris@17
|
31 */
|
Chris@17
|
32 public static $modules = ['entity_test', 'user', 'language'];
|
Chris@17
|
33
|
Chris@17
|
34 /**
|
Chris@17
|
35 * {@inheritdoc}
|
Chris@17
|
36 */
|
Chris@17
|
37 protected function setUp() {
|
Chris@17
|
38 parent::setUp();
|
Chris@17
|
39
|
Chris@17
|
40 EntityTestBundle::create([
|
Chris@17
|
41 'id' => 'default',
|
Chris@17
|
42 'label' => 'Default',
|
Chris@17
|
43 ])->save();
|
Chris@17
|
44 $this->account = $this->drupalCreateUser(['administer entity_test content']);
|
Chris@17
|
45 $this->drupalLogin($this->account);
|
Chris@17
|
46 }
|
Chris@17
|
47
|
Chris@17
|
48 /**
|
Chris@17
|
49 * Tests the delete form for translatable entities.
|
Chris@17
|
50 */
|
Chris@17
|
51 public function testTranslatableEntities() {
|
Chris@17
|
52 ConfigurableLanguage::create(['id' => 'es'])->save();
|
Chris@17
|
53 ConfigurableLanguage::create(['id' => 'fr'])->save();
|
Chris@17
|
54
|
Chris@17
|
55 $selection = [];
|
Chris@17
|
56
|
Chris@17
|
57 $entity1 = EntityTestMulRevPub::create(['type' => 'default', 'name' => 'entity1']);
|
Chris@17
|
58 $entity1->addTranslation('es', ['name' => 'entity1 spanish']);
|
Chris@17
|
59 $entity1->addTranslation('fr', ['name' => 'entity1 french']);
|
Chris@17
|
60 $entity1->save();
|
Chris@17
|
61 $selection[$entity1->id()]['en'] = 'en';
|
Chris@17
|
62
|
Chris@17
|
63 $entity2 = EntityTestMulRevPub::create(['type' => 'default', 'name' => 'entity2']);
|
Chris@17
|
64 $entity2->addTranslation('es', ['name' => 'entity2 spanish']);
|
Chris@17
|
65 $entity2->addTranslation('fr', ['name' => 'entity2 french']);
|
Chris@17
|
66 $entity2->save();
|
Chris@17
|
67 $selection[$entity2->id()]['es'] = 'es';
|
Chris@17
|
68 $selection[$entity2->id()]['fr'] = 'fr';
|
Chris@17
|
69
|
Chris@17
|
70 $entity3 = EntityTestMulRevPub::create(['type' => 'default', 'name' => 'entity3']);
|
Chris@17
|
71 $entity3->addTranslation('es', ['name' => 'entity3 spanish']);
|
Chris@17
|
72 $entity3->addTranslation('fr', ['name' => 'entity3 french']);
|
Chris@17
|
73 $entity3->save();
|
Chris@17
|
74 $selection[$entity3->id()]['fr'] = 'fr';
|
Chris@17
|
75
|
Chris@17
|
76 // This entity will be inaccessible because of
|
Chris@17
|
77 // Drupal\entity_test\EntityTestAccessControlHandler.
|
Chris@17
|
78 $entity4 = EntityTestMulRevPub::create(['type' => 'default', 'name' => 'forbid_access']);
|
Chris@17
|
79 $entity4->save();
|
Chris@17
|
80 $selection[$entity4->id()]['en'] = 'en';
|
Chris@17
|
81
|
Chris@17
|
82 // Add the selection to the tempstore just like DeleteAction would.
|
Chris@17
|
83 $tempstore = \Drupal::service('tempstore.private')->get('entity_delete_multiple_confirm');
|
Chris@17
|
84 $tempstore->set($this->account->id() . ':entity_test_mulrevpub', $selection);
|
Chris@17
|
85
|
Chris@17
|
86 $this->drupalGet('/entity_test/delete');
|
Chris@17
|
87 $assert = $this->assertSession();
|
Chris@17
|
88 $assert->statusCodeEquals(200);
|
Chris@17
|
89 $assert->elementTextContains('css', '.page-title', 'Are you sure you want to delete these test entity - revisions, data table, and published interface entities?');
|
Chris@17
|
90 $list_selector = '#entity-test-mulrevpub-delete-multiple-confirm-form > div.item-list > ul';
|
Chris@17
|
91 $assert->elementTextContains('css', $list_selector, 'entity1 (Original translation) - The following test entity - revisions, data table, and published interface translations will be deleted:');
|
Chris@17
|
92 $assert->elementTextContains('css', $list_selector, 'entity2 spanish');
|
Chris@17
|
93 $assert->elementTextContains('css', $list_selector, 'entity2 french');
|
Chris@17
|
94 $assert->elementTextNotContains('css', $list_selector, 'entity3 spanish');
|
Chris@17
|
95 $assert->elementTextContains('css', $list_selector, 'entity3 french');
|
Chris@17
|
96 $delete_button = $this->getSession()->getPage()->findButton('Delete');
|
Chris@17
|
97 $delete_button->click();
|
Chris@17
|
98 $assert = $this->assertSession();
|
Chris@17
|
99 $assert->addressEquals('/user/' . $this->account->id());
|
Chris@17
|
100 $assert->responseContains('Deleted 6 items.');
|
Chris@17
|
101 $assert->responseContains('1 item has not been deleted because you do not have the necessary permissions.');
|
Chris@17
|
102
|
Chris@17
|
103 \Drupal::entityTypeManager()->getStorage('entity_test_mulrevpub')->resetCache();
|
Chris@17
|
104 $remaining_entities = EntityTestMulRevPub::loadMultiple([$entity1->id(), $entity2->id(), $entity3->id(), $entity4->id()]);
|
Chris@17
|
105 $this->assertCount(3, $remaining_entities);
|
Chris@17
|
106 }
|
Chris@17
|
107
|
Chris@17
|
108 /**
|
Chris@17
|
109 * Tests the delete form for untranslatable entities.
|
Chris@17
|
110 */
|
Chris@17
|
111 public function testUntranslatableEntities() {
|
Chris@17
|
112 $selection = [];
|
Chris@17
|
113
|
Chris@17
|
114 $entity1 = EntityTestRev::create(['type' => 'default', 'name' => 'entity1']);
|
Chris@17
|
115 $entity1->save();
|
Chris@17
|
116 $selection[$entity1->id()]['en'] = 'en';
|
Chris@17
|
117
|
Chris@17
|
118 $entity2 = EntityTestRev::create(['type' => 'default', 'name' => 'entity2']);
|
Chris@17
|
119 $entity2->save();
|
Chris@17
|
120 $selection[$entity2->id()]['en'] = 'en';
|
Chris@17
|
121
|
Chris@17
|
122 // This entity will be inaccessible because of
|
Chris@17
|
123 // Drupal\entity_test\EntityTestAccessControlHandler.
|
Chris@17
|
124 $entity3 = EntityTestRev::create(['type' => 'default', 'name' => 'forbid_access']);
|
Chris@17
|
125 $entity3->save();
|
Chris@17
|
126 $selection[$entity3->id()]['en'] = 'en';
|
Chris@17
|
127
|
Chris@17
|
128 // This entity will be inaccessible because of
|
Chris@17
|
129 // Drupal\entity_test\EntityTestAccessControlHandler.
|
Chris@17
|
130 $entity4 = EntityTestRev::create(['type' => 'default', 'name' => 'forbid_access']);
|
Chris@17
|
131 $entity4->save();
|
Chris@17
|
132 $selection[$entity4->id()]['en'] = 'en';
|
Chris@17
|
133
|
Chris@17
|
134 // Add the selection to the tempstore just like DeleteAction would.
|
Chris@17
|
135 $tempstore = \Drupal::service('tempstore.private')->get('entity_delete_multiple_confirm');
|
Chris@17
|
136 $tempstore->set($this->account->id() . ':entity_test_rev', $selection);
|
Chris@17
|
137
|
Chris@17
|
138 $this->drupalGet('/entity_test_rev/delete_multiple');
|
Chris@17
|
139 $assert = $this->assertSession();
|
Chris@17
|
140 $assert->statusCodeEquals(200);
|
Chris@17
|
141 $assert->elementTextContains('css', '.page-title', 'Are you sure you want to delete these test entity - revisions entities?');
|
Chris@17
|
142 $list_selector = '#entity-test-rev-delete-multiple-confirm-form > div.item-list > ul';
|
Chris@17
|
143 $assert->elementTextContains('css', $list_selector, 'entity1');
|
Chris@17
|
144 $assert->elementTextContains('css', $list_selector, 'entity2');
|
Chris@17
|
145 $delete_button = $this->getSession()->getPage()->findButton('Delete');
|
Chris@17
|
146 $delete_button->click();
|
Chris@17
|
147 $assert = $this->assertSession();
|
Chris@17
|
148 $assert->addressEquals('/user/' . $this->account->id());
|
Chris@17
|
149 $assert->responseContains('Deleted 2 items.');
|
Chris@17
|
150 $assert->responseContains('2 items have not been deleted because you do not have the necessary permissions.');
|
Chris@17
|
151
|
Chris@17
|
152 \Drupal::entityTypeManager()->getStorage('entity_test_mulrevpub')->resetCache();
|
Chris@17
|
153 $remaining_entities = EntityTestRev::loadMultiple([$entity1->id(), $entity2->id(), $entity3->id(), $entity4->id()]);
|
Chris@17
|
154 $this->assertCount(2, $remaining_entities);
|
Chris@17
|
155 }
|
Chris@17
|
156
|
Chris@17
|
157 }
|