Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / rest / tests / src / Functional / Update / ResourceGranularityUpdateTest.php
1 <?php
2
3 namespace Drupal\Tests\rest\Functional\Update;
4
5 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
6
7 /**
8  * Tests method-granularity REST config is simplified to resource-granularity.
9  *
10  * @see https://www.drupal.org/node/2721595
11  * @see rest_post_update_resource_granularity()
12  *
13  * @group rest
14  */
15 class ResourceGranularityUpdateTest extends UpdatePathTestBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   protected static $modules = ['rest', 'serialization'];
21
22   /**
23    * {@inheritdoc}
24    */
25   public function setDatabaseDumpFiles() {
26     $this->databaseDumpFiles = [
27       __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
28       __DIR__ . '/../../../fixtures/update/drupal-8.rest-rest_post_update_resource_granularity.php',
29     ];
30   }
31
32   /**
33    * Tests rest_post_update_simplify_resource_granularity().
34    */
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');
38
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'));
45
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');
50
51     $this->runUpdates();
52
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'],
62     ]);
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'));
69   }
70
71 }