View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\lingotek\Lingotek;
class LingotekFieldBodyBulkCancelTest 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')
->save();
$this
->drupalGet('admin/lingotek/settings');
$edit = [
'table[node_fields][enabled]' => 1,
'table[node_fields][profile]' => 'automatic',
];
$this
->submitForm($edit, 'Save', 'lingoteksettings-tab-configuration-form');
\Drupal::state()
->set('lingotek.uploaded_content_type', 'body');
}
public function testFieldCancel() {
$assert_session = $this
->assertSession();
$this
->drupalLogin($this->rootUser);
$this
->createAndTranslateFieldWithLinks();
$edit = [
'table[node.article.body]' => 'node.article.body',
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCancel('node_fields'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$config_translation_service = \Drupal::service('lingotek.config_translation');
\Drupal::entityTypeManager()
->getStorage('field_config')
->resetCache();
$entity = \Drupal::entityTypeManager()
->getStorage('field_config')
->load('node.article.body');
$cancelled_docs = \Drupal::state()
->get('lingotek.cancelled_docs', []);
$this
->assertEqual(1, count($cancelled_docs), 'The document has been cancelled remotely.');
$deleted_docs = \Drupal::state()
->get('lingotek.deleted_docs', []);
$this
->assertEqual(0, count($deleted_docs), 'No document has been deleted remotely.');
$this
->assertNull($config_translation_service
->getDocumentId($entity));
$this
->assertSourceStatus('EN', Lingotek::STATUS_CANCELLED);
$this
->assertTargetStatus('ES', Lingotek::STATUS_CANCELLED);
\Drupal::entityTypeManager()
->getStorage('field_config')
->resetCache();
$entity = \Drupal::entityTypeManager()
->getStorage('field_config')
->load('node.article.body');
$this
->assertIdentical(Lingotek::STATUS_CANCELLED, $config_translation_service
->getSourceStatus($entity));
$this
->assertIdentical(Lingotek::STATUS_CANCELLED, $config_translation_service
->getTargetStatus($entity, 'es'));
$basepath = \Drupal::request()
->getBasePath();
$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_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->createAndTranslateFieldWithLinks();
}
public function testFieldCancelTarget() {
$assert_session = $this
->assertSession();
$this
->drupalLogin($this->rootUser);
$this
->createAndTranslateFieldWithLinks();
$edit = [
'table[node.article.body]' => 'node.article.body',
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCancelTarget('es', 'node_fields'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$config_translation_service = \Drupal::service('lingotek.config_translation');
\Drupal::entityTypeManager()
->getStorage('field_config')
->resetCache();
$entity = \Drupal::entityTypeManager()
->getStorage('field_config')
->load('node.article.body');
$cancelled_locales = \Drupal::state()
->get('lingotek.cancelled_locales', []);
$this
->assertTrue(isset($cancelled_locales['dummy-document-hash-id']) && in_array('es_ES', $cancelled_locales['dummy-document-hash-id']), 'The document target has been cancelled remotely.');
$this
->assertEquals('dummy-document-hash-id', $config_translation_service
->getDocumentId($entity));
$this
->assertSourceStatus('EN', Lingotek::STATUS_CURRENT);
$this
->assertTargetStatus('ES', Lingotek::STATUS_CANCELLED);
$this
->assertIdentical(Lingotek::STATUS_CURRENT, $config_translation_service
->getSourceStatus($entity));
$this
->assertIdentical(Lingotek::STATUS_CANCELLED, $config_translation_service
->getTargetStatus($entity, 'es'));
$basepath = \Drupal::request()
->getBasePath();
$assert_session
->linkByHrefNotExists($basepath . '/admin/lingotek/config/request/node_type/article/es_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
}
protected function createAndTranslateFieldWithLinks() {
$assert_session = $this
->assertSession();
$this
->goToConfigBulkManagementForm('node_fields');
$basepath = \Drupal::request()
->getBasePath();
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/field_config/node.article.body?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('EN');
$this
->assertText(t('Body uploaded successfully'));
$this
->clickLink('EN');
$this
->assertText('Body status checked successfully');
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/request/field_config/node.article.body/es_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('ES');
$this
->assertText("Translation to es_ES requested successfully");
$this
->clickLink('ES');
$this
->assertText("Translation to es_ES status checked successfully");
$this
->clickLink('ES');
$this
->assertText('Translation to es_ES downloaded successfully');
}
}