View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
class ChineseBulkTranslationTest extends LingotekTestBase {
public static $modules = [
'node',
'comment',
];
protected function setUp() : void {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
ConfigurableLanguage::createFromLangcode('zh-hans')
->setThirdPartySetting('lingotek', 'locale', 'zh_CN')
->save();
ContentLanguageSettings::loadByEntityTypeBundle('node', 'article')
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('node', 'article', TRUE);
drupal_static_reset();
\Drupal::entityTypeManager()
->clearCachedDefinitions();
$this
->applyEntityUpdates();
$this
->rebuildContainer();
$this
->saveLingotekContentTranslationSettingsForNodeTypes([
'article',
], 'manual');
$this
->saveLingotekConfigTranslationSettings([
'node_type' => 'manual',
]);
}
public function testNodeTranslationUsingLinks() {
$assert_session = $this
->assertSession();
$this
->drupalLogin($this->rootUser);
$edit = [];
$edit['title[0][value]'] = 'Llamas are cool';
$edit['body[0][value]'] = 'Llamas are very cool';
$edit['langcode[0][value]'] = 'en';
$edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
$this
->saveAndPublishNodeForm($edit);
$this
->goToContentBulkManagementForm();
$this
->assertLingotekUploadLink();
$this
->assertNoLingotekRequestTranslationLink('zh_CN');
$this
->clickLink('EN');
$this
->assertLingotekCheckSourceStatusLink();
$this
->assertLingotekRequestTranslationLink('zh_CN');
$this
->clickLink('EN');
$this
->assertText('The import for node Llamas are cool is complete.');
$this
->assertLingotekRequestTranslationLink('zh_CN');
$this
->clickLink('ZH');
$this
->assertText("Locale 'zh_CN' was added as a translation target for node Llamas are cool.");
$this
->assertIdentical('zh_CN', \Drupal::state()
->get('lingotek.added_target_locale'));
$this
->assertLingotekCheckTargetStatusLink('zh_CN');
$this
->clickLink('ZH');
$this
->assertText('The zh_CN translation for node Llamas are cool is ready for download.');
$this
->assertLingotekDownloadTargetLink('zh_CN');
$this
->clickLink('ZH');
$this
->assertText('The translation of node Llamas are cool into zh_CN has been downloaded.');
$this
->assertLingotekWorkbenchLink('zh_CN', 'dummy-document-hash-id', 'ZH-HANS');
}
public function testSystemSiteTranslationUsingLinks() {
$assert_session = $this
->assertSession();
\Drupal::state()
->set('lingotek.uploaded_content_type', 'system.site');
$this
->drupalLogin($this->rootUser);
$this
->goToConfigBulkManagementForm();
$basepath = \Drupal::request()
->getBasePath();
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/system.site_information_settings/system.site_information_settings?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefNotExists($basepath . '/admin/lingotek/config/request/system.site_information_settings/system.site_information_settings/zh_CN?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('EN', 1);
$this
->assertText(t('System information uploaded successfully'));
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/check_upload/system.site_information_settings/system.site_information_settings?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/request/system.site_information_settings/system.site_information_settings/zh_CN?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('EN', 1);
$this
->assertText('System information status checked successfully');
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/request/system.site_information_settings/system.site_information_settings/zh_CN?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('ZH');
$this
->assertText("Translation to zh_CN requested successfully");
$this
->assertIdentical('zh_CN', \Drupal::state()
->get('lingotek.added_target_locale'));
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/check_download/system.site_information_settings/system.site_information_settings/zh_CN?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('ZH');
$this
->assertIdentical('zh_CN', \Drupal::state()
->get('lingotek.checked_target_locale'));
$this
->assertText("Translation to zh_CN checked successfully");
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/download/system.site_information_settings/system.site_information_settings/zh_CN?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('ZH');
$this
->assertText('Translation to zh_CN downloaded successfully');
$this
->assertIdentical('zh_CN', \Drupal::state()
->get('lingotek.downloaded_locale'));
$this
->assertLingotekWorkbenchLink('zh_CN', 'dummy-document-hash-id', 'ZH-HANS');
}
public function testContentTypeTranslationUsingLinks() {
$assert_session = $this
->assertSession();
\Drupal::state()
->set('lingotek.uploaded_content_type', 'content_type');
$this
->drupalLogin($this->rootUser);
$this
->goToConfigBulkManagementForm('node_type');
$basepath = \Drupal::request()
->getBasePath();
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/node_type/article?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefNotExists($basepath . '/admin/lingotek/config/request/node_type/article/zh_CN?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('EN');
$this
->assertText(t('Article uploaded successfully'));
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/check_upload/node_type/article?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/request/node_type/article/zh_CN?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('EN');
$this
->assertText('Article status checked successfully');
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/request/node_type/article/zh_CN?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('ZH');
$this
->assertText("Translation to zh_CN requested successfully");
$this
->assertIdentical('zh_CN', \Drupal::state()
->get('lingotek.added_target_locale'));
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/check_download/node_type/article/zh_CN?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('ZH');
$this
->assertIdentical('zh_CN', \Drupal::state()
->get('lingotek.checked_target_locale'));
$this
->assertText("Translation to zh_CN status checked successfully");
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/download/node_type/article/zh_CN?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('ZH');
$this
->assertText('Translation to zh_CN downloaded successfully');
$this
->assertIdentical('zh_CN', \Drupal::state()
->get('lingotek.downloaded_locale'));
$this
->assertLingotekWorkbenchLink('zh_CN', 'dummy-document-hash-id', 'ZH-HANS');
}
}