function FieldEntityTranslationTest::testTranslationRows

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Functional/Entity/FieldEntityTranslationTest.php \Drupal\Tests\views\Functional\Entity\FieldEntityTranslationTest::testTranslationRows()
  2. 8.9.x core/modules/views/tests/src/Functional/Entity/FieldEntityTranslationTest.php \Drupal\Tests\views\Functional\Entity\FieldEntityTranslationTest::testTranslationRows()
  3. 11.x core/modules/views/tests/src/Functional/Entity/FieldEntityTranslationTest.php \Drupal\Tests\views\Functional\Entity\FieldEntityTranslationTest::testTranslationRows()

Tests that different translation mechanisms can be used for base fields.

File

core/modules/views/tests/src/Functional/Entity/FieldEntityTranslationTest.php, line 70

Class

FieldEntityTranslationTest
Tests the rendering of fields (base fields) and their translations.

Namespace

Drupal\Tests\views\Functional\Entity

Code

public function testTranslationRows() : void {
  $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',
    ],
  ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.