public function LingotekInterfaceTranslationTest::testInterfaceTranslationUsingLinks in Lingotek Translation 3.5.x
Same name and namespace in other branches
- 4.0.x tests/src/Functional/LingotekInterfaceTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekInterfaceTranslationTest::testInterfaceTranslationUsingLinks()
- 3.2.x tests/src/Functional/LingotekInterfaceTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekInterfaceTranslationTest::testInterfaceTranslationUsingLinks()
- 3.3.x tests/src/Functional/LingotekInterfaceTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekInterfaceTranslationTest::testInterfaceTranslationUsingLinks()
- 3.4.x tests/src/Functional/LingotekInterfaceTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekInterfaceTranslationTest::testInterfaceTranslationUsingLinks()
- 3.6.x tests/src/Functional/LingotekInterfaceTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekInterfaceTranslationTest::testInterfaceTranslationUsingLinks()
- 3.7.x tests/src/Functional/LingotekInterfaceTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekInterfaceTranslationTest::testInterfaceTranslationUsingLinks()
- 3.8.x tests/src/Functional/LingotekInterfaceTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekInterfaceTranslationTest::testInterfaceTranslationUsingLinks()
Tests that a node can be translated using the links on the management page.
1 call to LingotekInterfaceTranslationTest::testInterfaceTranslationUsingLinks()
- LingotekInterfaceTranslationTest::testAddingLanguageAllowsRequesting in tests/
src/ Functional/ LingotekInterfaceTranslationTest.php - Tests that a node can be translated using the links on the management page.
File
- tests/
src/ Functional/ LingotekInterfaceTranslationTest.php, line 74
Class
- LingotekInterfaceTranslationTest
- Tests translating the user interface using the Lingotek form.
Namespace
Drupal\Tests\lingotek\FunctionalCode
public function testInterfaceTranslationUsingLinks() {
// In Drupal.org CI the module will be at modules/contrib/lingotek.
// In my local that's modules/lingotek. We need to generate the path and not
// hardcode it.
$path = drupal_get_path('module', 'lingotek_interface_translation_test');
$component = $path;
$indexOfModuleLink = 2;
$assert_session = $this
->assertSession();
// Login as admin.
$this
->drupalLogin($this->rootUser);
$this
->goToInterfaceTranslationManagementForm();
$assert_session
->responseContains('lingotek');
$assert_session
->responseContains('lingotek_test');
$assert_session
->responseContains('lingotek_interface_translation_test');
$assert_session
->responseContains('stark');
// Clicking English must init the upload of content.
$this
->assertLingotekInterfaceTranslationUploadLink('core/profiles/testing');
$this
->assertLingotekInterfaceTranslationUploadLink('core/themes/stark');
$this
->assertLingotekInterfaceTranslationUploadLink($component);
// And we cannot request yet a translation.
$this
->assertNoLingotekInterfaceTranslationRequestTranslationLink($component, 'es_MX');
$this
->clickLink('EN', $indexOfModuleLink);
$assert_session
->responseContains('<em class="placeholder">' . $component . '</em> uploaded successfully');
$data = json_decode(\Drupal::state()
->get('lingotek.uploaded_content', '[]'), TRUE);
$singularStrings = [
'Test title for interface translation',
];
$pluralStrings = [
"This is a singular example<PLURAL>This is a plural @count example<CONTEXT>" => [
"This is a singular example" => "This is a singular example",
"This is a plural @count example" => "This is a plural @count example",
"_context" => '',
],
];
$contextStrings = [
"This is test of context<CONTEXT>" => [
"This is test of context" => "This is test of context",
"_context" => '',
],
"This is test of context<CONTEXT>multiple p" => [
"This is test of context" => "This is test of context",
"_context" => 'multiple p',
],
"This is test of context<CONTEXT>multiple t" => [
"This is test of context" => "This is test of context",
"_context" => 'multiple t',
],
];
foreach ($singularStrings as $singularString) {
$singularStringWithContext = $singularString . '<CONTEXT>';
$this
->assertTrue(isset($data[$singularStringWithContext]));
$this
->assertSame($singularString, $data[$singularStringWithContext][$singularString]);
$this
->assertSame('', $data[$singularStringWithContext]['_context']);
}
foreach ($pluralStrings as $key => $pluralData) {
$this
->assertTrue(isset($data[$key]));
$this
->assertSame('', $data[$key]['_context']);
foreach ($pluralData as $pluralString => $pluralTranslatedString) {
if ($pluralString !== '_context') {
$this
->assertTrue(isset($data[$key][$pluralString]));
$this
->assertSame($pluralTranslatedString, $data[$key][$pluralString]);
}
}
}
foreach ($contextStrings as $key => $contextData) {
$this
->assertTrue(isset($data[$key]));
foreach ($contextData as $contextString => $contextTranslatedString) {
$this
->assertSame($contextData['_context'], $data[$key]['_context']);
if ($contextString !== '_context') {
$this
->assertTrue(isset($data[$key][$contextString]));
$this
->assertSame($contextTranslatedString, $data[$key][$contextString]);
}
}
}
$this
->assertSame('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
// There is a link for checking status.
$this
->assertLingotekInterfaceTranslationCheckSourceStatusLink($component);
// And we can already request a translation.
$this
->assertLingotekInterfaceTranslationRequestTranslationLink($component, 'es_MX');
$this
->clickLink('EN', $indexOfModuleLink);
$assert_session
->responseContains('The import for <em class="placeholder">' . $component . '</em> is complete.');
// Request the Spanish translation.
$this
->assertLingotekInterfaceTranslationRequestTranslationLink($component, 'es_MX');
$this
->clickLink('ES');
$assert_session
->responseContains('Locale \'es_MX\' was added as a translation target for <em class="placeholder">' . $component . '</em>.');
$this
->assertIdentical('es_MX', \Drupal::state()
->get('lingotek.added_target_locale'));
// Check status of the Spanish translation.
$this
->assertLingotekInterfaceTranslationCheckTargetStatusLink($component, 'es_MX');
$this
->clickLink('ES');
$this
->assertSame('es_MX', \Drupal::state()
->get('lingotek.checked_target_locale'));
$assert_session
->responseContains('The es_MX translation for <em class="placeholder">' . $component . '</em> is ready for download.');
// Download the Spanish translation.
$this
->assertLingotekInterfaceTranslationDownloadLink($component, 'es_MX');
$this
->clickLink('ES');
$assert_session
->responseContains('The translation of <em class="placeholder">' . $component . '</em> into es_MX has been downloaded.');
$this
->assertSame('es_MX', \Drupal::state()
->get('lingotek.downloaded_locale'));
// Now the link is to the workbench, and it opens in a new tab.
$this
->assertLingotekWorkbenchLink('es_MX');
$this
->drupalGet('es/lingotek-interface-translation-test');
$assert_session
->responseContains('Título de Prueba para Traducción de Interfaz');
$assert_session
->responseContains('Este es un ejemplo en singular');
$assert_session
->responseNotContains('This is test of context');
$assert_session
->responseContains('Esto es una prueba de contexto');
$assert_session
->responseContains('Esto es una pppprueba de contexto');
$assert_session
->responseContains('Estttto es una prueba de conttttextttto');
$this
->drupalGet('es/lingotek-interface-translation-test', [
'query' => [
'count' => 10,
],
]);
$assert_session
->responseContains('Título de Prueba para Traducción de Interfaz');
$assert_session
->responseContains('Este es un ejemplo en plural: 10');
$assert_session
->responseNotContains('This is test of context');
$assert_session
->responseContains('Esto es una prueba de contexto');
$assert_session
->responseContains('Esto es una pppprueba de contexto');
$assert_session
->responseContains('Estttto es una prueba de conttttextttto');
}