You are here

public function LingotekNodeParagraphsTranslationTest::testTranslationsKeptInLastRevisionWhenDownloadingAll in Lingotek Translation 3.6.x

Same name and namespace in other branches
  1. 4.0.x tests/src/Functional/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeParagraphsTranslationTest::testTranslationsKeptInLastRevisionWhenDownloadingAll()
  2. 3.3.x tests/src/Functional/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeParagraphsTranslationTest::testTranslationsKeptInLastRevisionWhenDownloadingAll()
  3. 3.4.x tests/src/Functional/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeParagraphsTranslationTest::testTranslationsKeptInLastRevisionWhenDownloadingAll()
  4. 3.5.x tests/src/Functional/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeParagraphsTranslationTest::testTranslationsKeptInLastRevisionWhenDownloadingAll()
  5. 3.7.x tests/src/Functional/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeParagraphsTranslationTest::testTranslationsKeptInLastRevisionWhenDownloadingAll()
  6. 3.8.x tests/src/Functional/LingotekNodeParagraphsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeParagraphsTranslationTest::testTranslationsKeptInLastRevisionWhenDownloadingAll()

File

tests/src/Functional/LingotekNodeParagraphsTranslationTest.php, line 953

Class

LingotekNodeParagraphsTranslationTest
Tests translating a node with multiple locales including paragraphs.

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testTranslationsKeptInLastRevisionWhenDownloadingAll() {
  $assert_session = $this
    ->assertSession();
  $page = $this
    ->getSession()
    ->getPage();

  // Add an additional language.
  ConfigurableLanguage::createFromLangcode('it')
    ->save();

  // 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.');
  $this
    ->drupalGet('node/1');
  $this
    ->clickLink('Edit');
  $edit = [];
  $edit['title[0][value]'] = 'Dogs are cool';
  $edit['langcode[0][value]'] = 'en';
  $edit['field_paragraphs_demo[0][subform][field_text_demo][0][value]'] = 'Dogs are cool for the first time';
  $edit['field_paragraphs_demo[1][subform][field_text_demo][0][value]'] = 'Dogs are cool for the second time';
  $edit['moderation_state[0][state]'] = 'published';
  $this
    ->saveAndKeepPublishedNodeForm($edit, 1);
  $this
    ->goToContentBulkManagementForm();

  // Request all translations.
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForRequestTranslations('es-ar'),
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());

  // Download all translations.
  $this
    ->goToContentBulkManagementForm();
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForDownloadTranslations('node'),
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());
  $this
    ->drupalGet('node/1/translations');

  // The content is translated and published in all languages.
  $this
    ->assertLink('I lama sono belle');
  $this
    ->assertLink('Las llamas son chulas es-ES');
  $this
    ->assertText('Las llamas son chulas');
  $this
    ->assertLink('Dogs are cool');
  $this
    ->clickLink('I lama sono belle');
  $this
    ->assertText('I lama sono belle');
  $this
    ->assertText('I lama sono belle la prima volta');
  $this
    ->assertText('I lama sono belle la seconda volta');
  $this
    ->drupalGet('node/1/translations');
  $this
    ->clickLink('Las llamas son chulas es-ES');
  $this
    ->assertText('Las llamas son chulas es-ES');
  $this
    ->assertText('Las llamas son chulas por primera vez es-ES');
  $this
    ->assertText('Las llamas son chulas por segunda vez es-ES');
  $this
    ->drupalGet('node/1/translations');
  $this
    ->clickLink('Dogs are cool');
  $this
    ->assertText('Dogs are cool');
  $this
    ->assertNoText('Llamas are cool for the first time');
  $this
    ->assertNoText('Llamas are cool for the second time');
  $this
    ->assertText('Dogs are cool for the first time');
  $this
    ->assertText('Dogs are cool for the second time');
}