View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
class LingotekContentTypeBulkLocaleTranslationTest extends LingotekTestBase {
public static $modules = [
'node',
'comment',
];
protected function setUp() : void {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
ConfigurableLanguage::create([
'id' => 'de-at',
'name' => 'German (AT)',
])
->save();
ConfigurableLanguage::createFromLangcode('es')
->setThirdPartySetting('lingotek', 'locale', 'es_AR')
->save();
ConfigurableLanguage::createFromLangcode('es-es')
->setThirdPartySetting('lingotek', 'locale', 'es_ES')
->save();
$this
->saveLingotekConfigTranslationSettings([
'node_type' => 'automatic',
]);
\Drupal::state()
->set('lingotek.uploaded_content_type', 'content_type');
}
public function testSystemSiteTranslationUsingLinks() {
$assert_session = $this
->assertSession();
$this
->drupalLogin($this->rootUser);
$this
->goToConfigBulkManagementForm('node_type');
$basepath = \Drupal::request()
->getBasePath();
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/node_type/article?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefNotExists($basepath . '/admin/lingotek/config/request/node_type/article/es_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefNotExists($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'));
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/check_upload/node_type/article?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/request/node_type/article/es_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefExists($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');
$assert_session
->linkByHrefExists($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'));
\Drupal::state()
->resetCache();
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/request/node_type/article/es_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefExists($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'));
$assert_session
->linkByHrefExists($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");
$assert_session
->linkByHrefExists($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
->assertLingotekWorkbenchLink('es_AR', 'dummy-document-hash-id', 'ES');
$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', $target_links[0]
->getHtml(), 'DE-AT is the first language');
$this
->assertEqual('ES', $target_links[1]
->getHtml(), 'ES is the second language');
$this
->assertEqual('ES-ES', $target_links[2]
->getHtml(), 'ES-ES is the third language');
}
public function testSourceUpdatedAfterRequestingTranslation() {
$assert_session = $this
->assertSession();
$this
->drupalLogin($this->rootUser);
$this
->goToConfigBulkManagementForm('node_type');
$basepath = \Drupal::request()
->getBasePath();
$this
->clickLink('EN');
$this
->assertText(t('Article uploaded successfully'));
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/check_upload/node_type/article?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/request/node_type/article/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefExists($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");
$assert_session
->linkByHrefNotExists($basepath . '/admin/lingotek/config/check_upload/node_type/article?destination=' . $basepath . '/admin/lingotek/config/manage');
}
}