function ConfigSourceUiTest::testNodeTypeTranslateTabSingleCheckout in Translation Management Tool 8
Test the node type for a single checkout.
File
- sources/
tmgmt_config/ tests/ src/ Functional/ ConfigSourceUiTest.php, line 49
Class
- ConfigSourceUiTest
- Content entity source UI tests.
Namespace
Drupal\Tests\tmgmt_config\FunctionalCode
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
->assertText(t('Translations of Article content type'));
$this
->assertText(t('There are 0 items in the translation cart.'));
// Request a translation for german.
$edit = array(
'languages[de]' => TRUE,
);
$this
->drupalPostForm(NULL, $edit, t('Request translation'));
// Verify that we are on the translate tab.
$this
->assertText(t('One job needs to be checked out.'));
$this
->assertText('Article content type (English to German, Unprocessed)');
// Submit.
$this
->drupalPostForm(NULL, array(), t('Submit to provider'));
// Make sure that we're back on the originally defined destination URL.
$this
->assertUrl('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
->assertRaw('<strong>Source</strong>');
// Verify that the pending translation is shown.
$this
->clickLinkWithImageTitle('Needs review');
$this
->drupalPostForm(NULL, array(), t('Save'));
// Request a spanish translation.
$edit = array(
'languages[es]' => TRUE,
);
$this
->drupalPostForm(NULL, $edit, t('Request translation'));
// Verify that we are on the checkout page.
$this
->assertText(t('One job needs to be checked out.'));
$this
->assertText('Article content type (English to Spanish, Unprocessed)');
$this
->drupalPostForm(NULL, array(), t('Submit to provider'));
// Make sure that we're back on the originally defined destination URL.
$this
->assertUrl('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
->assertEqual($counter, 2);
// Test that a job can not be accepted if the translator does not exist.
// Request an italian translation.
$edit = array(
'languages[it]' => TRUE,
);
$this
->drupalPostForm(NULL, $edit, t('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(t('Inactive'));
// Try to save, should fail because the job has no translator assigned.
$edit = array(
'name[translation]' => $this
->randomMachineName(),
);
$this
->drupalPostForm(NULL, $edit, t('Save'));
// Verify that we are on the checkout page.
$this
->assertResponse(200);
}