You are here

function Drupali18nTestCase::drupalCreateTranslations in Internationalization 6

Create translation set from a node

Parameters

$source: Source node

$languages: Optional list of language codes

1 call to Drupali18nTestCase::drupalCreateTranslations()
i18n_API_Tests::testBasicAPI in tests/i18n_api.test

File

tests/drupal_i18n_test_case.php, line 48

Class

Drupali18nTestCase
Test case for typical Drupal tests.

Code

function drupalCreateTranslations(&$source, $languages = NULL) {
  $languages = $languages ? $languages : array_keys(language_list());
  if (empty($source->tnid)) {
    db_query("UPDATE {node} SET tnid = %d, translate = %d WHERE nid = %d", $source->nid, 0, $source->nid);
    $source->tnid = $source->nid;
  }
  $translations[$source->language] = $source;
  foreach ($languages as $lang) {
    if ($lang != $source->language) {
      $translations[$lang] = $this
        ->drupalCreateNode(array(
        'type' => $source->type,
        'language' => $lang,
        'translation_source' => $source,
        'status' => $source->status,
        'promote' => $source->promote,
        'uid' => $source->uid,
      ));
    }
  }
  return $translations;
}