class FieldEntityTranslationTest
Same name and namespace in other branches
- 11.x core/modules/views/tests/src/Functional/Entity/FieldEntityTranslationTest.php \Drupal\Tests\views\Functional\Entity\FieldEntityTranslationTest
- 10 core/modules/views/tests/src/Functional/Entity/FieldEntityTranslationTest.php \Drupal\Tests\views\Functional\Entity\FieldEntityTranslationTest
- 8.9.x core/modules/views/tests/src/Functional/Entity/FieldEntityTranslationTest.php \Drupal\Tests\views\Functional\Entity\FieldEntityTranslationTest
Tests the rendering of fields (base fields) and their translations.
@group views
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait extends \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\views\Functional\Entity\FieldEntityTranslationTest extends \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of FieldEntityTranslationTest
File
-
core/
modules/ views/ tests/ src/ Functional/ Entity/ FieldEntityTranslationTest.php, line 17
Namespace
Drupal\Tests\views\Functional\EntityView source
class FieldEntityTranslationTest extends ViewTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'language',
'locale',
'content_translation',
'node',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
public static $testViews = [
'test_entity_field_renderers',
];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE, $modules = [
'views_test_config',
]) : void {
parent::setUp($import_test_views, $modules);
$node_type = NodeType::create([
'type' => 'article',
'label' => 'Article',
]);
$node_type->save();
/** @var \Drupal\content_translation\ContentTranslationManagerInterface $content_translation_manager */
$content_translation_manager = \Drupal::service('content_translation.manager');
$content_translation_manager->setEnabled('node', 'article', TRUE);
$language = ConfigurableLanguage::create([
'id' => 'es',
'label' => 'Spanish',
]);
$language->save();
// Rebuild the container to setup the language path processors.
$this->rebuildContainer();
}
/**
* Tests that different translation mechanisms can be used for base fields.
*/
public function testTranslationRows() {
$node = Node::create([
'type' => 'article',
'title' => 'example EN',
'sticky' => FALSE,
]);
$node->save();
$translation = $node->addTranslation('es');
$translation->title->value = 'example ES';
$translation->sticky->value = TRUE;
$translation->save();
$this->drupalGet('test_entity_field_renderers/entity_translation');
$this->assertRows([
[
'title' => 'example EN',
'sticky' => 'Off',
],
[
'title' => 'example ES',
'sticky' => 'On',
],
]);
$this->drupalGet('test_entity_field_renderers/entity_default');
$this->assertRows([
[
'title' => 'example EN',
'sticky' => 'Off',
],
[
'title' => 'example EN',
'sticky' => 'Off',
],
]);
$this->drupalGet('test_entity_field_renderers/site_default');
$this->assertRows([
[
'title' => 'example EN',
'sticky' => 'Off',
],
[
'title' => 'example EN',
'sticky' => 'Off',
],
]);
$this->drupalGet('test_entity_field_renderers/language_interface');
$this->assertRows([
[
'title' => 'example EN',
'sticky' => 'Off',
],
[
'title' => 'example EN',
'sticky' => 'Off',
],
]);
$this->drupalGet('test_entity_field_renderers/language_interface', [
'language' => new Language([
'id' => 'es',
]),
]);
$this->assertRows([
[
'title' => 'example ES',
'sticky' => 'On',
],
[
'title' => 'example ES',
'sticky' => 'On',
],
]);
$this->drupalGet('test_entity_field_renderers/en');
$this->assertRows([
[
'title' => 'example EN',
'sticky' => 'Off',
],
[
'title' => 'example EN',
'sticky' => 'Off',
],
]);
$this->drupalGet('test_entity_field_renderers/es');
$this->assertRows([
[
'title' => 'example ES',
'sticky' => 'On',
],
[
'title' => 'example ES',
'sticky' => 'On',
],
]);
}
/**
* Ensures that the rendered results are working as expected.
*
* @param array $expected
* The expected rows of the result.
*
* @internal
*/
protected function assertRows(array $expected = []) : void {
$actual = [];
$rows = $this->cssSelect('div.views-row');
foreach ($rows as $row) {
$actual[] = [
'title' => $row->find('xpath', (new CssSelectorConverter())->toXPath('.views-field-title span.field-content a'))
->getText(),
'sticky' => $row->find('xpath', (new CssSelectorConverter())->toXPath('.views-field-sticky span.field-content'))
->getText(),
];
}
$this->assertEquals($expected, $actual);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.