You are here

class ConfigurableLanguageTest in Drupal 10

Same name in this branch
  1. 10 core/modules/jsonapi/tests/src/Functional/ConfigurableLanguageTest.php \Drupal\Tests\jsonapi\Functional\ConfigurableLanguageTest
  2. 10 core/modules/language/tests/src/Kernel/ConfigurableLanguageTest.php \Drupal\Tests\language\Kernel\ConfigurableLanguageTest
Same name and namespace in other branches
  1. 8 core/modules/jsonapi/tests/src/Functional/ConfigurableLanguageTest.php \Drupal\Tests\jsonapi\Functional\ConfigurableLanguageTest
  2. 9 core/modules/jsonapi/tests/src/Functional/ConfigurableLanguageTest.php \Drupal\Tests\jsonapi\Functional\ConfigurableLanguageTest

JSON:API integration test for the "ConfigurableLanguage" config entity type.

@group jsonapi

Hierarchy

Expanded class hierarchy of ConfigurableLanguageTest

File

core/modules/jsonapi/tests/src/Functional/ConfigurableLanguageTest.php, line 17

Namespace

Drupal\Tests\jsonapi\Functional
View source
class ConfigurableLanguageTest extends ConfigEntityResourceTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'language',
  ];

  /**
   * {@inheritdoc}
   */
  protected static $entityTypeId = 'configurable_language';

  /**
   * {@inheritdoc}
   */
  protected static $resourceTypeName = 'configurable_language--configurable_language';

  /**
   * {@inheritdoc}
   *
   * @var \Drupal\Core\Field\Entity\BaseFieldOverride
   */
  protected $entity;

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * {@inheritdoc}
   */
  protected function setUpAuthorization($method) {
    $this
      ->grantPermissionsToTestedRole([
      'administer languages',
    ]);
  }

  /**
   * {@inheritdoc}
   */
  protected function createEntity() {
    $configurable_language = ConfigurableLanguage::create([
      'id' => 'll',
      'label' => 'Llama Language',
    ]);
    $configurable_language
      ->save();
    return $configurable_language;
  }

  /**
   * {@inheritdoc}
   */
  protected function getExpectedDocument() {
    $self_url = Url::fromUri('base:/jsonapi/configurable_language/configurable_language/' . $this->entity
      ->uuid())
      ->setAbsolute()
      ->toString(TRUE)
      ->getGeneratedUrl();
    return [
      'jsonapi' => [
        'meta' => [
          'links' => [
            'self' => [
              'href' => 'http://jsonapi.org/format/1.0/',
            ],
          ],
        ],
        'version' => '1.0',
      ],
      'links' => [
        'self' => [
          'href' => $self_url,
        ],
      ],
      'data' => [
        'id' => $this->entity
          ->uuid(),
        'type' => 'configurable_language--configurable_language',
        'links' => [
          'self' => [
            'href' => $self_url,
          ],
        ],
        'attributes' => [
          'dependencies' => [],
          'direction' => 'ltr',
          'label' => 'Llama Language',
          'langcode' => 'en',
          'locked' => FALSE,
          'status' => TRUE,
          'weight' => 0,
          'drupal_internal__id' => 'll',
        ],
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  protected function getPostDocument() {

    // @todo Update in https://www.drupal.org/node/2300677.
    return [];
  }

  /**
   * {@inheritdoc}
   */
  protected function getExpectedCacheContexts(array $sparse_fieldset = NULL) {
    return Cache::mergeContexts(parent::getExpectedCacheContexts(), [
      'languages:language_interface',
    ]);
  }

  /**
   * Tests a GET request for a default config entity, which has a _core key.
   *
   * @see https://www.drupal.org/project/drupal/issues/2915539
   */
  public function testGetIndividualDefaultConfig() {

    // @todo Remove line below in favor of commented line in https://www.drupal.org/project/drupal/issues/2878463.
    $url = Url::fromRoute('jsonapi.configurable_language--configurable_language.individual', [
      'entity' => ConfigurableLanguage::load('en')
        ->uuid(),
    ]);

    /* $url = ConfigurableLanguage::load('en')->toUrl('jsonapi'); */
    $request_options = [];
    $request_options[RequestOptions::HEADERS]['Accept'] = 'application/vnd.api+json';
    $request_options = NestedArray::mergeDeep($request_options, $this
      ->getAuthenticationRequestOptions());
    $this
      ->setUpAuthorization('GET');
    $response = $this
      ->request('GET', $url, $request_options);
    $normalization = Json::decode((string) $response
      ->getBody());
    $this
      ->assertArrayNotHasKey('_core', $normalization['data']['attributes']);
  }

}

Members