3 namespace Drupal\Tests\entity\Kernel;
5 use Drupal\entity\Plugin\Action\DeleteAction;
6 use Drupal\entity_module_test\Entity\EnhancedEntity;
7 use Drupal\system\Entity\Action;
8 use Drupal\user\Entity\User;
9 use Drupal\KernelTests\KernelTestBase;
12 * Tests the delete entity action.
16 class DeleteActionTest extends KernelTestBase {
21 * @var \Drupal\user\UserInterface
28 public static $modules = [
29 'action', 'node', 'entity_module_test', 'entity', 'user', 'system',
35 protected function setUp() {
38 $this->installEntitySchema('user');
39 $this->installEntitySchema('entity_test_enhanced');
40 $this->installSchema('system', ['key_value_expire', 'sequences']);
42 $this->user = User::create([
47 \Drupal::service('current_user')->setAccount($this->user);
50 public function testAction() {
51 /** @var \Drupal\system\ActionConfigEntityInterface $action */
52 $action = Action::create([
53 'id' => 'enhanced_entity_delete_action',
54 'label' => 'Delete enhanced entity',
55 'plugin' => 'entity_delete_action:entity_test_enhanced',
57 $status = $action->save();
58 $this->assertEquals(SAVED_NEW, $status);
59 $this->assertInstanceOf(DeleteAction::class, $action->getPlugin());
62 for ($i = 0; $i < 2; $i++) {
63 $entity = EnhancedEntity::create([
67 $entities[$entity->id()] = $entity;
70 $action->execute($entities);
71 // Confirm that the entity ids and langcodes are now in the tempstore.
72 $tempstore = \Drupal::service('tempstore.private')->get('entity_delete_multiple_confirm');
73 $selection = $tempstore->get($this->user->id() . ':entity_test_enhanced');
74 $this->assertEquals(array_keys($entities), array_keys($selection));
75 $this->assertEquals([['en' => 'en'], ['en' => 'en']], array_values($selection));