Test the node type for a single checkout.
function testNodeTypeTranslateTabSingleCheckout() {
$this
->loginAsTranslator(array(
'translate configuration',
));
// Go to the translate tab.
$this
->drupalGet('admin/structure/types/manage/article/translate');
// Assert some basic strings on that page.
$this
->assertSession()
->pageTextContains('Translations of Article content type');
$this
->assertSession()
->pageTextContains('There are 0 items in the translation cart.');
// Request a translation for german.
$edit = array(
'languages[de]' => TRUE,
);
$this
->submitForm($edit, 'Request translation');
// Verify that we are on the translate tab.
$this
->assertSession()
->pageTextContains('One job needs to be checked out.');
$this
->assertSession()
->pageTextContains('Article content type (English to German, Unprocessed)');
// Submit.
$this
->submitForm([], 'Submit to provider');
// Make sure that we're back on the originally defined destination URL.
$this
->assertSession()
->addressEquals('admin/structure/types/manage/article/translate');
// We are redirected back to the correct page.
$this
->drupalGet('admin/structure/types/manage/article/translate');
// Translated languages - german should now be listed as Needs review.
$rows = $this
->xpath('//tbody/tr');
$found = FALSE;
foreach ($rows as $value) {
$image = $value
->find('css', 'td:nth-child(3) a img');
if ($image && $image
->getAttribute('title') == 'Needs review') {
$found = TRUE;
$this
->assertEquals('German', $value
->find('css', 'td:nth-child(2)')
->getText());
}
}
$this
->assertTrue($found);
// Assert that 'Source' label is displayed properly.
$this
->assertSession()
->responseContains('<strong>Source</strong>');
// Verify that the pending translation is shown.
$this
->clickLinkWithImageTitle('Needs review');
$this
->submitForm([], 'Save');
// Request a spanish translation.
$edit = array(
'languages[es]' => TRUE,
);
$this
->submitForm($edit, 'Request translation');
// Verify that we are on the checkout page.
$this
->assertSession()
->pageTextContains('One job needs to be checked out.');
$this
->assertSession()
->pageTextContains('Article content type (English to Spanish, Unprocessed)');
$this
->submitForm([], 'Submit to provider');
// Make sure that we're back on the originally defined destination URL.
$this
->assertSession()
->addressEquals('admin/structure/types/manage/article/translate');
// Translated languages should now be listed as Needs review.
$rows = $this
->xpath('//tbody/tr');
$counter = 0;
foreach ($rows as $element) {
$language = $element
->find('css', 'td:nth-child(2)')
->getText();
if ('Spanish' == $language || 'German' == $language) {
$this
->assertEquals('Needs review', $element
->find('css', 'td:nth-child(3) a img')
->getAttribute('title'));
$counter++;
}
}
$this
->assertEquals(2, $counter);
// Test that a job can not be accepted if the translator does not exist.
// Request an italian translation.
$edit = array(
'languages[it]' => TRUE,
);
$this
->submitForm($edit, 'Request translation');
// Go back to the originally defined destination URL without submitting.
$this
->drupalGet('admin/structure/types/manage/article/translate');
// Verify that the pending translation is shown.
$this
->clickLink('Inactive');
// Try to save, should fail because the job has no translator assigned.
$edit = array(
'name[translation]' => $this
->randomMachineName(),
);
$this
->submitForm($edit, 'Save');
// Verify that we are on the checkout page.
$this
->assertSession()
->statusCodeEquals(200);
}