3 namespace Drupal\Tests\rest\Functional\Update;
5 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
6 use Drupal\rest\RestResourceConfigInterface;
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()
18 class RestConfigurationEntitiesUpdateTest extends UpdatePathTestBase {
23 protected static $modules = ['rest', 'serialization'];
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',
36 * Tests rest_update_8201().
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');
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));
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([
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());