You are here

public function LingotekNodeParagraphsTranslationTest::testNodeWithParagraphsTranslation in Lingotek Translation 3.4.x

Same name in this branch
  1. 3.4.x tests/src/Functional/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeParagraphsTranslationTest::testNodeWithParagraphsTranslation()
  2. 3.4.x tests/src/FunctionalJavascript/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\FunctionalJavascript\LingotekNodeParagraphsTranslationTest::testNodeWithParagraphsTranslation()
Same name and namespace in other branches
  1. 8.2 tests/src/FunctionalJavascript/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\FunctionalJavascript\LingotekNodeParagraphsTranslationTest::testNodeWithParagraphsTranslation()
  2. 4.0.x tests/src/FunctionalJavascript/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\FunctionalJavascript\LingotekNodeParagraphsTranslationTest::testNodeWithParagraphsTranslation()
  3. 3.1.x tests/src/FunctionalJavascript/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\FunctionalJavascript\LingotekNodeParagraphsTranslationTest::testNodeWithParagraphsTranslation()
  4. 3.2.x tests/src/FunctionalJavascript/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\FunctionalJavascript\LingotekNodeParagraphsTranslationTest::testNodeWithParagraphsTranslation()
  5. 3.3.x tests/src/FunctionalJavascript/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\FunctionalJavascript\LingotekNodeParagraphsTranslationTest::testNodeWithParagraphsTranslation()
  6. 3.5.x tests/src/FunctionalJavascript/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\FunctionalJavascript\LingotekNodeParagraphsTranslationTest::testNodeWithParagraphsTranslation()
  7. 3.6.x tests/src/FunctionalJavascript/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\FunctionalJavascript\LingotekNodeParagraphsTranslationTest::testNodeWithParagraphsTranslation()
  8. 3.7.x tests/src/FunctionalJavascript/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\FunctionalJavascript\LingotekNodeParagraphsTranslationTest::testNodeWithParagraphsTranslation()
  9. 3.8.x tests/src/FunctionalJavascript/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\FunctionalJavascript\LingotekNodeParagraphsTranslationTest::testNodeWithParagraphsTranslation()

Tests that a node can be translated.

1 call to LingotekNodeParagraphsTranslationTest::testNodeWithParagraphsTranslation()
LingotekNodeParagraphsTranslationTest::testEditingAfterNodeWithParagraphsTranslation in tests/src/FunctionalJavascript/LingotekNodeParagraphsTranslationTest.php

File

tests/src/FunctionalJavascript/LingotekNodeParagraphsTranslationTest.php, line 84

Class

LingotekNodeParagraphsTranslationTest
@group lingotek @group legacy

Namespace

Drupal\Tests\lingotek\FunctionalJavascript

Code

public function testNodeWithParagraphsTranslation() {
  $page = $this
    ->getSession()
    ->getPage();
  $assert_session = $this
    ->assertSession();
  $messages_locator = '.messages--status';

  // Add paragraphed content.
  $this
    ->drupalGet('node/add/paragraphed_content_demo');
  $page
    ->pressButton('field_paragraphs_demo_image_text_add_more');
  $assert_session
    ->assertWaitOnAjaxRequest();
  $assert_session
    ->waitForElementVisible('css', '[name="field_paragraphs_demo[0][subform][field_text_demo][0][value]"]');
  $page
    ->pressButton('field_paragraphs_demo_image_text_add_more');
  $assert_session
    ->assertWaitOnAjaxRequest();
  $assert_session
    ->waitForElementVisible('css', '[name="field_paragraphs_demo[1][subform][field_text_demo][0][value]"]');
  $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['moderation_state[0][state]'] = 'published';
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));

  // Check that only the configured fields have been uploaded, including metatags.
  $data = json_decode(\Drupal::state()
    ->get('lingotek.uploaded_content', '[]'), TRUE);
  $this
    ->assertEqual($data['title'][0]['value'], 'Llamas are cool');
  $this
    ->assertEqual($data['field_paragraphs_demo'][0]['field_text_demo'][0]['value'], 'Llamas are very cool');

  // 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.
  $toggle = $page
    ->find('css', 'li.dropbutton-toggle button');
  $toggle
    ->click();
  $dropButton = $page
    ->find('css', 'li.check-upload-status.dropbutton-action a');
  $dropButton
    ->click();

  // This is a batch process, wait to finish.
  $assert_session
    ->waitForElementVisible('css', $messages_locator);
  $assert_session
    ->elementTextContains('css', $messages_locator, 'The import for node Llamas are cool is complete.');

  // Request translation.
  $toggle = $page
    ->findAll('css', 'li.dropbutton-toggle button')[1];
  $toggle
    ->click();
  $dropButton = $page
    ->find('css', 'li.request-translation.dropbutton-action a');
  $dropButton
    ->click();

  // This is a batch process, wait to finish.
  $assert_session
    ->waitForElementVisible('css', $messages_locator);
  $assert_session
    ->elementTextContains('css', $messages_locator, "Locale 'es_AR' was added as a translation target for node Llamas are cool.");

  // Check translation status.
  $toggle = $page
    ->findAll('css', 'li.dropbutton-toggle button')[1];
  $toggle
    ->click();
  $dropButton = $page
    ->find('css', 'li.check-translation-status.dropbutton-action a');
  $dropButton
    ->click();

  // This is a batch process, wait to finish.
  $assert_session
    ->waitForElementVisible('css', $messages_locator);
  $assert_session
    ->elementTextContains('css', $messages_locator, 'The es_AR translation for node Llamas are cool is ready for download.');

  // Download translation.
  $toggle = $page
    ->findAll('css', 'li.dropbutton-toggle button')[1];
  $toggle
    ->click();
  $dropButton = $page
    ->find('css', 'li.download-completed-translation.dropbutton-action a');
  $dropButton
    ->click();

  // This is a batch process, wait to finish.
  $assert_session
    ->waitForElementVisible('css', $messages_locator);
  $assert_session
    ->elementTextContains('css', $messages_locator, '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');
}