Test the translate tab for a multiple checkout.
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
->assertSession()
->pageTextContains(t('Translations of @title', array(
'@title' => $node
->getTitle(),
)));
$this
->assertSession()
->pageTextContains('Pending Translations');
// Request a translation for german, spanish and french.
$edit = array(
'languages[de]' => TRUE,
'languages[es]' => TRUE,
'languages[it]' => TRUE,
);
$this
->submitForm($edit, 'Request translation');
// Verify that we are on the translate tab.
$this
->assertSession()
->pageTextContains('3 jobs need to be checked out.');
// Assert progress bar.
$this
->assertSession()
->pageTextContains('3 jobs pending');
$this
->assertSession()
->pageTextContains($node
->label() . ', English to German');
$this
->assertSession()
->pageTextContains($node
->label() . ', English to Spanish');
$this
->assertSession()
->pageTextContains($node
->label() . ', English to Italian');
$this
->assertSession()
->responseContains('progress__track');
$this
->assertSession()
->responseContains('<div class="progress__bar" style="width: 3%"></div>');
// Submit all jobs.
$edit = [
'label[0][value]' => 'Customized label',
'submit_all' => TRUE,
];
$this
->submitForm($edit, 'Submit to provider and continue');
// 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('canonical', array(
'absolute' => TRUE,
))
->toString() . '/translations', $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.', 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
->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);
// Assert that all jobs were updated to use the customized label.
foreach (Job::loadMultiple() as $job) {
$this
->assertEquals('Customized label', $job
->label());
}
}