public function LingotekNodeCohesionTranslationTest::testNodeWithCohesionLayoutCanvasTranslation in Lingotek Translation 3.5.x
Same name and namespace in other branches
- 4.0.x tests/src/Functional/LingotekNodeCohesionTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeCohesionTranslationTest::testNodeWithCohesionLayoutCanvasTranslation()
- 3.3.x tests/src/Functional/LingotekNodeCohesionTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeCohesionTranslationTest::testNodeWithCohesionLayoutCanvasTranslation()
- 3.4.x tests/src/Functional/LingotekNodeCohesionTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeCohesionTranslationTest::testNodeWithCohesionLayoutCanvasTranslation()
- 3.6.x tests/src/Functional/LingotekNodeCohesionTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeCohesionTranslationTest::testNodeWithCohesionLayoutCanvasTranslation()
- 3.7.x tests/src/Functional/LingotekNodeCohesionTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeCohesionTranslationTest::testNodeWithCohesionLayoutCanvasTranslation()
- 3.8.x tests/src/Functional/LingotekNodeCohesionTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeCohesionTranslationTest::testNodeWithCohesionLayoutCanvasTranslation()
Tests that a node can be translated.
File
- tests/
src/ Functional/ LingotekNodeCohesionTranslationTest.php, line 133
Class
- LingotekNodeCohesionTranslationTest
- Tests translating a node with multiple locales including paragraphs.
Namespace
Drupal\Tests\lingotek\FunctionalCode
public function testNodeWithCohesionLayoutCanvasTranslation() {
// Login as admin.
$this
->drupalLogin($this->rootUser);
// Add a site studio powered content.
$this
->drupalGet('node/add/article');
$edit = [];
$edit['title[0][value]'] = 'Llamas are cool';
$edit['langcode[0][value]'] = 'en';
$edit['layout_canvas[0][target_id][json_values]'] = <<<'JSON'
{"canvas":[{"uid":"3fedc674","type":"component","title":"Text","enabled":true,"category":"category-3","componentId":"3fedc674","componentType":"container","uuid":"ac9583af-74f9-419d-9f8a-68f6ca0ef5e8","parentUid":"root","isContainer":0,"children":[]}],"mapper":{},"model":{"ac9583af-74f9-419d-9f8a-68f6ca0ef5e8":{"settings":{"title":"Text: Llamas are very cool"},"6b671446-cb09-46cb-b84a-7366da00be36":{"text":"<p>Llamas are very cool</p>\n","textFormat":"cohesion"},"fdaea1d1-6b7c-4aad-978a-e6981fb5eb7d":{"name":"White","uid":"white","value":{"hex":"#ffffff","rgba":"rgba(255, 255, 255, 1)"},"wysiwyg":true,"class":".coh-color-white","variable":"$coh-color-white","inuse":true,"link":true},"e6f07bf5-1bfa-4fef-8baa-62abb3016788":"coh-style-max-width---narrow","165f1de9-336c-42cc-bed2-28ef036ec7e3":"coh-style-padding-bottom---large","4c27d36c-a473-47ec-8d43-3b9696d45d74":""}},"previewModel":{"ac9583af-74f9-419d-9f8a-68f6ca0ef5e8":{}},"variableFields":{"ac9583af-74f9-419d-9f8a-68f6ca0ef5e8":[]},"meta":{"fieldHistory":[]}}
JSON;
$edit['moderation_state[0][state]'] = 'published';
// Mink does not "see" hidden elements, so we need to set the value of the
// hidden element directly.
$this
->assertSession()
->elementExists('css', 'input[name="layout_canvas[0][target_id][json_values]"]')
->setValue($edit['layout_canvas[0][target_id][json_values]']);
unset($edit['layout_canvas[0][target_id][json_values]']);
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this->node = Node::load(1);
/** @var \Drupal\cohesion_elements\Entity\CohesionLayout $layout */
$layout = CohesionLayout::load(1);
$jsonValues = $layout
->get('json_values')->value;
$jsonValuesData = Json::decode($jsonValues);
$modelUuid = $jsonValuesData['canvas'][0]['uuid'];
$components = array_keys($jsonValuesData['model'][$modelUuid]);
// The first element is settings, the second one is our component uuid.
$componentUuid = $components[1];
// Check that only the configured fields have been uploaded, including metatags.
$data = Json::decode(\Drupal::state()
->get('lingotek.uploaded_content', '[]'));
// As those uuids are generated, we don't know them in our document fake
// responses. We need a token replacement system for fixing that.
\Drupal::state()
->set('lingotek.data_replacements', [
'###MODEL_UUID###' => $modelUuid,
'###COMPONENT_UUID###' => $componentUuid,
]);
$this
->assertUploadedDataFieldCount($data, 2);
$this
->assertEquals($data['title'][0]['value'], 'Llamas are cool');
$this
->assertTrue(isset($data['layout_canvas'][0]['json_values'][$modelUuid]));
$this
->assertTrue(isset($data['layout_canvas'][0]['json_values'][$modelUuid][$componentUuid]));
$this
->assertEquals($data['layout_canvas'][0]['json_values'][$modelUuid][$componentUuid], '<p>Llamas are very cool</p>' . PHP_EOL . '');
// Check that the url used was the right one.
$uploaded_url = \Drupal::state()
->get('lingotek.uploaded_url');
$this
->assertIdentical(\Drupal::request()
->getUriForPath('/node/1'), $uploaded_url, 'The node url was used.');
// Check that the profile used was the right one.
$used_profile = \Drupal::state()
->get('lingotek.used_profile');
$this
->assertIdentical('automatic', $used_profile, 'The automatic profile was used.');
// Check that the translate tab is in the node.
$this
->drupalGet('node/1');
$this
->clickLink('Translate');
// The document should have been automatically uploaded, so let's check
// the upload status.
$this
->clickLink('Check Upload Status');
$this
->assertText('The import for node Llamas are cool is complete.');
// Request translation.
$link = $this
->xpath('//a[normalize-space()="Request translation" and contains(@href,"es_AR")]');
$link[0]
->click();
$this
->assertText("Locale 'es_AR' was added as a translation target for node Llamas are cool.");
// Check translation status.
$this
->clickLink('Check translation status');
$this
->assertText('The es_AR translation for node Llamas are cool is ready for download.');
// Check that the Edit link points to the workbench and it is opened in a new tab.
$this
->assertLingotekWorkbenchLink('es_AR');
// Download translation.
$this
->clickLink('Download completed translation');
$this
->assertText('The translation of node Llamas are cool into es_AR has been downloaded.');
// The content is translated and published.
$this
->clickLink('Las llamas son chulas');
$this
->assertText('Las llamas son chulas');
$this
->assertText('Las llamas son muy chulas');
/** @var \Drupal\Core\Entity\EntityStorageInterface $cohesionLayoutStorage */
$cohesionLayoutStorage = $this->container
->get('entity_type.manager')
->getStorage('cohesion_layout');
$cohesionLayoutStorage
->resetCache([
1,
]);
/** @var \Drupal\cohesion_elements\Entity\CohesionLayout $layout */
$layout = CohesionLayout::load(1);
$layout = $layout
->getTranslation('es-ar');
$jsonValues = $layout
->get('json_values')->value;
$jsonValuesData = Json::decode($jsonValues);
$textValue = $jsonValuesData['model'][$modelUuid][$componentUuid]['text'];
$this
->assertEquals($textValue, '<p>Las llamas son muy chulas</p>' . PHP_EOL . '');
// The original content didn't change.
$this
->drupalGet('node/1');
$this
->assertText('Llamas are cool');
$this
->assertText('Llamas are very cool');
}