View source
<?php
namespace Drupal\Tests\tmgmt_config\Functional;
use Drupal\Core\Url;
use Drupal\Tests\tmgmt\Functional\TmgmtEntityTestTrait;
use Drupal\Tests\tmgmt\Functional\TMGMTTestBase;
use Drupal\tmgmt\Entity\Job;
use Drupal\views\Entity\View;
class ConfigSourceUiTest extends TMGMTTestBase {
use TmgmtEntityTestTrait;
public static $modules = array(
'tmgmt_config',
'views',
'views_ui',
'field_ui',
'config_translation',
);
function setUp() : void {
parent::setUp();
$this
->loginAsAdmin(array(
'create translation jobs',
'submit translation jobs',
'accept translation jobs',
));
$this
->addLanguage('de');
$this
->addLanguage('it');
$this
->addLanguage('es');
$this
->addLanguage('el');
$this
->createNodeType('article', 'Article', TRUE);
}
function testNodeTypeTranslateTabSingleCheckout() {
$this
->loginAsTranslator(array(
'translate configuration',
));
$this
->drupalGet('admin/structure/types/manage/article/translate');
$this
->assertText(t('Translations of Article content type'));
$this
->assertText(t('There are 0 items in the translation cart.'));
$edit = array(
'languages[de]' => TRUE,
);
$this
->drupalPostForm(NULL, $edit, t('Request translation'));
$this
->assertText(t('One job needs to be checked out.'));
$this
->assertText('Article content type (English to German, Unprocessed)');
$this
->drupalPostForm(NULL, array(), t('Submit to provider'));
$this
->assertUrl('admin/structure/types/manage/article/translate');
$this
->drupalGet('admin/structure/types/manage/article/translate');
$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);
$this
->assertRaw('<strong>Source</strong>');
$this
->clickLinkWithImageTitle('Needs review');
$this
->drupalPostForm(NULL, array(), t('Save'));
$edit = array(
'languages[es]' => TRUE,
);
$this
->drupalPostForm(NULL, $edit, t('Request translation'));
$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'));
$this
->assertUrl('admin/structure/types/manage/article/translate');
$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);
$edit = array(
'languages[it]' => TRUE,
);
$this
->drupalPostForm(NULL, $edit, t('Request translation'));
$this
->drupalGet('admin/structure/types/manage/article/translate');
$this
->clickLink(t('Inactive'));
$edit = array(
'name[translation]' => $this
->randomMachineName(),
);
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertResponse(200);
}
function testNodeTypeTranslateTabMultipeCheckout() {
$this
->loginAsTranslator(array(
'translate configuration',
));
$this
->drupalGet('admin/structure/types/manage/article/translate');
$this
->assertText(t('Translations of Article content type'));
$this
->assertText(t('There are 0 items in the translation cart.'));
$edit = array(
'languages[de]' => TRUE,
'languages[es]' => TRUE,
);
$this
->drupalPostForm(NULL, $edit, t('Request translation'));
$this
->assertText(t('2 jobs need to be checked out.'));
$this
->assertText('Article content type (English to German, Unprocessed)');
$this
->drupalPostForm(NULL, array(), t('Submit to provider and continue'));
$this
->assertText('Article content type (English to Spanish, Unprocessed)');
$this
->drupalPostForm(NULL, array(), t('Submit to provider'));
$this
->assertUrl('admin/structure/types/manage/article/translate');
$this
->assertText(t('Test translation created.'));
$this
->assertNoText(t('The translation of @title to @language is finished and can now be reviewed.', array(
'@title' => 'Article',
'@language' => t('Spanish'),
)));
$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);
}
function testViewTranslateTabSingleCheckout() {
$this
->loginAsTranslator(array(
'translate configuration',
));
$this
->drupalGet('admin/structure/views/view/content/translate');
$this
->assertText(t('Translations of Content view'));
$this
->assertText(t('There are 0 items in the translation cart.'));
$edit = array(
'languages[de]' => TRUE,
);
$this
->drupalPostForm(NULL, $edit, t('Request translation'));
$this
->assertText(t('One job needs to be checked out.'));
$this
->assertText('Content view (English to German, Unprocessed)');
$this
->drupalPostForm(NULL, array(), t('Submit to provider'));
$this
->assertUrl('admin/structure/views/view/content/translate');
$this
->drupalGet('admin/structure/views/view/content/translate');
$rows = $this
->xpath('//tbody/tr');
foreach ($rows as $element) {
if ($element
->find('css', 'td:nth-child(2)')
->getText() == 'German') {
$this
->assertEquals('Needs review', $element
->find('css', 'td:nth-child(3) a img')
->getAttribute('title'));
}
}
$this
->clickLinkWithImageTitle('Needs review');
$this
->drupalPostForm(NULL, array(), t('Save'));
$edit = array(
'languages[es]' => TRUE,
);
$this
->drupalPostForm(NULL, $edit, t('Request translation'));
$this
->assertText(t('One job needs to be checked out.'));
$this
->assertText('Content view (English to Spanish, Unprocessed)');
$this
->drupalPostForm(NULL, array(), t('Submit to provider'));
$this
->assertUrl('admin/structure/views/view/content/translate');
$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);
$this
->clickLinkWithImageTitle('Needs review');
$view_content = View::load('content');
$view_content
->delete();
$this
->drupalPostForm(NULL, array(), t('Save as completed'));
$this
->assertText(t('@id of type @type does not exist, the job can not be completed.', array(
'@id' => $view_content
->id(),
'@type' => $view_content
->getEntityTypeId(),
)));
}
function testFieldConfigTranslateTabSingleCheckout() {
$this
->loginAsAdmin(array(
'translate configuration',
));
$job = $this
->createJob('en', 'de', 1, [
'job_type' => Job::TYPE_CONTINUOUS,
]);
$job
->save();
$this
->drupalGet('admin/tmgmt/sources/config/field_config');
$this
->assertText(t('Configuration ID'));
$this
->assertText('field.field.node.article.body');
$edit = [
'items[field.field.node.article.body]' => TRUE,
];
$this
->drupalPostForm(NULL, $edit, t('Add to cart'));
$this
->clickLink(t('cart'));
$this
->assertText('Body');
$edit = [
'target_language[]' => 'de',
];
$this
->drupalPostForm(NULL, $edit, t('Request translation'));
$this
->assertNoText(t('Check for continuous jobs'));
$this
->assertNoField('add_all_to_continuous_jobs');
$this
->drupalGet('admin/structure/types/manage/article/fields/node.article.body/translate');
$this
->drupalPostForm(NULL, array(
'languages[de]' => TRUE,
), t('Request translation'));
$this
->assertResponse(200);
$this
->assertText(t('One job needs to be checked out.'));
$this
->drupalPostForm(NULL, array(), t('Submit to provider'));
$this
->clickLinkWithImageTitle('Needs review');
$this
->drupalPostForm(NULL, array(), t('Save as completed'));
}
function testCart() {
$this
->loginAsTranslator(array(
'translate configuration',
));
$this
->drupalPostForm('admin/structure/views/view/content/translate', array(), t('Add to cart'));
$this
->drupalPostForm('admin/structure/types/manage/article/translate', array(), t('Add to cart'));
$this
->drupalGet('admin/tmgmt/cart');
$this
->assertLink('Content view');
$this
->assertLink('Article content type');
$this
->drupalGet('admin/structure/views/view/content/translate');
$this
->assertRaw(t('There are @count items in the <a href=":url">translation cart</a> including the current item.', array(
'@count' => 2,
':url' => Url::fromRoute('tmgmt.cart')
->toString(),
)));
}
function testSimpleConfiguration() {
$this
->loginAsTranslator(array(
'translate configuration',
));
$this
->drupalGet('admin/config/system/site-information/translate');
$this
->assertText(t('Translations of System information'));
$edit = array(
'languages[de]' => TRUE,
);
$this
->drupalPostForm(NULL, $edit, t('Request translation'));
$this
->assertText(t('One job needs to be checked out.'));
$this
->assertText('System information (English to German, Unprocessed)');
$this
->drupalPostForm(NULL, array(), t('Submit to provider'));
$this
->assertUrl('admin/config/system/site-information/translate');
$this
->drupalGet('admin/config/system/site-information/translate');
$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);
$this
->clickLinkWithImageTitle('Needs review');
$this
->drupalPostForm(NULL, array(
'name[translation]' => 'de_Druplicon',
), t('Save'));
$this
->clickLinkWithImageTitle('Needs review');
$this
->assertText('de_Druplicon');
$this
->drupalPostForm(NULL, array(), t('Save'));
$edit = array(
'languages[es]' => TRUE,
);
$this
->drupalPostForm(NULL, $edit, t('Request translation'));
$this
->assertText(t('One job needs to be checked out.'));
$this
->assertText('System information (English to Spanish, Unprocessed)');
$this
->drupalPostForm(NULL, array(), t('Submit to provider'));
$this
->assertUrl('admin/config/system/site-information/translate');
$rows = $this
->xpath('//tbody/tr');
$counter = 0;
foreach ($rows as $value) {
$image = $value
->find('css', 'td:nth-child(3) a img');
if ($image && $image
->getAttribute('title') == 'Needs review') {
$this
->assertTrue(in_array($value
->find('css', 'td:nth-child(2)')
->getText(), [
'Spanish',
'German',
]));
$counter++;
}
}
$this
->assertEquals(2, $counter);
$this
->drupalGet('admin/config/people/accounts/translate');
$this
->drupalPostForm(NULL, [
'languages[de]' => TRUE,
], t('Request translation'));
$this
->drupalPostForm(NULL, array(), t('Submit to provider'));
$this
->clickLinkWithImageTitle('Needs review');
$this
->drupalPostForm(NULL, array(
'user__settings|anonymous[translation]' => 'de_Druplicon',
), t('Validate HTML tags'));
$this
->assertText('de_Druplicon');
$this
->drupalPostForm(NULL, array(), t('Save'));
$this
->clickLinkWithImageTitle('Needs review');
$this
->assertText('de_Druplicon');
}
}