3 namespace Drupal\rest\Tests\Update;
5 use Drupal\system\Tests\Update\UpdatePathTestBase;
8 * Tests method-granularity REST config is simplified to resource-granularity.
10 * @see https://www.drupal.org/node/2721595
11 * @see rest_post_update_resource_granularity()
15 class ResourceGranularityUpdateTest extends UpdatePathTestBase {
20 protected static $modules = ['rest', 'serialization'];
25 public function setDatabaseDumpFiles() {
26 $this->databaseDumpFiles = [
27 __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
28 __DIR__ . '/../../../../rest/tests/fixtures/update/drupal-8.rest-rest_post_update_resource_granularity.php',
33 * Tests rest_post_update_simplify_resource_granularity().
35 public function testMethodGranularityConvertedToResourceGranularity() {
36 /** @var \Drupal\Core\Entity\EntityStorageInterface $resource_config_storage */
37 $resource_config_storage = $this->container->get('entity_type.manager')->getStorage('rest_resource_config');
39 // Make sure we have the expected values before the update.
40 $resource_config_entities = $resource_config_storage->loadMultiple();
41 $this->assertIdentical(['entity.comment', 'entity.node', 'entity.user'], array_keys($resource_config_entities));
42 $this->assertIdentical('method', $resource_config_entities['entity.node']->get('granularity'));
43 $this->assertIdentical('method', $resource_config_entities['entity.comment']->get('granularity'));
44 $this->assertIdentical('method', $resource_config_entities['entity.user']->get('granularity'));
46 // Read the existing 'entity:comment' and 'entity:user' resource
47 // configuration so we can verify it after the update.
48 $comment_resource_configuration = $resource_config_entities['entity.comment']->get('configuration');
49 $user_resource_configuration = $resource_config_entities['entity.user']->get('configuration');
53 // Make sure we have the expected values after the update.
54 $resource_config_entities = $resource_config_storage->loadMultiple();
55 $this->assertIdentical(['entity.comment', 'entity.node', 'entity.user'], array_keys($resource_config_entities));
56 // 'entity:node' should be updated.
57 $this->assertIdentical('resource', $resource_config_entities['entity.node']->get('granularity'));
58 $this->assertidentical($resource_config_entities['entity.node']->get('configuration'), [
59 'methods' => ['GET', 'POST', 'PATCH', 'DELETE'],
60 'formats' => ['hal_json'],
61 'authentication' => ['basic_auth'],
63 // 'entity:comment' should be unchanged.
64 $this->assertIdentical('method', $resource_config_entities['entity.comment']->get('granularity'));
65 $this->assertIdentical($comment_resource_configuration, $resource_config_entities['entity.comment']->get('configuration'));
66 // 'entity:user' should be unchanged.
67 $this->assertIdentical('method', $resource_config_entities['entity.user']->get('granularity'));
68 $this->assertIdentical($user_resource_configuration, $resource_config_entities['entity.user']->get('configuration'));