4094d00313d8e8b7af69fa1371828d3a27bc79fc
[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  */
13 class UpdateActionsWithEntityPluginsTest extends UpdatePathTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   protected function setDatabaseDumpFiles() {
19     $this->databaseDumpFiles = [__DIR__ . '/../../../../tests/fixtures/update/drupal-8.bare.standard.php.gz'];
20   }
21
22   /**
23    * Tests upgrading comment and node actions to generic entity ones.
24    *
25    * @see system_post_update_change_action_plugins()
26    */
27   public function testUpdateActionsWithEntityPlugins() {
28     $old_new_action_id_map = [
29       'comment_publish_action' => ['comment_publish_action', 'entity:publish_action:comment'],
30       'comment_unpublish_action' => ['comment_unpublish_action', 'entity:unpublish_action:comment'],
31       'comment_save_action' => ['comment_save_action', 'entity:save_action:comment'],
32       'node_publish_action' => ['node_publish_action', 'entity:publish_action:node'],
33       'node_unpublish_action' => ['node_unpublish_action', 'entity:unpublish_action:node'],
34       'node_save_action' => ['node_save_action', 'entity:save_action:node'],
35     ];
36
37     foreach ($old_new_action_id_map as $key => list($before, $after)) {
38       $config = \Drupal::configFactory()->get('system.action.' . $key);
39       $this->assertSame($before, $config->get('plugin'));
40     }
41
42     $this->runUpdates();
43
44     foreach ($old_new_action_id_map as $key => list($before, $after)) {
45       /** @var \Drupal\system\Entity\Action $action */
46       $action = Action::load($key);
47       $this->assertSame($after, $action->getPlugin()->getPluginId());
48       $config = \Drupal::configFactory()->get('system.action.' . $key);
49       $this->assertSame($after, $config->get('plugin'));
50
51       // Check that the type the action is based on will be a module dependency.
52       $this->assertArraySubset(['module' => [$action->getPluginDefinition()['type']]], $action->getDependencies());
53     }
54   }
55
56 }