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