You are here

protected function I18nBookNavigationTestBase::createBookNode in Book translation 7.2

Create a book node.

Port of the book module test cases.

See also

BooktestCase::createBookNode()

1 call to I18nBookNavigationTestBase::createBookNode()
I18nBookNavigationTestBase::createBookOutline in tests/i18n_book_navigation.test
Creates a book outline in the desired language.

File

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

Class

I18nBookNavigationTestBase
@file Unit tests for the Book translation module.

Code

protected function createBookNode($bid, $plid = NULL, $language = NULL, $use_entity_translation = FALSE) {
  static $number = 0;
  $edit = array();

  // Weird bug in ET? Don't know why when the Book ID is given, the key is
  // correct, and when not, the key is "und".
  $language_key = $bid == 'new' && $use_entity_translation || !$use_entity_translation ? LANGUAGE_NONE : $language;
  $title_key = $use_entity_translation ? "title_field[{$language_key}][0][value]" : "title";
  $edit[$title_key] = $number . ' - Simpletest test node ' . $this
    ->randomName(10);
  $edit["body[{$language_key}][0][value]"] = 'Simpletest test body ' . $this
    ->randomName(32) . ' ' . $this
    ->randomName(32);
  $edit['book[bid]'] = $bid;
  $edit['language'] = isset($language) ? $language : LANGUAGE_NONE;
  if (isset($plid)) {
    $this
      ->drupalPost('node/add/book', $edit, t('Change book (update list of parents)'));
    $edit['book[plid]'] = $plid;
    $this
      ->drupalPost(NULL, $edit, t('Save'));
  }
  else {
    $this
      ->drupalPost('node/add/book', $edit, t('Save'));
  }
  $number++;
  return $this
    ->drupalGetNodeByTitle($edit[$title_key]);
}