public function LocalTranslatorTest::testAbilitiesAPI in Translation Management Tool 8
File
- translators/
tmgmt_local/ tests/ src/ Functional/ LocalTranslatorTest.php, line 624
Class
- LocalTranslatorTest
- Basic tests for the local translator.
Namespace
Drupal\Tests\tmgmt_local\FunctionalCode
public function testAbilitiesAPI() {
$this
->addLanguage('fr');
$this
->addLanguage('ru');
$this
->addLanguage('it');
$all_assignees = array();
$assignee1 = $this
->drupalCreateUser($this->localTranslatorPermissions);
$all_assignees[$assignee1
->id()] = $assignee1
->getDisplayName();
$this
->drupalLogin($assignee1);
$edit = array(
'tmgmt_translation_skills[0][language_from]' => 'en',
'tmgmt_translation_skills[0][language_to]' => 'de',
);
$this
->drupalPostForm('user/' . $assignee1
->id() . '/edit', $edit, t('Save'));
$assignee2 = $this
->drupalCreateUser($this->localTranslatorPermissions);
$all_assignees[$assignee2
->id()] = $assignee2
->getDisplayName();
$this
->drupalLogin($assignee2);
$edit = array(
'tmgmt_translation_skills[0][language_from]' => 'en',
'tmgmt_translation_skills[0][language_to]' => 'ru',
);
$this
->drupalPostForm('user/' . $assignee2
->id() . '/edit', $edit, t('Save'));
$edit = array(
'tmgmt_translation_skills[1][language_from]' => 'en',
'tmgmt_translation_skills[1][language_to]' => 'fr',
);
$this
->drupalPostForm('user/' . $assignee2
->id() . '/edit', $edit, t('Save'));
$edit = array(
'tmgmt_translation_skills[2][language_from]' => 'fr',
'tmgmt_translation_skills[2][language_to]' => 'it',
);
$this
->drupalPostForm('user/' . $assignee2
->id() . '/edit', $edit, t('Save'));
$assignee3 = $this
->drupalCreateUser($this->localTranslatorPermissions);
$all_assignees[$assignee3
->id()] = $assignee3
->getDisplayName();
$this
->drupalLogin($assignee3);
$edit = array(
'tmgmt_translation_skills[0][language_from]' => 'fr',
'tmgmt_translation_skills[0][language_to]' => 'ru',
);
$this
->drupalPostForm('user/' . $assignee3
->id() . '/edit', $edit, t('Save'));
$edit = array(
'tmgmt_translation_skills[1][language_from]' => 'it',
'tmgmt_translation_skills[1][language_to]' => 'en',
);
$this
->drupalPostForm('user/' . $assignee3
->id() . '/edit', $edit, t('Save'));
// Test target languages.
$target_languages = tmgmt_local_supported_target_languages('fr');
$this
->assertTrue(isset($target_languages['it']));
$this
->assertTrue(isset($target_languages['ru']));
$target_languages = tmgmt_local_supported_target_languages('en');
$this
->assertTrue(isset($target_languages['fr']));
$this
->assertTrue(isset($target_languages['ru']));
// Test language pairs.
$this
->assertEqual(tmgmt_local_supported_language_pairs(), array(
'en__de' => array(
'source_language' => 'en',
'target_language' => 'de',
),
'en__ru' => array(
'source_language' => 'en',
'target_language' => 'ru',
),
'en__fr' => array(
'source_language' => 'en',
'target_language' => 'fr',
),
'fr__it' => array(
'source_language' => 'fr',
'target_language' => 'it',
),
'fr__ru' => array(
'source_language' => 'fr',
'target_language' => 'ru',
),
'it__en' => array(
'source_language' => 'it',
'target_language' => 'en',
),
));
$this
->assertEqual(tmgmt_local_supported_language_pairs('fr', array(
$assignee2
->id(),
)), array(
'fr__it' => array(
'source_language' => 'fr',
'target_language' => 'it',
),
));
// Test if we got all translators.
$assignees = tmgmt_local_assignees();
foreach ($all_assignees as $uid => $name) {
if (!isset($assignees[$uid])) {
$this
->fail('Expected translator not present');
}
if (!in_array($name, $all_assignees)) {
$this
->fail('Expected translator name not present');
}
}
// Only translator2 has such abilities.
$assignees = tmgmt_local_assignees('en', array(
'ru',
'fr',
));
$this
->assertTrue(isset($assignees[$assignee2
->id()]));
}