cf5be74737bd83a0808622407993a05567174757
[yaffs-website] / web / core / modules / rest / tests / src / Functional / EntityResource / ConfigurableLanguage / ConfigurableLanguageResourceTestBase.php
1 <?php
2
3 namespace Drupal\Tests\rest\Functional\EntityResource\ConfigurableLanguage;
4
5 use Drupal\Core\Cache\Cache;
6 use Drupal\Core\Url;
7 use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
8 use Drupal\language\Entity\ConfigurableLanguage;
9
10 abstract class ConfigurableLanguageResourceTestBase extends EntityResourceTestBase {
11
12   /**
13    * {@inheritdoc}
14    */
15   public static $modules = ['language'];
16
17   /**
18    * {@inheritdoc}
19    */
20   protected static $entityTypeId = 'configurable_language';
21
22   /**
23    * @var \Drupal\language\ConfigurableLanguageInterface
24    */
25   protected $entity;
26
27   /**
28    * {@inheritdoc}
29    */
30   protected function setUpAuthorization($method) {
31     $this->grantPermissionsToTestedRole(['administer languages']);
32   }
33
34   /**
35    * {@inheritdoc}
36    */
37   protected function createEntity() {
38     $configurable_language = ConfigurableLanguage::create([
39       'id' => 'll',
40       'label' => 'Llama Language',
41     ]);
42     $configurable_language->save();
43
44     return $configurable_language;
45   }
46
47   /**
48    * {@inheritdoc}
49    */
50   protected function getExpectedNormalizedEntity() {
51     return [
52       'dependencies' => [],
53       'direction' => 'ltr',
54       'id' => 'll',
55       'label' => 'Llama Language',
56       'langcode' => 'en',
57       'locked' => FALSE,
58       'status' => TRUE,
59       'uuid' => $this->entity->uuid(),
60       'weight' => 0,
61     ];
62   }
63
64   /**
65    * {@inheritdoc}
66    */
67   protected function getExpectedCacheContexts() {
68     return Cache::mergeContexts(parent::getExpectedCacheContexts(), ['languages:language_interface']);
69   }
70
71   /**
72    * {@inheritdoc}
73    */
74   protected function getNormalizedPostEntity() {
75     // @todo Update in https://www.drupal.org/node/2300677.
76   }
77
78   /**
79    * Test a GET request for a default config entity, which has a _core key.
80    *
81    * @see https://www.drupal.org/node/2915414
82    */
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);
90
91     $normalization = $this->serializer->decode((string) $response->getBody(), static::$format);
92     $this->assertArrayNotHasKey('_core', $normalization);
93   }
94
95 }