View source
<?php
namespace Drupal\lingotek\Tests;
use Drupal\content_translation\ContentTranslationManagerInterface;
use Drupal\Core\Url;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\lingotek\Lingotek;
use Drupal\lingotek\LingotekContentTranslationServiceInterface;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
class LingotekNodeBulkDisassociateTest extends LingotekTestBase {
public static $modules = [
'block',
'node',
];
protected function setUp() {
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::entityManager()
->clearCachedDefinitions();
\Drupal::service('entity.definition_update_manager')
->applyUpdates();
$this
->rebuildContainer();
$edit = [
'node[article][enabled]' => 1,
'node[article][profiles]' => 'automatic',
'node[article][fields][title]' => 1,
'node[article][fields][body]' => 1,
];
$this
->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-content-form');
}
public function testNodeDisassociate() {
$this
->drupalLogin($this->rootUser);
$edit = array();
$edit['title[0][value]'] = 'Llamas are cool';
$edit['body[0][value]'] = 'Llamas are very cool';
$edit['langcode[0][value]'] = 'en';
$edit['lingotek_translation_profile'] = 'manual';
$this
->drupalPostForm('node/add/article', $edit, t('Save and publish'));
$this
->createAndTranslateNodeWithLinks();
$this
->goToContentBulkManagementForm();
$edit = [
'table[1]' => TRUE,
'operation' => 'disassociate',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$node = Node::load(1);
$content_translation_service = \Drupal::service('lingotek.content_translation');
$deleted_docs = \Drupal::state()
->get('lingotek.deleted_docs', []);
$this
->assertEqual(0, count($deleted_docs), 'No document has been deleted remotely because the module is not configured to perform the operation.');
$this
->assertNull($content_translation_service
->getDocumentId($node));
$this
->assertIdentical(Lingotek::STATUS_UNTRACKED, $content_translation_service
->getSourceStatus($node));
$this
->createAndTranslateNodeWithLinks();
}
public function testNodeDisassociateWithRemovalOfRemoteDocument() {
$edit = [
'delete_tms_documents_upon_disassociation' => TRUE,
];
$this
->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-preferences-form');
$edit = array();
$edit['title[0][value]'] = 'Llamas are cool';
$edit['body[0][value]'] = 'Llamas are very cool';
$edit['langcode[0][value]'] = 'en';
$edit['lingotek_translation_profile'] = 'manual';
$this
->drupalPostForm('node/add/article', $edit, t('Save and publish'));
$this
->createAndTranslateNodeWithLinks();
$this
->goToContentBulkManagementForm();
$edit = [
'table[1]' => TRUE,
'operation' => 'disassociate',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$node = Node::load(1);
$deleted_docs = \Drupal::state()
->get('lingotek.deleted_docs', []);
$this
->assertEqual(1, count($deleted_docs), 'The document has been deleted remotely.');
$content_translation_service = \Drupal::service('lingotek.content_translation');
$this
->assertNull($content_translation_service
->getDocumentId($node));
$this
->assertIdentical(Lingotek::STATUS_UNTRACKED, $content_translation_service
->getSourceStatus($node));
$this
->createAndTranslateNodeWithLinks();
}
protected function createAndTranslateNodeWithLinks() {
$this
->goToContentBulkManagementForm();
$basepath = \Drupal::request()
->getBasePath();
$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.');
}
}