3 namespace Drupal\rest\Tests\Update;
5 use Drupal\rest\RestResourceConfigInterface;
6 use Drupal\system\Tests\Update\UpdatePathTestBase;
9 * Tests that rest.settings is converted to rest_resource_config entities.
11 * @see https://www.drupal.org/node/2308745
12 * @see rest_update_8201()
13 * @see rest_post_update_create_rest_resource_config_entities()
17 class RestConfigurationEntitiesUpdateTest extends UpdatePathTestBase {
22 protected static $modules = ['rest', 'serialization'];
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',
35 * Tests rest_update_8201().
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');
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));
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([
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());