You are here

function ContentTmgmtEntitySourceUiTest::testNodeTranslateTabMultipleCheckout in Translation Management Tool 8

Test the translate tab for a multiple checkout.

File

sources/content/tests/src/Functional/ContentTmgmtEntitySourceUiTest.php, line 230

Class

ContentTmgmtEntitySourceUiTest
Content entity source UI tests.

Namespace

Drupal\Tests\tmgmt_content\Functional

Code

function testNodeTranslateTabMultipleCheckout() {

  // Allow auto-accept.
  $default_translator = Translator::load('test_translator');
  $default_translator
    ->setAutoAccept(TRUE)
    ->save();
  $this
    ->loginAsTranslator(array(
    'translate any entity',
    'create content translations',
  ));

  // Create an english source node.
  $node = $this
    ->createTranslatableNode('page', 'en');

  // Go to the translate tab.
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->clickLink('Translate');

  // Assert some basic strings on that page.
  $this
    ->assertText(t('Translations of @title', array(
    '@title' => $node
      ->getTitle(),
  )));
  $this
    ->assertText(t('Pending Translations'));

  // Request a translation for german, spanish and french.
  $edit = array(
    'languages[de]' => TRUE,
    'languages[es]' => TRUE,
    'languages[it]' => TRUE,
  );
  $this
    ->drupalPostForm(NULL, $edit, t('Request translation'));

  // Verify that we are on the translate tab.
  $this
    ->assertText(t('3 jobs need to be checked out.'));

  // Assert progress bar.
  $this
    ->assertText('3 jobs pending');
  $this
    ->assertText($node
    ->label() . ', English to German');
  $this
    ->assertText($node
    ->label() . ', English to Spanish');
  $this
    ->assertText($node
    ->label() . ', English to Italian');
  $this
    ->assertRaw('progress__track');
  $this
    ->assertRaw('<div class="progress__bar" style="width: 3%"></div>');

  // Submit all jobs.
  $edit = [
    'label[0][value]' => 'Customized label',
    'submit_all' => TRUE,
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Submit to provider and continue'));

  // Assert messages.
  $this
    ->assertText('Test translation created.');
  $this
    ->assertText('The translation job has been finished.');
  $this
    ->assertText('The translation for ' . $node
    ->label() . ' has been accepted as de(de-ch): ' . $node
    ->label() . '.');
  $this
    ->assertText('The translation for ' . $node
    ->label() . ' has been accepted as es: ' . $node
    ->label() . '.');
  $this
    ->assertText('The translation for ' . $node
    ->label() . ' has been accepted as it: ' . $node
    ->label() . '.');

  // Make sure that we're back on the translate tab.
  $this
    ->assertEqual($node
    ->toUrl('canonical', array(
    'absolute' => TRUE,
  ))
    ->toString() . '/translations', $this
    ->getUrl());
  $this
    ->assertText(t('Test translation created.'));
  $this
    ->assertNoText(t('The translation of @title to @language is finished and can now be reviewed.', array(
    '@title' => $node
      ->getTitle(),
    '@language' => t('Spanish'),
  )));
  $node = Node::load($node
    ->id());
  $translation = $node
    ->getTranslation('es');
  $this
    ->assertText(t('The translation for @title has been accepted as @target.', array(
    '@title' => $node
      ->getTitle(),
    '@target' => $translation
      ->label(),
  )));

  //Assert link is clickable.
  $this
    ->clickLink($node
    ->getTitle());

  // Translated nodes should now be listed and be clickable.
  // @todo Use links on translate tab.
  $this
    ->drupalGet('de/node/' . $node
    ->id());
  $this
    ->assertText('de(de-ch): ' . $node
    ->getTitle());
  $this
    ->assertText('de(de-ch): ' . $node->body->value);
  $this
    ->drupalGet('es/node/' . $node
    ->id());
  $this
    ->assertText('es: ' . $node
    ->getTitle());
  $this
    ->assertText('es: ' . $node->body->value);

  // Assert that all jobs were updated to use the customized label.
  foreach (Job::loadMultiple() as $job) {
    $this
      ->assertEqual($job
      ->label(), 'Customized label');
  }
}