View source
<?php
namespace Drupal\lingotek\Tests;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
class LingotekEntityTestBulkTranslationTest extends LingotekTestBase {
public static $modules = [
'entity_test',
];
protected function setUp() {
parent::setUp();
ConfigurableLanguage::createFromLangcode('es')
->setThirdPartySetting('lingotek', 'locale', 'es_MX')
->save();
ContentLanguageSettings::loadByEntityTypeBundle('entity_test_mul', 'entity_test_mul')
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('entity_test_mul', 'entity_test_mul', TRUE);
drupal_static_reset();
\Drupal::entityManager()
->clearCachedDefinitions();
\Drupal::service('entity.definition_update_manager')
->applyUpdates();
$this
->rebuildContainer();
$edit = [
'entity_test_mul[entity_test_mul][enabled]' => 1,
'entity_test_mul[entity_test_mul][profiles]' => 'automatic',
'entity_test_mul[entity_test_mul][fields][name]' => 1,
];
$this
->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-content-form');
\Drupal::state()
->set('lingotek.uploaded_content_type', 'entity_test_mul');
}
public function testEntityTestTranslationUsingLinks() {
$this
->drupalLogin($this->rootUser);
$edit = [];
$edit['name[0][value]'] = 'Llamas are cool';
$edit['field_test_text[0][value]'] = 'Llamas are very cool';
$edit['langcode[0][value]'] = 'en';
$edit['lingotek_translation_profile'] = 'manual';
$this
->drupalPostForm('/entity_test_mul/add/entity_test_mul', $edit, t('Save'));
$this
->goToContentBulkManagementForm('entity_test_mul');
$basepath = \Drupal::request()
->getBasePath();
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/upload/entity_test_mul/1?destination=' . $basepath . '/admin/lingotek/manage/entity_test_mul');
$this
->assertNoLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/es_MX?destination=' . $basepath . '/admin/lingotek/manage/entity_test_mul');
$this
->clickLink('EN');
$this
->assertText('Entity_test_mul Llamas are cool has been uploaded.');
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/check_upload/dummy-document-hash-id?destination=' . $basepath . '/admin/lingotek/manage/entity_test_mul');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/es_MX?destination=' . $basepath . '/admin/lingotek/manage/entity_test_mul');
$this
->clickLink('EN');
$this
->assertText('The import for entity_test_mul Llamas are cool is complete.');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/es_MX?destination=' . $basepath . '/admin/lingotek/manage/entity_test_mul');
$this
->clickLink('ES');
$this
->assertText("Locale 'es_MX' was added as a translation target for entity_test_mul Llamas are cool.");
$this
->assertIdentical('es_MX', \Drupal::state()
->get('lingotek.added_target_locale'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/check_target/dummy-document-hash-id/es_MX?destination=' . $basepath . '/admin/lingotek/manage/entity_test_mul');
$this
->clickLink('ES');
$this
->assertIdentical('es_MX', \Drupal::state()
->get('lingotek.checked_target_locale'));
$this
->assertText('The es_MX translation for entity_test_mul Llamas are cool is ready for download.');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/download/dummy-document-hash-id/es_MX?destination=' . $basepath . '/admin/lingotek/manage/entity_test_mul');
$this
->clickLink('ES');
$this
->assertText('The translation of entity_test_mul Llamas are cool into es_MX has been downloaded.');
$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 testEntityTestTranslationUsingActions() {
ConfigurableLanguage::createFromLangcode('de')
->setThirdPartySetting('lingotek', 'locale', 'de_AT')
->save();
$edit = [];
$edit['name[0][value]'] = 'Llamas are cool';
$edit['field_test_text[0][value]'] = 'Llamas are very cool';
$edit['langcode[0][value]'] = 'en';
$edit['lingotek_translation_profile'] = 'manual';
$this
->drupalPostForm('/entity_test_mul/add/entity_test_mul', $edit, t('Save'));
$this
->goToContentBulkManagementForm('entity_test_mul');
$basepath = \Drupal::request()
->getBasePath();
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/upload/entity_test_mul/1?destination=' . $basepath . '/admin/lingotek/manage/entity_test_mul');
$edit = [
'table[1]' => TRUE,
'operation' => 'upload',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/check_upload/dummy-document-hash-id?destination=' . $basepath . '/admin/lingotek/manage/entity_test_mul');
$edit = [
'table[1]' => TRUE,
'operation' => 'check_upload',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/de_AT?destination=' . $basepath . '/admin/lingotek/manage/entity_test_mul');
$edit = [
'table[1]' => 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/entity/check_target/dummy-document-hash-id/de_AT?destination=' . $basepath . '/admin/lingotek/manage/entity_test_mul');
$edit = [
'table[1]' => 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/entity/download/dummy-document-hash-id/de_AT?destination=' . $basepath . '/admin/lingotek/manage/entity_test_mul');
$edit = [
'table[1]' => 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 testCheckTranslationsAction() {
ConfigurableLanguage::create([
'id' => 'de_AT',
'label' => 'German (Austria)',
])
->setThirdPartySetting('lingotek', 'locale', 'de_AT')
->save();
$edit = [];
$edit['name[0][value]'] = 'Llamas are cool';
$edit['field_test_text[0][value]'] = 'Llamas are very cool';
$edit['langcode[0][value]'] = 'en';
$edit['lingotek_translation_profile'] = 'manual';
$this
->drupalPostForm('/entity_test_mul/add/entity_test_mul', $edit, t('Save'));
$this
->goToContentBulkManagementForm('entity_test_mul');
$basepath = \Drupal::request()
->getBasePath();
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/upload/entity_test_mul/1?destination=' . $basepath . '/admin/lingotek/manage/entity_test_mul');
$edit = [
'table[1]' => TRUE,
'operation' => 'upload',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/check_upload/dummy-document-hash-id?destination=' . $basepath . '/admin/lingotek/manage/entity_test_mul');
$edit = [
'table[1]' => TRUE,
'operation' => 'check_upload',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/de_AT?destination=' . $basepath . '/admin/lingotek/manage/entity_test_mul');
$edit = [
'table[1]' => TRUE,
'operation' => 'check_translations',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/download/dummy-document-hash-id/de_AT?destination=' . $basepath . '/admin/lingotek/manage/entity_test_mul');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/download/dummy-document-hash-id/es_MX?destination=' . $basepath . '/admin/lingotek/manage/entity_test_mul');
ConfigurableLanguage::createFromLangcode('de')
->setThirdPartySetting('lingotek', 'locale', 'de_DE')
->save();
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/download/dummy-document-hash-id/de_DE?destination=' . $basepath . '/admin/lingotek/manage/entity_test_mul');
\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/entity/download/dummy-document-hash-id/de_AT?destination=' . $basepath . '/admin/lingotek/manage/entity_test_mul');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/download/dummy-document-hash-id/de_DE?destination=' . $basepath . '/admin/lingotek/manage/entity_test_mul');
$this
->assertNoLinkByHref($basepath . '/admin/lingotek/entity/download/dummy-document-hash-id/es_MX?destination=' . $basepath . '/admin/lingotek/manage/entity_test_mul');
}
public function testCheckSourceStatusNotCompleted() {
$edit = [];
$edit['name[0][value]'] = 'Llamas are cool';
$edit['field_test_text[0][value]'] = 'Llamas are very cool';
$edit['langcode[0][value]'] = 'en';
$edit['lingotek_translation_profile'] = 'manual';
$this
->drupalPostForm('/entity_test_mul/add/entity_test_mul', $edit, t('Save'));
$this
->goToContentBulkManagementForm('entity_test_mul');
$basepath = \Drupal::request()
->getBasePath();
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/upload/entity_test_mul/1?destination=' . $basepath . '/admin/lingotek/manage/entity_test_mul');
$edit = [
'table[1]' => TRUE,
'operation' => 'upload',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/check_upload/dummy-document-hash-id?destination=' . $basepath . '/admin/lingotek/manage/entity_test_mul');
\Drupal::state()
->set('lingotek.document_status_completion', FALSE);
$edit = [
'table[1]' => TRUE,
'operation' => 'check_upload',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/check_upload/dummy-document-hash-id?destination=' . $basepath . '/admin/lingotek/manage/entity_test_mul');
\Drupal::state()
->set('lingotek.document_status_completion', TRUE);
$edit = [
'table[1]' => TRUE,
'operation' => 'check_upload',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/es_MX?destination=' . $basepath . '/admin/lingotek/manage/entity_test_mul');
}
}