097da35bb1bd13ebe39a4f81da5f7376d7ed4892
[yaffs-website] / web / core / modules / rest / src / Tests / Update / RestConfigurationEntitiesUpdateTest.php
1 <?php
2
3 namespace Drupal\rest\Tests\Update;
4
5 use Drupal\rest\RestResourceConfigInterface;
6 use Drupal\system\Tests\Update\UpdatePathTestBase;
7
8 /**
9  * Tests that rest.settings is converted to rest_resource_config entities.
10  *
11  * @see https://www.drupal.org/node/2308745
12  * @see rest_update_8201()
13  * @see rest_post_update_create_rest_resource_config_entities()
14  *
15  * @group rest
16  */
17 class RestConfigurationEntitiesUpdateTest extends UpdatePathTestBase {
18
19   /**
20    * {@inheritdoc}
21    */
22   protected static $modules = ['rest', 'serialization'];
23
24   /**
25    * {@inheritdoc}
26    */
27   public function setDatabaseDumpFiles() {
28     $this->databaseDumpFiles = [
29       __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
30       __DIR__ . '/../../../../rest/tests/fixtures/update/drupal-8.rest-rest_update_8201.php',
31     ];
32   }
33
34   /**
35    * Tests rest_update_8201().
36    */
37   public function testResourcesConvertedToConfigEntities() {
38     /** @var \Drupal\Core\Entity\EntityStorageInterface $resource_config_storage */
39     $resource_config_storage = $this->container->get('entity_type.manager')->getStorage('rest_resource_config');
40
41     // Make sure we have the expected values before the update.
42     $rest_settings = $this->config('rest.settings');
43     $this->assertTrue(array_key_exists('resources', $rest_settings->getRawData()));
44     $this->assertTrue(array_key_exists('entity:node', $rest_settings->getRawData()['resources']));
45     $resource_config_entities = $resource_config_storage->loadMultiple();
46     $this->assertIdentical([], array_keys($resource_config_entities));
47
48     $this->runUpdates();
49
50     // Make sure we have the expected values after the update.
51     $rest_settings = $this->config('rest.settings');
52     $this->assertFalse(array_key_exists('resources', $rest_settings->getRawData()));
53     $resource_config_entities = $resource_config_storage->loadMultiple();
54     $this->assertIdentical(['entity.node'], array_keys($resource_config_entities));
55     $node_resource_config_entity = $resource_config_entities['entity.node'];
56     $this->assertIdentical(RestResourceConfigInterface::RESOURCE_GRANULARITY, $node_resource_config_entity->get('granularity'));
57     $this->assertIdentical([
58       'methods' => ['GET'],
59       'formats' => ['json'],
60       'authentication' => ['basic_auth'],
61     ], $node_resource_config_entity->get('configuration'));
62     $this->assertIdentical(['module' => ['basic_auth', 'node', 'serialization']], $node_resource_config_entity->getDependencies());
63   }
64
65 }