View source
<?php
namespace Drupal\Tests\lingotek\Functional\Form;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\lingotek\Entity\LingotekConfigMetadata;
use Drupal\Tests\lingotek\Functional\LingotekTestBase;
class LingotekConfigBulkFormTest extends LingotekTestBase {
public static $modules = [
'block',
'node',
'field_ui',
];
protected function setUp() : void {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
$this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Page',
]);
ConfigurableLanguage::createFromLangcode('es')
->setThirdPartySetting('lingotek', 'locale', 'es_MX')
->save();
ContentLanguageSettings::loadByEntityTypeBundle('node', 'article')
->setLanguageAlterable(TRUE)
->save();
ContentLanguageSettings::loadByEntityTypeBundle('node', 'page')
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('node', 'article', TRUE);
\Drupal::service('content_translation.manager')
->setEnabled('node', 'page', TRUE);
drupal_static_reset();
\Drupal::entityTypeManager()
->clearCachedDefinitions();
$this
->applyEntityUpdates();
$this
->rebuildContainer();
$this
->saveLingotekContentTranslationSettingsForNodeTypes([
'article',
'page',
]);
$this
->saveLingotekConfigTranslationSettings([
'node_type' => 'automatic',
]);
}
public function testConfigFilter() {
$assert_session = $this
->assertSession();
$this
->goToConfigBulkManagementForm();
$second_header = $this
->xpath('//*[@id="edit-table"]/thead/tr/th[2]')[0];
$this
->assertEqual($second_header
->getHtml(), 'Entity', 'There is a Entity header.');
}
public function testFieldConfigFilter() {
$assert_session = $this
->assertSession();
$this
->goToConfigBulkManagementForm();
$edit = [
'filters[wrapper][bundle]' => 'node_fields',
];
$this
->drupalPostForm(NULL, $edit, t('Filter'));
$second_header = $this
->xpath('//*[@id="edit-table"]/thead/tr/th[2]/a')[0];
$this
->assertEqual($second_header
->getHtml(), 'Bundle', 'There is a Bundle header.');
$third_header = $this
->xpath('//*[@id="edit-table"]/thead/tr/th[3]/a')[0];
$this
->assertEqual($third_header
->getHtml(), 'Entity', 'There is a Entity header.');
$this
->assertUniqueText('Article');
$this
->assertUniqueText('Page');
$this
->assertText('Body');
$this
->assertNoUniqueText('Body');
}
public function testDisabledLanguage() {
$assert_session = $this
->assertSession();
$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');
$this
->assertNoLingotekRequestTranslationLink('es_MX');
$this
->clickLink('EN');
$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_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
$lingotekConfig = \Drupal::service('lingotek.configuration');
$language = ConfigurableLanguage::load('es');
$lingotekConfig
->disableLanguage($language);
$this
->goToConfigBulkManagementForm();
$assert_session
->linkByHrefNotExists($basepath . '/admin/lingotek/config/request/node_type/article/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
$lingotekConfig
->enableLanguage($language);
$this
->goToConfigBulkManagementForm();
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/request/node_type/article/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
}
public function testJobIdOnUpload() {
$assert_session = $this
->assertSession();
$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
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/node_type/page?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[article]' => TRUE,
'table[page]' => TRUE,
'job_id' => 'my_custom_job_id',
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForUpload('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertEquals('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertEquals('my_custom_job_id', \Drupal::state()
->get('lingotek.uploaded_job_id'));
$metadatas = LingotekConfigMetadata::loadMultiple();
foreach ($metadatas as $metadata) {
$this
->assertEquals('my_custom_job_id', $metadata
->getJobId(), 'The job id was saved along with metadata.');
}
$this
->assertText('Job ID');
$this
->assertText('my_custom_job_id');
}
public function testJobIdOnUpdate() {
$assert_session = $this
->assertSession();
$this
->drupalCreateContentType([
'type' => 'banner',
'name' => 'Banner',
]);
$this
->drupalCreateContentType([
'type' => 'book',
'name' => 'Book',
]);
$this
->drupalCreateContentType([
'type' => 'ingredient',
'name' => 'Ingredient',
]);
$this
->drupalCreateContentType([
'type' => 'recipe',
'name' => 'Recipe',
]);
$this
->goToConfigBulkManagementForm('node_type');
$metadatas = LingotekConfigMetadata::loadMultiple();
foreach ($metadatas as $metadata) {
$this
->assertEmpty($metadata
->getJobId(), 'There was no job id to save along with metadata.');
}
$basepath = \Drupal::request()
->getBasePath();
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/check_upload/node_type/book?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/check_upload/node_type/recipe?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[ingredient]' => TRUE,
'table[recipe]' => TRUE,
'table[book]' => TRUE,
'table[banner]' => TRUE,
'job_id' => 'my_custom_job_id',
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForUpload('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertEquals('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertEquals('my_custom_job_id', \Drupal::state()
->get('lingotek.uploaded_job_id'));
$metadatas = LingotekConfigMetadata::loadMultiple();
foreach ($metadatas as $metadata) {
$this
->assertEquals('my_custom_job_id', $metadata
->getJobId(), 'The job id was saved along with metadata.');
}
$this
->assertText('Job ID');
$this
->assertText('my_custom_job_id');
}
public function testAssignJobIds() {
$assert_session = $this
->assertSession();
$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
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/node_type/page?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[article]' => TRUE,
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'job_id' => 'my_custom_job_id',
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('Job ID was assigned successfully.');
$this
->assertNull(\Drupal::state()
->get('lingotek.uploaded_title'));
$this
->assertNull(\Drupal::state()
->get('lingotek.uploaded_job_id'));
$this
->assertText('my_custom_job_id');
$this
->clickLink('EN');
$this
->assertText('Article uploaded successfully');
\Drupal::state()
->resetCache();
$this
->assertIdentical(\Drupal::state()
->get('lingotek.uploaded_job_id'), 'my_custom_job_id');
$edit = [
'table[article]' => TRUE,
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'job_id' => 'other_job_id',
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('Job ID was assigned successfully.');
\Drupal::state()
->resetCache();
$this
->assertNotNull(\Drupal::state()
->get('lingotek.uploaded_title'));
$this
->assertNotNull(\Drupal::state()
->get('lingotek.uploaded_content'));
$this
->assertEquals('my_custom_job_id', \Drupal::state()
->get('lingotek.uploaded_job_id'));
}
public function testAssignJobIdsWithTMSUpdate() {
$assert_session = $this
->assertSession();
$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
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/node_type/page?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[article]' => TRUE,
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'job_id' => 'my_custom_job_id',
'update_tms' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('Job ID was assigned successfully.');
\Drupal::state()
->resetCache();
$this
->assertNull(\Drupal::state()
->get('lingotek.uploaded_title'));
$this
->assertNull(\Drupal::state()
->get('lingotek.uploaded_content'));
$this
->assertNull(\Drupal::state()
->get('lingotek.uploaded_job_id'));
$this
->assertText('my_custom_job_id');
$this
->clickLink('EN');
$this
->assertText('Article uploaded successfully');
\Drupal::state()
->resetCache();
$this
->assertIdentical(\Drupal::state()
->get('lingotek.uploaded_job_id'), 'my_custom_job_id');
$edit = [
'table[article]' => TRUE,
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'job_id' => 'other_job_id',
'update_tms' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('Job ID was assigned successfully.');
\Drupal::state()
->resetCache();
$this
->assertNull(\Drupal::state()
->get('lingotek.uploaded_title'));
$this
->assertNull(\Drupal::state()
->get('lingotek.uploaded_content'));
$this
->assertIdentical(\Drupal::state()
->get('lingotek.uploaded_job_id'), 'other_job_id');
}
public function testAssignJobIdsWithTMSUpdateWithADocumentArchivedError() {
$assert_session = $this
->assertSession();
$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
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/node_type/page?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[article]' => TRUE,
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'job_id' => 'my_custom_job_id',
'update_tms' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('Job ID was assigned successfully.');
\Drupal::state()
->resetCache();
$this
->assertNull(\Drupal::state()
->get('lingotek.uploaded_title'));
$this
->assertNull(\Drupal::state()
->get('lingotek.uploaded_content'));
$this
->assertNull(\Drupal::state()
->get('lingotek.uploaded_job_id'));
$this
->assertText('my_custom_job_id');
$this
->clickLink('EN');
$this
->assertText('Article uploaded successfully');
\Drupal::state()
->resetCache();
$this
->assertIdentical(\Drupal::state()
->get('lingotek.uploaded_job_id'), 'my_custom_job_id');
\Drupal::state()
->set('lingotek.must_document_archived_error_in_update', TRUE);
$edit = [
'table[article]' => TRUE,
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'job_id' => 'other_job_id',
'update_tms' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('Document node_type Article has been archived. Please upload again.');
$this
->assertText('Job ID for some config failed to sync to the TMS.');
\Drupal::state()
->resetCache();
$this
->assertEquals('my_custom_job_id', \Drupal::state()
->get('lingotek.uploaded_job_id'));
$this
->assertText('my_custom_job_id');
$this
->assertText('other_job_id');
}
public function testAssignJobIdsWithTMSUpdateWithADocumentLockedError() {
$assert_session = $this
->assertSession();
$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
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/node_type/page?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[article]' => TRUE,
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'job_id' => 'my_custom_job_id',
'update_tms' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('Job ID was assigned successfully.');
\Drupal::state()
->resetCache();
$this
->assertNull(\Drupal::state()
->get('lingotek.uploaded_title'));
$this
->assertNull(\Drupal::state()
->get('lingotek.uploaded_content'));
$this
->assertNull(\Drupal::state()
->get('lingotek.uploaded_job_id'));
$this
->assertText('my_custom_job_id');
$this
->clickLink('EN');
$this
->assertText('Article uploaded successfully');
\Drupal::state()
->resetCache();
$this
->assertIdentical(\Drupal::state()
->get('lingotek.uploaded_job_id'), 'my_custom_job_id');
\Drupal::state()
->set('lingotek.must_document_locked_error_in_update', TRUE);
$edit = [
'table[article]' => TRUE,
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'job_id' => 'other_job_id',
'update_tms' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('Document node_type Article has a new version. The document id has been updated for all future interactions. Please try again.');
$this
->assertText('Job ID for some config failed to sync to the TMS.');
\Drupal::state()
->resetCache();
$this
->assertEquals('my_custom_job_id', \Drupal::state()
->get('lingotek.uploaded_job_id'));
$this
->assertText('my_custom_job_id');
$this
->assertText('other_job_id');
}
public function testAssignJobIdsWithTMSUpdateWithAPaymentRequiredError() {
$assert_session = $this
->assertSession();
$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
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/node_type/page?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[article]' => TRUE,
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'job_id' => 'my_custom_job_id',
'update_tms' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('Job ID was assigned successfully.');
\Drupal::state()
->resetCache();
$this
->assertNull(\Drupal::state()
->get('lingotek.uploaded_title'));
$this
->assertNull(\Drupal::state()
->get('lingotek.uploaded_content'));
$this
->assertNull(\Drupal::state()
->get('lingotek.uploaded_job_id'));
$this
->assertText('my_custom_job_id');
$this
->clickLink('EN');
$this
->assertText('Article uploaded successfully');
\Drupal::state()
->resetCache();
$this
->assertIdentical(\Drupal::state()
->get('lingotek.uploaded_job_id'), 'my_custom_job_id');
\Drupal::state()
->set('lingotek.must_payment_required_error_in_update', TRUE);
$edit = [
'table[article]' => TRUE,
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'job_id' => 'other_job_id',
'update_tms' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('Community has been disabled. Please contact support@lingotek.com to re-enable your community.');
$this
->assertText('Job ID for some config failed to sync to the TMS.');
\Drupal::state()
->resetCache();
$this
->assertEquals('my_custom_job_id', \Drupal::state()
->get('lingotek.uploaded_job_id'));
$this
->assertText('my_custom_job_id');
$this
->assertText('other_job_id');
}
public function testAssignJobIdsWithTMSUpdateWithAnError() {
$assert_session = $this
->assertSession();
$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
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/node_type/page?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[article]' => TRUE,
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'job_id' => 'my_custom_job_id',
'update_tms' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('Job ID was assigned successfully.');
\Drupal::state()
->resetCache();
$this
->assertNull(\Drupal::state()
->get('lingotek.uploaded_title'));
$this
->assertNull(\Drupal::state()
->get('lingotek.uploaded_content'));
$this
->assertNull(\Drupal::state()
->get('lingotek.uploaded_job_id'));
$this
->assertText('my_custom_job_id');
$this
->clickLink('EN');
$this
->assertText('Article uploaded successfully');
\Drupal::state()
->resetCache();
$this
->assertIdentical(\Drupal::state()
->get('lingotek.uploaded_job_id'), 'my_custom_job_id');
\Drupal::state()
->set('lingotek.must_error_in_upload', TRUE);
$edit = [
'table[article]' => TRUE,
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'job_id' => 'other_job_id',
'update_tms' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('The Job ID change submission for node_type Article failed. Please try again.');
$this
->assertText('Job ID for some config failed to sync to the TMS.');
\Drupal::state()
->resetCache();
$this
->assertEquals('my_custom_job_id', \Drupal::state()
->get('lingotek.uploaded_job_id'));
$this
->assertText('my_custom_job_id');
$this
->assertText('other_job_id');
}
public function testAssignInvalidJobIdsWithTMSUpdate() {
$assert_session = $this
->assertSession();
$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
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/node_type/page?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('EN');
$edit = [
'table[article]' => TRUE,
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'job_id' => 'my\\invalid\\id',
'update_tms' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('The job ID name cannot contain invalid chars as "/" or "\\".');
$this
->assertNull(\Drupal::state()
->get('lingotek.uploaded_job_id'));
$edit = [
'job_id' => 'my/invalid/id',
'update_tms' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('The job ID name cannot contain invalid chars as "/" or "\\".');
$this
->assertNull(\Drupal::state()
->get('lingotek.uploaded_job_id'));
}
public function testCancelAssignJobIds() {
$assert_session = $this
->assertSession();
$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
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/node_type/page?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[article]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertText('Article content type');
$this
->assertNoText('Page content type');
$this
->drupalPostForm(NULL, [], 'Cancel');
$edit = [
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertNoText('Article content type');
$this
->assertText('Page content type');
}
public function testResetAssignJobIds() {
$assert_session = $this
->assertSession();
$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
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/node_type/page?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[article]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertText('Article content type');
$this
->assertNoText('Page content type');
$this
->goToConfigBulkManagementForm('node_type');
$edit = [
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertNoText('Article content type');
$this
->assertText('Page content type');
}
public function testClearJobIds() {
$assert_session = $this
->assertSession();
$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
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/node_type/page?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('EN');
$edit = [
'table[article]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'job_id' => 'my_custom_job_id_1',
'update_tms' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('Job ID was assigned successfully.');
$edit = [
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'job_id' => 'my_custom_job_id_2',
'update_tms' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('Job ID was assigned successfully.');
$this
->assertText('my_custom_job_id_1');
$this
->assertText('my_custom_job_id_2');
$edit = [
'table[article]' => TRUE,
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForClearJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->drupalPostForm(NULL, [], 'Clear Job ID');
$this
->assertText('Job ID was cleared successfully.');
\Drupal::state()
->resetCache();
$this
->assertEquals('my_custom_job_id_1', \Drupal::state()
->get('lingotek.uploaded_job_id'));
$this
->assertNoText('my_custom_job_id_1');
$this
->assertNoText('my_custom_job_id_2');
}
public function testClearJobIdsWithTMSUpdate() {
$assert_session = $this
->assertSession();
$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
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/node_type/page?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('EN');
$edit = [
'table[article]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'job_id' => 'my_custom_job_id_1',
'update_tms' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('Job ID was assigned successfully.');
$edit = [
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'job_id' => 'my_custom_job_id_2',
'update_tms' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('Job ID was assigned successfully.');
$this
->assertText('my_custom_job_id_1');
$this
->assertText('my_custom_job_id_2');
$edit = [
'table[article]' => TRUE,
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForClearJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->drupalPostForm(NULL, [
'update_tms' => 1,
], 'Clear Job ID');
$this
->assertText('Job ID was cleared successfully.');
\Drupal::state()
->resetCache();
$this
->assertEquals('', \Drupal::state()
->get('lingotek.uploaded_job_id'));
$this
->assertNoText('my_custom_job_id_1');
$this
->assertNoText('my_custom_job_id_2');
}
public function testClearJobIdsWithTMSUpdateWithAnError() {
$assert_session = $this
->assertSession();
$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
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/node_type/page?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('EN');
$edit = [
'table[article]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'job_id' => 'my_custom_job_id_1',
'update_tms' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('Job ID was assigned successfully.');
$edit = [
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'job_id' => 'my_custom_job_id_2',
'update_tms' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('Job ID was assigned successfully.');
$this
->assertText('my_custom_job_id_1');
$this
->assertText('my_custom_job_id_2');
\Drupal::state()
->set('lingotek.must_error_in_upload', TRUE);
$edit = [
'table[article]' => TRUE,
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForClearJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->drupalPostForm(NULL, [
'update_tms' => 1,
], 'Clear Job ID');
$this
->assertText('The Job ID change submission for node_type Article failed. Please try again.');
$this
->assertText('Job ID for some config failed to sync to the TMS.');
\Drupal::state()
->resetCache();
$this
->assertEquals('my_custom_job_id_1', \Drupal::state()
->get('lingotek.uploaded_job_id'));
$this
->assertText('my_custom_job_id_1');
$this
->assertNoText('my_custom_job_id_2');
}
public function testClearJobIdsWithTMSUpdateWithADocumentArchivedError() {
$assert_session = $this
->assertSession();
$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
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/node_type/page?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('EN');
$edit = [
'table[article]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'job_id' => 'my_custom_job_id_1',
'update_tms' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('Job ID was assigned successfully.');
$edit = [
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'job_id' => 'my_custom_job_id_2',
'update_tms' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('Job ID was assigned successfully.');
$this
->assertText('my_custom_job_id_1');
$this
->assertText('my_custom_job_id_2');
\Drupal::state()
->set('lingotek.must_document_archived_error_in_update', TRUE);
$edit = [
'table[article]' => TRUE,
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForClearJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->drupalPostForm(NULL, [
'update_tms' => 1,
], 'Clear Job ID');
$this
->assertText('Document node_type Article has been archived. Please upload again.');
$this
->assertText('Job ID for some config failed to sync to the TMS.');
\Drupal::state()
->resetCache();
$this
->assertEquals('my_custom_job_id_1', \Drupal::state()
->get('lingotek.uploaded_job_id'));
$this
->assertText('my_custom_job_id_1');
$this
->assertNoText('my_custom_job_id_2');
}
public function testClearJobIdsWithTMSUpdateWithADocumentLockedError() {
$assert_session = $this
->assertSession();
$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
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/node_type/page?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('EN');
$edit = [
'table[article]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'job_id' => 'my_custom_job_id_1',
'update_tms' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('Job ID was assigned successfully.');
$edit = [
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'job_id' => 'my_custom_job_id_2',
'update_tms' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('Job ID was assigned successfully.');
$this
->assertText('my_custom_job_id_1');
$this
->assertText('my_custom_job_id_2');
\Drupal::state()
->set('lingotek.must_document_locked_error_in_update', TRUE);
$edit = [
'table[article]' => TRUE,
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForClearJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->drupalPostForm(NULL, [
'update_tms' => 1,
], 'Clear Job ID');
$this
->assertText('Document node_type Article has a new version. The document id has been updated for all future interactions. Please try again.');
$this
->assertText('Job ID for some config failed to sync to the TMS.');
\Drupal::state()
->resetCache();
$this
->assertEquals('my_custom_job_id_1', \Drupal::state()
->get('lingotek.uploaded_job_id'));
$this
->assertText('my_custom_job_id_1');
$this
->assertNoText('my_custom_job_id_2');
}
public function testClearJobIdsWithTMSUpdateWithAPaymentRequiredError() {
$assert_session = $this
->assertSession();
$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
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/node_type/page?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('EN');
$edit = [
'table[article]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'job_id' => 'my_custom_job_id_1',
'update_tms' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('Job ID was assigned successfully.');
$edit = [
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForAssignJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'job_id' => 'my_custom_job_id_2',
'update_tms' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Assign Job ID');
$this
->assertText('Job ID was assigned successfully.');
$this
->assertText('my_custom_job_id_1');
$this
->assertText('my_custom_job_id_2');
\Drupal::state()
->set('lingotek.must_error_in_upload', TRUE);
$edit = [
'table[article]' => TRUE,
'table[page]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForClearJobId('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->drupalPostForm(NULL, [
'update_tms' => 1,
], 'Clear Job ID');
$this
->assertText('The Job ID change submission for node_type Article failed. Please try again.');
$this
->assertText('Job ID for some config failed to sync to the TMS.');
\Drupal::state()
->resetCache();
$this
->assertEquals('my_custom_job_id_1', \Drupal::state()
->get('lingotek.uploaded_job_id'));
$this
->assertText('my_custom_job_id_1');
$this
->assertNoText('my_custom_job_id_2');
}
public function testJobIdFilter() {
$assert_session = $this
->assertSession();
\Drupal::configFactory()
->getEditable('lingotek.settings')
->set('translate.config.node_type.profile', 'manual')
->save();
$basepath = \Drupal::request()
->getBasePath();
$node_types = [];
$indexes = "ABCDEFGHIJKLMNOPQ";
for ($i = 1; $i < 10; $i++) {
$node_types[$i] = $this
->drupalCreateContentType([
'type' => 'content_type_' . $i,
'name' => 'Content Type ' . $indexes[$i],
]);
}
$this
->goToConfigBulkManagementForm('node_type');
$this
->assertNoText('No content available');
$edit = [
'filters[wrapper][job]' => 'this job does not exist',
];
$this
->drupalPostForm(NULL, $edit, 'edit-filters-actions-submit');
$this
->assertText('No content available');
$this
->drupalPostForm(NULL, [], 'Reset');
$this
->goToConfigBulkManagementForm('node_type');
foreach (range(1, 9) as $j) {
$this
->assertText('Content Type ' . $indexes[$j]);
}
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/node_type/article?destination=' . $basepath . '/admin/lingotek/config/manage');
$edit = [
'table[content_type_2]' => TRUE,
'table[content_type_4]' => TRUE,
'table[content_type_6]' => TRUE,
'table[content_type_8]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForUpload('node_type'),
'job_id' => 'even numbers',
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'table[content_type_1]' => TRUE,
'table[content_type_2]' => TRUE,
'table[content_type_3]' => TRUE,
'table[content_type_5]' => TRUE,
'table[content_type_7]' => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForUpload('node_type'),
'job_id' => 'prime numbers',
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$edit = [
'filters[wrapper][job]' => 'prime',
];
$this
->drupalPostForm(NULL, $edit, 'edit-filters-actions-submit');
foreach ([
1,
2,
3,
5,
7,
] as $j) {
$this
->assertText('Content Type ' . $indexes[$j]);
}
$this
->assertNoText('Content Type ' . $indexes[4]);
$this
->assertNoText('Content Type ' . $indexes[6]);
$edit = [
'filters[wrapper][job]' => 'even',
];
$this
->drupalPostForm(NULL, $edit, 'edit-filters-actions-submit');
foreach ([
4,
6,
8,
] as $j) {
$this
->assertText('Content Type ' . $indexes[$j]);
}
$this
->assertNoText('Content Type ' . $indexes[5]);
$this
->drupalPostForm(NULL, [], 'Reset');
$this
->goToConfigBulkManagementForm('node_type');
foreach (range(1, 9) as $j) {
$this
->assertText('Content Type ' . $indexes[$j]);
}
}
public function testLabelFilter() {
$assert_session = $this
->assertSession();
$this
->goToConfigBulkManagementForm();
$this
->assertNoField('filters[wrapper][label]');
\Drupal::configFactory()
->getEditable('lingotek.settings')
->set('translate.config.node_type.profile', 'manual')
->save();
$node_types = [];
$indexes = "ABCDEFGHIJKLMNOPQ";
for ($i = 1; $i < 10; $i++) {
$odd_index = $i % 2 == 0;
$name = 'Content Type ' . $indexes[$i] . ' ' . ($odd_index ? 'odd' : 'even');
$node_types[$i] = $this
->drupalCreateContentType([
'type' => 'content_type_' . $i,
'name' => $name,
]);
}
$this
->goToConfigBulkManagementForm('node_type');
$this
->assertField('filters[wrapper][label]');
$this
->assertNoText('No content available');
$edit = [
'filters[wrapper][label]' => 'this label does not exist',
];
$this
->drupalPostForm(NULL, $edit, 'edit-filters-actions-submit');
$this
->assertText('No content available');
$this
->drupalPostForm(NULL, [], 'Reset');
$this
->goToConfigBulkManagementForm('node_type');
foreach (range(1, 9) as $j) {
$this
->assertText('Content Type ' . $indexes[$j]);
}
$edit = [
'filters[wrapper][label]' => 'even',
];
$this
->drupalPostForm(NULL, $edit, 'edit-filters-actions-submit');
foreach ([
1,
3,
5,
7,
9,
] as $j) {
$this
->assertText('Content Type ' . $indexes[$j]);
}
$this
->assertNoText('Content Type ' . $indexes[2]);
$this
->assertNoText('Content Type ' . $indexes[4]);
$this
->assertNoText('Content Type ' . $indexes[6]);
$edit = [
'filters[wrapper][label]' => 'odd',
];
$this
->drupalPostForm(NULL, $edit, 'edit-filters-actions-submit');
foreach ([
2,
4,
6,
8,
] as $j) {
$this
->assertText('Content Type ' . $indexes[$j]);
}
$this
->assertNoText('Content Type ' . $indexes[1]);
$this
->assertNoText('Content Type ' . $indexes[3]);
$this
->assertNoText('Content Type ' . $indexes[5]);
$this
->drupalPostForm(NULL, [], 'Reset');
$this
->goToConfigBulkManagementForm('node_type');
foreach (range(1, 9) as $j) {
$this
->assertText('Content Type ' . $indexes[$j]);
}
$edit = [
'filters[wrapper][label]' => ' even ',
];
$this
->drupalPostForm(NULL, $edit, 'edit-filters-actions-submit');
foreach ([
1,
3,
5,
7,
9,
] as $j) {
$this
->assertText('Content Type ' . $indexes[$j]);
}
$this
->assertFieldByName('filters[wrapper][label]', 'even', 'The value is trimmed in the filter.');
}
public function testLabelsAndLinksWhenAvailable() {
$assert_session = $this
->assertSession();
$this
->goToConfigBulkManagementForm();
$this
->assertText('System maintenance');
$assert_session
->linkNotExists('System maintenance');
$this
->goToConfigBulkManagementForm('configurable_language');
$assert_session
->linkExists('Spanish language');
}
}