View source
<?php
namespace Drupal\lingotek\Tests;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\lingotek\Lingotek;
use Drupal\lingotek\LingotekConfigTranslationServiceInterface;
class LingotekContentTypeBulkDisassociateTest extends LingotekTestBase {
public static $modules = [
'block',
'node',
];
protected function setUp() {
parent::setUp();
$this
->drupalCreateContentType(array(
'type' => 'article',
'name' => 'Article',
));
ConfigurableLanguage::createFromLangcode('es')
->save();
$edit = [
'table[node_type][enabled]' => 1,
'table[node_type][profile]' => 'automatic',
];
$this
->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-configuration-form');
}
public function testContentTypeDisassociate() {
\Drupal::state()
->set('lingotek.uploaded_content_type', 'content_type');
$this
->drupalLogin($this->rootUser);
$this
->createAndTranslateContentTypeWithLinks();
$edit = [
'table[article]' => 'article',
'operation' => 'disassociate',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$config_translation_service = \Drupal::service('lingotek.config_translation');
\Drupal::entityManager()
->getStorage('node_type')
->resetCache();
$entity = \Drupal::entityManager()
->getStorage('node_type')
->load('article');
$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($config_translation_service
->getDocumentId($entity));
$this
->assertIdentical(Lingotek::STATUS_UNTRACKED, $config_translation_service
->getSourceStatus($entity));
$this
->createAndTranslateContentTypeWithLinks();
}
public function testContentTypeDisassociateWithRemovalOfRemoteDocument() {
\Drupal::state()
->set('lingotek.uploaded_content_type', 'content_type');
$edit = [
'delete_tms_documents_upon_disassociation' => TRUE,
];
$this
->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-preferences-form');
$this
->createAndTranslateContentTypeWithLinks();
$edit = [
'table[article]' => 'article',
'operation' => 'disassociate',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$config_translation_service = \Drupal::service('lingotek.config_translation');
\Drupal::entityManager()
->getStorage('node_type')
->resetCache();
$entity = \Drupal::entityManager()
->getStorage('node_type')
->load('article');
$deleted_docs = \Drupal::state()
->get('lingotek.deleted_docs', []);
$this
->assertEqual(1, count($deleted_docs), 'The document has been deleted remotely.');
$this
->assertNull($config_translation_service
->getDocumentId($entity));
$this
->assertIdentical(Lingotek::STATUS_UNTRACKED, $config_translation_service
->getSourceStatus($entity));
$this
->createAndTranslateContentTypeWithLinks();
}
protected function createAndTranslateContentTypeWithLinks() {
$this
->goToConfigBulkManagementForm('node_type');
$this
->clickLink('EN');
$this
->assertText(t('Article uploaded successfully'));
$this
->clickLink('EN');
$this
->assertText('Article status checked successfully');
$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');
}
}