View source
<?php
namespace Drupal\Tests\lingotek\Functional\Views;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\lingotek\Lingotek;
use Drupal\Tests\lingotek\Functional\LingotekNodeBulkTranslationTest;
class LingotekNodeBulkViewsTranslationTest extends LingotekNodeBulkTranslationTest {
use LingotekViewsTestTrait;
public static $modules = [
'block',
'node',
'views',
];
protected function setUp() : void {
parent::setUp();
\Drupal::getContainer()
->get('module_installer')
->install([
'lingotek_views_test',
], TRUE);
}
public function testAddContentLinkPresent() {
$this
->markTestSkipped('This doesn\'t apply if we replace the management pages with views. Or if you do, it is your decision to add the content creation link.');
}
public function testNodeTranslationMessageWhenBundleNotConfiguredWithLinks() {
$this
->markTestSkipped('This doesn\'t apply if we replace the management pages with views.');
}
public function testRequestTranslationWithActionWhenLanguageDisabled() {
$italian = ConfigurableLanguage::createFromLangcode('it');
$italian
->save();
$lingotek_config = \Drupal::service('lingotek.configuration');
$lingotek_config
->disableLanguage($italian);
$edit = [];
$edit['title[0][value]'] = 'Llamas are cool';
$edit['body[0][value]'] = 'Llamas are very cool';
$edit['langcode[0][value]'] = 'en';
$edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
$this
->saveAndPublishNodeForm($edit);
$this
->goToContentBulkManagementForm();
$this
->assertLingotekUploadLink();
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForUpload('node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertLingotekCheckSourceStatusLink();
$this
->assertLingotekRequestTranslationLink('es_MX');
$this
->assertTargetStatus('ES', Lingotek::STATUS_REQUEST);
$this
->assertSession()
->optionExists('edit-action', 'Request content item translation to Lingotek for Italian');
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForRequestTranslation('it', 'node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertText('Cannot request language Italian (it). That language is not enabled for Lingotek translation.');
}
protected function assertSelectionIsKept(string $key) {
$this
->assertText('You are not authorized to access this page.');
}
protected function assertSourceStatus($language, $status) {
if ($status === Lingotek::STATUS_UNTRACKED) {
$status_target = $this
->xpath("//a[contains(@class,'language-icon') and contains(@class,'source-" . strtolower($status) . "') and contains(text(), '" . strtoupper($language) . "')]");
if (count($status_target) === 1) {
$this
->assertEqual(count($status_target), 1, 'The source ' . strtoupper($language) . ' has been marked with status ' . strtolower($status) . '.');
}
else {
$status_target = $this
->xpath("//span[contains(@class,'language-icon') and contains(@class,'source-" . strtolower($status) . "') and contains(text(), '" . strtoupper($language) . "')]");
if (count($status_target) === 1) {
$this
->assertEqual(count($status_target), 1, 'The source ' . strtoupper($language) . ' has been marked with status ' . strtolower($status) . '.');
}
else {
$status_target = $this
->xpath("//span[contains(@class,'language-icon')]");
$this
->assertEqual(count($status_target), 0, 'The source ' . strtoupper($language) . ' has been marked with status ' . strtolower($status) . '.');
}
}
}
else {
$status_target = $this
->xpath("//a[contains(@class,'language-icon') and contains(@class,'source-" . strtolower($status) . "') and contains(text(), '" . strtoupper($language) . "')]");
if (count($status_target) === 1) {
$this
->assertEqual(count($status_target), 1, 'The source ' . strtoupper($language) . ' has been marked with status ' . strtolower($status) . '.');
}
else {
$status_target = $this
->xpath("//span[contains(@class,'language-icon') and contains(@class,'source-" . strtolower($status) . "') and contains(text(), '" . strtoupper($language) . "')]");
$this
->assertEqual(count($status_target), 1, 'The source ' . strtoupper($language) . ' has been marked with status ' . strtolower($status) . '.');
}
}
}
}