3 namespace Drupal\Tests\views\Functional\Entity;
5 use Drupal\Core\Language\Language;
6 use Drupal\language\Entity\ConfigurableLanguage;
7 use Drupal\node\Entity\Node;
8 use Drupal\node\Entity\NodeType;
9 use Drupal\Tests\views\Functional\ViewTestBase;
10 use Symfony\Component\CssSelector\CssSelectorConverter;
13 * Tests the rendering of fields (base fields) and their translations.
17 class FieldEntityTranslationTest extends ViewTestBase {
22 public static $modules = ['language', 'locale', 'content_translation', 'node'];
27 public static $testViews = ['test_entity_field_renderers'];
32 protected function setUp($import_test_views = TRUE) {
33 parent::setUp($import_test_views);
35 $node_type = NodeType::create([
41 /** @var \Drupal\content_translation\ContentTranslationManagerInterface $content_translation_manager */
42 $content_translation_manager = \Drupal::service('content_translation.manager');
44 $content_translation_manager->setEnabled('node', 'article', TRUE);
46 $language = ConfigurableLanguage::create([
51 // Rebuild the container to setup the language path processors.
52 $this->rebuildContainer();
56 * Tests that different translation mechanisms can be used for base fields.
58 public function testTranslationRows() {
59 $node = Node::create([
61 'title' => 'example EN',
66 $translation = $node->addTranslation('es');
67 $translation->title->value = 'example ES';
68 $translation->sticky->value = TRUE;
71 $this->drupalGet('test_entity_field_renderers/entity_translation');
74 'title' => 'example EN',
78 'title' => 'example ES',
83 $this->drupalGet('test_entity_field_renderers/entity_default');
86 'title' => 'example EN',
90 'title' => 'example EN',
95 $this->drupalGet('test_entity_field_renderers/site_default');
98 'title' => 'example EN',
102 'title' => 'example EN',
107 $this->drupalGet('test_entity_field_renderers/language_interface');
110 'title' => 'example EN',
114 'title' => 'example EN',
119 $this->drupalGet('test_entity_field_renderers/language_interface', ['language' => new Language(['id' => 'es'])]);
122 'title' => 'example ES',
126 'title' => 'example ES',
131 $this->drupalGet('test_entity_field_renderers/en');
134 'title' => 'example EN',
138 'title' => 'example EN',
143 $this->drupalGet('test_entity_field_renderers/es');
146 'title' => 'example ES',
150 'title' => 'example ES',
157 * Ensures that the rendered results are working as expected.
159 * @param array $expected
160 * The expected rows of the result.
162 protected function assertRows($expected = []) {
164 $rows = $this->cssSelect('div.views-row');
165 foreach ($rows as $row) {
167 'title' => $row->find('xpath', (new CssSelectorConverter())->toXPath('.views-field-title span.field-content a'))->getText(),
168 'sticky' => $row->find('xpath', (new CssSelectorConverter())->toXPath('.views-field-sticky span.field-content'))->getText(),
171 $this->assertEqual($actual, $expected);