<?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\JobItem;
class ConfigSourceListTest extends TMGMTTestBase {
use TmgmtEntityTestTrait;
protected static $modules = array(
'tmgmt_config',
'tmgmt_content',
'config_translation',
'views',
'views_ui',
'field_ui',
);
protected $nodes = array();
function setUp() : void {
parent::setUp();
$this
->loginAsAdmin();
$this
->loginAsTranslator(array(
'translate configuration',
));
$this
->addLanguage('de');
$this
->addLanguage('it');
$this
->drupalCreateContentType(array(
'type' => 'article',
'name' => 'Article',
));
$this
->drupalCreateContentType(array(
'type' => 'page',
'name' => 'Page',
));
$this
->drupalCreateContentType(array(
'type' => 'simplenews_issue',
'name' => 'Newsletter issue',
));
}
function testNodeTypeSubmissions() {
$this
->drupalGet('admin/tmgmt/sources/config/node_type');
$edit = array(
'items[node.type.article]' => TRUE,
);
$this
->submitForm($edit, 'Request translation');
$this
->assertSession()
->pageTextContains('One job needs to be checked out.');
$this
->assertSession()
->pageTextContains('Article content type (English to ?, Unprocessed)');
$this
->submitForm([], 'Submit to provider');
$this
->assertSession()
->addressEquals('admin/tmgmt/sources/config/node_type');
$this
->assertSession()
->pageTextContains('Test translation created.');
$this
->assertSession()
->pageTextContains('The translation of Article content type to German is finished and can now be reviewed.');
$this
->drupalGet('admin/tmgmt/sources/config/node_type');
$edit = array(
'items[node.type.article]' => TRUE,
'items[node.type.page]' => TRUE,
);
$this
->submitForm($edit, 'Request translation');
$this
->assertSession()
->pageTextContains('One job needs to be checked out.');
$this
->assertSession()
->pageTextContains('Article content type and 1 more (English to ?, Unprocessed)');
$this
->assertSession()
->pageTextContains('1 item conflicts with pending item and will be dropped on submission. Conflicting item: Article content type.');
$this
->submitForm([], 'Submit to provider');
$this
->assertSession()
->addressEquals('admin/tmgmt/sources/config/node_type');
$this
->assertSession()
->pageTextContains('Test translation created.');
$this
->assertSession()
->pageTextNotContains('The translation of Article content type to German is finished and can now be reviewed.');
$this
->assertSession()
->pageTextContains('The translation of Page content type to German is finished and can now be reviewed.');
}
function testViewTranslation() {
$this
->drupalGet('admin/tmgmt/sources/config/view');
$this
->assertSession()
->pageTextContains('View overview (Config Entity)');
$edit = array(
'items[views.view.archive]' => TRUE,
);
$this
->submitForm($edit, 'Request translation');
$this
->assertSession()
->pageTextContains('One job needs to be checked out.');
$this
->assertSession()
->pageTextContains('Archive view (English to ?, Unprocessed)');
$this
->submitForm([], 'Submit to provider');
$this
->assertSession()
->addressEquals('admin/tmgmt/sources/config/view');
$this
->assertSession()
->pageTextContains('Test translation created.');
$this
->assertSession()
->pageTextContains('The translation of Archive view to German is finished and can now be reviewed.');
$edit = array(
'items[views.view.archive]' => TRUE,
'items[views.view.content_recent]' => TRUE,
'items[views.view.content]' => TRUE,
'items[views.view.tmgmt_job_overview]' => TRUE,
);
$this
->submitForm($edit, 'Request translation');
$this
->assertSession()
->pageTextContains('One job needs to be checked out.');
$this
->assertSession()
->pageTextContains('Archive view and 3 more (English to ?, Unprocessed)');
$this
->assertSession()
->pageTextContains('1 item conflicts with pending item and will be dropped on submission. Conflicting item: Archive view.');
$this
->submitForm([], 'Submit to provider');
$this
->assertSession()
->addressEquals('admin/tmgmt/sources/config/view');
$this
->assertSession()
->pageTextContains('Test translation created.');
$this
->assertSession()
->pageTextNotContains('The translation of Archive view to German is finished and can now be reviewed.');
$this
->assertSession()
->pageTextContains('The translation of Recent content view to German is finished and can now be reviewed.');
$this
->assertSession()
->pageTextContains('The translation of Content view to German is finished and can now be reviewed.');
$this
->assertSession()
->pageTextContains('The translation of Job overview view to German is finished and can now be reviewed.');
$edit = array(
'items[views.view.tmgmt_job_items]' => TRUE,
);
$this
->submitForm($edit, 'Add to cart');
$this
->clickLink('cart');
$cart_tab_active = $this
->xpath('//ul[@class="tabs primary"]/li[@class="is-active"]/a')[0];
$this
->assertStringContainsString('Cart', $cart_tab_active
->getText());
$this
->assertSession()
->titleEquals('Cart | Drupal');
$this
->assertSession()
->pageTextContains('Request translation');
}
function testNodeTypeFilter() {
$this
->drupalGet('admin/tmgmt/sources/config/node_type');
$this
->assertSession()
->pageTextContains('Content type overview (Config Entity)');
$this
->drupalGet('admin/tmgmt/sources/config/node_type');
$filters = array(
'search[name]' => '',
'search[langcode]' => '',
'search[target_language]' => '',
);
$this
->submitForm($filters, 'Search');
$this
->drupalGet('admin/tmgmt/sources/config/node_type');
$filters = array(
'search[name]' => $this
->randomMachineName(5),
'search[langcode]' => '',
'search[target_language]' => '',
);
$this
->submitForm($filters, 'Search');
$this
->assertSession()
->pageTextContains('No source items matching given criteria have been found.');
$this
->drupalGet('admin/tmgmt/sources/config/node_type');
$filters = array(
'search[name]' => 'article',
'search[langcode]' => '',
'search[target_language]' => '',
);
$this
->submitForm($filters, 'Search');
$rows = $this
->xpath('//tbody/tr/td[2]/a');
foreach ($rows as $value) {
$this
->assertEquals('Article', $value
->getText());
}
$this
->drupalGet('admin/tmgmt/sources/config/node_type');
$filters = array(
'search[name]' => 'article',
'search[langcode]' => 'en',
'search[target_language]' => 'it',
);
$this
->submitForm($filters, 'Search');
$rows = $this
->xpath('//tbody/tr/td[2]/a');
foreach ($rows as $value) {
$this
->assertEquals('Article', $value
->getText());
}
$this
->drupalGet('admin/tmgmt/sources/config/node_type');
$filters = array(
'search[name]' => 'art',
'search[langcode]' => 'en',
'search[target_language]' => 'it',
);
$this
->submitForm($filters, 'Search');
$rows = $this
->xpath('//tbody/tr/td[2]/a');
foreach ($rows as $value) {
$this
->assertEquals('Article', $value
->getText());
}
}
function testSimpleConfigTranslation() {
$this
->loginAsTranslator(array(
'translate configuration',
));
$this
->drupalGet('admin/tmgmt/sources/config/_simple_config');
$this
->assertSession()
->pageTextContains('Simple configuration overview (Config Entity)');
$edit = array(
'items[system.site_information_settings]' => TRUE,
);
$this
->submitForm($edit, 'Request translation');
$this
->assertSession()
->pageTextContains('One job needs to be checked out.');
$this
->assertSession()
->pageTextContains('System information (English to ?, Unprocessed)');
$this
->submitForm([], 'Submit to provider');
$this
->assertSession()
->addressEquals('admin/tmgmt/sources/config/_simple_config');
$overview_url = Url::fromRoute('tmgmt.source_overview', array(
'plugin' => 'config',
'item_type' => '_simple_config',
))
->toString();
$url = JobItem::load(1)
->toUrl()
->setOption('query', [
'destination' => $overview_url,
])
->toString();
$imgs = $this
->xpath('//a[@href=:href]/img', [
':href' => $url,
]);
$this
->assertEquals('Active job item: Needs review', $imgs[0]
->getAttribute('title'));
$this
->assertSession()
->pageTextContains('Test translation created.');
$this
->assertSession()
->pageTextContains('The translation of System information to German is finished and can now be reviewed.');
$review = $this
->xpath('//table[@id="edit-items"]/tbody/tr[@class="even"][1]/td[@class="langstatus-de"]/a');
$destination = $this
->getAbsoluteUrl($review[0]
->getAttribute('href'));
$this
->drupalGet($destination);
$this
->submitForm([], 'Save');
$edit = array(
'items[entity.user.admin_form]' => TRUE,
);
$this
->submitForm($edit, 'Request translation');
$this
->assertSession()
->pageTextContains('One job needs to be checked out.');
$this
->assertSession()
->pageTextContains('Account settings (English to ?, Unprocessed)');
$this
->submitForm([], 'Submit to provider');
$this
->assertSession()
->addressEquals('admin/tmgmt/sources/config/_simple_config');
$links = $this
->xpath('//table[@id="edit-items"]/tbody/tr/td/a');
$this
->assertEquals(2, count($links));
$this
->drupalGet('admin/tmgmt/items/1');
$this
->submitForm([], 'Save as completed');
$this
->drupalGet('admin/tmgmt/sources/config/_simple_config');
$filters = array(
'search[name]' => 'system',
);
$this
->submitForm($filters, 'Search');
$this
->assertCount(2, $this
->xpath('//tbody/tr'));
$this
->drupalGet('admin/tmgmt/sources/config/_simple_config');
$filters = array(
'search[target_language]' => 'de',
'search[target_status]' => 'translated',
);
$this
->submitForm($filters, 'Search');
$this
->assertCount(1, $this
->xpath('//tbody/tr'));
$this
->drupalGet('admin/tmgmt/sources/config/_simple_config');
$filters = array(
'search[name]' => 'settings',
'search[target_language]' => 'de',
'search[target_status]' => 'untranslated',
);
$this
->submitForm($filters, 'Search');
$this
->assertCount(1, $this
->xpath('//tbody/tr'));
$this
->drupalGet('admin/tmgmt/sources/config/_simple_config');
$filters = array(
'search[name]' => 'sys',
'search[target_language]' => 'de',
'search[target_status]' => 'translated',
);
$this
->submitForm($filters, 'Search');
$this
->assertCount(1, $this
->xpath('//tbody/tr'));
}
function testFieldConfigList() {
$this
->drupalGet('admin/tmgmt/sources/config/field_config');
$this
->submitForm([
'items[field.field.node.article.body]' => TRUE,
], 'Request translation');
$this
->assertSession()
->pageTextContains('One job needs to be checked out.');
$this
->submitForm([], 'Submit to provider');
$this
->assertSession()
->addressEquals('admin/tmgmt/sources/config/field_config');
$this
->assertSession()
->pageTextContains('Test translation created.');
$this
->assertSession()
->pageTextContains('The translation of Body to German is finished and can now be reviewed.');
}
}