View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\lingotek\Entity\LingotekConfigMetadata;
use Drupal\lingotek\Lingotek;
class LingotekSystemSiteTranslationTest extends LingotekTestBase {
public static $modules = [
'block',
'node',
'image',
'frozenintime',
];
protected function setUp() : void {
parent::setUp();
$this
->drupalPlaceBlock('page_title_block', [
'region' => 'header',
]);
$this
->drupalPlaceBlock('local_tasks_block', [
'region' => 'header',
]);
$this
->drupalPlaceBlock('system_branding_block', [
'region' => 'header',
]);
ConfigurableLanguage::createFromLangcode('es')
->setThirdPartySetting('lingotek', 'locale', 'es_AR')
->save();
\Drupal::state()
->set('lingotek.uploaded_content_type', 'system.site');
}
public function testSystemSiteTranslation() {
$assert_session = $this
->assertSession();
$this
->drupalGet('/admin/config/system/site-information');
$this
->clickLink('Translate system information');
$this
->clickLink(t('Upload'));
$this
->assertText(t('System information uploaded successfully'));
$data = json_decode(\Drupal::state()
->get('lingotek.uploaded_content', '[]'), TRUE);
$this
->assertEqual(1, count($data));
$this
->assertTrue(array_key_exists('system.site', $data));
$this
->assertEqual(2, count($data['system.site']));
$this
->assertTrue(array_key_exists('name', $data['system.site']));
$this
->assertTrue(array_key_exists('slogan', $data['system.site']));
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$timestamp = \Drupal::time()
->getRequestTime();
foreach (LingotekConfigMetadata::loadMultiple() as $metadata) {
$this
->assertEquals($timestamp, $metadata
->getLastUploaded());
$this
->assertEmpty($metadata
->getLastUpdated());
}
$uploaded_url = \Drupal::state()
->get('lingotek.uploaded_url');
$this
->assertIdentical(NULL, $uploaded_url, 'There was not associated url.');
$used_profile = \Drupal::state()
->get('lingotek.used_profile');
$this
->assertIdentical('manual', $used_profile, 'The manual profile was used.');
$this
->clickLink(t('Check upload status'));
$this
->assertText(t('System information status checked successfully'));
$link = $this
->xpath('//a[normalize-space()="Request translation" and contains(@href,"es_AR")]');
$link[0]
->click();
$this
->assertIdentical('es_AR', \Drupal::state()
->get('lingotek.added_target_locale'));
$this
->assertText(t('Translation to es_AR requested successfully'));
$this
->clickLink(t('Check Download'));
$this
->assertIdentical('es_AR', \Drupal::state()
->get('lingotek.checked_target_locale'));
$this
->assertText(t('Translation to es_AR checked successfully'));
$this
->clickLink('Download');
$this
->assertIdentical('es_AR', \Drupal::state()
->get('lingotek.downloaded_locale'));
$this
->assertText(t('Translation to es_AR downloaded successfully'));
$basepath = \Drupal::request()
->getBasePath();
$assert_session
->linkByHrefExists($basepath . '/admin/config/system/site-information/translate/es/edit');
$this
->clickLink('Edit', 1);
$this
->assertFieldByName('translation[config_names][system.site][slogan]', 'Las llamas son muy chulas');
$this
->drupalGet('/es/');
$this
->assertText('Las llamas son muy chulas');
}
public function testEditedSystemConfigTranslation() {
$assert_session = $this
->assertSession();
$this
->testSystemSiteTranslation();
ConfigurableLanguage::createFromLangcode('eu')
->setThirdPartySetting('lingotek', 'locale', 'eu_ES')
->save();
$edit = [
'site_name' => 'The Llamas site',
];
$this
->drupalPostForm('admin/config/system/site-information', $edit, 'Save configuration');
$this
->clickLink('Translate system information');
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$timestamp = \Drupal::time()
->getRequestTime();
foreach (LingotekConfigMetadata::loadMultiple() as $metadata) {
$this
->assertEquals($timestamp, $metadata
->getLastUploaded());
$this
->assertEquals($timestamp, $metadata
->getLastUpdated());
}
$assert_session
->linkByHrefExists('admin/lingotek/config/request/system.site_information_settings/system.site_information_settings/eu_ES');
$this
->clickLink('Check Download');
$this
->assertText('Translation to es_AR checked successfully');
$this
->clickLink('Download');
$this
->assertText('Translation to es_AR downloaded successfully');
}
public function testLanguageDisabled() {
$assert_session = $this
->assertSession();
$italian = ConfigurableLanguage::createFromLangcode('it')
->setThirdPartySetting('lingotek', 'locale', 'it_IT');
$italian
->save();
$this
->drupalGet('/admin/config/system/site-information');
$this
->clickLink('Translate system information');
$this
->clickLink(t('Upload'));
$this
->assertText(t('System information uploaded successfully'));
$data = json_decode(\Drupal::state()
->get('lingotek.uploaded_content', '[]'), TRUE);
$this
->assertEqual(1, count($data));
$this
->assertTrue(array_key_exists('system.site', $data));
$this
->assertEqual(2, count($data['system.site']));
$this
->assertTrue(array_key_exists('name', $data['system.site']));
$this
->assertTrue(array_key_exists('slogan', $data['system.site']));
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$used_profile = \Drupal::state()
->get('lingotek.used_profile');
$this
->assertIdentical('manual', $used_profile, 'The manual profile was used.');
$this
->clickLink(t('Check upload status'));
$this
->assertText(t('System information status checked successfully'));
$assert_session
->linkByHrefExists('/admin/config/system/site-information/translate/it/add');
$assert_session
->linkByHrefExists('/admin/config/system/site-information/translate/es/add');
$assert_session
->linkByHrefExists('/admin/lingotek/config/request/system.site_information_settings/system.site_information_settings/it_IT');
$assert_session
->linkByHrefExists('/admin/lingotek/config/request/system.site_information_settings/system.site_information_settings/es_AR');
$lingotek_config = \Drupal::service('lingotek.configuration');
$lingotek_config
->disableLanguage($italian);
$this
->drupalGet('/admin/config/system/site-information');
$this
->clickLink('Translate system information');
$assert_session
->linkByHrefExists('/admin/config/system/site-information/translate/it/add');
$assert_session
->linkByHrefExists('/admin/config/system/site-information/translate/es/add');
$assert_session
->linkByHrefNotExists('/admin/lingotek/config/request/system.site_information_settings/system.site_information_settings/it_IT');
$assert_session
->linkByHrefExists('/admin/lingotek/config/request/system.site_information_settings/system.site_information_settings/es_AR');
}
public function testUploadingWithAnError() {
\Drupal::state()
->set('lingotek.must_error_in_upload', TRUE);
$this
->drupalGet('/admin/config/system/site-information');
$this
->clickLink('Translate system information');
$this
->clickLink(t('Upload'));
$this
->assertText('System information upload failed. Please try again.');
$mapperManager = \Drupal::service('plugin.manager.config_translation.mapper');
$mapper = $mapperManager
->getMappers()['system.site_information_settings'];
$translation_service = \Drupal::service('lingotek.config_translation');
$source_status = $translation_service
->getConfigSourceStatus($mapper);
$this
->assertEqual(Lingotek::STATUS_ERROR, $source_status, 'The system information has been marked as error.');
\Drupal::state()
->set('lingotek.must_error_in_upload', FALSE);
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('System information uploaded successfully');
}
public function testUploadingWithAPaymentRequiredError() {
\Drupal::state()
->set('lingotek.must_payment_required_error_in_upload', TRUE);
$this
->drupalGet('/admin/config/system/site-information');
$this
->clickLink('Translate system information');
$this
->clickLink(t('Upload'));
$this
->checkForMetaRefresh();
$this
->assertText('Community has been disabled. Please contact support@lingotek.com to re-enable your community.');
$mapperManager = \Drupal::service('plugin.manager.config_translation.mapper');
$mapper = $mapperManager
->getMappers()['system.site_information_settings'];
$translation_service = \Drupal::service('lingotek.config_translation');
$source_status = $translation_service
->getConfigSourceStatus($mapper);
$this
->assertEqual(Lingotek::STATUS_ERROR, $source_status, 'The system information has been marked as error.');
\Drupal::state()
->set('lingotek.must_payment_required_error_in_upload', FALSE);
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('System information uploaded successfully');
}
public function testUpdatingWithAnError() {
$this
->drupalGet('/admin/config/system/site-information');
$this
->clickLink('Translate system information');
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('System information uploaded successfully');
$this
->clickLink('Check upload status');
$this
->assertText('System information status checked successfully');
$edit['site_name'] = 'Llamas are cool';
$this
->drupalPostForm('/admin/config/system/site-information', $edit, t('Save configuration'));
$this
->drupalGet('/admin/config/system/site-information');
$this
->clickLink('Translate system information');
\Drupal::state()
->set('lingotek.must_error_in_upload', TRUE);
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('System information update failed. Please try again.');
$mapperManager = \Drupal::service('plugin.manager.config_translation.mapper');
$mapper = $mapperManager
->getMappers()['system.site_information_settings'];
$translation_service = \Drupal::service('lingotek.config_translation');
$source_status = $translation_service
->getConfigSourceStatus($mapper);
$this
->assertEqual(Lingotek::STATUS_ERROR, $source_status, 'The system information has been marked as error.');
\Drupal::state()
->set('lingotek.must_error_in_upload', FALSE);
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('System information has been updated.');
}
public function testUpdatingWithAPaymentRequiredError() {
$this
->drupalGet('/admin/config/system/site-information');
$this
->clickLink('Translate system information');
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('System information uploaded successfully');
$this
->clickLink('Check upload status');
$this
->assertText('System information status checked successfully');
$edit['site_name'] = 'Llamas are cool';
$this
->drupalPostForm('/admin/config/system/site-information', $edit, t('Save configuration'));
$this
->drupalGet('/admin/config/system/site-information');
$this
->clickLink('Translate system information');
\Drupal::state()
->set('lingotek.must_payment_required_error_in_update', TRUE);
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Community has been disabled. Please contact support@lingotek.com to re-enable your community.');
$mapperManager = \Drupal::service('plugin.manager.config_translation.mapper');
$mapper = $mapperManager
->getMappers()['system.site_information_settings'];
$translation_service = \Drupal::service('lingotek.config_translation');
$source_status = $translation_service
->getConfigSourceStatus($mapper);
$this
->assertEqual(Lingotek::STATUS_ERROR, $source_status, 'The system information has been marked as error.');
\Drupal::state()
->set('lingotek.must_payment_required_error_in_update', FALSE);
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('System information has been updated.');
}
public function testUpdatingWithADocumentArchivedError() {
$this
->drupalGet('/admin/config/system/site-information');
$this
->clickLink('Translate system information');
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('System information uploaded successfully');
$this
->clickLink('Check upload status');
$this
->assertText('System information status checked successfully');
$edit['site_name'] = 'Llamas are cool';
$this
->drupalPostForm('/admin/config/system/site-information', $edit, t('Save configuration'));
$this
->drupalGet('/admin/config/system/site-information');
$this
->clickLink('Translate system information');
\Drupal::state()
->set('lingotek.must_document_archived_error_in_update', TRUE);
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Document System information has been archived. Please upload again.');
$mapperManager = \Drupal::service('plugin.manager.config_translation.mapper');
$mapper = $mapperManager
->getMappers()['system.site_information_settings'];
$translation_service = \Drupal::service('lingotek.config_translation');
$source_status = $translation_service
->getConfigSourceStatus($mapper);
$this
->assertEqual(Lingotek::STATUS_UNTRACKED, $source_status, 'The system information has been marked as error.');
\Drupal::state()
->set('lingotek.must_document_archived_error_in_update', FALSE);
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('System information uploaded successfully');
}
public function testUpdatingWithADocumentLockedError() {
$this
->drupalGet('/admin/config/system/site-information');
$this
->clickLink('Translate system information');
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('System information uploaded successfully');
$this
->clickLink('Check upload status');
$this
->assertText('System information status checked successfully');
$edit['site_name'] = 'Llamas are cool';
$this
->drupalPostForm('/admin/config/system/site-information', $edit, t('Save configuration'));
$this
->drupalGet('/admin/config/system/site-information');
$this
->clickLink('Translate system information');
\Drupal::state()
->set('lingotek.must_document_locked_error_in_update', TRUE);
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Document System information has a new version. The document id has been updated for all future interactions. Please try again.');
$mapperManager = \Drupal::service('plugin.manager.config_translation.mapper');
$mapper = $mapperManager
->getMappers()['system.site_information_settings'];
$translation_service = \Drupal::service('lingotek.config_translation');
$source_status = $translation_service
->getConfigSourceStatus($mapper);
$this
->assertEqual(Lingotek::STATUS_EDITED, $source_status, 'The system information has been marked as error.');
\Drupal::state()
->set('lingotek.must_document_locked_error_in_update', FALSE);
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('System information has been updated.');
}
}