3 namespace Drupal\Tests\rest\Functional\Update;
5 use Drupal\FunctionalTests\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()
16 class ResourceGranularityUpdateTest extends UpdatePathTestBase {
21 protected static $modules = ['rest', 'serialization'];
26 public function setDatabaseDumpFiles() {
27 $this->databaseDumpFiles = [
28 __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
29 __DIR__ . '/../../../fixtures/update/drupal-8.rest-rest_post_update_resource_granularity.php',
34 * Tests rest_post_update_simplify_resource_granularity().
36 public function testMethodGranularityConvertedToResourceGranularity() {
37 /** @var \Drupal\Core\Entity\EntityStorageInterface $resource_config_storage */
38 $resource_config_storage = $this->container->get('entity_type.manager')->getStorage('rest_resource_config');
40 // Make sure we have the expected values before the update.
41 $resource_config_entities = $resource_config_storage->loadMultiple();
42 $this->assertIdentical(['entity.comment', 'entity.node', 'entity.user'], array_keys($resource_config_entities));
43 $this->assertIdentical('method', $resource_config_entities['entity.node']->get('granularity'));
44 $this->assertIdentical('method', $resource_config_entities['entity.comment']->get('granularity'));
45 $this->assertIdentical('method', $resource_config_entities['entity.user']->get('granularity'));
47 // Read the existing 'entity:comment' and 'entity:user' resource
48 // configuration so we can verify it after the update.
49 $comment_resource_configuration = $resource_config_entities['entity.comment']->get('configuration');
50 $user_resource_configuration = $resource_config_entities['entity.user']->get('configuration');
54 // Make sure we have the expected values after the update.
55 $resource_config_entities = $resource_config_storage->loadMultiple();
56 $this->assertIdentical(['entity.comment', 'entity.node', 'entity.user'], array_keys($resource_config_entities));
57 // 'entity:node' should be updated.
58 $this->assertIdentical('resource', $resource_config_entities['entity.node']->get('granularity'));
59 $this->assertidentical($resource_config_entities['entity.node']->get('configuration'), [
60 'methods' => ['GET', 'POST', 'PATCH', 'DELETE'],
61 'formats' => ['hal_json'],
62 'authentication' => ['basic_auth'],
64 // 'entity:comment' should be unchanged.
65 $this->assertIdentical('method', $resource_config_entities['entity.comment']->get('granularity'));
66 $this->assertIdentical($comment_resource_configuration, $resource_config_entities['entity.comment']->get('configuration'));
67 // 'entity:user' should be unchanged.
68 $this->assertIdentical('method', $resource_config_entities['entity.user']->get('granularity'));
69 $this->assertIdentical($user_resource_configuration, $resource_config_entities['entity.user']->get('configuration'));