You are here

public function LingotekSystemSiteBulkDisassociateTest::testSystemSiteDisassociateWithRemovalOfRemoteDocument in Lingotek Translation 8

Tests that a config entity can be disassociated using the bulk operations on the management page.

File

src/Tests/LingotekSystemSiteBulkDisassociateTest.php, line 72

Class

LingotekSystemSiteBulkDisassociateTest
Tests translating config using the bulk management form.

Namespace

Drupal\lingotek\Tests

Code

public function testSystemSiteDisassociateWithRemovalOfRemoteDocument() {

  // This is a hack for avoiding writing different lingotek endpoint mocks.
  \Drupal::state()
    ->set('lingotek.uploaded_content_type', 'system.site');

  // Enable remote delete while disassociating.
  $edit = [
    'delete_tms_documents_upon_disassociation' => TRUE,
  ];
  $this
    ->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-preferences-form');
  $this
    ->createAndTranslateSystemSiteWithLinks();

  // Go to the bulk config management page.
  $this
    ->goToConfigBulkManagementForm();

  // Mark the first two for disassociation.
  $edit = [
    'table[system.site_information_settings]' => TRUE,
    // System information.
    'operation' => 'disassociate',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Execute'));

  /** @var LingotekConfigTranslationServiceInterface $config_translation_service */
  $config_translation_service = \Drupal::service('lingotek.config_translation');
  $mappers = \Drupal::service('plugin.manager.config_translation.mapper')
    ->getMappers();
  $mapper = $mappers['system.site_information_settings'];

  // Assert that the document has been deleted remotely.
  $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));

  // We can request again.
  $this
    ->createAndTranslateSystemSiteWithLinks();
}