You are here

public function LingotekFieldBodyTranslationTest::testUpdatingWithAnError in Lingotek Translation 8

Test that we handle errors in update.

File

src/Tests/LingotekFieldBodyTranslationTest.php, line 234

Class

LingotekFieldBodyTranslationTest
Tests translating a field.

Namespace

Drupal\lingotek\Tests

Code

public function testUpdatingWithAnError() {

  // Check that the translate tab is in the field.
  $this
    ->drupalGet('/admin/config/regional/config-translation/node_fields');
  $this
    ->clickLink(t('Translate'));

  // Upload the document, which must succeed.
  $this
    ->clickLink('Upload');
  $this
    ->assertText('Body uploaded successfully');

  // Check that the upload succeeded.
  $this
    ->clickLink('Check upload status');
  $this
    ->assertText('Body status checked successfully');

  // Edit the field.
  $edit = [
    'label' => 'Contents',
  ];
  $this
    ->drupalPostForm('/admin/structure/types/manage/article/fields/node.article.body', $edit, t('Save settings'));
  $this
    ->assertText('Saved Contents configuration.');

  // Go back to the form.
  $this
    ->drupalGet('/admin/config/regional/config-translation/node_fields');
  $this
    ->clickLink(t('Translate'));
  \Drupal::state()
    ->set('lingotek.must_error_in_upload', TRUE);

  // Re-upload. Must fail now.
  $this
    ->clickLink('Upload');
  $this
    ->assertText('Contents update failed. Please try again.');

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

  /** @var LingotekConfigTranslationServiceInterface $translation_service */
  $translation_service = \Drupal::service('lingotek.config_translation');
  $source_status = $translation_service
    ->getSourceStatus($fieldConfig);
  $this
    ->assertEqual(Lingotek::STATUS_ERROR, $source_status, 'The field has been marked as error.');

  // I can still re-try the upload.
  \Drupal::state()
    ->set('lingotek.must_error_in_upload', FALSE);
  $this
    ->clickLink('Upload');
  $this
    ->assertText('Contents has been updated.');
}