You are here

function TMGMTNodeSourceTestCase::testNodeSource in Translation Management Tool 7

Tests nodes field translation.

File

sources/node/tmgmt_node.test, line 28

Class

TMGMTNodeSourceTestCase
Basic Node Source tests.

Code

function testNodeSource() {

  // Create a translation job.
  $job = $this
    ->createJob();
  $job->translator = $this->default_translator->name;
  $job->settings = array();
  $job
    ->save();
  for ($i = 0; $i < 2; $i++) {
    $node = $this
      ->createNode('page');

    // Create a job item for this node and add it to the job.
    $item = $job
      ->addItem('node', 'node', $node->nid);
    $this
      ->assertEqual('Basic page', $item
      ->getSourceType());
  }

  // Translate the job.
  $job
    ->requestTranslation();
  foreach ($job
    ->getItems() as $item) {

    // The source is only available in en.
    $this
      ->assertJobItemLangCodes($item, 'en', array(
      'en',
    ));
    $item
      ->acceptTranslation();
    $node = node_load($item->item_id);

    // Check if the tnid attribute is bigger than 0.
    $this
      ->assertTrue($node->tnid > 0, 'The source node is part of a translation set.');

    // The translations may be statically cached, so make make sure
    // to reset the cache before loading the node translations.
    $cached_translations =& drupal_static('translation_node_get_translations', array());
    unset($cached_translations[$node->tnid]);

    // Load the translation set of the source node.
    $translations = translation_node_get_translations($node->tnid);
    $this
      ->assertNotNull($translations['de'], 'Translation found for the source node.');
    if (isset($translations['de'])) {
      $tnode = node_load($translations['de']->nid, NULL, TRUE);
      $this
        ->checkTranslatedData($tnode, $item
        ->getData(), 'de');
    }

    // The source should be now available for en and de.
    $this
      ->assertJobItemLangCodes($item, 'en', array(
      'de',
      'en',
    ));
  }
}