You are here

function TMGMTFieldCollectionSourceTestCase::testFieldCollectionSource in Translation Management Tool 7

Tests nodes field translation.

File

sources/field/tmgmt_field_collection.test, line 93

Class

TMGMTFieldCollectionSourceTestCase
Basic Field Collection Source tests.

Code

function testFieldCollectionSource() {

  // Create a translation job.
  $job = $this
    ->createJob();
  $job->translator = $this->default_translator->name;
  $job->settings = array();
  $job
    ->save();
  $node = $this
    ->createNode('page');

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

  // Translate the job.
  $job
    ->requestTranslation();
  foreach ($job
    ->getItems() as $item) {
    $item
      ->acceptTranslation();
    $node = node_load($item->item_id);

    // 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);
    if (isset($translations['de'])) {
      $translated_node = node_load($translations['de']->nid, NULL, TRUE);
      $translated_collection = field_collection_item_load($translated_node->field_test_collection['und'][0]['value']);
      $translated_collection_text = $translated_collection->field_text['de'][0]['value'];
      $data = $item
        ->getData();
      $job_item_text = $data['field_test_collection'][0]['field_text'][0]['value']['#translation']['#text'];
      $this
        ->assertEqual($translated_collection_text, $job_item_text, 'Job item translation and field collection translation do not match');
      $this
        ->assertEqual('de_' . self::FIELD_COLLECTION_TEXT, $translated_collection_text, 'Text from field collection is not translated');
    }
  }
}