public function LingotekWebformBulkTranslationTest::testWebformTranslationUsingLinks in Lingotek Translation 4.0.x
Same name and namespace in other branches
- 3.5.x tests/src/Functional/LingotekWebformBulkTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekWebformBulkTranslationTest::testWebformTranslationUsingLinks()
- 3.6.x tests/src/Functional/LingotekWebformBulkTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekWebformBulkTranslationTest::testWebformTranslationUsingLinks()
- 3.7.x tests/src/Functional/LingotekWebformBulkTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekWebformBulkTranslationTest::testWebformTranslationUsingLinks()
- 3.8.x tests/src/Functional/LingotekWebformBulkTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekWebformBulkTranslationTest::testWebformTranslationUsingLinks()
Tests that a webform can be translated using the links on the management page.
File
- tests/
src/ Functional/ LingotekWebformBulkTranslationTest.php, line 84
Class
- LingotekWebformBulkTranslationTest
- Tests translating a config entity using the bulk management form.
Namespace
Drupal\Tests\lingotek\FunctionalCode
public function testWebformTranslationUsingLinks() {
$assert_session = $this
->assertSession();
// Login as admin.
$this
->drupalLogin($this->rootUser);
// Go to the bulk config management page.
$this
->goToConfigBulkManagementForm('webform');
$basepath = \Drupal::request()
->getBasePath();
// Clicking English must init the upload of content.
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/webform/test?destination=' . $basepath . '/admin/lingotek/config/manage');
// And we cannot request yet a translation.
$assert_session
->linkByHrefNotExists($basepath . '/admin/lingotek/config/request/webform/test/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('EN', 1);
$this
->assertText(t('Test uploaded successfully'));
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
// Check that only the configured fields have been uploaded.
$data = json_decode(\Drupal::state()
->get('lingotek.uploaded_content', '[]'), TRUE);
$this
->assertEqual('Test', $data['title']);
$this
->assertEqual(6, count($data['elements']));
$this
->assertEqual('First name', $data['elements']['first_name']['#title']);
$this
->assertEqual('Last name', $data['elements']['last_name']['#title']);
$this
->assertEqual('Sex', $data['elements']['sex']['#title']);
$this
->assertEqual('Martial status', $data['elements']['martial_status']['#title']);
$this
->assertEqual('Employment status', $data['elements']['employment_status']['#title']);
$this
->assertEqual('Age', $data['elements']['age']['#title']);
// There is a link for checking status.
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/check_upload/webform/test?destination=' . $basepath . '/admin/lingotek/config/manage');
// And we can already request a translation.
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/request/webform/test/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('EN', 1);
$this
->assertText('Test status checked successfully');
// Request the Spanish translation.
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/request/webform/test/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('ES');
$this
->assertText("Translation to es_MX requested successfully");
$this
->assertIdentical('es_MX', \Drupal::state()
->get('lingotek.added_target_locale'));
// Check status of the Spanish translation.
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/check_download/webform/test/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('ES');
$this
->assertIdentical('es_MX', \Drupal::state()
->get('lingotek.checked_target_locale'));
$this
->assertText("Translation to es_MX status checked successfully");
// Download the Spanish translation.
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/download/webform/test/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('ES');
$this
->assertText('Translation to es_MX downloaded successfully');
$this
->assertIdentical('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', 'dummy-document-hash-id', 'ES');
$this
->drupalGet('es/webform/test');
$assert_session
->pageTextContains('Nombre');
$assert_session
->pageTextContains('Apellidos');
$assert_session
->pageTextContains('Sexo');
$assert_session
->pageTextContains('Estado civil');
$assert_session
->pageTextContains('Situación laboral');
$assert_session
->pageTextContains('Edad');
}