View source
<?php
namespace Drupal\lingotek\Tests;
use Drupal\Core\Url;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\lingotek\Lingotek;
use Drupal\lingotek\LingotekConfigTranslationServiceInterface;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\node\NodeInterface;
class LingotekContentTypeBulkTranslationTest extends LingotekTestBase {
public static $modules = [
'block',
'node',
];
protected function setUp() {
parent::setUp();
$this
->drupalCreateContentType(array(
'type' => 'article',
'name' => 'Article',
));
ConfigurableLanguage::createFromLangcode('es')
->setThirdPartySetting('lingotek', 'locale', 'es_MX')
->save();
$edit = [
'table[node_type][enabled]' => 1,
'table[node_type][profile]' => 'automatic',
];
$this
->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-configuration-form');
\Drupal::state()
->set('lingotek.uploaded_content_type', 'content_type');
}
public function testContentTypeTranslationUsingLinks() {
$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/es_MX?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/es_MX?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/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'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/check_download/node_type/article/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");
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/download/node_type/article/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
->assertLinkByHref($basepath . '/admin/lingotek/workbench/dummy-document-hash-id/es_MX');
$workbench_link = $this
->xpath("//a[@href='{$basepath}/admin/lingotek/workbench/dummy-document-hash-id/es_MX' and @target='_blank']");
$this
->assertEqual(count($workbench_link), 1, 'Workbench links open in a new tab.');
}
public function testContentTypeTranslationUsingActions() {
$this
->drupalLogin($this->rootUser);
ConfigurableLanguage::createFromLangcode('de')
->setThirdPartySetting('lingotek', 'locale', 'de_AT')
->save();
$this
->goToConfigBulkManagementForm('node_type');
$basepath = \Drupal::request()
->getBasePath();
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/upload/node_type/article?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[article]' => TRUE,
'operation' => 'upload',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$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');
$edit = [
'table[article]' => TRUE,
'operation' => 'check_upload',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/request/node_type/article/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[article]' => TRUE,
'operation' => 'request_translation:de',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertIdentical('de_AT', \Drupal::state()
->get('lingotek.added_target_locale'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/check_download/node_type/article/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[article]' => TRUE,
'operation' => 'check_translation:de',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertIdentical('de_AT', \Drupal::state()
->get('lingotek.checked_target_locale'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/download/node_type/article/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[article]' => TRUE,
'operation' => 'download:de',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertIdentical('de_AT', \Drupal::state()
->get('lingotek.downloaded_locale'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/workbench/dummy-document-hash-id/de_AT');
$workbench_link = $this
->xpath("//a[@href='{$basepath}/admin/lingotek/workbench/dummy-document-hash-id/de_AT' and @target='_blank']");
$this
->assertEqual(count($workbench_link), 1, 'Workbench links open in a new tab.');
}
public function testContentTypeMultipleLanguageTranslationUsingActions() {
$this
->drupalLogin($this->rootUser);
$edit = [
'table[node_type][enabled]' => 1,
'table[node_type][profile]' => 'manual',
];
$this
->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-configuration-form');
ConfigurableLanguage::createFromLangcode('de')
->setThirdPartySetting('lingotek', 'locale', 'de_AT')
->save();
$this
->drupalCreateContentType(array(
'type' => 'page',
'name' => 'Page',
));
$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
->assertLinkByHref($basepath . '/admin/lingotek/config/upload/node_type/page?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[article]' => TRUE,
'table[page]' => TRUE,
'operation' => 'upload',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/check_upload/node_type/article?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/check_upload/node_type/page?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[article]' => TRUE,
'table[page]' => TRUE,
'operation' => 'check_upload',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/request/node_type/article/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/request/node_type/page/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[article]' => TRUE,
'table[page]' => TRUE,
'operation' => 'request_translations',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/check_download/node_type/article/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/check_download/node_type/page/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[article]' => TRUE,
'table[page]' => TRUE,
'operation' => 'check_translations',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/download/node_type/article/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/download/node_type/page/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[article]' => TRUE,
'table[page]' => TRUE,
'operation' => 'download',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
}
public function testEditedConfigTranslationUsingLinks() {
$this
->testContentTypeTranslationUsingLinks();
$edit = [
'table[node_type][enabled]' => 1,
'table[node_type][profile]' => 'manual',
];
$this
->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-configuration-form');
ConfigurableLanguage::createFromLangcode('eu')
->setThirdPartySetting('lingotek', 'locale', 'eu_ES')
->save();
ConfigurableLanguage::createFromLangcode('ko')
->setThirdPartySetting('lingotek', 'locale', 'ko_KR')
->save();
$this
->drupalPostForm('/admin/structure/types/manage/article', [
'name' => 'Article EDITED',
], t('Save content type'));
$this
->goToConfigBulkManagementForm('node_type');
$untracked = $this
->xpath("//a[contains(@class,'language-icon') and contains(@class, 'target-edited') and contains(text(), 'ES')]");
$this
->assertEqual(count($untracked), 1, 'Edited translation is shown.');
$eu_edited = $this
->xpath("//a[contains(@class,'language-icon') and contains(@class, 'target-edited') and contains(text(), 'EU')]");
$this
->assertEqual(count($eu_edited), 0, 'Vasque is not marked as edited.');
$eu_request = $this
->xpath("//a[contains(@class,'language-icon') and contains(@class, 'target-request') and contains(text(), 'EU')]");
$this
->assertEqual(count($eu_request), 1, 'Vasque is ready for request.');
$this
->clickLink('KO');
$this
->assertText("Translation to ko_KR requested successfully");
$this
->clickLink('EN');
$this
->assertText('Article EDITED has been updated.');
$this
->clickLink('EN');
$this
->assertText('Article EDITED status checked successfully');
$status = $this
->xpath("//a[contains(@class,'language-icon') and contains(@class, 'target-pending') and contains(text(), 'KO')]");
$this
->assertEqual(count($status), 1, 'Korean is still requested, so we can still check the progress status of the translation');
$edit = [
'table[article]' => TRUE,
'operation' => 'check_translations',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertText('Operations completed.');
$this
->clickLink('ES');
$this
->assertText('Translation to es_MX downloaded successfully');
}
public function testEditedConfigTranslationUsingLinksInAutomaticUploadMode() {
$this
->testContentTypeTranslationUsingLinks();
$edit = [
'table[node_type][enabled]' => 1,
'table[node_type][profile]' => 'automatic',
];
$this
->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-configuration-form');
ConfigurableLanguage::createFromLangcode('eu')
->setThirdPartySetting('lingotek', 'locale', 'eu_ES')
->save();
$this
->drupalPostForm('/admin/structure/types/manage/article', [
'name' => 'Article EDITED',
], t('Save content type'));
$this
->goToConfigBulkManagementForm('node_type');
$untracked = $this
->xpath("//a[contains(@class,'language-icon') and contains(@class, 'target-edited') and contains(text(), 'ES')]");
$this
->assertEqual(count($untracked), 1, 'Edited translation is shown.');
$eu_edited = $this
->xpath("//a[contains(@class,'language-icon') and contains(@class, 'target-edited') and contains(text(), 'EU')]");
$this
->assertEqual(count($eu_edited), 0, 'Vasque is not marked as edited.');
$eu_request = $this
->xpath("//a[contains(@class,'language-icon') and contains(@class, 'target-request') and contains(text(), 'EU')]");
$this
->assertEqual(count($eu_request), 1, 'Vasque is ready for request.');
$this
->clickLink('EN');
$this
->assertText('Article EDITED status checked successfully');
$edit = [
'table[article]' => TRUE,
'operation' => 'check_translations',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertText('Operations completed.');
$this
->clickLink('ES');
$this
->assertText('Translation to es_MX downloaded successfully');
}
public function testAddingLanguageAllowsRequesting() {
$this
->testContentTypeTranslationUsingLinks();
ConfigurableLanguage::createFromLangcode('ca')
->save();
$this
->goToConfigBulkManagementForm('node_type');
$basepath = \Drupal::request()
->getBasePath();
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/request/node_type/article/ca_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('CA');
$this
->assertText("Translation to ca_ES requested successfully");
}
public function testFormWorksAfterRemovingLanguageWithStatuses() {
$this
->testAddingLanguageAllowsRequesting();
ConfigurableLanguage::load('es')
->delete();
$this
->goToConfigBulkManagementForm();
$this
->assertNoLink('ES');
$this
->assertLink('CA');
}
public function testAddingConfigInDifferentLocale() {
$this
->pass('Test not implemented yet.');
}
public function testUploadingWithAnError() {
\Drupal::state()
->set('lingotek.must_error_in_upload', TRUE);
$this
->goToConfigBulkManagementForm('node_type');
$this
->clickLink('EN');
$this
->assertText('Article upload failed. Please try again.');
$source_error = $this
->xpath("//span[contains(@class,'language-icon') and contains(@class,'source-error') and ./a[contains(text(), 'EN')]]");
$this
->assertEqual(count($source_error), 1, 'The node type has been marked as error.');
$nodeType = NodeType::load('article');
$translation_service = \Drupal::service('lingotek.config_translation');
$source_status = $translation_service
->getSourceStatus($nodeType);
$this
->assertEqual(Lingotek::STATUS_ERROR, $source_status, 'The node type has been marked as error.');
\Drupal::state()
->set('lingotek.must_error_in_upload', FALSE);
$this
->clickLink('EN');
$this
->assertText('Article uploaded successfully');
}
public function testUpdatingWithAnError() {
$edit = [
'table[node_type][profile]' => 'manual',
];
$this
->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-configuration-form');
$this
->goToConfigBulkManagementForm('node_type');
$this
->clickLink('EN');
$this
->assertText('Article uploaded successfully');
$this
->clickLink('EN');
$edit = [
'name' => 'Blogpost',
];
$this
->drupalPostForm('/admin/structure/types/manage/article', $edit, t('Save content type'));
\Drupal::state()
->set('lingotek.must_error_in_upload', TRUE);
$this
->goToConfigBulkManagementForm('node_type');
$this
->clickLink('EN');
$this
->assertText('Blogpost update failed. Please try again.');
$source_error = $this
->xpath("//span[contains(@class,'language-icon') and contains(@class,'source-error') and ./a[contains(text(), 'EN')]]");
$this
->assertEqual(count($source_error), 1, 'The node type has been marked as error.');
$nodeType = NodeType::load('article');
$translation_service = \Drupal::service('lingotek.config_translation');
$source_status = $translation_service
->getSourceStatus($nodeType);
$this
->assertEqual(Lingotek::STATUS_ERROR, $source_status, 'The node type has been marked as error.');
\Drupal::state()
->set('lingotek.must_error_in_upload', FALSE);
$this
->clickLink('EN');
$this
->assertText('Blogpost has been updated.');
}
public function testUploadingWithAnErrorUsingActions() {
$edit = [
'table[node_type][profile]' => 'manual',
];
$this
->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-configuration-form');
\Drupal::state()
->set('lingotek.must_error_in_upload', TRUE);
$this
->goToConfigBulkManagementForm('node_type');
$basepath = \Drupal::request()
->getBasePath();
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/upload/node_type/article?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[article]' => TRUE,
'operation' => 'upload',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertText('Article upload failed. Please try again.');
$source_error = $this
->xpath("//span[contains(@class,'language-icon') and contains(@class,'source-error') and ./a[contains(text(), 'EN')]]");
$this
->assertEqual(count($source_error), 1, 'The node type has been marked as error.');
$nodeType = NodeType::load('article');
$translation_service = \Drupal::service('lingotek.config_translation');
$source_status = $translation_service
->getSourceStatus($nodeType);
$this
->assertEqual(Lingotek::STATUS_ERROR, $source_status, 'The node type has been marked as error.');
\Drupal::state()
->set('lingotek.must_error_in_upload', FALSE);
$this
->clickLink('EN');
$this
->assertText('Article uploaded successfully');
}
public function testUpdatingWithAnErrorUsingActions() {
$edit = [
'table[node_type][profile]' => 'manual',
];
$this
->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-configuration-form');
$this
->goToConfigBulkManagementForm('node_type');
$basepath = \Drupal::request()
->getBasePath();
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/upload/node_type/article?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[article]' => TRUE,
'operation' => 'upload',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertText('Operations completed.');
$this
->clickLink('EN');
$edit = [
'name' => 'Blogpost',
];
$this
->drupalPostForm('/admin/structure/types/manage/article', $edit, t('Save content type'));
\Drupal::state()
->set('lingotek.must_error_in_upload', TRUE);
$this
->goToConfigBulkManagementForm('node_type');
$edit = [
'table[article]' => TRUE,
'operation' => 'upload',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertText('Blogpost update failed. Please try again.');
$source_error = $this
->xpath("//span[contains(@class,'language-icon') and contains(@class,'source-error') and ./a[contains(text(), 'EN')]]");
$this
->assertEqual(count($source_error), 1, 'The node type has been marked as error.');
$nodeType = NodeType::load('article');
$translation_service = \Drupal::service('lingotek.config_translation');
$source_status = $translation_service
->getSourceStatus($nodeType);
$this
->assertEqual(Lingotek::STATUS_ERROR, $source_status, 'The node type has been marked as error.');
\Drupal::state()
->set('lingotek.must_error_in_upload', FALSE);
$this
->clickLink('EN');
$this
->assertText('Blogpost has been updated.');
}
public function testCheckTranslationsAction() {
ConfigurableLanguage::create([
'id' => 'de_AT',
'label' => 'German (Austria)',
])
->setThirdPartySetting('lingotek', 'locale', 'de_AT')
->save();
$this
->goToConfigBulkManagementForm('node_type');
$basepath = \Drupal::request()
->getBasePath();
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/upload/node_type/article?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[article]' => TRUE,
'operation' => 'upload',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$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');
$edit = [
'table[article]' => TRUE,
'operation' => 'check_upload',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/request/node_type/article/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[article]' => TRUE,
'operation' => 'check_translations',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/download/node_type/article/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/download/node_type/article/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
ConfigurableLanguage::createFromLangcode('de')
->setThirdPartySetting('lingotek', 'locale', 'de_DE')
->save();
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/download/node_type/article/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');
\Drupal::state()
->set('lingotek.document_completion_statuses', [
'de-AT' => 50,
'de-DE' => 100,
'es-MX' => 10,
]);
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertNoLinkByHref($basepath . '/admin/lingotek/config/download/node_type/article/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/download/node_type/article/de_DE?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->assertNoLinkByHref($basepath . '/admin/lingotek/config/download/node_type/article/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
}
}