View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\lingotek\Lingotek;
class LingotekSystemSiteBulkCancelTest extends LingotekTestBase {
public static $modules = [
'block',
'node',
];
protected function setUp() : void {
parent::setUp();
ConfigurableLanguage::createFromLangcode('es')
->save();
}
public function testSystemSiteCancellation() {
$assert_session = $this
->assertSession();
\Drupal::state()
->set('lingotek.uploaded_content_type', 'system.site');
$this
->drupalLogin($this->rootUser);
$this
->createAndTranslateSystemSiteWithLinks();
$this
->goToConfigBulkManagementForm();
$edit = [
'table[system.site_information_settings]' => TRUE,
$this
->getBulkOperationFormName() => 'cancel',
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$config_translation_service = \Drupal::service('lingotek.config_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.');
$mappers = \Drupal::service('plugin.manager.config_translation.mapper')
->getMappers();
$mapper = $mappers['system.site_information_settings'];
$this
->assertNull($config_translation_service
->getConfigDocumentId($mapper));
$this
->assertSourceStatus('EN', Lingotek::STATUS_CANCELLED);
$this
->assertTargetStatus('ES', Lingotek::STATUS_CANCELLED);
$this
->assertIdentical(Lingotek::STATUS_CANCELLED, $config_translation_service
->getConfigSourceStatus($mapper));
$this
->assertIdentical(Lingotek::STATUS_CANCELLED, $config_translation_service
->getConfigTargetStatus($mapper, 'es'));
$basepath = \Drupal::request()
->getBasePath();
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/system.site_information_settings/system.site_information_settings?destination=' . $basepath . '/admin/lingotek/config/manage');
$assert_session
->linkByHrefNotExists($basepath . '/admin/lingotek/config/request/system.site_information_settings/system.site_information_settings/es_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->createAndTranslateSystemSiteWithLinks();
}
public function testSystemSiteCancelTarget() {
$assert_session = $this
->assertSession();
\Drupal::state()
->set('lingotek.uploaded_content_type', 'system.site');
$this
->drupalLogin($this->rootUser);
$this
->createAndTranslateSystemSiteWithLinks();
$this
->goToConfigBulkManagementForm();
$edit = [
'table[system.site_information_settings]' => TRUE,
$this
->getBulkOperationFormName() => 'cancel:es',
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$config_translation_service = \Drupal::service('lingotek.config_translation');
$mappers = \Drupal::service('plugin.manager.config_translation.mapper')
->getMappers();
$mapper = $mappers['system.site_information_settings'];
$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
->getConfigDocumentId($mapper));
$this
->assertSourceStatus('EN', Lingotek::STATUS_CURRENT);
$this
->assertTargetStatus('ES', Lingotek::STATUS_CANCELLED);
$this
->assertIdentical(Lingotek::STATUS_CURRENT, $config_translation_service
->getConfigSourceStatus($mapper));
$this
->assertIdentical(Lingotek::STATUS_CANCELLED, $config_translation_service
->getConfigTargetStatus($mapper, 'es'));
$basepath = \Drupal::request()
->getBasePath();
$assert_session
->linkByHrefNotExists($basepath . '/admin/lingotek/config/request/system.site_information_settings/system.site_information_settings/es_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
}
protected function createAndTranslateSystemSiteWithLinks() {
$assert_session = $this
->assertSession();
$this
->goToConfigBulkManagementForm();
$basepath = \Drupal::request()
->getBasePath();
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/upload/system.site_information_settings/system.site_information_settings?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('EN', 1);
$this
->assertText(t('System information uploaded successfully'));
$this
->clickLink('EN', 1);
$this
->assertText('System information status checked successfully');
$assert_session
->linkByHrefExists($basepath . '/admin/lingotek/config/request/system.site_information_settings/system.site_information_settings/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 checked successfully");
$this
->clickLink('ES');
$this
->assertText('Translation to es_ES downloaded successfully');
}
}