You are here

public function LingotekFieldBodyTranslationTest::testUploadingWithAnErrorViaAPI in Lingotek Translation 8

Test that we handle errors in upload.

File

src/Tests/LingotekFieldBodyTranslationTest.php, line 278

Class

LingotekFieldBodyTranslationTest
Tests translating a field.

Namespace

Drupal\lingotek\Tests

Code

public function testUploadingWithAnErrorViaAPI() {
  $edit = [
    'table[node_fields][enabled]' => 1,
    'table[node_fields][profile]' => 'automatic',
  ];
  $this
    ->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-configuration-form');
  \Drupal::state()
    ->set('lingotek.must_error_in_upload', TRUE);
  $this
    ->drupalGet('admin/lingotek/settings');

  // Create a field.
  $edit = [
    'label' => 'Excerpt',
    'new_storage_type' => 'text',
    'field_name' => 'excerpt',
  ];
  $this
    ->drupalPostForm('/admin/structure/types/manage/article/fields/add-field', $edit, 'Save and continue');

  // The document was uploaded automatically and failed.
  $this
    ->assertText('The upload for field_config Excerpt failed. Please try again.');

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

  /** @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.');
}