You are here

public function LingotekFieldBodyBulkDisassociateTest::testFieldDisassociateWithRemovalOfRemoteDocument in Lingotek Translation 8

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

File

src/Tests/LingotekFieldBodyBulkDisassociateTest.php, line 82

Class

LingotekFieldBodyBulkDisassociateTest
Tests disassociating a field using the bulk management form.

Namespace

Drupal\lingotek\Tests

Code

public function testFieldDisassociateWithRemovalOfRemoteDocument() {

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

  // Mark the first for disassociation.
  $edit = [
    'table[node.article.body]' => 'node.article.body',
    // Article.
    'operation' => 'disassociate',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Execute'));

  /** @var \Drupal\lingotek\LingotekConfigTranslationServiceInterface $config_translation_service */
  $config_translation_service = \Drupal::service('lingotek.config_translation');
  \Drupal::entityManager()
    ->getStorage('field_config')
    ->resetCache();
  $entity = \Drupal::entityManager()
    ->getStorage('field_config')
    ->load('node.article.body');

  // 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
    ->getDocumentId($entity));
  $this
    ->assertIdentical(Lingotek::STATUS_UNTRACKED, $config_translation_service
    ->getSourceStatus($entity));

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