TranslationTestCase::createTranslation

7 translation.test TranslationTestCase::createTranslation($node, $title, $body, $language)
8 translation.test TranslationTestCase::createTranslation(Node $node, $title, $body, $langcode)

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

Parameters

$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.

$language: Language code.

Return value

Translation object.

File

modules/translation/translation.test, line 361
Tests for the Translation module.

Code

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

  $langcode = LANGUAGE_NONE;
  $body_key = "body[$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->drupalPost(NULL, $edit, t('Save'));
  $this->assertRaw(t('Basic page %title has been created.', array('%title' => $title)), t('Translation created.'));

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

  return $translation;
}
Login or register to post comments