3 namespace Drupal\Tests\rest\Functional\EntityResource\ConfigurableLanguage;
5 use Drupal\Core\Cache\Cache;
7 use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
8 use Drupal\language\Entity\ConfigurableLanguage;
10 abstract class ConfigurableLanguageResourceTestBase extends EntityResourceTestBase {
15 public static $modules = ['language'];
20 protected static $entityTypeId = 'configurable_language';
23 * @var \Drupal\language\ConfigurableLanguageInterface
30 protected function setUpAuthorization($method) {
31 $this->grantPermissionsToTestedRole(['administer languages']);
37 protected function createEntity() {
38 $configurable_language = ConfigurableLanguage::create([
40 'label' => 'Llama Language',
42 $configurable_language->save();
44 return $configurable_language;
50 protected function getExpectedNormalizedEntity() {
55 'label' => 'Llama Language',
59 'uuid' => $this->entity->uuid(),
67 protected function getExpectedCacheContexts() {
68 return Cache::mergeContexts(parent::getExpectedCacheContexts(), ['languages:language_interface']);
74 protected function getNormalizedPostEntity() {
75 // @todo Update in https://www.drupal.org/node/2300677.
79 * Test a GET request for a default config entity, which has a _core key.
81 * @see https://www.drupal.org/node/2915414
83 public function testGetDefaultConfig() {
84 $this->initAuthentication();
85 $url = Url::fromUri('base:/entity/configurable_language/en')->setOption('query', ['_format' => static::$format]);;
86 $request_options = $this->getAuthenticationRequestOptions('GET');
87 $this->provisionEntityResource();
88 $this->setUpAuthorization('GET');
89 $response = $this->request('GET', $url, $request_options);
91 $normalization = $this->serializer->decode((string) $response->getBody(), static::$format);
92 $this->assertArrayNotHasKey('_core', $normalization);