739089a9886e73739099cfee454ba11e9380256c
[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  * @group legacy
14  */
15 class EntityResourcePermissionsUpdateTest 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_update_8203.php',
29     ];
30   }
31
32   /**
33    * Tests rest_update_8203().
34    */
35   public function testBcEntityResourcePermissionSettingAdded() {
36     $permission_handler = $this->container->get('user.permissions');
37
38     $is_rest_resource_permission = function ($permission) {
39       return $permission['provider'] === 'rest' && (string) $permission['title'] !== 'Administer REST resource configuration';
40     };
41
42     // Make sure we have the expected values before the update.
43     $rest_settings = $this->config('rest.settings');
44     $this->assertFalse(array_key_exists('bc_entity_resource_permissions', $rest_settings->getRawData()));
45     $this->assertEqual([], array_filter($permission_handler->getPermissions(), $is_rest_resource_permission));
46
47     $this->runUpdates();
48
49     // Make sure we have the expected values after the update.
50     $rest_settings = $this->config('rest.settings');
51     $this->assertTrue(array_key_exists('bc_entity_resource_permissions', $rest_settings->getRawData()));
52     $this->assertTrue($rest_settings->get('bc_entity_resource_permissions'));
53     $rest_permissions = array_keys(array_filter($permission_handler->getPermissions(), $is_rest_resource_permission));
54     $this->assertEqual(['restful delete entity:node', 'restful get entity:node', 'restful patch entity:node', 'restful post entity:node'], $rest_permissions);
55   }
56
57 }