View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\lingotek\Entity\LingotekProfile;
use Drupal\lingotek\Lingotek;
class LingotekFieldBodyBulkDisabledTargetOverrideTranslationTest extends LingotekTestBase {
public static $modules = [
'block',
'node',
'field_ui',
];
protected function setUp() : void {
parent::setUp();
$type = $this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
node_add_body_field($type);
ConfigurableLanguage::createFromLangcode('es')
->setThirdPartySetting('lingotek', 'locale', 'es_MX')
->save();
ConfigurableLanguage::createFromLangcode('ca')
->setThirdPartySetting('lingotek', 'locale', 'ca_ES')
->save();
$profile = LingotekProfile::create([
'label' => 'Profile with disabled targets',
'id' => 'profile_with_disabled_targets',
'project' => 'test_project',
'vault' => 'test_vault',
'auto_upload' => FALSE,
'workflow' => 'test_workflow',
'language_overrides' => [
'es' => [
'overrides' => 'custom',
'custom' => [
'auto_request' => TRUE,
'workflow' => 'test_workflow',
'vault' => 'test_vault',
],
],
'ca' => [
'overrides' => 'disabled',
],
],
]);
$profile
->save();
$this
->saveLingotekConfigTranslationSettings([
'node_fields' => 'profile_with_disabled_targets',
]);
\Drupal::state()
->set('lingotek.uploaded_content_type', 'body');
}
public function testFieldBodyTranslationUsingLinks() {
$assert_session = $this
->assertSession();
$basepath = \Drupal::request()
->getBasePath();
$this
->goToConfigBulkManagementForm('node_fields');
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/field_config/node.article.body?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefNotExists($basepath . '/admin/lingotek/config/request/field_config/node.article.body/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefNotExists($basepath . '/admin/lingotek/config/request/field_config/node.article.body/ca_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('EN');
$this
->assertText('Body uploaded successfully');
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/check_upload/field_config/node.article.body?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/request/field_config/node.article.body/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefNotExists($basepath . '/admin/lingotek/config/request/field_config/node.article.body/ca_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('EN');
$this
->assertText('Body status checked successfully');
$assert_session
->linkByHrefNotExists($basepath . '/admin/lingotek/config/request/field_config/node.article.body/ca_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/request/field_config/node.article.body/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->assertTargetStatus('es', Lingotek::STATUS_REQUEST);
$this
->assertTargetStatus('ca', Lingotek::STATUS_DISABLED);
}
public function testFieldBodyTranslationUsingActions() {
$assert_session = $this
->assertSession();
$basepath = \Drupal::request()
->getBasePath();
$this
->goToConfigBulkManagementForm('node_fields');
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/field_config/node.article.body?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefNotExists($basepath . '/admin/lingotek/config/request/field_config/node.article.body/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefNotExists($basepath . '/admin/lingotek/config/request/field_config/node.article.body/ca_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[node.article.body]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForUpload('node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertText('Operations completed.');
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/request/field_config/node.article.body/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefNotExists($basepath . '/admin/lingotek/config/request/field_config/node.article.body/ca_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->assertTargetStatus('es', Lingotek::STATUS_REQUEST);
$this
->assertTargetStatus('ca', Lingotek::STATUS_DISABLED);
$edit = [
'table[node.article.body]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForRequestTranslation('ca', 'node_fields'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical(NULL, \Drupal::state()
->get('lingotek.added_target_locale'));
$this
->assertIdentical(NULL, \Drupal::state()
->get('lingotek.requested_locales'));
$this
->assertText('Operations completed.');
$this
->assertTargetStatus('es', Lingotek::STATUS_REQUEST);
$this
->assertTargetStatus('ca', Lingotek::STATUS_DISABLED);
$assert_session
->linkByHrefNotExists($basepath . '/admin/lingotek/config/check_download/field_config/node.article.body/ca_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[node.article.body]' => TRUE,
$this
->getBulkOperationFormName() => 'check_translation:ca',
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical(NULL, \Drupal::state()
->get('lingotek.checked_target_locale'));
$this
->assertTargetStatus('es', Lingotek::STATUS_REQUEST);
$this
->assertTargetStatus('ca', Lingotek::STATUS_DISABLED);
$assert_session
->linkByHrefNotExists($basepath . '/admin/lingotek/config/download/field_config/node.article.body/ca_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[node.article.body]' => TRUE,
$this
->getBulkOperationFormName() => 'download:ca',
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical(NULL, \Drupal::state()
->get('lingotek.downloaded_locale'));
$this
->assertTargetStatus('es', Lingotek::STATUS_REQUEST);
$this
->assertTargetStatus('ca', Lingotek::STATUS_DISABLED);
}
public function testFieldBodyTranslationUsingActionsForMultipleLocales() {
$assert_session = $this
->assertSession();
$basepath = \Drupal::request()
->getBasePath();
$this
->goToConfigBulkManagementForm('node_fields');
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/field_config/node.article.body?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefNotExists($basepath . '/admin/lingotek/config/request/field_config/node.article.body/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefNotExists($basepath . '/admin/lingotek/config/request/field_config/node.article.body/ca_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[node.article.body]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForUpload('node_fields'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertText('Operations completed.');
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/check_upload/field_config/node.article.body?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[node.article.body]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCheckUpload('node_fields'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertText('Operations completed.');
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/request/field_config/node.article.body/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefNotExists($basepath . '/admin/lingotek/config/request/field_config/node.article.body/ca_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->assertTargetStatus('es', Lingotek::STATUS_REQUEST);
$this
->assertTargetStatus('ca', Lingotek::STATUS_DISABLED);
$edit = [
'table[node.article.body]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForRequestTranslations('node_fields'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical([
'dummy-document-hash-id' => [
'es_MX',
],
], \Drupal::state()
->get('lingotek.requested_locales'));
$this
->assertText('Operations completed.');
$this
->assertTargetStatus('es', Lingotek::STATUS_PENDING);
$this
->assertTargetStatus('ca', Lingotek::STATUS_DISABLED);
$assert_session
->linkByHrefNotExists($basepath . '/admin/lingotek/config/check_download/field_config/node.article.body/ca_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[node.article.body]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCheckTranslations('node_fields'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical(NULL, \Drupal::state()
->get('lingotek.checked_target_locale'));
$this
->assertTargetStatus('es', Lingotek::STATUS_READY);
$this
->assertTargetStatus('ca', Lingotek::STATUS_DISABLED);
$assert_session
->linkByHrefNotExists($basepath . '/admin/lingotek/config/download/field_config/node.article.body/ca_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[node.article.body]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForDownloadTranslations('node_fields'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('es_MX', \Drupal::state()
->get('lingotek.downloaded_locale'));
$this
->assertTargetStatus('es', Lingotek::STATUS_CURRENT);
$this
->assertTargetStatus('ca', Lingotek::STATUS_DISABLED);
}
}