You are here

function TranslationTestCase::createTranslation in Drupal 7

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.

3 calls to TranslationTestCase::createTranslation()
TranslationTestCase::testContentTranslation in modules/translation/translation.test
Creates, modifies, and updates a basic page with a translation.
TranslationTestCase::testLanguageSwitcherBlockIntegration in modules/translation/translation.test
Tests that the language switcher block alterations work as intended.
TranslationTestCase::testLanguageSwitchLinks in modules/translation/translation.test
Checks that the language switch links behave properly.

File

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

Class

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