View source
<?php
namespace Drupal\lingotek\Tests;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
class ChineseBulkTranslationTest extends LingotekTestBase {
public static $modules = [
'node',
'comment',
];
protected function setUp() {
parent::setUp();
$this
->drupalCreateContentType(array(
'type' => 'article',
'name' => 'Article',
));
$post = [
'code' => 'zh_CN',
'language' => 'Chinese',
'native' => 'Chinese',
'direction' => '',
];
$this
->drupalPost('/admin/lingotek/dashboard_endpoint', 'application/json', $post);
ContentLanguageSettings::loadByEntityTypeBundle('node', 'article')
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('node', 'article', TRUE);
drupal_static_reset();
\Drupal::entityManager()
->clearCachedDefinitions();
\Drupal::service('entity.definition_update_manager')
->applyUpdates();
$this
->rebuildContainer();
$edit = [
'node[article][enabled]' => 1,
'node[article][profiles]' => 'manual',
'node[article][fields][title]' => 1,
'node[article][fields][body]' => 1,
];
$this
->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-content-form');
$edit = [
'table[node_type][enabled]' => 1,
'table[node_type][profile]' => 'manual',
];
$this
->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-configuration-form');
}
public function testNodeTranslationUsingLinks() {
$this
->drupalLogin($this->rootUser);
$edit = array();
$edit['title[0][value]'] = 'Llamas are cool';
$edit['body[0][value]'] = 'Llamas are very cool';
$edit['langcode[0][value]'] = 'en';
$edit['lingotek_translation_profile'] = 'manual';
$this
->drupalPostForm('node/add/article', $edit, t('Save and publish'));
$this
->goToContentBulkManagementForm();
$basepath = \Drupal::request()
->getBasePath();
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/upload/node/1?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->assertNoLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/zh_CN?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->clickLink('EN');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/check_upload/dummy-document-hash-id?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/zh_CN?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->clickLink('EN');
$this
->assertText('The import for node Llamas are cool is complete.');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/zh_CN?destination=' . $basepath . '/admin/lingotek/manage/node');
$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
->assertLinkByHref($basepath . '/admin/lingotek/entity/check_target/dummy-document-hash-id/zh_CN?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->clickLink('ZH');
$this
->assertText('The zh_CN translation for node Llamas are cool is ready for download.');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/download/dummy-document-hash-id/zh_CN?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->clickLink('ZH');
$this
->assertText('The translation of node Llamas are cool into zh_CN has been downloaded.');
$this
->assertLinkByHref($basepath . '/admin/lingotek/workbench/dummy-document-hash-id/zh_CN');
$workbench_link = $this
->xpath("//a[@href='{$basepath}/admin/lingotek/workbench/dummy-document-hash-id/zh_CN' and @target='_blank']");
$this
->assertEqual(count($workbench_link), 1, 'Workbench links open in a new tab.');
}
public function testSystemSiteTranslationUsingLinks() {
\Drupal::state()
->set('lingotek.uploaded_content_type', 'system.site');
$this
->drupalLogin($this->rootUser);
$this
->goToConfigBulkManagementForm();
$basepath = \Drupal::request()
->getBasePath();
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/upload/system.site_information_settings/system.site_information_settings?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->assertNoLinkByHref($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'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/check_upload/system.site_information_settings/system.site_information_settings?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->assertLinkByHref($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');
$this
->assertLinkByHref($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'));
$this
->assertLinkByHref($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");
$this
->assertLinkByHref($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
->assertLinkByHref($basepath . '/admin/lingotek/workbench/dummy-document-hash-id/zh_CN');
$workbench_link = $this
->xpath("//a[@href='{$basepath}/admin/lingotek/workbench/dummy-document-hash-id/zh_CN' and @target='_blank']");
$this
->assertEqual(count($workbench_link), 1, 'Workbench links open in a new tab.');
}
public function testContentTypeTranslationUsingLinks() {
\Drupal::state()
->set('lingotek.uploaded_content_type', 'content_type');
$this
->drupalLogin($this->rootUser);
$this
->goToConfigBulkManagementForm('node_type');
$basepath = \Drupal::request()
->getBasePath();
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/upload/node_type/article?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->assertNoLinkByHref($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'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/check_upload/node_type/article?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->assertLinkByHref($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');
$this
->assertLinkByHref($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'));
$this
->assertLinkByHref($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");
$this
->assertLinkByHref($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
->assertLinkByHref($basepath . '/admin/lingotek/workbench/dummy-document-hash-id/zh_CN');
$workbench_link = $this
->xpath("//a[@href='{$basepath}/admin/lingotek/workbench/dummy-document-hash-id/zh_CN' and @target='_blank']");
$this
->assertEqual(count($workbench_link), 1, 'Workbench links open in a new tab.');
}
}