Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / entity / tests / src / Kernel / DeleteActionTest.php
1 <?php
2
3 namespace Drupal\Tests\entity\Kernel;
4
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;
11
12 /**
13  * Tests the delete entity action.
14  * @group entity
15  */
16 class DeleteActionTest extends KernelTestBase {
17
18   /**
19    * The current user.
20    *
21    * @var \Drupal\user\UserInterface
22    */
23   protected $user;
24
25   /**
26    * {@inheritdoc}
27    */
28   public static $modules = ['action', 'node', 'entity_module_test', 'entity',
29                             'user', 'system'];
30
31   /**
32    * {@inheritdoc}
33    */
34   protected function setUp() {
35     parent::setUp();
36
37     $this->installEntitySchema('user');
38     $this->installEntitySchema('entity_test_enhanced');
39     $this->installSchema('system', ['key_value_expire', 'sequences']);
40
41     $bundle = EnhancedEntityBundle::create([
42       'id' => 'default',
43       'label' => 'Default',
44     ]);
45     $bundle->save();
46
47     $this->user = User::create([
48       'name' => 'username',
49       'status' => 1,
50     ]);
51     $this->user->save();
52     \Drupal::service('current_user')->setAccount($this->user);
53   }
54
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',
61     ]);
62     $status = $action->save();
63     $this->assertEquals(SAVED_NEW, $status);
64     $this->assertInstanceOf(DeleteAction::class, $action->getPlugin());
65
66     $entities = [];
67     for ($i = 0; $i < 2; $i++) {
68       $entity = EnhancedEntity::create([
69         'type' => 'default',
70       ]);
71       $entity->save();
72       $entities[$entity->id()] = $entity;
73     }
74
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));
81   }
82
83 }