You are here

public function LingotekNodeNestedParagraphsTranslationTest::testParagraphedNodeDownloadDoesntChangeReferencesOnSource in Lingotek Translation 3.4.x

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/LingotekNodeNestedParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNestedParagraphsTranslationTest::testParagraphedNodeDownloadDoesntChangeReferencesOnSource()
  2. 4.0.x tests/src/Functional/LingotekNodeNestedParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNestedParagraphsTranslationTest::testParagraphedNodeDownloadDoesntChangeReferencesOnSource()
  3. 3.0.x tests/src/Functional/LingotekNodeNestedParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNestedParagraphsTranslationTest::testParagraphedNodeDownloadDoesntChangeReferencesOnSource()
  4. 3.1.x tests/src/Functional/LingotekNodeNestedParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNestedParagraphsTranslationTest::testParagraphedNodeDownloadDoesntChangeReferencesOnSource()
  5. 3.2.x tests/src/Functional/LingotekNodeNestedParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNestedParagraphsTranslationTest::testParagraphedNodeDownloadDoesntChangeReferencesOnSource()
  6. 3.3.x tests/src/Functional/LingotekNodeNestedParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNestedParagraphsTranslationTest::testParagraphedNodeDownloadDoesntChangeReferencesOnSource()
  7. 3.5.x tests/src/Functional/LingotekNodeNestedParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNestedParagraphsTranslationTest::testParagraphedNodeDownloadDoesntChangeReferencesOnSource()
  8. 3.6.x tests/src/Functional/LingotekNodeNestedParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNestedParagraphsTranslationTest::testParagraphedNodeDownloadDoesntChangeReferencesOnSource()
  9. 3.7.x tests/src/Functional/LingotekNodeNestedParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNestedParagraphsTranslationTest::testParagraphedNodeDownloadDoesntChangeReferencesOnSource()
  10. 3.8.x tests/src/Functional/LingotekNodeNestedParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNestedParagraphsTranslationTest::testParagraphedNodeDownloadDoesntChangeReferencesOnSource()

Tests that paragraph references aren't removed on download.

File

tests/src/Functional/LingotekNodeNestedParagraphsTranslationTest.php, line 548

Class

LingotekNodeNestedParagraphsTranslationTest
Tests translating a node with multiple locales including nested paragraphs.

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testParagraphedNodeDownloadDoesntChangeReferencesOnSource() {

  // This is a hack for avoiding writing different lingotek endpoint mocks.
  \Drupal::state()
    ->set('lingotek.uploaded_content_type', 'node+nestedparagraphs_multiple');

  // Add paragraphed content via API.
  $this
    ->createNestedParagraphedNode();
  $this
    ->drupalGet('node/1/edit');
  $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_paragraph_container'][0]['field_paragraphs_demo'][0]['field_text_demo'][0]['value'], 'Llamas are very cool for the first time');
  $this
    ->assertEqual($data['field_paragraph_container'][0]['field_paragraphs_demo'][1]['field_text_demo'][0]['value'], 'Llamas are very cool for the second time');
  $this
    ->assertEqual($data['field_paragraph_container'][1]['field_paragraphs_demo'][0]['field_text_demo'][0]['value'], 'Dogs are very cool for the first time');
  $this
    ->assertEqual($data['field_paragraph_container'][1]['field_paragraphs_demo'][1]['field_text_demo'][0]['value'], 'Dogs are very 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() => 'request_translation:es-ar',
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());
  $this
    ->drupalGet('node/1');
  $this
    ->clickLink('Edit');
  $this
    ->drupalPostForm(NULL, NULL, t('Remove'));
  $this
    ->drupalPostForm(NULL, NULL, t('Confirm removal'));
  $this
    ->drupalPostForm(NULL, NULL, t('Add Image + Text'));
  $edit = [];
  $edit['field_paragraph_container[1][subform][field_paragraphs_demo][0][subform][field_text_demo][0][value]'] = 'Cats are very cool for the second time';
  $edit['field_paragraph_container[1][subform][field_paragraphs_demo][0][_weight]'] = 2;
  $edit['field_paragraph_container[1][subform][field_paragraphs_demo][1][subform][field_text_demo][0][value]'] = 'Cats are very cool for the third time';
  $edit['field_paragraph_container[1][subform][field_paragraphs_demo][1][_weight]'] = 1;
  $edit['field_paragraph_container[1][subform][field_paragraphs_demo][2][subform][field_text_demo][0][value]'] = 'Cats are very cool for the FOURTH time';
  $this
    ->saveAndKeepPublishedNodeForm($edit, 1, FALSE);
  $this
    ->assertNoText('Llamas are very cool for the first time');
  $this
    ->assertNoText('Llamas are very cool for the second time');
  $this
    ->assertNoText('Dogs are very cool for the first time');
  $this
    ->assertNoText('Dogs are very cool for the second time');
  $this
    ->assertNoText('Cats are very cool for the first time');
  $this
    ->assertText('Cats are very cool for the second time');
  $this
    ->assertText('Cats are very cool for the third time');
  $this
    ->assertText('Cats are very cool for the FOURTH time');

  // 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 muy chulas por primera vez');
    $this
      ->assertText('Las llamas son muy chulas por segunda vez');
  }
  else {
    $this
      ->assertNoText('Las llamas son muy chulas por primera vez');
    $this
      ->assertNoText('Las llamas son muy chulas por segunda vez');

    // We show the data that was actually uploaded and translated from the
    // previous revision. The first revision is missing, as it was not
    // translated.
    $this
      ->assertText('Los perros son muy chulos por primera vez');
    $this
      ->assertText('Los perros son muy chulos por segunda vez');

    // That paragraph exists, but was not translated so it's not shown at all.
    $this
      ->assertNoText('Los gatos son muy chulos por primera vez');
    $this
      ->assertNoText('Los gatos son muy chulos por segunda vez');
    $this
      ->assertNoText('Los gatos son muy chulos por tercera vez');
    $this
      ->assertNoText('Los gatos son muy chulos por cuarta vez');
  }
  $this
    ->clickLink('Translate');
  $this
    ->clickLink('Llamas are cool');
  $this
    ->assertText('Llamas are cool');
  $this
    ->assertNoText('Llamas are very cool for the first time');
  $this
    ->assertNoText('Llamas are very cool for the second time');
  $this
    ->assertNoText('Dogs are very cool for the first time');
  $this
    ->assertNoText('Dogs are very cool for the second time');
  $this
    ->assertNoText('Cats are very cool for the first time');
  $this
    ->assertText('Cats are very cool for the FOURTH time');
  $this
    ->assertText('Cats are very cool for the third time');
  $this
    ->assertText('Cats are very cool for the second time');
}