public function LingotekNodeLayoutBuilderAsymmetricTranslationTest::testNodeWithLayoutBuilderATCustomBlockTranslation in Lingotek Translation 3.5.x
Same name and namespace in other branches
- 4.0.x tests/src/Functional/LingotekNodeLayoutBuilderAsymmetricTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeLayoutBuilderAsymmetricTranslationTest::testNodeWithLayoutBuilderATCustomBlockTranslation()
- 3.4.x tests/src/Functional/LingotekNodeLayoutBuilderAsymmetricTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeLayoutBuilderAsymmetricTranslationTest::testNodeWithLayoutBuilderATCustomBlockTranslation()
- 3.6.x tests/src/Functional/LingotekNodeLayoutBuilderAsymmetricTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeLayoutBuilderAsymmetricTranslationTest::testNodeWithLayoutBuilderATCustomBlockTranslation()
- 3.7.x tests/src/Functional/LingotekNodeLayoutBuilderAsymmetricTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeLayoutBuilderAsymmetricTranslationTest::testNodeWithLayoutBuilderATCustomBlockTranslation()
- 3.8.x tests/src/Functional/LingotekNodeLayoutBuilderAsymmetricTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeLayoutBuilderAsymmetricTranslationTest::testNodeWithLayoutBuilderATCustomBlockTranslation()
Tests that a node can be translated.
File
- tests/
src/ Functional/ LingotekNodeLayoutBuilderAsymmetricTranslationTest.php, line 255
Class
- LingotekNodeLayoutBuilderAsymmetricTranslationTest
- Tests translating a node with multiple locales including paragraphs.
Namespace
Drupal\Tests\lingotek\FunctionalCode
public function testNodeWithLayoutBuilderATCustomBlockTranslation() {
// This is a hack for avoiding writing different lingotek endpoint mocks.
\Drupal::state()
->set('lingotek.uploaded_content_type', 'node+layoutbuilderatcustom');
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalGet('node/add/article');
$edit = [];
$edit['title[0][value]'] = 'Llamas are cool';
$edit['body[0][value]'] = 'Llamas are very cool';
$edit['langcode[0][value]'] = 'en';
$this
->drupalPostForm(NULL, $edit, t('Save'));
// Add a block with a custom label.
$page
->clickLink('Layout');
$assert_session
->elementTextContains('css', '.layout-builder__message.layout-builder__message--overrides', 'You are editing the layout for this Article content item. Edit the template for all Article content items instead.');
$assert_session
->linkExists('Edit the template for all Article content items instead.');
$page
->clickLink('Add block');
$page
->clickLink('Create custom block');
$page
->fillField('settings[label]', 'Overridden block with Dogs title');
$page
->fillField('settings[block_form][body][0][value]', 'Block Dogs are very cool');
$page
->checkField('settings[label_display]');
$page
->pressButton('Add block');
$page
->pressButton('Save layout');
$assert_session
->pageTextContains('Overridden block with Dogs title');
$assert_session
->pageTextContains('Block Dogs are very cool');
// Get the UUID of the component.
$components = Node::load(1)
->get('layout_builder__layout')
->getSection(0)
->getComponents();
$uuids = array_keys($components);
$uuidArticleLinks = $uuids[0];
$uuidArticleBody = $uuids[1];
$uuidArticleContentBlock = $uuids[2];
// 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', [
'###UID_LINKS###' => $uuidArticleLinks,
'###UID_BODY###' => $uuidArticleBody,
'###UID_CONTENTBLOCK###' => $uuidArticleContentBlock,
]);
$this
->clickLink('Translate');
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$assert_session
->pageTextContains('Uploaded 1 document to Lingotek.');
// Check that only the configured fields have been uploaded.
$data = Json::decode(\Drupal::state()
->get('lingotek.uploaded_content', '[]'));
file_put_contents('/tmp/uploaded-json', \Drupal::state()
->get('lingotek.uploaded_content', '[]'));
$this
->assertUploadedDataFieldCount($data, 3);
$this
->assertEquals($data['title'][0]['value'], 'Llamas are cool');
$this
->assertEquals($data['body'][0]['value'], 'Llamas are very cool');
$this
->assertCount(3, $data['layout_builder__layout']['components']);
$this
->assertEquals($data['layout_builder__layout']['components'][$uuidArticleContentBlock]['label'], 'Overridden block with Dogs title');
$this
->assertCount(1, $data['layout_builder__layout']['entities']);
$this
->assertCount(1, $data['layout_builder__layout']['entities']['block_content']);
$this
->assertUploadedDataFieldCount($data['layout_builder__layout']['entities']['block_content'][1], 1);
$this
->assertEquals($data['layout_builder__layout']['entities']['block_content'][1]['body'][0]['value'], 'Block Dogs are very cool');
$this
->assertEquals($data['layout_builder__layout']['entities']['block_content'][1]['_lingotek_metadata']['_entity_type_id'], 'block_content');
$this
->assertEquals($data['layout_builder__layout']['entities']['block_content'][1]['_lingotek_metadata']['_entity_id'], '1');
// 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('manual', $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');
$assert_session
->pageTextContains('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();
$assert_session
->pageTextContains("Locale 'es_AR' was added as a translation target for node Llamas are cool.");
// Check translation status.
$this
->clickLink('Check translation status');
$assert_session
->pageTextContains('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', 'dummy-document-hash-id');
// Download translation.
$this
->clickLink('Download completed translation');
$assert_session
->pageTextContains('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');
$assert_session
->pageTextContains('Las llamas son chulas');
$assert_session
->pageTextContains('Las llamas son muy chulas');
$assert_session
->pageTextContains('Bloque sobreescrito con título Perros');
$assert_session
->pageTextContains('Bloque Los perros son muy chulos');
// The original content didn't change.
$this
->drupalGet('node/1');
$assert_session
->pageTextContains('Llamas are cool');
$assert_session
->pageTextContains('Llamas are very cool');
$assert_session
->pageTextContains('Overridden block with Dogs title');
$assert_session
->pageTextContains('Block Dogs are very cool');
}