View source
<?php
namespace Drupal\lingotek\Tests;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\lingotek\Lingotek;
use Drupal\lingotek\LingotekConfigTranslationServiceInterface;
class LingotekSystemSiteBulkDisassociateTest extends LingotekTestBase {
public static $modules = [
'block',
'node',
];
protected function setUp() {
parent::setUp();
ConfigurableLanguage::createFromLangcode('es')
->save();
}
public function testSystemSiteDisassociate() {
\Drupal::state()
->set('lingotek.uploaded_content_type', 'system.site');
$this
->drupalLogin($this->rootUser);
$this
->createAndTranslateSystemSiteWithLinks();
$this
->goToConfigBulkManagementForm();
$edit = [
'table[system.site_information_settings]' => TRUE,
'operation' => 'disassociate',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$config_translation_service = \Drupal::service('lingotek.config_translation');
$mappers = \Drupal::service('plugin.manager.config_translation.mapper')
->getMappers();
$mapper = $mappers['system.site_information_settings'];
$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
->getConfigDocumentId($mapper));
$this
->assertIdentical(Lingotek::STATUS_UNTRACKED, $config_translation_service
->getConfigSourceStatus($mapper));
$this
->createAndTranslateSystemSiteWithLinks();
}
public function testSystemSiteDisassociateWithRemovalOfRemoteDocument() {
\Drupal::state()
->set('lingotek.uploaded_content_type', 'system.site');
$edit = [
'delete_tms_documents_upon_disassociation' => TRUE,
];
$this
->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-preferences-form');
$this
->createAndTranslateSystemSiteWithLinks();
$this
->goToConfigBulkManagementForm();
$edit = [
'table[system.site_information_settings]' => TRUE,
'operation' => 'disassociate',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$config_translation_service = \Drupal::service('lingotek.config_translation');
$mappers = \Drupal::service('plugin.manager.config_translation.mapper')
->getMappers();
$mapper = $mappers['system.site_information_settings'];
$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
->getConfigDocumentId($mapper));
$this
->assertIdentical(Lingotek::STATUS_UNTRACKED, $config_translation_service
->getConfigSourceStatus($mapper));
$this
->createAndTranslateSystemSiteWithLinks();
}
protected function createAndTranslateSystemSiteWithLinks() {
$this
->goToConfigBulkManagementForm();
$this
->clickLink('EN', 1);
$this
->assertText(t('System information uploaded successfully'));
$this
->clickLink('EN', 1);
$this
->assertText('System information status checked successfully');
$this
->clickLink('ES');
$this
->assertText("Translation to es_ES requested successfully");
$this
->clickLink('ES');
$this
->assertText("Translation to es_ES checked successfully");
$this
->clickLink('ES');
$this
->assertText('Translation to es_ES downloaded successfully');
}
}