function ContentTmgmtEntitySourceUiTest::testNodeTranslateTabQuickCheckout

Test the translate tab for a quick checkout.

File

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

Class

ContentTmgmtEntitySourceUiTest
Content entity source UI tests.

Namespace

Drupal\Tests\tmgmt_content\Functional

Code

function testNodeTranslateTabQuickCheckout() {

  // Allow auto-accept and do not expose checkout settings.
  $default_translator = Translator::load('test_translator');
  $default_translator
    ->setSetting('expose_settings', FALSE)
    ->setAutoAccept(TRUE)
    ->save();
  $this
    ->loginAsTranslator([
    'translate any entity',
    'create content translations',
  ]);

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

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

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

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

  // Make sure that we're back on the translate tab.
  $this
    ->assertEquals($node
    ->toUrl('drupal:content-translation-overview', [
    'absolute' => TRUE,
  ])
    ->toString(), $this
    ->getUrl());
  $this
    ->assertSession()
    ->pageTextContains('Test translation created.');
  $this
    ->assertSession()
    ->pageTextNotContains(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
    ->assertSession()
    ->pageTextContains(t('The translation for @title has been accepted as @target.', [
    '@title' => $node
      ->getTitle(),
    '@target' => $translation
      ->label(),
  ]));

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

  // Translated nodes should now be listed and be clickable.
  $this
    ->clickLink('Translate');
  $this
    ->clickLink('de(de-ch): ' . $node
    ->getTitle());
  $this
    ->assertSession()
    ->pageTextContains('de(de-ch): ' . $node
    ->getTitle());
  $this
    ->assertSession()
    ->pageTextContains('de(de-ch): ' . $node->body->value);
  $this
    ->drupalGet('es/node/' . $node
    ->id());
  $this
    ->assertSession()
    ->pageTextContains('es: ' . $node
    ->getTitle());
  $this
    ->assertSession()
    ->pageTextContains('es: ' . $node->body->value);
}