View source
<?php
namespace Drupal\Tests\rest\Functional\Update;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
class ResourceGranularityUpdateTest extends UpdatePathTestBase {
protected static $modules = [
'rest',
'serialization',
];
public function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
__DIR__ . '/../../../fixtures/update/drupal-8.rest-rest_post_update_resource_granularity.php',
];
}
public function testMethodGranularityConvertedToResourceGranularity() {
$resource_config_storage = $this->container
->get('entity_type.manager')
->getStorage('rest_resource_config');
$resource_config_entities = $resource_config_storage
->loadMultiple();
$this
->assertIdentical([
'entity.comment',
'entity.node',
'entity.user',
], array_keys($resource_config_entities));
$this
->assertIdentical('method', $resource_config_entities['entity.node']
->get('granularity'));
$this
->assertIdentical('method', $resource_config_entities['entity.comment']
->get('granularity'));
$this
->assertIdentical('method', $resource_config_entities['entity.user']
->get('granularity'));
$comment_resource_configuration = $resource_config_entities['entity.comment']
->get('configuration');
$user_resource_configuration = $resource_config_entities['entity.user']
->get('configuration');
$this
->runUpdates();
$resource_config_entities = $resource_config_storage
->loadMultiple();
$this
->assertIdentical([
'entity.comment',
'entity.node',
'entity.user',
], array_keys($resource_config_entities));
$this
->assertIdentical('resource', $resource_config_entities['entity.node']
->get('granularity'));
$this
->assertidentical($resource_config_entities['entity.node']
->get('configuration'), [
'methods' => [
'GET',
'POST',
'PATCH',
'DELETE',
],
'formats' => [
'hal_json',
],
'authentication' => [
'basic_auth',
],
]);
$this
->assertIdentical('method', $resource_config_entities['entity.comment']
->get('granularity'));
$this
->assertIdentical($comment_resource_configuration, $resource_config_entities['entity.comment']
->get('configuration'));
$this
->assertIdentical('method', $resource_config_entities['entity.user']
->get('granularity'));
$this
->assertIdentical($user_resource_configuration, $resource_config_entities['entity.user']
->get('configuration'));
}
}