Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / system / tests / src / Functional / Update / UpdateActionsWithEntityPluginsTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Update;
4
5 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
6 use Drupal\system\Entity\Action;
7
8 /**
9  * Tests upgrading comment and node actions to generic entity ones.
10  *
11  * @group Update
12  * @group legacy
13  */
14 class UpdateActionsWithEntityPluginsTest extends UpdatePathTestBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   protected function setDatabaseDumpFiles() {
20     $this->databaseDumpFiles = [__DIR__ . '/../../../../tests/fixtures/update/drupal-8.bare.standard.php.gz'];
21   }
22
23   /**
24    * Tests upgrading comment and node actions to generic entity ones.
25    *
26    * @see system_post_update_change_action_plugins()
27    */
28   public function testUpdateActionsWithEntityPlugins() {
29     $old_new_action_id_map = [
30       'comment_publish_action' => ['comment_publish_action', 'entity:publish_action:comment'],
31       'comment_unpublish_action' => ['comment_unpublish_action', 'entity:unpublish_action:comment'],
32       'comment_save_action' => ['comment_save_action', 'entity:save_action:comment'],
33       'node_publish_action' => ['node_publish_action', 'entity:publish_action:node'],
34       'node_unpublish_action' => ['node_unpublish_action', 'entity:unpublish_action:node'],
35       'node_save_action' => ['node_save_action', 'entity:save_action:node'],
36     ];
37
38     foreach ($old_new_action_id_map as $key => list($before, $after)) {
39       $config = \Drupal::configFactory()->get('system.action.' . $key);
40       $this->assertSame($before, $config->get('plugin'));
41     }
42
43     $this->runUpdates();
44
45     foreach ($old_new_action_id_map as $key => list($before, $after)) {
46       /** @var \Drupal\system\Entity\Action $action */
47       $action = Action::load($key);
48       $this->assertSame($after, $action->getPlugin()->getPluginId());
49       $config = \Drupal::configFactory()->get('system.action.' . $key);
50       $this->assertSame($after, $config->get('plugin'));
51
52       // Check that the type the action is based on will be a module dependency.
53       $this->assertArraySubset(['module' => [$action->getPluginDefinition()['type']]], $action->getDependencies());
54     }
55   }
56
57   /**
58    * Tests upgrading comment and node delete actions to generic entity ones.
59    *
60    * @see system_post_update_change_delete_action_plugins()
61    */
62   public function testUpdateDeleteActionsWithEntityPlugins() {
63     // comment_delete_actions is not part of the dump files.
64     $array = [
65       'node_delete_action' => ['node_delete_action', 'entity:delete_action:node'],
66     ];
67
68     foreach ($array as $key => list($before, $after)) {
69       /** @var \Drupal\system\Entity\Action $action */
70       $action = Action::load($key);
71       $this->assertSame($before, $action->getPlugin()->getPluginId());
72     }
73
74     $this->runUpdates();
75
76     foreach ($array as $key => list($before, $after)) {
77       /** @var \Drupal\system\Entity\Action $action */
78       $action = Action::load($key);
79       $this->assertSame($after, $action->getPlugin()->getPluginId());
80
81       // Check that the type the action is based on will be a module dependency.
82       $this->assertArraySubset(['module' => [$action->getPluginDefinition()['type']]], $action->getDependencies());
83     }
84   }
85
86 }