View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\webform\Traits\WebformBrowserTestTrait;
class LingotekWebformBulkTranslationTest extends LingotekTestBase {
use WebformBrowserTestTrait;
public static $modules = [
'block',
'node',
'frozenintime',
'webform',
];
protected $webform;
protected function setUp() : void {
parent::setUp();
$values = [
'id' => 'test',
'title' => 'Test',
];
$elements = [
'first_name' => [
'#type' => 'textfield',
'#title' => 'First name',
],
'last_name' => [
'#type' => 'textfield',
'#title' => 'Last name',
],
'sex' => [
'#type' => 'webform_select_other',
'#options' => 'sex',
'#title' => 'Sex',
],
'martial_status' => [
'#type' => 'webform_select_other',
'#options' => 'marital_status',
'#title' => 'Martial status',
],
'employment_status' => [
'#type' => 'webform_select_other',
'#options' => 'employment_status',
'#title' => 'Employment status',
],
'age' => [
'#type' => 'number',
'#title' => 'Age',
],
];
$this->webform = $this
->createWebform($values, $elements);
ConfigurableLanguage::createFromLangcode('es')
->setThirdPartySetting('lingotek', 'locale', 'es_MX')
->save();
$this
->saveLingotekConfigTranslationSettings([
'webform' => 'automatic',
]);
\Drupal::state()
->set('lingotek.uploaded_content_type', 'webform');
}
public function testWebformTranslationUsingLinks() {
$assert_session = $this
->assertSession();
$this
->drupalLogin($this->rootUser);
$this
->goToConfigBulkManagementForm('webform');
$basepath = \Drupal::request()
->getBasePath();
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/webform/test?destination=' . $basepath . '/admin/lingotek/config/manage');
$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'));
$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']);
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/check_upload/webform/test?destination=' . $basepath . '/admin/lingotek/config/manage');
$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');
$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'));
$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");
$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'));
$this
->assertLingotekWorkbenchLink('es_MX');
$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');
}
}