View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\lingotek\Lingotek;
use Drupal\node\Entity\Node;
class LingotekNodeBulkCancelTest extends LingotekTestBase {
public static $modules = [
'block',
'node',
];
protected function setUp() : void {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
ConfigurableLanguage::createFromLangcode('es')
->save();
ContentLanguageSettings::loadByEntityTypeBundle('node', 'article')
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('node', 'article', TRUE);
drupal_static_reset();
\Drupal::entityTypeManager()
->clearCachedDefinitions();
$this
->applyEntityUpdates();
$this
->rebuildContainer();
$this
->saveLingotekContentTranslationSettingsForNodeTypes();
}
public function testNodeCancel() {
$this
->drupalLogin($this->rootUser);
$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
->createAndTranslateNodeWithLinks();
$this
->goToContentBulkManagementForm();
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCancel('node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$content_translation_service = \Drupal::service('lingotek.content_translation');
$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.');
$node = Node::load(1);
$this
->assertNull($content_translation_service
->getDocumentId($node));
$this
->assertSourceStatus('EN', Lingotek::STATUS_CANCELLED);
$this
->assertTargetStatus('ES', Lingotek::STATUS_CANCELLED);
$this
->assertIdentical(Lingotek::STATUS_CANCELLED, $content_translation_service
->getSourceStatus($node));
$this
->assertIdentical(Lingotek::STATUS_CANCELLED, $content_translation_service
->getTargetStatus($node, 'es'));
$this
->assertLingotekUploadLink();
$this
->assertNoLingotekRequestTranslationLink('es_ES');
$this
->createAndTranslateNodeWithLinks();
}
public function testNodeCancelTarget() {
$this
->drupalLogin($this->rootUser);
$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
->createAndTranslateNodeWithLinks();
$this
->goToContentBulkManagementForm();
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCancelTarget('es', 'node'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$content_translation_service = \Drupal::service('lingotek.content_translation');
$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.');
$entity = Node::load(1);
$this
->assertEquals('dummy-document-hash-id', $content_translation_service
->getDocumentId($entity));
$this
->assertSourceStatus('EN', Lingotek::STATUS_CURRENT);
$this
->assertTargetStatus('ES', Lingotek::STATUS_CANCELLED);
$this
->assertIdentical(Lingotek::STATUS_CURRENT, $content_translation_service
->getSourceStatus($entity));
$this
->assertIdentical(Lingotek::STATUS_CANCELLED, $content_translation_service
->getTargetStatus($entity, 'es'));
$this
->assertNoLingotekRequestTranslationLink('es_ES');
}
protected function createAndTranslateNodeWithLinks() {
$this
->goToContentBulkManagementForm();
$this
->clickLink('EN');
$this
->assertText('Node Llamas are cool has been uploaded.');
$this
->clickLink('EN');
$this
->assertText('The import for node Llamas are cool is complete.');
$this
->clickLink('ES');
$this
->assertText("Locale 'es_ES' was added as a translation target for node Llamas are cool.");
$this
->clickLink('ES');
$this
->assertText('The es_ES translation for node Llamas are cool is ready for download.');
$this
->clickLink('ES');
$this
->assertText('The translation of node Llamas are cool into es_ES has been downloaded.');
}
}