You are here

function TMGMTEntitySourceTestCase::testEntitySourceNode in Translation Management Tool 7

Tests nodes field translation.

File

sources/entity/tmgmt_entity.source.test, line 35

Class

TMGMTEntitySourceTestCase
Basic Entity Source tests.

Code

function testEntitySourceNode() {
  $this
    ->setEnvironment('de');
  $this
    ->createNodeType('article', 'Article', ENTITY_TRANSLATION_ENABLED);

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

  // Create some nodes.
  for ($i = 1; $i <= 5; $i++) {
    $node = $this
      ->createNode('article');

    // Create a job item for this node and add it to the job.
    $item = $job
      ->addItem('entity', 'node', $node->nid);
    $this
      ->assertEqual(t('@type (@bundle)', array(
      '@type' => t('Node'),
      '@bundle' => 'Article',
    )), $item
      ->getSourceType());
  }

  // Translate the job.
  $job
    ->requestTranslation();

  // Check the translated job items.
  foreach ($job
    ->getItems() as $item) {

    // The source is available only for en.
    $this
      ->assertJobItemLangCodes($item, 'en', array(
      'en',
    ));
    $item
      ->acceptTranslation();
    $this
      ->assertTrue($item
      ->isAccepted());
    $entity = entity_load_single($item->item_type, $item->item_id);
    $data = $item
      ->getData();
    $this
      ->checkTranslatedData($entity, $data, 'de');
    $this
      ->checkUntranslatedData($entity, $this->field_names['node']['article'], $data, 'de');

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