You are here

public function NodeTypeTranslationTest::testNodeTypeTranslation in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/node/src/Tests/NodeTypeTranslationTest.php \Drupal\node\Tests\NodeTypeTranslationTest::testNodeTypeTranslation()

Tests the node type translation.

File

core/modules/node/src/Tests/NodeTypeTranslationTest.php, line 89
Contains \Drupal\node\Tests\NodeTypeTranslationTest.

Class

NodeTypeTranslationTest
Ensures that node types translation work correctly.

Namespace

Drupal\node\Tests

Code

public function testNodeTypeTranslation() {
  $type = Unicode::strtolower($this
    ->randomMachineName(16));
  $name = $this
    ->randomString();
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalCreateContentType(array(
    'type' => $type,
    'name' => $name,
  ));

  // Translate the node type name.
  $langcode = $this->additionalLangcodes[0];
  $translated_name = $langcode . '-' . $name;
  $edit = array(
    "translation[config_names][node.type.{$type}][name]" => $translated_name,
  );

  // Edit the title label to avoid having an exception when we save the translation.
  $this
    ->drupalPostForm("admin/structure/types/manage/{$type}/translate/{$langcode}/add", $edit, t('Save translation'));

  // Check the name is translated without admin theme for editing.
  $this
    ->drupalPostForm('admin/appearance', array(
    'use_admin_theme' => '0',
  ), t('Save configuration'));
  $this
    ->drupalGet("{$langcode}/node/add/{$type}");
  $this
    ->assertRaw(t('Create @name', array(
    '@name' => $translated_name,
  )));

  // Check the name is translated with admin theme for editing.
  $this
    ->drupalPostForm('admin/appearance', array(
    'use_admin_theme' => '1',
  ), t('Save configuration'));
  $this
    ->drupalGet("{$langcode}/node/add/{$type}");
  $this
    ->assertRaw(t('Create @name', array(
    '@name' => $translated_name,
  )));
}