9add9c5d90d8d9e9c2b227b33751916ec0414dd3
[yaffs-website] / web / core / modules / rest / tests / src / Functional / Update / EntityResourcePermissionsUpdateTest.php
1 <?php
2
3 namespace Drupal\Tests\rest\Functional\Update;
4
5 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
6
7 /**
8  * Tests that existing sites continue to use permissions for EntityResource.
9  *
10  * @see https://www.drupal.org/node/2664780
11  *
12  * @group rest
13  */
14 class EntityResourcePermissionsUpdateTest extends UpdatePathTestBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   protected static $modules = ['rest', 'serialization'];
20
21   /**
22    * {@inheritdoc}
23    */
24   public function setDatabaseDumpFiles() {
25     $this->databaseDumpFiles = [
26       __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
27       __DIR__ . '/../../../fixtures/update/drupal-8.rest-rest_update_8203.php',
28     ];
29   }
30
31   /**
32    * Tests rest_update_8203().
33    */
34   public function testBcEntityResourcePermissionSettingAdded() {
35     $permission_handler = $this->container->get('user.permissions');
36
37     $is_rest_resource_permission = function ($permission) {
38       return $permission['provider'] === 'rest' && (string) $permission['title'] !== 'Administer REST resource configuration';
39     };
40
41     // Make sure we have the expected values before the update.
42     $rest_settings = $this->config('rest.settings');
43     $this->assertFalse(array_key_exists('bc_entity_resource_permissions', $rest_settings->getRawData()));
44     $this->assertEqual([], array_filter($permission_handler->getPermissions(), $is_rest_resource_permission));
45
46     $this->runUpdates();
47
48     // Make sure we have the expected values after the update.
49     $rest_settings = $this->config('rest.settings');
50     $this->assertTrue(array_key_exists('bc_entity_resource_permissions', $rest_settings->getRawData()));
51     $this->assertTrue($rest_settings->get('bc_entity_resource_permissions'));
52     $rest_permissions = array_keys(array_filter($permission_handler->getPermissions(), $is_rest_resource_permission));
53     $this->assertEqual(['restful delete entity:node', 'restful get entity:node', 'restful patch entity:node', 'restful post entity:node'], $rest_permissions);
54   }
55
56 }