Verifies functionality of translator handling.
@group tmgmt
Expanded class hierarchy of TranslatorJavascriptTest
class TranslatorJavascriptTest extends WebDriverTestBase {
use TmgmtTestTrait;
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = array(
'tmgmt',
'tmgmt_test',
'node',
'block',
'locale',
);
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
function setUp() : void {
parent::setUp();
// Login as admin to be able to set environment variables.
$this
->loginAsAdmin();
$this
->addLanguage('de');
$this
->addLanguage('es');
$this
->addLanguage('el');
// Login as translation administrator to run these tests.
$this
->loginAsTranslator(array(
'administer tmgmt',
), TRUE);
}
/**
* Test multiple local language with one single remote language.
*/
public function testMultipleLocalToSingleRemoteMapping() {
$this
->addLanguage('pt-br');
$this
->addLanguage('pt-pt');
$page = $this
->getSession()
->getPage();
$assert_session = $this
->assertSession();
// Add mapping to the file translator.
$this
->drupalGet('admin/tmgmt/translators/manage/test_translator');
$edit = array(
'remote_languages_mappings[pt-br]' => 'pt',
'remote_languages_mappings[pt-pt]' => 'pt',
);
$this
->submitForm($edit, 'Save');
$this
->drupalGet('admin/tmgmt/translators/manage/test_translator');
$assert_session
->fieldValueEquals('edit-remote-languages-mappings-pt-br', 'pt');
// Test first local language.
$job = tmgmt_job_match_item('en', 'pt-br');
$job
->addItem('test_source', 'test', 0);
$edit = array(
'target_language' => 'pt-br',
);
$this
->drupalGet('admin/tmgmt/jobs/' . $job
->id());
$page
->selectFieldOption('Target language', 'pt-br');
$this
->assertSession()
->elementTextEquals('xpath', '//select[@id="edit-translator"]//option[@value="test_translator"]', 'Test provider');
$this
->submitForm($edit, 'Submit to provider');
$assert_session
->pageTextContains('Portuguese, Brazil');
$this
->assertCount(1, $job
->getItems());
$this
->assertNotEmpty($job
->getItems()[1]
->accepted());
$this
->drupalGet('admin/tmgmt/items/' . 1);
$assert_session
->pageTextContains('pt-br(pt): Text for job item with type ' . $job
->getItems()[1]
->getItemType() . ' and id ' . $job
->getItems()[1]
->getItemId() . '.');
$this
->assertEquals('pt-br', $job
->getTargetLangcode());
// Test the other local language.
$job = tmgmt_job_match_item('en', 'pt-pt');
$job
->addItem('test_source', 'test', 0);
$this
->drupalGet('admin/tmgmt/jobs/' . $job
->id());
$page
->selectFieldOption('Target language', 'pt-pt');
$this
->assertSession()
->elementTextEquals('xpath', '//select[@id="edit-translator"]//option[@value="test_translator"]', 'Test provider');
$this
->submitForm($edit, 'Submit to provider');
$assert_session
->pageTextContains('Portuguese, Portugal');
$this
->assertCount(1, $job
->getItems());
$this
->assertNotEmpty($job
->getItems()[2]
->accepted());
$this
->drupalGet('admin/tmgmt/items/' . 2);
$this
->assertEquals('pt-pt', $job
->getTargetLangcode());
// Fails on Gitlab CI for unclear reasons, assertion disabled.
// $assert_session->fieldValueEquals('dummy|deep_nesting[translation]', 'pt-pt(pt): Text for job item with type ' . $job->getItems()[2]->getItemType() . ' and id ' . $job->getItems()[2]->getItemId() . '.');
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TmgmtTestTrait:: |
protected | property | List of permissions used by loginAsAdmin(). | |
TmgmtTestTrait:: |
protected | property | Drupal user object created by loginAsAdmin(). | |
TmgmtTestTrait:: |
protected | property | The language weight for new languages. | |
TmgmtTestTrait:: |
protected | property | List of permissions used by loginAsTranslator(). | |
TmgmtTestTrait:: |
protected | property | Drupal user object created by loginAsTranslator(). | |
TmgmtTestTrait:: |
function | Sets the proper environment. | ||
TmgmtTestTrait:: |
function | Asserts job item language codes. | ||
TmgmtTestTrait:: |
protected | function | Asserts text in the page with an xpath expression. | |
TmgmtTestTrait:: |
function | Clicks on an image link with the provided title attribute. | ||
TmgmtTestTrait:: |
function | Creates, saves and returns a translation job. | ||
TmgmtTestTrait:: |
function | Creates, saves and returns a translator. | ||
TmgmtTestTrait:: |
function | Will create a user with admin permissions and log it in. | ||
TmgmtTestTrait:: |
function | Will create a user with translator permissions and log it in. | ||
TranslatorJavascriptTest:: |
protected | property | ||
TranslatorJavascriptTest:: |
protected static | property | Modules to enable. | |
TranslatorJavascriptTest:: |
function | |||
TranslatorJavascriptTest:: |
public | function | Test multiple local language with one single remote language. |