View source
<?php
namespace Drupal\Tests\graphql_core\Kernel\Entity;
use Drupal\Tests\graphql_core\Kernel\GraphQLContentTestBase;
class EntityByIdTest extends GraphQLContentTestBase {
protected $frenchLangcode = 'fr';
protected $chineseSimplifiedLangcode = 'zh-hans';
protected function setUp() {
parent::setUp();
$languageStorage = $this->container
->get('entity_type.manager')
->getStorage('configurable_language');
$language = $languageStorage
->create([
'id' => $this->chineseSimplifiedLangcode,
]);
$language
->save();
}
public function testEntityByIdWithTranslation() {
$node = $this
->createNode([
'title' => 'English node',
'type' => 'test',
]);
$node
->save();
$node
->addTranslation($this->frenchLangcode, [
'title' => 'French node',
])
->save();
$node
->addTranslation($this->chineseSimplifiedLangcode, [
'title' => 'Chinese simplified node',
])
->save();
$this
->getNewDraft($node)
->setPublished(FALSE)
->setTitle('English node unpublished')
->save();
$metadata = $this
->defaultCacheMetaData();
$metadata
->addCacheTags([
'node:1',
]);
$this
->assertResults($this
->getQueryFromFile('entity_by_id.gql'), [
'id' => $node
->id(),
'language' => 'EN',
], [
'nodeById' => [
'entityLabel' => 'English node',
],
], $metadata);
$this
->assertResults($this
->getQueryFromFile('entity_by_id.gql'), [
'id' => $node
->id(),
'language' => 'FR',
], [
'nodeById' => [
'entityLabel' => 'French node',
],
], $metadata);
$this
->assertResults($this
->getQueryFromFile('entity_by_id.gql'), [
'id' => $node
->id(),
'language' => 'ZH_HANS',
], [
'nodeById' => [
'entityLabel' => 'Chinese simplified node',
],
], $metadata);
}
}