<?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;
protected 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
->assertSession()
->pageTextContains('Translations of Article content type');
$this
->assertSession()
->pageTextContains('There are 0 items in the translation cart.');
$edit = array(
'languages[de]' => TRUE,
);
$this
->submitForm($edit, 'Request translation');
$this
->assertSession()
->pageTextContains('One job needs to be checked out.');
$this
->assertSession()
->pageTextContains('Article content type (English to German, Unprocessed)');
$this
->submitForm([], 'Submit to provider');
$this
->assertSession()
->addressEquals('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
->assertSession()
->responseContains('<strong>Source</strong>');
$this
->clickLinkWithImageTitle('Needs review');
$this
->submitForm([], 'Save');
$edit = array(
'languages[es]' => TRUE,
);
$this
->submitForm($edit, 'Request translation');
$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');
$this
->assertSession()
->addressEquals('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
->assertEquals(2, $counter);
$edit = array(
'languages[it]' => TRUE,
);
$this
->submitForm($edit, 'Request translation');
$this
->drupalGet('admin/structure/types/manage/article/translate');
$this
->clickLink('Inactive');
$edit = array(
'name[translation]' => $this
->randomMachineName(),
);
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->statusCodeEquals(200);
}
function testNodeTypeTranslateTabMultipeCheckout() {
$this
->loginAsTranslator(array(
'translate configuration',
));
$this
->drupalGet('admin/structure/types/manage/article/translate');
$this
->assertSession()
->pageTextContains('Translations of Article content type');
$this
->assertSession()
->pageTextContains('There are 0 items in the translation cart.');
$edit = array(
'languages[de]' => TRUE,
'languages[es]' => TRUE,
);
$this
->submitForm($edit, 'Request translation');
$this
->assertSession()
->pageTextContains('2 jobs need to be checked out.');
$this
->assertSession()
->pageTextContains('Article content type (English to German, Unprocessed)');
$this
->submitForm([], 'Submit to provider and continue');
$this
->assertSession()
->pageTextContains('Article content type (English to Spanish, Unprocessed)');
$this
->submitForm([], 'Submit to provider');
$this
->assertSession()
->addressEquals('admin/structure/types/manage/article/translate');
$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' => '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
->assertEquals(2, $counter);
}
function testViewTranslateTabSingleCheckout() {
$this
->loginAsTranslator(array(
'translate configuration',
));
$this
->drupalGet('admin/structure/views/view/content/translate');
$this
->assertSession()
->pageTextContains('Translations of Content view');
$this
->assertSession()
->pageTextContains('There are 0 items in the translation cart.');
$edit = array(
'languages[de]' => TRUE,
);
$this
->submitForm($edit, 'Request translation');
$this
->assertSession()
->pageTextContains('One job needs to be checked out.');
$this
->assertSession()
->pageTextContains('Content view (English to German, Unprocessed)');
$this
->submitForm([], 'Submit to provider');
$this
->assertSession()
->addressEquals('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
->submitForm([], 'Save');
$edit = array(
'languages[es]' => TRUE,
);
$this
->submitForm($edit, 'Request translation');
$this
->assertSession()
->pageTextContains('One job needs to be checked out.');
$this
->assertSession()
->pageTextContains('Content view (English to Spanish, Unprocessed)');
$this
->submitForm([], 'Submit to provider');
$this
->assertSession()
->addressEquals('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
->submitForm([], 'Save as completed');
$this
->assertSession()
->pageTextContains(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
->assertSession()
->pageTextContains('Configuration ID');
$this
->assertSession()
->pageTextContains('field.field.node.article.body');
$edit = [
'items[field.field.node.article.body]' => TRUE,
];
$this
->submitForm($edit, 'Add to cart');
$this
->clickLink('cart');
$this
->assertSession()
->pageTextContains('Body');
$edit = [
'target_language[]' => 'de',
];
$this
->submitForm($edit, 'Request translation');
$this
->assertSession()
->pageTextNotContains('Check for continuous jobs');
$this
->assertSession()
->fieldNotExists('add_all_to_continuous_jobs');
$this
->drupalGet('admin/structure/types/manage/article/fields/node.article.body/translate');
$this
->submitForm([
'languages[de]' => TRUE,
], 'Request translation');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('One job needs to be checked out.');
$this
->submitForm([], 'Submit to provider');
$this
->clickLinkWithImageTitle('Needs review');
$this
->submitForm([], 'Save as completed');
}
function testCart() {
$this
->loginAsTranslator(array(
'translate configuration',
));
$this
->drupalGet('admin/structure/views/view/content/translate');
$this
->submitForm([], 'Add to cart');
$this
->drupalGet('admin/structure/types/manage/article/translate');
$this
->submitForm([], 'Add to cart');
$this
->drupalGet('admin/tmgmt/cart');
$this
->assertSession()
->linkExists('Content view');
$this
->assertSession()
->linkExists('Article content type');
$this
->drupalGet('admin/structure/views/view/content/translate');
$this
->assertSession()
->responseContains(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
->assertSession()
->pageTextContains('Translations of System information');
$edit = array(
'languages[de]' => TRUE,
);
$this
->submitForm($edit, 'Request translation');
$this
->assertSession()
->pageTextContains('One job needs to be checked out.');
$this
->assertSession()
->pageTextContains('System information (English to German, Unprocessed)');
$this
->submitForm([], 'Submit to provider');
$this
->assertSession()
->addressEquals('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
->submitForm([
'name[translation]' => 'de_Druplicon',
], 'Save');
$this
->clickLinkWithImageTitle('Needs review');
$this
->assertSession()
->pageTextContains('de_Druplicon');
$this
->submitForm([], 'Save');
$edit = array(
'languages[es]' => TRUE,
);
$this
->submitForm($edit, 'Request translation');
$this
->assertSession()
->pageTextContains('One job needs to be checked out.');
$this
->assertSession()
->pageTextContains('System information (English to Spanish, Unprocessed)');
$this
->submitForm([], 'Submit to provider');
$this
->assertSession()
->addressEquals('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
->submitForm([
'languages[de]' => TRUE,
], 'Request translation');
$this
->submitForm([], 'Submit to provider');
$this
->clickLinkWithImageTitle('Needs review');
$this
->submitForm([
'user__settings|anonymous[translation]' => 'de_Druplicon',
], 'Validate HTML tags');
$this
->assertSession()
->pageTextContains('de_Druplicon');
$this
->submitForm([], 'Save');
$this
->clickLinkWithImageTitle('Needs review');
$this
->assertSession()
->pageTextContains('de_Druplicon');
}
}