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\JobItem;
class ConfigSourceListTest extends TMGMTTestBase {
use TmgmtEntityTestTrait;
public 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() {
$edit = array(
'items[node.type.article]' => TRUE,
);
$this
->drupalPostForm('admin/tmgmt/sources/config/node_type', $edit, t('Request translation'));
$this
->assertText(t('One job needs to be checked out.'));
$this
->assertText(t('Article content type (English to ?, Unprocessed)'));
$this
->drupalPostForm(NULL, array(), t('Submit to provider'));
$this
->assertUrl('admin/tmgmt/sources/config/node_type');
$this
->assertText(t('Test translation created.'));
$this
->assertText(t('The translation of Article content type to German is finished and can now be reviewed.'));
$edit = array(
'items[node.type.article]' => TRUE,
'items[node.type.page]' => TRUE,
);
$this
->drupalPostForm('admin/tmgmt/sources/config/node_type', $edit, t('Request translation'));
$this
->assertText(t('One job needs to be checked out.'));
$this
->assertText(t('Article content type and 1 more (English to ?, Unprocessed)'));
$this
->assertText('1 item conflicts with pending item and will be dropped on submission. Conflicting item: Article content type.');
$this
->drupalPostForm(NULL, array(), t('Submit to provider'));
$this
->assertUrl('admin/tmgmt/sources/config/node_type');
$this
->assertText(t('Test translation created.'));
$this
->assertNoText(t('The translation of Article content type to German is finished and can now be reviewed.'));
$this
->assertText(t('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
->assertText(t('View overview (Config Entity)'));
$edit = array(
'items[views.view.archive]' => TRUE,
);
$this
->drupalPostForm(NULL, $edit, t('Request translation'));
$this
->assertText(t('One job needs to be checked out.'));
$this
->assertText(t('Archive view (English to ?, Unprocessed)'));
$this
->drupalPostForm(NULL, array(), t('Submit to provider'));
$this
->assertUrl('admin/tmgmt/sources/config/view');
$this
->assertText(t('Test translation created.'));
$this
->assertText(t('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
->drupalPostForm(NULL, $edit, t('Request translation'));
$this
->assertText(t('One job needs to be checked out.'));
$this
->assertText(t('Archive view and 3 more (English to ?, Unprocessed)'));
$this
->assertText('1 item conflicts with pending item and will be dropped on submission. Conflicting item: Archive view.');
$this
->drupalPostForm(NULL, array(), t('Submit to provider'));
$this
->assertUrl('admin/tmgmt/sources/config/view');
$this
->assertText(t('Test translation created.'));
$this
->assertNoText(t('The translation of Archive view to German is finished and can now be reviewed.'));
$this
->assertText(t('The translation of Recent content view to German is finished and can now be reviewed.'));
$this
->assertText(t('The translation of Content view to German is finished and can now be reviewed.'));
$this
->assertText(t('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
->drupalPostForm(NULL, $edit, t('Add to cart'));
$this
->clickLink('cart');
$cart_tab_active = $this
->xpath('//ul[@class="tabs primary"]/li[@class="is-active"]/a')[0];
$this
->assertEquals('Cart(active tab)', $cart_tab_active
->getText());
$this
->assertTitle('Cart | Drupal');
$this
->assertText('Request translation');
}
function testNodeTypeFilter() {
$this
->drupalGet('admin/tmgmt/sources/config/node_type');
$this
->assertText(t('Content type overview (Config Entity)'));
$filters = array(
'search[name]' => '',
'search[langcode]' => '',
'search[target_language]' => '',
);
$this
->drupalPostForm('admin/tmgmt/sources/config/node_type', $filters, t('Search'));
$filters = array(
'search[name]' => $this
->randomMachineName(5),
'search[langcode]' => '',
'search[target_language]' => '',
);
$this
->drupalPostForm('admin/tmgmt/sources/config/node_type', $filters, t('Search'));
$this
->assertText(t('No source items matching given criteria have been found.'));
$filters = array(
'search[name]' => 'article',
'search[langcode]' => '',
'search[target_language]' => '',
);
$this
->drupalPostForm('admin/tmgmt/sources/config/node_type', $filters, t('Search'));
$rows = $this
->xpath('//tbody/tr/td[2]/a');
foreach ($rows as $value) {
$this
->assertEquals('Article', $value
->getText());
}
$filters = array(
'search[name]' => 'article',
'search[langcode]' => 'en',
'search[target_language]' => 'it',
);
$this
->drupalPostForm('admin/tmgmt/sources/config/node_type', $filters, t('Search'));
$rows = $this
->xpath('//tbody/tr/td[2]/a');
foreach ($rows as $value) {
$this
->assertEquals('Article', $value
->getText());
}
$filters = array(
'search[name]' => 'art',
'search[langcode]' => 'en',
'search[target_language]' => 'it',
);
$this
->drupalPostForm('admin/tmgmt/sources/config/node_type', $filters, t('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
->assertText(t('Simple configuration overview (Config Entity)'));
$edit = array(
'items[system.site_information_settings]' => TRUE,
);
$this
->drupalPostForm(NULL, $edit, t('Request translation'));
$this
->assertText(t('One job needs to be checked out.'));
$this
->assertText('System information (English to ?, Unprocessed)');
$this
->drupalPostForm(NULL, array(), t('Submit to provider'));
$this
->assertUrl('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
->assertEqual('Active job item: Needs review', $imgs[0]
->getAttribute('title'));
$this
->assertText(t('Test translation created.'));
$this
->assertText('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
->drupalPostForm(NULL, array(), t('Save'));
$edit = array(
'items[entity.user.admin_form]' => TRUE,
);
$this
->drupalPostForm(NULL, $edit, t('Request translation'));
$this
->assertText(t('One job needs to be checked out.'));
$this
->assertText('Account settings (English to ?, Unprocessed)');
$this
->drupalPostForm(NULL, array(), t('Submit to provider'));
$this
->assertUrl('admin/tmgmt/sources/config/_simple_config');
$links = $this
->xpath('//table[@id="edit-items"]/tbody/tr/td/a');
$this
->assertEquals(2, count($links));
$this
->drupalPostForm('admin/tmgmt/items/1', array(), t('Save as completed'));
$filters = array(
'search[name]' => 'system',
);
$this
->drupalPostForm('admin/tmgmt/sources/config/_simple_config', $filters, t('Search'));
$this
->assertEqual(count($this
->xpath('//tbody/tr')), 2);
$filters = array(
'search[target_language]' => 'de',
'search[target_status]' => 'translated',
);
$this
->drupalPostForm('admin/tmgmt/sources/config/_simple_config', $filters, t('Search'));
$this
->assertEqual(count($this
->xpath('//tbody/tr')), 1);
$filters = array(
'search[name]' => 'settings',
'search[target_language]' => 'de',
'search[target_status]' => 'untranslated',
);
$this
->drupalPostForm('admin/tmgmt/sources/config/_simple_config', $filters, t('Search'));
$this
->assertEqual(count($this
->xpath('//tbody/tr')), 1);
$filters = array(
'search[name]' => 'sys',
'search[target_language]' => 'de',
'search[target_status]' => 'translated',
);
$this
->drupalPostForm('admin/tmgmt/sources/config/_simple_config', $filters, t('Search'));
$this
->assertEqual(count($this
->xpath('//tbody/tr')), 1);
}
function testFieldConfigList() {
$this
->drupalGet('admin/tmgmt/sources/config/field_config');
$this
->drupalPostForm(NULL, array(
'items[field.field.node.article.body]' => TRUE,
), t('Request translation'));
$this
->assertText(t('One job needs to be checked out.'));
$this
->drupalPostForm(NULL, array(), t('Submit to provider'));
$this
->assertUrl('admin/tmgmt/sources/config/field_config');
$this
->assertText(t('Test translation created.'));
$this
->assertText(t('The translation of Body to German is finished and can now be reviewed.'));
}
}