View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\entity_test\Entity\EntityTestMul;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\lingotek\Lingotek;
class LingotekEntityTestBulkTranslationTest extends LingotekTestBase {
public static $modules = [
'block',
'entity_test',
];
protected function setUp() : void {
parent::setUp();
$this
->drupalPlaceBlock('page_title_block', [
'region' => 'content',
'weight' => -5,
]);
$this
->drupalPlaceBlock('local_tasks_block', [
'region' => 'content',
'weight' => -10,
]);
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::entityTypeManager()
->clearCachedDefinitions();
$this
->applyEntityUpdates();
$this
->rebuildContainer();
$this
->saveLingotekContentTranslationSettings([
'entity_test_mul' => [
'entity_test_mul' => [
'profiles' => 'automatic',
'fields' => [
'name' => 1,
],
],
],
]);
\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_management[lingotek_translation_profile]'] = 'manual';
$this
->drupalPostForm('/entity_test_mul/add/entity_test_mul', $edit, t('Save'));
$this
->goToContentBulkManagementForm('entity_test_mul');
$this
->assertLingotekUploadLink(1, 'entity_test_mul');
$this
->assertNoLingotekRequestTranslationLink('es_MX', 'dummy-document-hash-id', '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
->assertLingotekCheckSourceStatusLink('dummy-document-hash-id', 'entity_test_mul');
$this
->assertLingotekRequestTranslationLink('es_MX', 'dummy-document-hash-id', 'entity_test_mul');
$this
->clickLink('EN');
$this
->assertText('The import for entity_test_mul Llamas are cool is complete.');
$this
->assertLingotekRequestTranslationLink('es_MX', 'dummy-document-hash-id', '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
->assertLingotekCheckTargetStatusLink('es_MX', 'dummy-document-hash-id', '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
->assertLingotekDownloadTargetLink('es_MX', 'dummy-document-hash-id', '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
->assertLingotekWorkbenchLink('es_MX');
}
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_management[lingotek_translation_profile]'] = 'manual';
$this
->drupalPostForm('/entity_test_mul/add/entity_test_mul', $edit, t('Save'));
$this
->goToContentBulkManagementForm('entity_test_mul');
$this
->assertLingotekUploadLink(1, 'entity_test_mul');
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForUpload('entity_test_mul'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertLingotekCheckSourceStatusLink('dummy-document-hash-id', 'entity_test_mul');
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCheckUpload('entity_test_mul'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertLingotekRequestTranslationLink('de_AT', 'dummy-document-hash-id', 'entity_test_mul');
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForRequestTranslation('de', 'entity_test_mul'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('de_AT', \Drupal::state()
->get('lingotek.added_target_locale'));
$this
->assertLingotekCheckTargetStatusLink('de_AT', 'dummy-document-hash-id', 'entity_test_mul');
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => 'check_translation:de',
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('de_AT', \Drupal::state()
->get('lingotek.checked_target_locale'));
$this
->assertLingotekDownloadTargetLink('de_AT', 'dummy-document-hash-id', 'entity_test_mul');
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => 'download:de',
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('de_AT', \Drupal::state()
->get('lingotek.downloaded_locale'));
$this
->assertLingotekWorkbenchLink('de_AT');
}
public function testCheckTranslationsAction() {
ConfigurableLanguage::create([
'id' => 'de_AT',
'label' => 'German (Austria)',
])
->setThirdPartySetting('lingotek', 'locale', 'de_AT')
->save();
ConfigurableLanguage::createFromLangcode('ca')
->setThirdPartySetting('lingotek', 'locale', 'ca_ES')
->save();
ConfigurableLanguage::createFromLangcode('it')
->setThirdPartySetting('lingotek', 'locale', 'it_IT')
->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_management[lingotek_translation_profile]'] = 'manual';
$this
->drupalPostForm('/entity_test_mul/add/entity_test_mul', $edit, t('Save'));
$this
->goToContentBulkManagementForm('entity_test_mul');
$this
->assertLingotekUploadLink(1, 'entity_test_mul');
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForUpload('entity_test_mul'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertLingotekCheckSourceStatusLink('dummy-document-hash-id', 'entity_test_mul');
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCheckUpload('entity_test_mul'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertLingotekRequestTranslationLink('de_AT', 'dummy-document-hash-id', 'entity_test_mul');
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCheckTranslations('entity_test_mul'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertLingotekDownloadTargetLink('de_AT', 'dummy-document-hash-id', 'entity_test_mul');
$this
->assertLingotekDownloadTargetLink('es_MX', 'dummy-document-hash-id', 'entity_test_mul');
ConfigurableLanguage::createFromLangcode('de')
->setThirdPartySetting('lingotek', 'locale', 'de_DE')
->save();
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertLingotekDownloadTargetLink('de_DE', 'dummy-document-hash-id', 'entity_test_mul');
\Drupal::state()
->set('lingotek.document_completion_statuses', [
'de-AT' => 50,
'de-DE' => 100,
'es-MX' => 10,
]);
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertNoLingotekDownloadTargetLink('de_AT', 'dummy-document-hash-id', 'entity_test_mul');
$this
->assertLingotekDownloadTargetLink('de_DE', 'dummy-document-hash-id', 'entity_test_mul');
$this
->assertNoLingotekDownloadTargetLink('es_MX', 'dummy-document-hash-id', 'entity_test_mul');
$this
->assertLingotekRequestTranslationLink('ca_ES', 'dummy-document-hash-id', 'entity_test_mul');
$this
->assertLingotekRequestTranslationLink('it_IT', 'dummy-document-hash-id', 'entity_test_mul');
\Drupal::state()
->set('lingotek.document_completion_statuses', [
'it-IT' => 100,
'de-DE' => 50,
'es-MX' => 10,
]);
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertLingotekRequestTranslationLink('de_AT', 'dummy-document-hash-id', 'entity_test_mul');
$this
->assertLingotekCheckTargetStatusLink('de_DE', 'dummy-document-hash-id', 'entity_test_mul');
$this
->assertLingotekCheckTargetStatusLink('es_MX', 'dummy-document-hash-id', 'entity_test_mul');
$this
->assertLingotekRequestTranslationLink('ca_ES', 'dummy-document-hash-id', 'entity_test_mul');
$this
->assertLingotekDownloadTargetLink('it_IT', 'dummy-document-hash-id', 'entity_test_mul');
$this
->assertSourceStatusStateCount(Lingotek::STATUS_CURRENT, 'EN', 1);
}
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_management[lingotek_translation_profile]'] = 'manual';
$this
->drupalPostForm('/entity_test_mul/add/entity_test_mul', $edit, t('Save'));
$this
->goToContentBulkManagementForm('entity_test_mul');
$this
->assertLingotekUploadLink(1, 'entity_test_mul');
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForUpload('entity_test_mul'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertLingotekCheckSourceStatusLink('dummy-document-hash-id', 'entity_test_mul');
\Drupal::state()
->set('lingotek.document_status_completion', FALSE);
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCheckUpload('entity_test_mul'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertLingotekCheckSourceStatusLink('dummy-document-hash-id', 'entity_test_mul');
\Drupal::state()
->set('lingotek.document_status_completion', TRUE);
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCheckUpload('entity_test_mul'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertLingotekRequestTranslationLink('es_MX', 'dummy-document-hash-id', 'entity_test_mul');
}
public function testUploadingWithoutAuthor() {
$entity = EntityTestMul::create([
'type' => 'entity_test_mul',
'name' => 'Test article',
]);
$entity
->setOwnerId(NULL);
$entity
->save();
$this
->assertNull($entity
->getOwner());
$this
->drupalGet('/entity_test_mul/manage/1');
}
public function testTranslationDownloadWithUnrequestedLocales() {
ConfigurableLanguage::createFromLangcode('de')
->setThirdPartySetting('lingotek', 'locale', 'de_DE')
->save();
ConfigurableLanguage::createFromLangcode('it')
->setThirdPartySetting('lingotek', 'locale', 'it_IT')
->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_management[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
->assertLingotekUploadLink(1, 'entity_test_mul');
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForUpload('entity_test_mul'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertLingotekCheckSourceStatusLink('dummy-document-hash-id', 'entity_test_mul');
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCheckUpload('entity_test_mul'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertLingotekRequestTranslationLink('es_MX', 'dummy-document-hash-id', '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
->assertLingotekCheckTargetStatusLink('es_MX', 'dummy-document-hash-id', '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
->assertLingotekDownloadTargetLink('es_MX', 'dummy-document-hash-id', 'entity_test_mul');
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForDownloadTranslations('entity_test_mul'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertLingotekRequestTranslationLink('de_DE', 'dummy-document-hash-id', 'entity_test_mul');
$this
->assertLingotekRequestTranslationLink('it_IT', 'dummy-document-hash-id', 'entity_test_mul');
$this
->assertNoTargetError('Llamas are cool', 'DE', 'de_DE');
$this
->assertNoTargetError('Llamas are cool', 'IT', 'it_IT');
}
public function testCheckTranslationsWithDownloadedLocales() {
ConfigurableLanguage::createFromLangcode('de')
->setThirdPartySetting('lingotek', 'locale', 'de_DE')
->save();
ConfigurableLanguage::createFromLangcode('it')
->setThirdPartySetting('lingotek', 'locale', 'it_IT')
->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_management[lingotek_translation_profile]'] = 'manual';
$this
->drupalPostForm('/entity_test_mul/add/entity_test_mul', $edit, t('Save'));
$this
->goToContentBulkManagementForm('entity_test_mul');
$this
->assertLingotekUploadLink(1, 'entity_test_mul');
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForUpload('entity_test_mul'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertLingotekCheckSourceStatusLink('dummy-document-hash-id', 'entity_test_mul');
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCheckUpload('entity_test_mul'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertLingotekRequestTranslationLink('es_MX', 'dummy-document-hash-id', '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'));
\Drupal::state()
->resetCache();
$this
->assertLingotekRequestTranslationLink('it_IT', 'dummy-document-hash-id', 'entity_test_mul');
$this
->clickLink('IT');
$this
->assertText("Locale 'it_IT' was added as a translation target for entity_test_mul Llamas are cool.");
$this
->assertIdentical('it_IT', \Drupal::state()
->get('lingotek.added_target_locale'));
$this
->assertLingotekCheckTargetStatusLink('es_MX', 'dummy-document-hash-id', '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.');
\Drupal::state()
->resetCache();
$this
->assertLingotekCheckTargetStatusLink('it_IT', 'dummy-document-hash-id', 'entity_test_mul');
$this
->clickLink('IT');
$this
->assertIdentical('it_IT', \Drupal::state()
->get('lingotek.checked_target_locale'));
$this
->assertText('The it_IT translation for entity_test_mul Llamas are cool is ready for download.');
$this
->assertLingotekDownloadTargetLink('es_MX', 'dummy-document-hash-id', 'entity_test_mul');
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForDownloadTranslations('entity_test_mul'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertTargetStatus('ES', 'current');
$this
->assertTargetStatus('IT', 'current');
$this
->assertTargetStatus('DE', 'request');
\Drupal::state()
->set('lingotek.document_completion_statuses', [
'es-ES' => 100,
'it-IT' => 100,
]);
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCheckTranslations('entity_test_mul'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertTargetStatus('ES', 'current');
$this
->assertTargetStatus('IT', 'current');
$this
->assertTargetStatus('DE', 'request');
}
public function testCannotAssignProfileToContentWithoutRightPermission() {
$editor = $this
->drupalCreateUser([
'administer entity_test content',
'view test entity',
]);
$this
->drupalLogin($editor);
$this
->drupalGet('entity_test_mul/add/entity_test_mul');
$this
->assertNoField('lingotek_translation_management[lingotek_translation_profile]');
$translation_manager = $this
->drupalCreateUser([
'administer entity_test content',
'view test entity',
'assign lingotek translation profiles',
]);
$this
->drupalLogin($translation_manager);
$this
->drupalGet('entity_test_mul/add/entity_test_mul');
$this
->assertField('lingotek_translation_management[lingotek_translation_profile]');
$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_management[lingotek_translation_profile]'] = 'manual';
$this
->drupalPostForm('/entity_test_mul/add/entity_test_mul', $edit, t('Save'));
$this
->clickLink('Edit');
$this
->assertFieldById('edit-lingotek-translation-management-lingotek-translation-profile', 'manual');
}
}