public function LingotekNodeParagraphsTranslationTest::testParagraphedNodeDownloadDoesntChangeReferencesOnSource in Lingotek Translation 3.4.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeParagraphsTranslationTest::testParagraphedNodeDownloadDoesntChangeReferencesOnSource()
 - 4.0.x tests/src/Functional/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeParagraphsTranslationTest::testParagraphedNodeDownloadDoesntChangeReferencesOnSource()
 - 3.0.x tests/src/Functional/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeParagraphsTranslationTest::testParagraphedNodeDownloadDoesntChangeReferencesOnSource()
 - 3.1.x tests/src/Functional/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeParagraphsTranslationTest::testParagraphedNodeDownloadDoesntChangeReferencesOnSource()
 - 3.2.x tests/src/Functional/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeParagraphsTranslationTest::testParagraphedNodeDownloadDoesntChangeReferencesOnSource()
 - 3.3.x tests/src/Functional/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeParagraphsTranslationTest::testParagraphedNodeDownloadDoesntChangeReferencesOnSource()
 - 3.5.x tests/src/Functional/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeParagraphsTranslationTest::testParagraphedNodeDownloadDoesntChangeReferencesOnSource()
 - 3.6.x tests/src/Functional/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeParagraphsTranslationTest::testParagraphedNodeDownloadDoesntChangeReferencesOnSource()
 - 3.7.x tests/src/Functional/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeParagraphsTranslationTest::testParagraphedNodeDownloadDoesntChangeReferencesOnSource()
 - 3.8.x tests/src/Functional/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeParagraphsTranslationTest::testParagraphedNodeDownloadDoesntChangeReferencesOnSource()
 
Tests that paragraph references aren't removed on download.
File
- tests/
src/ Functional/ LingotekNodeParagraphsTranslationTest.php, line 749  
Class
- LingotekNodeParagraphsTranslationTest
 - Tests translating a node with multiple locales including paragraphs.
 
Namespace
Drupal\Tests\lingotek\FunctionalCode
public function testParagraphedNodeDownloadDoesntChangeReferencesOnSource() {
  // This is a hack for avoiding writing different lingotek endpoint mocks.
  \Drupal::state()
    ->set('lingotek.uploaded_content_type', 'node+paragraphs_multiple');
  // Add paragraphed content.
  $this
    ->drupalGet('node/add/paragraphed_content_demo');
  $this
    ->drupalPostForm(NULL, NULL, t('Add Image + Text'));
  $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 cool for the first time';
  $edit['field_paragraphs_demo[1][subform][field_text_demo][0][value]'] = 'Llamas are cool for the second time';
  $edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
  $edit['moderation_state[0][state]'] = 'published';
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));
  $this
    ->goToContentBulkManagementForm();
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForUpload('node'),
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());
  // Check that only the configured fields have been uploaded,
  // but not the missing one.
  $data = json_decode(\Drupal::state()
    ->get('lingotek.uploaded_content', '[]'), TRUE);
  $this
    ->verbose(var_export($data, TRUE));
  $this
    ->assertUploadedDataFieldCount($data, 2);
  $this
    ->assertEqual($data['title'][0]['value'], 'Llamas are cool');
  $this
    ->assertEqual($data['field_paragraphs_demo'][0]['field_text_demo'][0]['value'], 'Llamas are cool for the first time');
  $this
    ->assertEqual($data['field_paragraphs_demo'][1]['field_text_demo'][0]['value'], 'Llamas are cool for the second time');
  // 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 manual profile was used.');
  // Request translation.
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForRequestTranslation('es-ar', 'node'),
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());
  $this
    ->drupalGet('node/1');
  $this
    ->clickLink('Edit');
  $this
    ->drupalPostForm(NULL, NULL, t('Remove'));
  $this
    ->drupalPostForm(NULL, NULL, t('Add Image + Text'));
  $edit = [];
  $edit['title[0][value]'] = 'Llamas are very cool';
  $edit['field_paragraphs_demo[1][subform][field_text_demo][0][value]'] = 'Llamas are very cool for the second time';
  $edit['field_paragraphs_demo[2][subform][field_text_demo][0][value]'] = 'Llamas are very cool for the third time';
  $edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
  $this
    ->saveAndKeepPublishedNodeForm($edit, 1, FALSE);
  // Download translation.
  $this
    ->goToContentBulkManagementForm();
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    $this
      ->getBulkOperationFormName() => 'download:es-ar',
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());
  $this
    ->assertIdentical('es_AR', \Drupal::state()
    ->get('lingotek.downloaded_locale'));
  $this
    ->drupalGet('node/1/translations');
  // The content is translated and published.
  $this
    ->clickLink('Las llamas son chulas');
  $this
    ->assertText('Las llamas son chulas');
  if ($this->paragraphsTranslatable) {
    $this
      ->assertText('Las llamas son chulas por primera vez');
    $this
      ->assertText('Las llamas son chulas por segunda vez');
    $this
      ->assertNoText('Las llamas son chulas por tercera vez');
    $this
      ->assertNoText('Llamas are very cool for the third time');
  }
  else {
    $this
      ->assertNoText('Las llamas son chulas por primera vez');
    $this
      ->assertText('Las llamas son chulas por segunda vez');
    $this
      ->assertText('Llamas are very cool for the third time');
  }
  $this
    ->clickLink('Translate');
  $this
    ->clickLink('Llamas are very cool');
  $this
    ->assertText('Llamas are very cool');
  $this
    ->assertNoText('Llamas are very cool for the first time');
  $this
    ->assertText('Llamas are very cool for the second time');
  $this
    ->assertText('Llamas are very cool for the third time');
}