core/modules/rest/rest.install | 10 ++++ .../Update/EntityResourcePermissionsUpdateTest.php | 56 +++++++++++++++++++ .../update/drupal-8.rest-rest_update_8201.php | 63 ++++++++++++++++++++++ 3 files changed, 129 insertions(+) diff --git a/core/modules/rest/rest.install b/core/modules/rest/rest.install index 3b2f097..9a08e34 100644 --- a/core/modules/rest/rest.install +++ b/core/modules/rest/rest.install @@ -23,6 +23,12 @@ function rest_requirements($phase) { } /** + * @defgroup updates-8.1.x-to-8.2.x Updates from 8.1.x to 8.2.x + * @{ + * Update functions from 8.1.x to 8.2.x. + */ + +/** * Enable BC for EntityResource: continue to use permissions. */ function rest_update_8201() { @@ -31,3 +37,7 @@ function rest_update_8201() { $rest_settings->set('bc_entity_resource_permissions', TRUE) ->save(TRUE); } + +/** + * @} End of "defgroup updates-8.1.x-to-8.2.x". + */ diff --git a/core/modules/rest/src/Tests/Update/EntityResourcePermissionsUpdateTest.php b/core/modules/rest/src/Tests/Update/EntityResourcePermissionsUpdateTest.php new file mode 100644 index 0000000..ff20c1e --- /dev/null +++ b/core/modules/rest/src/Tests/Update/EntityResourcePermissionsUpdateTest.php @@ -0,0 +1,56 @@ +databaseDumpFiles = [ + __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz', + __DIR__ . '/../../../../rest/tests/fixtures/update/drupal-8.rest-rest_update_8201.php', + ]; + } + + /** + * Tests rest_update_8201(). + */ + public function testAllowedHtmlUpdate() { + $permission_handler = $this->container->get('user.permissions'); + + // Make sure we have the expected values before the update. + $rest_settings = $this->config('rest.settings'); + $this->assertFalse(array_key_exists('bc_entity_resource_permissions', $rest_settings->getRawData())); + $this->assertFalse($permission_handler->moduleProvidesPermissions('rest')); + + $this->runUpdates(); + + // Make sure we have the expected values after the update. + $rest_settings = $this->config('rest.settings'); + $this->assertTrue(array_key_exists('bc_entity_resource_permissions', $rest_settings->getRawData())); + $this->assertTrue($rest_settings->get('bc_entity_resource_permissions')); + $this->assertTrue($permission_handler->moduleProvidesPermissions('rest')); + $permissions = $permission_handler->getPermissions(); + $rest_permissions = array_keys(array_filter($permissions, function ($permission) { + return $permission['provider'] === 'rest'; + })); + $this->assertEqual(['restful delete entity:node', 'restful get entity:node', 'restful patch entity:node', 'restful post entity:node'], $rest_permissions); + } + +} diff --git a/core/modules/rest/tests/fixtures/update/drupal-8.rest-rest_update_8201.php b/core/modules/rest/tests/fixtures/update/drupal-8.rest-rest_update_8201.php new file mode 100644 index 0000000..f035e94 --- /dev/null +++ b/core/modules/rest/tests/fixtures/update/drupal-8.rest-rest_update_8201.php @@ -0,0 +1,63 @@ +insert('key_value') + ->fields([ + 'collection' => 'system.schema', + 'name' => 'rest', + 'value' => 'i:8000;', + ]) + ->fields([ + 'collection' => 'system.schema', + 'name' => 'serialization', + 'value' => 'i:8000;', + ]) + ->execute(); + +// Update core.extension. +$extensions = $connection->select('config') + ->fields('config', ['data']) + ->condition('collection', '') + ->condition('name', 'core.extension') + ->execute() + ->fetchField(); +$extensions = unserialize($extensions); +$extensions['module']['rest'] = 8000; +$extensions['module']['serialization'] = 8000; +$connection->update('config') + ->fields([ + 'data' => serialize($extensions), + ]) + ->condition('collection', '') + ->condition('name', 'core.extension') + ->execute(); + +// Install the rest configuration. +$config = [ + 'resources' => [ + 'entity:node' => [ + 'GET' => [ + 'supported_formats' => ['json'], + 'supported_auth' => [], + ], + ], + ], + 'link_domain' => '~', +]; +$data = $connection->insert('config') + ->fields([ + 'name' => 'rest.settings', + 'data' => serialize($config), + 'collection' => '' + ]) + ->execute();