You are here

public function FieldEntityTranslationTest::testTranslationRows in Drupal 8

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. 10 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 68

Class

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

Namespace

Drupal\Tests\views\Functional\Entity

Code

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',
    ],
  ]);
}