View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\lingotek\Lingotek;
class LingotekNodeBulkLocaleTranslationTest extends LingotekTestBase {
public static $modules = [
'node',
'comment',
];
protected $node;
protected function setUp() : void {
parent::setUp();
ConfigurableLanguage::create([
'id' => 'de-at',
'name' => 'German (AT)',
])
->save();
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
ConfigurableLanguage::createFromLangcode('es')
->setThirdPartySetting('lingotek', 'locale', 'es_AR')
->save();
ConfigurableLanguage::createFromLangcode('es-es')
->setThirdPartySetting('lingotek', 'locale', 'es_ES')
->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();
}
public function testNodeTranslationUsingLinks() {
$this
->drupalLogin($this->rootUser);
$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]'] = 'manual';
$this
->saveAndPublishNodeForm($edit);
$this
->goToContentBulkManagementForm();
$this
->assertLingotekUploadLink();
$this
->assertNoLingotekRequestTranslationLink('es_ES');
$this
->assertNoLingotekRequestTranslationLink('es_AR');
$this
->clickLink('EN');
$this
->assertLingotekCheckSourceStatusLink();
$this
->assertLingotekRequestTranslationLink('es_ES');
$this
->assertLingotekRequestTranslationLink('es_AR');
$this
->clickLink('EN');
$this
->assertText('The import for node Llamas are cool is complete.');
$this
->assertLingotekRequestTranslationLink('de_AT', 'dummy-document-hash-id');
$this
->clickLink('DE-AT');
$this
->assertText("Locale 'de_AT' was added as a translation target for node Llamas are cool.");
$this
->assertIdentical('de_AT', \Drupal::state()
->get('lingotek.added_target_locale'));
\Drupal::state()
->resetCache();
$this
->assertLingotekRequestTranslationLink('es_ES');
$this
->assertLingotekRequestTranslationLink('es_AR');
$this
->clickLink('ES');
$this
->assertText("Locale 'es_AR' was added as a translation target for node Llamas are cool.");
$this
->assertIdentical('es_AR', \Drupal::state()
->get('lingotek.added_target_locale'));
$this
->assertLingotekCheckTargetStatusLink('es_AR');
$this
->clickLink('ES');
$this
->assertText('The es_AR translation for node Llamas are cool is ready for download.');
$this
->assertLingotekDownloadTargetLink('es_AR');
$this
->clickLink('ES');
$this
->assertText('The translation of node Llamas are cool into es_AR has been downloaded.');
$this
->assertLingotekWorkbenchLink('es_AR', 'dummy-document-hash-id', 'ES');
$target_links = $this
->xpath("//a[contains(@class,'language-icon')]");
$this
->assertEqual(count($target_links), 3, 'The three languages appear as targets');
$this
->assertEqual('DE-AT', $target_links[0]
->getHtml(), 'DE-AT is the first language');
$this
->assertEqual('ES', $target_links[1]
->getHtml(), 'ES is the second language');
$this
->assertEqual('ES-ES', $target_links[2]
->getHtml(), 'ES-ES is the third language');
}
public function testSourceUpdatedAfterRequestingTranslation() {
$this
->drupalLogin($this->rootUser);
$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]'] = 'automatic';
$this
->saveAndPublishNodeForm($edit);
$this
->goToContentBulkManagementForm();
$this
->assertLingotekCheckSourceStatusLink();
$this
->assertLingotekRequestTranslationLink('de_AT', 'dummy-document-hash-id');
$this
->assertLingotekRequestTranslationLink('de_AT', 'dummy-document-hash-id');
$this
->clickLink('DE-AT');
$this
->assertText("Locale 'de_AT' was added as a translation target for node Llamas are cool.");
$this
->assertNoLingotekCheckSourceStatusLink();
}
public function testDownloadAllWithoutSplitDownload() {
$this
->drupalLogin($this->rootUser);
$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]'] = 'automatic';
$this
->saveAndPublishNodeForm($edit);
$this
->goToContentBulkManagementForm();
$this
->assertLingotekCheckSourceStatusLink();
$this
->assertLingotekRequestTranslationLink('de_AT', 'dummy-document-hash-id');
$this
->assertLingotekRequestTranslationLink('de_AT', 'dummy-document-hash-id');
$this
->clickLink('ES-ES');
$this
->assertText("Locale 'es_ES' was added as a translation target for node Llamas are cool.");
$this
->clickLink('DE-AT');
$this
->assertText("Locale 'de_AT' was added as a translation target for node Llamas are cool.");
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForDownloadTranslations('node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertTargetStatus('DE-AT', Lingotek::STATUS_CURRENT);
$this
->assertTargetStatus('ES-ES', Lingotek::STATUS_CURRENT);
$this
->assertTargetStatus('ES', Lingotek::STATUS_REQUEST);
}
public function testDownloadAllWithSplitDownload() {
$this
->drupalGet('admin/lingotek/settings');
$edit = [
'split_download_all' => TRUE,
];
$this
->submitForm($edit, 'Save', 'lingoteksettings-tab-preferences-form');
$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]'] = 'automatic';
$this
->saveAndPublishNodeForm($edit);
$this
->goToContentBulkManagementForm();
$this
->assertLingotekCheckSourceStatusLink();
$this
->assertLingotekRequestTranslationLink('de_AT', 'dummy-document-hash-id');
$this
->assertLingotekRequestTranslationLink('de_AT', 'dummy-document-hash-id');
$this
->clickLink('ES-ES');
$this
->assertText("Locale 'es_ES' was added as a translation target for node Llamas are cool.");
$this
->clickLink('DE-AT');
$this
->assertText("Locale 'de_AT' was added as a translation target for node Llamas are cool.");
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForDownloadTranslations('node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertTargetStatus('DE-AT', Lingotek::STATUS_CURRENT);
$this
->assertTargetStatus('ES-ES', Lingotek::STATUS_CURRENT);
$this
->assertTargetStatus('ES', Lingotek::STATUS_REQUEST);
}
}