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