Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Action / DeleteActionTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Action;
4
5 use Drupal\Core\Action\Plugin\Action\Derivative\EntityDeleteActionDeriver;
6 use Drupal\entity_test\Entity\EntityTestMulRevPub;
7 use Drupal\KernelTests\KernelTestBase;
8 use Drupal\system\Entity\Action;
9 use Drupal\user\Entity\User;
10
11 /**
12  * @group Action
13  */
14 class DeleteActionTest extends KernelTestBase {
15
16   protected $testUser;
17
18   /**
19    * {@inheritdoc}
20    */
21   public static $modules = ['system', 'entity_test', 'user'];
22
23   /**
24    * {@inheritdoc}
25    */
26   protected function setUp() {
27     parent::setUp();
28     $this->installEntitySchema('entity_test_mulrevpub');
29     $this->installEntitySchema('user');
30     $this->installSchema('system', ['sequences', 'key_value_expire']);
31
32     $this->testUser = User::create([
33       'name' => 'foobar',
34       'mail' => 'foobar@example.com',
35     ]);
36     $this->testUser->save();
37     \Drupal::service('current_user')->setAccount($this->testUser);
38   }
39
40   /**
41    * @covers \Drupal\Core\Action\Plugin\Action\Derivative\EntityDeleteActionDeriver::getDerivativeDefinitions
42    */
43   public function testGetDerivativeDefinitions() {
44     $deriver = new EntityDeleteActionDeriver(\Drupal::entityTypeManager(), \Drupal::translation());
45     $this->assertEquals([
46       'entity_test_mulrevpub' => [
47         'type' => 'entity_test_mulrevpub',
48         'label' => 'Delete test entity - revisions, data table, and published interface',
49         'action_label' => 'Delete',
50         'confirm_form_route_name' => 'entity.entity_test_mulrevpub.delete_multiple_form',
51       ],
52       'entity_test_rev' => [
53         'type' => 'entity_test_rev',
54         'label' => 'Delete test entity - revisions',
55         'action_label' => 'Delete',
56         'confirm_form_route_name' => 'entity.entity_test_rev.delete_multiple_form',
57       ],
58     ], $deriver->getDerivativeDefinitions([
59       'action_label' => 'Delete',
60     ]));
61   }
62
63   /**
64    * @covers \Drupal\Core\Action\Plugin\Action\DeleteAction::execute
65    */
66   public function testDeleteAction() {
67     $entity = EntityTestMulRevPub::create(['name' => 'test']);
68     $entity->save();
69
70     $action = Action::create([
71       'id' => 'entity_delete_action',
72       'plugin' => 'entity:delete_action:entity_test_mulrevpub',
73     ]);
74     $action->save();
75
76     $action->execute([$entity]);
77     $this->assertArraySubset(['module' => ['entity_test']], $action->getDependencies());
78
79     /** @var \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store */
80     $temp_store = \Drupal::service('tempstore.private');
81     $store_entries = $temp_store->get('entity_delete_multiple_confirm')->get($this->testUser->id() . ':entity_test_mulrevpub');
82     $this->assertArraySubset([$this->testUser->id() => ['en' => 'en']], $store_entries);
83   }
84
85 }