View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\lingotek\Entity\LingotekProfile;
use Drupal\lingotek\Lingotek;
class LingotekNodeBulkDisabledTargetOverrideTranslationTest extends LingotekTestBase {
public static $modules = [
'block',
'node',
];
protected $node;
protected function setUp() : void {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
ConfigurableLanguage::createFromLangcode('es')
->setThirdPartySetting('lingotek', 'locale', 'es_MX')
->save();
ConfigurableLanguage::createFromLangcode('ca')
->setThirdPartySetting('lingotek', 'locale', 'ca_ES')
->save();
$profile = LingotekProfile::create([
'label' => 'Profile with disabled targets',
'id' => 'profile_with_disabled_targets',
'project' => 'test_project',
'vault' => 'test_vault',
'auto_upload' => FALSE,
'workflow' => 'test_workflow',
'language_overrides' => [
'es' => [
'overrides' => 'custom',
'custom' => [
'auto_request' => TRUE,
'workflow' => 'test_workflow',
'vault' => 'test_vault',
],
],
'ca' => [
'overrides' => 'disabled',
],
],
]);
$profile
->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',
], 'profile_with_disabled_targets');
}
public function testNodeTranslationUsingLinks() {
$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]'] = 'profile_with_disabled_targets';
$this
->saveAndPublishNodeForm($edit);
$this
->goToContentBulkManagementForm();
$this
->assertLingotekUploadLink();
$this
->assertNoLingotekRequestTranslationLink('es_MX');
$this
->clickLink('EN');
$this
->assertText('Node Llamas are cool has been uploaded.');
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertLingotekCheckSourceStatusLink();
$this
->assertNoLingotekRequestTranslationLink('ca_ES');
$this
->assertLingotekRequestTranslationLink('es_MX');
$this
->clickLink('EN');
$this
->assertText('The import for node Llamas are cool is complete.');
$this
->assertNoLingotekRequestTranslationLink('ca_ES');
$this
->assertLingotekRequestTranslationLink('es_MX');
$this
->assertTargetStatus('es', Lingotek::STATUS_REQUEST);
$this
->assertTargetStatus('ca', Lingotek::STATUS_DISABLED);
}
public function testNodeTranslationUsingActions() {
$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]'] = 'profile_with_disabled_targets';
$this
->saveAndPublishNodeForm($edit);
$this
->goToContentBulkManagementForm();
$this
->assertLingotekUploadLink();
$this
->assertNoLingotekRequestTranslationLink('ca_ES');
$this
->assertNoLingotekRequestTranslationLink('es_MX');
$this
->clickLink('EN');
$this
->assertText('Node Llamas are cool has been uploaded.');
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertLingotekCheckSourceStatusLink();
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCheckUpload('node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertText('Operations completed.');
$this
->assertNoLingotekRequestTranslationLink('ca_ES');
$this
->assertLingotekRequestTranslationLink('es_MX');
$this
->assertTargetStatus('es', Lingotek::STATUS_REQUEST);
$this
->assertTargetStatus('ca', Lingotek::STATUS_DISABLED);
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForRequestTranslation('ca', 'node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical(NULL, \Drupal::state()
->get('lingotek.added_target_locale'));
$this
->assertIdentical(NULL, \Drupal::state()
->get('lingotek.requested_locales'));
$this
->assertText('Operations completed.');
$this
->assertTargetStatus('es', Lingotek::STATUS_REQUEST);
$this
->assertTargetStatus('ca', Lingotek::STATUS_DISABLED);
$this
->assertNoLingotekCheckTargetStatusLink('ca_ES');
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCheckTranslation('ca', 'node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical(NULL, \Drupal::state()
->get('lingotek.checked_target_locale'));
$this
->assertTargetStatus('es', Lingotek::STATUS_REQUEST);
$this
->assertTargetStatus('ca', Lingotek::STATUS_DISABLED);
$this
->assertNoLingotekDownloadTargetLink('ca_ES');
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForDownloadTranslation('ca', 'node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical(NULL, \Drupal::state()
->get('lingotek.downloaded_locale'));
$this
->assertTargetStatus('es', Lingotek::STATUS_REQUEST);
$this
->assertTargetStatus('ca', Lingotek::STATUS_DISABLED);
}
public function testNodeTranslationUsingActionsForMultipleLocales() {
$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]'] = 'profile_with_disabled_targets';
$this
->saveAndPublishNodeForm($edit);
$this
->goToContentBulkManagementForm();
$this
->assertLingotekUploadLink();
$this
->assertNoLingotekRequestTranslationLink('ca_ES');
$this
->assertNoLingotekRequestTranslationLink('es_MX');
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForUpload('node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertText('Operations completed.');
$this
->assertLingotekCheckSourceStatusLink();
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCheckUpload('node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertText('Operations completed.');
$this
->assertNoLingotekRequestTranslationLink('ca_ES');
$this
->assertLingotekRequestTranslationLink('es_MX');
$this
->assertTargetStatus('es', Lingotek::STATUS_REQUEST);
$this
->assertTargetStatus('ca', Lingotek::STATUS_DISABLED);
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForRequestTranslations('node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical([
'dummy-document-hash-id' => [
'es_MX',
],
], \Drupal::state()
->get('lingotek.requested_locales'));
$this
->assertText('Operations completed.');
$this
->assertTargetStatus('es', Lingotek::STATUS_PENDING);
$this
->assertTargetStatus('ca', Lingotek::STATUS_DISABLED);
$this
->assertNoLingotekCheckTargetStatusLink('ca_ES');
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCheckTranslations('node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical(NULL, \Drupal::state()
->get('lingotek.checked_target_locale'));
$this
->assertTargetStatus('es', Lingotek::STATUS_READY);
$this
->assertTargetStatus('ca', Lingotek::STATUS_DISABLED);
$this
->assertNoLingotekDownloadTargetLink('ca_ES');
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForDownloadTranslations('node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('es_MX', \Drupal::state()
->get('lingotek.downloaded_locale'));
$this
->assertTargetStatus('es', Lingotek::STATUS_CURRENT);
$this
->assertTargetStatus('ca', Lingotek::STATUS_DISABLED);
}
}