View source
<?php
namespace Drupal\lingotek\Tests;
use Drupal\language\Entity\ConfigurableLanguage;
class LingotekContentTypeBulkLocaleTranslationTest extends LingotekTestBase {
public static $modules = [
'node',
'comment',
];
protected function setUp() {
parent::setUp();
$this
->drupalCreateContentType(array(
'type' => 'article',
'name' => 'Article',
));
ConfigurableLanguage::create([
'id' => 'de-at',
'name' => 'German (AT)',
])
->save();
$post = [
'code' => 'es_AR',
'language' => 'Spanish',
'native' => 'Español',
'direction' => '',
];
$this
->drupalPost('/admin/lingotek/dashboard_endpoint', 'application/json', $post);
$post = [
'code' => 'es_ES',
'language' => 'Spanish',
'native' => 'Español',
'direction' => '',
];
$this
->drupalPost('/admin/lingotek/dashboard_endpoint', 'application/json', $post);
$edit = [
'table[node_type][enabled]' => 1,
'table[node_type][profile]' => 'automatic',
];
$this
->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-configuration-form');
\Drupal::state()
->set('lingotek.uploaded_content_type', 'content_type');
}
public function testSystemSiteTranslationUsingLinks() {
$this
->drupalLogin($this->rootUser);
$this
->goToConfigBulkManagementForm('node_type');
$basepath = \Drupal::request()
->getBasePath();
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/upload/node_type/article?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->assertNoLinkByHref($basepath . '/admin/lingotek/config/request/node_type/article/es_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->assertNoLinkByHref($basepath . '/admin/lingotek/config/request/node_type/article/es_AR?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('EN');
$this
->assertText(t('Article uploaded successfully'));
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/check_upload/node_type/article?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/request/node_type/article/es_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/request/node_type/article/es_AR?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('EN');
$this
->assertText('Article status checked successfully');
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/request/node_type/article/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('DE-AT');
$this
->assertText("Translation to de_AT requested successfully");
$this
->assertIdentical('de_AT', \Drupal::state()
->get('lingotek.added_target_locale'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/request/node_type/article/es_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/request/node_type/article/es_AR?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('ES');
$this
->assertText("Translation to es_AR requested successfully");
$this
->assertIdentical('es_AR', \Drupal::state()
->get('lingotek.added_target_locale'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/check_download/node_type/article/es_AR?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('ES');
$this
->assertIdentical('es_AR', \Drupal::state()
->get('lingotek.checked_target_locale'));
$this
->assertText("Translation to es_AR status checked successfully");
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/download/node_type/article/es_AR?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('ES');
$this
->assertText('Translation to es_AR downloaded successfully');
$this
->assertIdentical('es_AR', \Drupal::state()
->get('lingotek.downloaded_locale'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/workbench/dummy-document-hash-id/es_AR');
$workbench_link = $this
->xpath("//a[@href='{$basepath}/admin/lingotek/workbench/dummy-document-hash-id/es_AR' and @target='_blank']");
$this
->assertEqual(count($workbench_link), 1, 'Workbench links open in a new tab.');
$target_links = $this
->xpath("//a[contains(@class,'language-icon')]");
$this
->assertEqual(count($target_links), 3, 'The three languages appear as targets');
$this
->assertEqual('DE-AT', (string) $target_links[0], 'DE-AT is the first language');
$this
->assertEqual('ES', (string) $target_links[1], 'ES is the second language');
$this
->assertEqual('ES-ES', (string) $target_links[2], 'ES-ES is the third language');
}
public function testSourceUpdatedAfterRequestingTranslation() {
$this
->drupalLogin($this->rootUser);
$this
->goToConfigBulkManagementForm('node_type');
$basepath = \Drupal::request()
->getBasePath();
$this
->clickLink('EN');
$this
->assertText(t('Article uploaded successfully'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/check_upload/node_type/article?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/request/node_type/article/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/request/node_type/article/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('DE-AT');
$this
->assertText("Translation to de_AT requested successfully");
$this
->assertNoLinkByHref($basepath . '/admin/lingotek/config/check_upload/node_type/article?destination=' . $basepath . '/admin/lingotek/config/manage');
}
}