3 namespace Drupal\KernelTests\Core\Action;
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;
14 class DeleteActionTest extends KernelTestBase {
21 public static $modules = ['system', 'entity_test', 'user'];
26 protected function setUp() {
28 $this->installEntitySchema('entity_test_mulrevpub');
29 $this->installEntitySchema('user');
30 $this->installSchema('system', ['sequences', 'key_value_expire']);
32 $this->testUser = User::create([
34 'mail' => 'foobar@example.com',
36 $this->testUser->save();
37 \Drupal::service('current_user')->setAccount($this->testUser);
41 * @covers \Drupal\Core\Action\Plugin\Action\Derivative\EntityDeleteActionDeriver::getDerivativeDefinitions
43 public function testGetDerivativeDefinitions() {
44 $deriver = new EntityDeleteActionDeriver(\Drupal::entityTypeManager(), \Drupal::translation());
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',
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',
58 ], $deriver->getDerivativeDefinitions([
59 'action_label' => 'Delete',
64 * @covers \Drupal\Core\Action\Plugin\Action\DeleteAction::execute
66 public function testDeleteAction() {
67 $entity = EntityTestMulRevPub::create(['name' => 'test']);
70 $action = Action::create([
71 'id' => 'entity_delete_action',
72 'plugin' => 'entity:delete_action:entity_test_mulrevpub',
76 $action->execute([$entity]);
77 $this->assertArraySubset(['module' => ['entity_test']], $action->getDependencies());
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);