View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
class LingotekNodeWithParagraphsManageTranslationTabTest extends LingotekTestBase {
use EntityReferenceTestTrait;
public static $modules = [
'block',
'node',
'image',
'paragraphs',
'lingotek_paragraphs_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('node', 'paragraphed_content_demo')
->setLanguageAlterable(TRUE)
->save();
ContentLanguageSettings::loadByEntityTypeBundle('paragraph', 'image_text')
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('node', 'paragraphed_content_demo', TRUE);
drupal_static_reset();
\Drupal::entityTypeManager()
->clearCachedDefinitions();
$this
->applyEntityUpdates();
$this
->rebuildContainer();
$this
->saveLingotekContentTranslationSettings([
'node' => [
'paragraphed_content_demo' => [
'profiles' => 'automatic',
'fields' => [
'title' => 1,
'field_paragraphs_demo' => 1,
],
],
],
'paragraph' => [
'image_text' => [
'fields' => [
'field_image_demo' => [
'title',
'alt',
],
'field_text_demo' => 1,
],
],
],
]);
\Drupal::state()
->set('lingotek.uploaded_content_type', 'node+paragraphs');
}
public function testNodeTranslationUsingLinks() {
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('node/add/paragraphed_content_demo');
$this
->drupalPostForm(NULL, NULL, t('Add Image + Text'));
$edit = [];
$edit['title[0][value]'] = 'Llamas are cool';
$edit['langcode[0][value]'] = 'en';
$edit['field_paragraphs_demo[0][subform][field_text_demo][0][value]'] = 'Llamas are very cool';
$edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
$this
->saveAndPublishNodeForm($edit, NULL);
$this
->drupalLogin($this->translationManagerUser);
$this
->drupalGet('node/1');
$this
->clickLink('Manage Translations');
$this
->assertText('Llamas are cool');
$this
->assertText('Image + Text');
$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
->assertLingotekRequestTranslationLink('es_MX');
$this
->clickLink('EN');
$this
->assertText('The import for node Llamas are cool is complete.');
$this
->assertLingotekRequestTranslationLink('es_MX');
$this
->clickLink('ES');
$this
->assertText("Locale 'es_MX' was added as a translation target for node Llamas are cool.");
$this
->assertIdentical('es_MX', \Drupal::state()
->get('lingotek.added_target_locale'));
$this
->assertLingotekCheckTargetStatusLink('es_MX');
$this
->clickLink('ES');
$this
->assertIdentical('es_MX', \Drupal::state()
->get('lingotek.checked_target_locale'));
$this
->assertText('The es_MX translation for node Llamas are cool is ready for download.');
$this
->assertLingotekDownloadTargetLink('es_MX');
$this
->clickLink('ES');
$this
->assertText('The translation of node 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 testNodeTranslationUsingActions() {
$this
->drupalLogin($this->rootUser);
ConfigurableLanguage::createFromLangcode('de')
->setThirdPartySetting('lingotek', 'locale', 'de_AT')
->save();
$this
->drupalGet('node/add/paragraphed_content_demo');
$this
->drupalPostForm(NULL, NULL, t('Add Image + Text'));
$edit = [];
$edit['title[0][value]'] = 'Llamas are cool';
$edit['langcode[0][value]'] = 'en';
$edit['field_paragraphs_demo[0][subform][field_text_demo][0][value]'] = 'Llamas are very cool';
$edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
$this
->saveAndPublishNodeForm($edit, NULL);
$this
->drupalLogin($this->translationManagerUser);
$this
->drupalGet('node/1');
$this
->clickLink('Manage Translations');
$this
->assertText('Llamas are cool');
$this
->assertText('Image + Text');
$this
->assertLingotekUploadLink();
$edit = [
'table[node:1]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForUpload('node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertLingotekCheckSourceStatusLink();
$edit = [
'table[node:1]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCheckUpload('node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertLingotekRequestTranslationLink('de_AT');
$edit = [
'table[node:1]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForRequestTranslation('de', 'node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('de_AT', \Drupal::state()
->get('lingotek.added_target_locale'));
$this
->assertLingotekCheckTargetStatusLink('de_AT');
$edit = [
'table[node:1]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCheckTranslation('de', 'node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('de_AT', \Drupal::state()
->get('lingotek.checked_target_locale'));
$this
->assertLingotekDownloadTargetLink('de_AT');
$edit = [
'table[node:1]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForDownloadTranslation('de', 'node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('de_AT', \Drupal::state()
->get('lingotek.downloaded_locale'));
$this
->assertLingotekWorkbenchLink('de_AT');
}
protected function getContentBulkManagementFormUrl($entity_type_id = 'node', $prefix = NULL) {
return ($prefix === NULL ? '' : '/' . $prefix) . '/' . $entity_type_id . '/1/manage';
}
}