View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\lingotek\Lingotek;
class LingotekUserSettingsBulkTranslationTest extends LingotekTestBase {
public static $modules = [
'block',
'node',
];
protected function setUp() : void {
parent::setUp();
ConfigurableLanguage::createFromLangcode('es')
->setThirdPartySetting('lingotek', 'locale', 'es_MX')
->save();
\Drupal::state()
->set('lingotek.uploaded_content_type', 'user.settings');
}
public function testUserSettingsTranslationUsingLinks() {
$assert_session = $this
->assertSession();
$this
->drupalLogin($this->rootUser);
$this
->goToConfigBulkManagementForm();
$basepath = \Drupal::request()
->getBasePath();
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/entity.user.admin_form/entity.user.admin_form?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefNotExists($basepath . '/admin/lingotek/config/request/entity.user.admin_form/entity.user.admin_form/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('EN', 3);
$this
->assertText(t('Account settings uploaded successfully'));
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->verbose(var_export(\Drupal::state()
->get('lingotek.uploaded_content'), TRUE));
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/check_upload/entity.user.admin_form/entity.user.admin_form?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/request/entity.user.admin_form/entity.user.admin_form/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('EN', 3);
$this
->assertText('Account settings status checked successfully');
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/request/entity.user.admin_form/entity.user.admin_form/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/entity.user.admin_form/entity.user.admin_form/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 checked successfully");
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/download/entity.user.admin_form/entity.user.admin_form/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');
}
public function testUserSettingsTranslationUsingActions() {
$assert_session = $this
->assertSession();
$this
->drupalLogin($this->rootUser);
ConfigurableLanguage::createFromLangcode('de')
->setThirdPartySetting('lingotek', 'locale', 'de_AT')
->save();
$this
->goToConfigBulkManagementForm();
$basepath = \Drupal::request()
->getBasePath();
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/entity.user.admin_form/entity.user.admin_form?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[entity.user.admin_form]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForUpload('node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/check_upload/entity.user.admin_form/entity.user.admin_form?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[entity.user.admin_form]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCheckUpload('node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/request/entity.user.admin_form/entity.user.admin_form/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[entity.user.admin_form]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForRequestTranslation('de', 'node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('de_AT', \Drupal::state()
->get('lingotek.added_target_locale'));
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/check_download/entity.user.admin_form/entity.user.admin_form/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[entity.user.admin_form]' => TRUE,
$this
->getBulkOperationFormName() => 'check_translation:de',
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('de_AT', \Drupal::state()
->get('lingotek.checked_target_locale'));
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/download/entity.user.admin_form/entity.user.admin_form/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[entity.user.admin_form]' => TRUE,
$this
->getBulkOperationFormName() => 'download:de',
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('de_AT', \Drupal::state()
->get('lingotek.downloaded_locale'));
$this
->assertLingotekWorkbenchLink('de_AT');
}
public function testEditedConfigTranslationUsingLinks() {
$this
->testUserSettingsTranslationUsingLinks();
ConfigurableLanguage::createFromLangcode('eu')
->setThirdPartySetting('lingotek', 'locale', 'eu_ES')
->save();
ConfigurableLanguage::createFromLangcode('ko')
->setThirdPartySetting('lingotek', 'locale', 'ko_KR')
->save();
$this
->drupalPostForm('/admin/config/people/accounts', [
'anonymous' => 'Unknown user',
], t('Save configuration'));
$this
->goToConfigBulkManagementForm();
$this
->assertSourceStatus('EN', Lingotek::STATUS_EDITED);
$this
->assertTargetStatus('ES', Lingotek::STATUS_PENDING);
$this
->assertNoTargetStatus('EU', Lingotek::STATUS_EDITED);
$this
->assertTargetStatus('EU', Lingotek::STATUS_REQUEST);
$this
->clickLink('KO');
$this
->assertText("Translation to ko_KR requested successfully");
$this
->clickLink('EN', 3);
$this
->assertText('Account settings has been updated.');
$status = $this
->xpath("//a[contains(@class,'language-icon') and contains(@class, 'target-pending') and contains(text(), 'KO')]");
$this
->assertEqual(count($status), 1, 'Korean is requested, so we can still check the progress status of the translation');
$this
->clickLink('EN', 3);
$this
->assertText('Account settings status checked successfully');
$edit = [
'table[entity.user.admin_form]' => TRUE,
$this
->getBulkOperationFormName() => 'check_translation:es',
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertText('Operations completed.');
$this
->clickLink('ES');
$this
->assertText('Translation to es_MX downloaded successfully');
}
public function testUserSettingsMultipleLanguageTranslationUsingActions() {
$assert_session = $this
->assertSession();
$this
->drupalLogin($this->rootUser);
ConfigurableLanguage::createFromLangcode('de')
->setThirdPartySetting('lingotek', 'locale', 'de_AT')
->save();
$this
->goToConfigBulkManagementForm();
$basepath = \Drupal::request()
->getBasePath();
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/entity.user.admin_form/entity.user.admin_form?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[entity.user.admin_form]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForUpload('node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/check_upload/entity.user.admin_form/entity.user.admin_form?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[entity.user.admin_form]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCheckUpload('node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/request/entity.user.admin_form/entity.user.admin_form/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[entity.user.admin_form]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForRequestTranslations('node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/check_download/entity.user.admin_form/entity.user.admin_form/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[entity.user.admin_form]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCheckTranslations('node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/download/entity.user.admin_form/entity.user.admin_form/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[entity.user.admin_form]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForDownloadTranslations('node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
}
public function testAddingLanguageAllowsRequesting() {
$assert_session = $this
->assertSession();
$this
->testUserSettingsTranslationUsingLinks();
ConfigurableLanguage::createFromLangcode('ca')
->save();
$this
->goToConfigBulkManagementForm();
$basepath = \Drupal::request()
->getBasePath();
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/request/entity.user.admin_form/entity.user.admin_form/ca_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('CA');
$this
->assertText("Translation to ca_ES requested successfully");
}
public function testAddingConfigInDifferentLocale() {
$this
->pass('Test not implemented yet.');
}
}