Updated Drupal to 8.6. This goes with the following updates because it's possible...
[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  * @group legacy
15  */
16 class ResourceGranularityUpdateTest extends UpdatePathTestBase {
17
18   /**
19    * {@inheritdoc}
20    */
21   protected static $modules = ['rest', 'serialization'];
22
23   /**
24    * {@inheritdoc}
25    */
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',
30     ];
31   }
32
33   /**
34    * Tests rest_post_update_simplify_resource_granularity().
35    */
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');
39
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'));
46
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');
51
52     $this->runUpdates();
53
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'],
63     ]);
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'));
70   }
71
72 }