You are here

function TMGMTLocalTestCase::testTranslatorSkillsForTasks in Translation Management Tool 7

File

translators/tmgmt_local/tmgmt_local.test, line 38
Test cases for the local translator module.

Class

TMGMTLocalTestCase
Basic tests for the local translator.

Code

function testTranslatorSkillsForTasks() {
  $this
    ->setEnvironment('fr');
  $translator1 = $this
    ->drupalCreateUser($this->local_translator_permissions);
  $this
    ->drupalLogin($translator1);
  $edit = array(
    'tmgmt_translation_skills[und][0][language_from]' => 'en',
    'tmgmt_translation_skills[und][0][language_to]' => 'de',
  );
  $this
    ->drupalPost('user/' . $translator1->uid . '/edit', $edit, t('Save'));
  $translator2 = $this
    ->drupalCreateUser($this->local_translator_permissions);
  $this
    ->drupalLogin($translator2);
  $edit = array(
    'tmgmt_translation_skills[und][0][language_from]' => 'en',
    'tmgmt_translation_skills[und][0][language_to]' => 'de',
  );
  $this
    ->drupalPost('user/' . $translator2->uid . '/edit', $edit, t('Save'));
  $edit = array(
    'tmgmt_translation_skills[und][1][language_from]' => 'de',
    'tmgmt_translation_skills[und][1][language_to]' => 'en',
  );
  $this
    ->drupalPost('user/' . $translator2->uid . '/edit', $edit, t('Save'));
  $translator3 = $this
    ->drupalCreateUser($this->local_translator_permissions);
  $this
    ->drupalLogin($translator3);
  $edit = array(
    'tmgmt_translation_skills[und][0][language_from]' => 'en',
    'tmgmt_translation_skills[und][0][language_to]' => 'de',
  );
  $this
    ->drupalPost('user/' . $translator3->uid . '/edit', $edit, t('Save'));
  $edit = array(
    'tmgmt_translation_skills[und][1][language_from]' => 'de',
    'tmgmt_translation_skills[und][1][language_to]' => 'en',
  );
  $this
    ->drupalPost('user/' . $translator3->uid . '/edit', $edit, t('Save'));
  $edit = array(
    'tmgmt_translation_skills[und][2][language_from]' => 'en',
    'tmgmt_translation_skills[und][2][language_to]' => 'fr',
  );
  $this
    ->drupalPost('user/' . $translator3->uid . '/edit', $edit, t('Save'));
  $job1 = $this
    ->createJob('en', 'de');
  $job2 = $this
    ->createJob('de', 'en');
  $job3 = $this
    ->createJob('en', 'fr');
  $local_task1 = tmgmt_local_task_create(array(
    'uid' => $job1->uid,
    'tjid' => $job1->tjid,
    'title' => 'Task 1',
  ));
  $local_task1
    ->save();
  $local_task2 = tmgmt_local_task_create(array(
    'uid' => $job2->uid,
    'tjid' => $job2->tjid,
    'title' => 'Task 2',
  ));
  $local_task2
    ->save();
  $local_task3 = tmgmt_local_task_create(array(
    'uid' => $job3->uid,
    'tjid' => $job3->tjid,
    'title' => 'Task 3',
  ));
  $local_task3
    ->save();

  // Test languages involved in tasks.
  $this
    ->assertEqual(tmgmt_local_tasks_languages(array(
    $local_task1->tltid,
    $local_task2->tltid,
    $local_task3->tltid,
  )), array(
    'en' => array(
      'de',
      'fr',
    ),
    'de' => array(
      'en',
    ),
  ));

  // Test available translators for task en - de.
  $this
    ->assertEqual(tmgmt_local_get_translators_for_tasks(array(
    $local_task1->tltid,
  )), array(
    $translator1->uid => entity_label('user', $translator1),
    $translator2->uid => entity_label('user', $translator2),
    $translator3->uid => entity_label('user', $translator3),
  ));

  // Test available translators for tasks en - de, de - en.
  $this
    ->assertEqual(tmgmt_local_get_translators_for_tasks(array(
    $local_task1->tltid,
    $local_task2->tltid,
  )), array(
    $translator2->uid => entity_label('user', $translator2),
    $translator3->uid => entity_label('user', $translator3),
  ));

  // Test available translators for tasks en - de, de - en, en - fr.
  $this
    ->assertEqual(tmgmt_local_get_translators_for_tasks(array(
    $local_task1->tltid,
    $local_task2->tltid,
    $local_task3->tltid,
  )), array(
    $translator3->uid => entity_label('user', $translator3),
  ));
}