You are here

protected function I18nBookNavigationTestBase::translateBookNode in Book translation 7.2

Translate book node.

Parameters

object $node: The book node to translate.

string $language: The language to translate the node in.

bool $use_entity_translation: (optional) Wether to use Entity translation. Defaults to false.

Return value

object The new translated node

1 call to I18nBookNavigationTestBase::translateBookNode()
I18nBookNavigationTestBase::translateNodes in tests/i18n_book_navigation.test
Translate nodes.

File

tests/i18n_book_navigation.test, line 234
Unit tests for the Book translation module.

Class

I18nBookNavigationTestBase
@file Unit tests for the Book translation module.

Code

protected function translateBookNode($node, $language, $use_entity_translation = FALSE) {
  $edit = array();
  $body_language = $use_entity_translation ? $language : LANGUAGE_NONE;
  $title_key = $use_entity_translation ? "title_field[{$language}][0][value]" : "title";
  $edit[$title_key] = $language . ' - Simpletest test node ' . $this
    ->randomName(10);
  $edit["body[{$body_language}][0][value]"] = 'Simpletest test body ' . $this
    ->randomName(32) . ' ' . $this
    ->randomName(32);
  if ($use_entity_translation) {
    $this
      ->drupalPost('node/' . $node->nid . '/edit/add/' . $node->language . '/' . $language, $edit, t("Save"));
  }
  else {
    $edit['language'] = $language;
    $this
      ->drupalPost('node/add/book', $edit, t("Save"));
  }
  if (!$use_entity_translation) {

    // Add the translation link, because Drupal stores the translation link in
    // the form cache, not in the hidden form elements.
    $new_node = $this
      ->drupalGetNodeByTitle($edit[$title_key]);
    $new_node->tnid = $node->nid;
    node_save($new_node);
  }
  else {

    // Clone trick using multiple casting.
    $new_node = (object) (array) $node;
    $new_node->title = $edit[$title_key];
  }
  return $new_node;
}