function TranslationTest::createTranslation

Creates a translation for a basic page in the specified language.

Parameters

\Drupal\Core\Entity\EntityInterface $node: The basic page to create the translation for.

$title: The title of a basic page in the specified language.

$body: The body of a basic page in the specified language.

$langcode: (optional) Language code.

Return value

Translation object.

4 calls to TranslationTest::createTranslation()
TranslationTest::testContentTranslation in drupal/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php
Creates, modifies, and updates a basic page with a translation.
TranslationTest::testLanguageSwitcherBlockIntegration in drupal/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php
Tests that the language switcher block alterations work as intended.
TranslationTest::testLanguageSwitchLinks in drupal/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php
Checks that the language switch links behave properly.
TranslationTest::testTranslateOwnContentRole in drupal/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php
Checks that users with "translate own content" role only can translate own content.

File

drupal/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php, line 377
Definition of Drupal\translation\Tests\TranslationTest.

Class

TranslationTest
Functional tests for the Translation module.

Namespace

Drupal\translation\Tests

Code

function createTranslation(EntityInterface $node, $title, $body, $langcode) {
  $this
    ->drupalGet('node/add/page', array(
    'query' => array(
      'translation' => $node->nid,
      'target' => $langcode,
    ),
  ));
  $field_langcode = Language::LANGCODE_NOT_SPECIFIED;
  $body_key = "body[{$field_langcode}][0][value]";
  $this
    ->assertFieldByXPath('//input[@id="edit-title"]', $node
    ->label(), "Original title value correctly populated.");
  $this
    ->assertFieldByXPath("//textarea[@name='{$body_key}']", $node->body[Language::LANGCODE_NOT_SPECIFIED][0]['value'], "Original body value correctly populated.");
  $edit = array();
  $edit["title"] = $title;
  $edit[$body_key] = $body;
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  $this
    ->assertRaw(t('Basic page %title has been created.', array(
    '%title' => $title,
  )), 'Translation created.');

  // Check to make sure that translation was successful.
  $translation = $this
    ->drupalGetNodeByTitle($title);
  $this
    ->assertTrue($translation, 'Node found in database.');
  $this
    ->assertTrue($translation->tnid == $node->nid, 'Translation set id correctly stored.');
  return $translation;
}