You are here

public function LingotekFieldBodyBulkTranslationTest::testDownloadingConfigFieldWithAnError in Lingotek Translation 3.6.x

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

Test that we handle errors in download for configs.

File

tests/src/Functional/LingotekFieldBodyBulkTranslationTest.php, line 976

Class

LingotekFieldBodyBulkTranslationTest
Tests translating a field using the bulk management form.

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testDownloadingConfigFieldWithAnError() {
  $assert_session = $this
    ->assertSession();

  // Login as admin.
  $this
    ->drupalLogin($this->rootUser);

  // Go to the bulk config management page.
  $this
    ->goToConfigBulkManagementForm('node_fields');
  $basepath = \Drupal::request()
    ->getBasePath();

  // Clicking English must init the upload of content.
  $assert_session
    ->linkByHrefExists($basepath . '/admin/lingotek/config/upload/field_config/node.article.body?destination=' . $basepath . '/admin/lingotek/config/manage');

  // And we cannot request yet a translation.
  $assert_session
    ->linkByHrefNotExists($basepath . '/admin/lingotek/config/request/field_config/node.article.body/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
  $this
    ->clickLink('EN');
  $this
    ->assertText(t('Body uploaded successfully'));
  $this
    ->assertIdentical('en_US', \Drupal::state()
    ->get('lingotek.uploaded_locale'));

  // There is a link for checking status.
  $assert_session
    ->linkByHrefExists($basepath . '/admin/lingotek/config/check_upload/field_config/node.article.body?destination=' . $basepath . '/admin/lingotek/config/manage');

  // And we can already request a translation.
  $assert_session
    ->linkByHrefExists($basepath . '/admin/lingotek/config/request/field_config/node.article.body/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
  $this
    ->clickLink('EN');
  $this
    ->assertText('Body status checked successfully');

  // Request the Spanish translation.
  $assert_session
    ->linkByHrefExists($basepath . '/admin/lingotek/config/request/field_config/node.article.body/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
  $this
    ->clickLink('ES');
  $this
    ->assertText("Translation to es_MX requested successfully");
  $this
    ->assertIdentical('es_MX', \Drupal::state()
    ->get('lingotek.added_target_locale'));

  // Check status of the Spanish translation.
  $assert_session
    ->linkByHrefExists($basepath . '/admin/lingotek/config/check_download/field_config/node.article.body/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
  $this
    ->clickLink('ES');
  $this
    ->assertIdentical('es_MX', \Drupal::state()
    ->get('lingotek.checked_target_locale'));
  $this
    ->assertText("Translation to es_MX status checked successfully");
  \Drupal::state()
    ->set('lingotek.must_error_in_download', TRUE);

  // Download the Spanish translation.
  $assert_session
    ->linkByHrefExists($basepath . '/admin/lingotek/config/download/field_config/node.article.body/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
  $this
    ->clickLink('ES');
  $this
    ->assertText('Body es_MX translation download failed. Please try again.');
  $this
    ->assertIdentical(NULL, \Drupal::state()
    ->get('lingotek.downloaded_locale'));
  $this
    ->goToConfigBulkManagementForm('node_fields');

  // Check the right class is added.
  $this
    ->assertTargetStatus('ES', Lingotek::STATUS_ERROR);

  // The field has been marked with the error status.
  $fieldConfig = FieldConfig::load('node.article.body');

  /** @var \Drupal\lingotek\LingotekConfigTranslationServiceInterface $translation_service */
  $translation_service = \Drupal::service('lingotek.config_translation');
  $target_status = $translation_service
    ->getTargetStatus($fieldConfig, 'es');
  $this
    ->assertEqual(Lingotek::STATUS_ERROR, $target_status, 'The field has been marked as error.');
  \Drupal::state()
    ->set('lingotek.must_error_in_download', FALSE);

  // Download the Spanish translation.
  $assert_session
    ->linkByHrefExists($basepath . '/admin/lingotek/config/download/field_config/node.article.body/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
  $this
    ->clickLink('ES');
  $this
    ->assertText('Translation to es_MX downloaded successfully');
  $this
    ->assertIdentical('es_MX', \Drupal::state()
    ->get('lingotek.downloaded_locale'));
}