You are here

public function LingotekNodeBulkTranslationTest::testUpdatingWithAnErrorUsingActions in Lingotek Translation 8

Test that we handle errors in update.

File

src/Tests/LingotekNodeBulkTranslationTest.php, line 764

Class

LingotekNodeBulkTranslationTest
Tests translating a node using the bulk management form.

Namespace

Drupal\lingotek\Tests

Code

public function testUpdatingWithAnErrorUsingActions() {

  // Create a node.
  $edit = array();
  $edit['title[0][value]'] = 'Llamas are cool';
  $edit['body[0][value]'] = 'Llamas are very cool';
  $edit['langcode[0][value]'] = 'en';
  $edit['lingotek_translation_profile'] = 'manual';
  $this
    ->drupalPostForm('node/add/article', $edit, t('Save and publish'));
  $this
    ->goToContentBulkManagementForm();

  // Upload the document, which must succeed.
  $basepath = \Drupal::request()
    ->getBasePath();
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/entity/upload/node/1?destination=' . $basepath . '/admin/lingotek/manage/node');
  $edit = [
    'table[1]' => TRUE,
    // Node 1.
    'operation' => 'upload',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Execute'));
  $this
    ->assertText('Operations completed.');

  // Check upload.
  $this
    ->clickLink('EN');

  // Edit the node.
  $edit = [
    'title[0][value]' => 'Llamas are cool EDITED',
  ];
  $this
    ->drupalPostForm('node/1/edit', $edit, t('Save and keep published'));
  \Drupal::state()
    ->set('lingotek.must_error_in_upload', TRUE);
  $this
    ->goToContentBulkManagementForm();
  $edit = [
    'table[1]' => TRUE,
    // Node 1.
    'operation' => 'upload',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Execute'));
  $this
    ->assertText('The update for node Llamas are cool EDITED failed. Please try again.');

  // Check the right class is added.
  $source_error = $this
    ->xpath("//span[contains(@class,'language-icon') and contains(@class,'source-error')  and ./a[contains(text(), 'EN')]]");
  $this
    ->assertEqual(count($source_error), 1, 'The node has been marked as error.');

  // The node has been marked with the error status.
  $this->node = Node::load(1);

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

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