grantPermissionsToTestedRole(['administer languages']); } /** * {@inheritdoc} */ protected function createEntity() { // Create a "Camelids" node type. $camelids = NodeType::create([ 'name' => 'Camelids', 'type' => 'camelids', ]); $camelids->save(); $entity = ContentLanguageSettings::create([ 'target_entity_type_id' => 'node', 'target_bundle' => 'camelids', ]); $entity->setDefaultLangcode('site_default') ->save(); return $entity; } /** * {@inheritdoc} */ protected function getExpectedDocument(): array { $self_url = Url::fromUri('base:/jsonapi/language_content_settings/language_content_settings/' . $this->entity->uuid())->setAbsolute()->toString(TRUE)->getGeneratedUrl(); return [ 'jsonapi' => [ 'meta' => [ 'links' => [ 'self' => ['href' => JsonApiSpec::SUPPORTED_SPECIFICATION_PERMALINK], ], ], 'version' => JsonApiSpec::SUPPORTED_SPECIFICATION_VERSION, ], 'links' => [ 'self' => ['href' => $self_url], ], 'data' => [ 'id' => $this->entity->uuid(), 'type' => 'language_content_settings--language_content_settings', 'links' => [ 'self' => ['href' => $self_url], ], 'attributes' => [ 'default_langcode' => 'site_default', 'dependencies' => [ 'config' => [ 'node.type.camelids', ], ], 'langcode' => 'en', 'language_alterable' => FALSE, 'status' => TRUE, 'target_bundle' => 'camelids', 'target_entity_type_id' => 'node', 'drupal_internal__id' => 'node.camelids', ], ], ]; } /** * {@inheritdoc} */ protected function getPostDocument(): array { // @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']); } /** * {@inheritdoc} */ protected function createAnotherEntity($key) { NodeType::create([ 'name' => 'Llamaids', 'type' => 'llamaids', ])->save(); $entity = ContentLanguageSettings::create([ 'target_entity_type_id' => 'node', 'target_bundle' => 'llamaids', ]); $entity->setDefaultLangcode('site_default'); $entity->save(); return $entity; } /** * {@inheritdoc} */ protected static function getExpectedCollectionCacheability(AccountInterface $account, array $collection, ?array $sparse_fieldset = NULL, $filtered = FALSE) { $cacheability = parent::getExpectedCollectionCacheability($account, $collection, $sparse_fieldset, $filtered); if (static::entityAccess(reset($collection), 'view', $account)->isAllowed()) { $cacheability->addCacheContexts(['languages:language_interface']); } return $cacheability; } }