1 translation.test TranslationTestCase::createTranslation(Node $node, $title, $body, $langcode)

Creates a translation for a page in the specified language.

Parameters

Node $node: The page to create the translation for.

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

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

$langcode: Language code.

Return value

Translation object.:

File

core/modules/translation/tests/translation.test, line 367
Tests for the Translation module.

Class

TranslationTestCase
Functional tests for the Translation module.

Code

function createTranslation(Node $node, $title, $body, $langcode) {
  $this->backdropGet('node/add/page', array('query' => array('translation' => $node->nid, 'target' => $langcode)));

  $field_langcode = LANGUAGE_NONE;
  $body_key = "body[$field_langcode][0][value]";
  $this->assertFieldByXPath('//input[@id="edit-title"]', $node->title, 'Original title value correctly populated.');
  $this->assertFieldByXPath("//textarea[@name='$body_key']", $node->body[LANGUAGE_NONE][0]['value'], 'Original body value correctly populated.');

  $edit = array();
  $edit["title"] = $title;
  $edit[$body_key] = $body;
  $this->backdropPost(NULL, $edit, t('Save'));
  $this->assertRaw(t('Page %title has been created.', array('%title' => $title)), 'Translation created.');

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

  return $translation;
}