You are here

public function LingotekUtilitiesDisassociateAllDocumentsTest::testDisassociateAllDocuments in Lingotek Translation 8

File

src/Tests/LingotekUtilitiesDisassociateAllDocumentsTest.php, line 179

Class

LingotekUtilitiesDisassociateAllDocumentsTest
Tests disassociating all site documents.

Namespace

Drupal\lingotek\Tests

Code

public function testDisassociateAllDocuments() {
  $this
    ->drupalGet('/admin/lingotek/settings');
  $this
    ->drupalPostForm('admin/lingotek/settings', [], 'Disassociate');
  $node = Node::load(1);
  $term = Term::load(1);

  /** @var LingotekContentTranslationServiceInterface $content_translation_service */
  $content_translation_service = \Drupal::service('lingotek.content_translation');

  /** @var \Drupal\lingotek\LingotekConfigTranslationServiceInterface $config_translation_service */
  $config_translation_service = \Drupal::service('lingotek.config_translation');

  // Ensure we have disassociated the node.
  $this
    ->assertNull($content_translation_service
    ->getDocumentId($node), 'The node has been disassociated from its Lingotek Document ID');
  $this
    ->assertIdentical(Lingotek::STATUS_UNTRACKED, $content_translation_service
    ->getSourceStatus($node));

  // Ensure we have disassociated the term.
  $this
    ->assertNull($content_translation_service
    ->getDocumentId($term), 'The term has been disassociated from its Lingotek Document ID');
  $this
    ->assertIdentical(Lingotek::STATUS_UNTRACKED, $content_translation_service
    ->getSourceStatus($term));

  // Ensure we are disassociated the article type.
  $article_type = \Drupal::entityManager()
    ->getStorage('node_type')
    ->load('article');
  $this
    ->assertNull($config_translation_service
    ->getDocumentId($article_type), 'The article node type has been disassociated from its Lingotek Document ID');
  $this
    ->assertIdentical(Lingotek::STATUS_UNTRACKED, $config_translation_service
    ->getSourceStatus($article_type));

  // Ensure we are disassociated the config system.site.
  $mappers = \Drupal::service('plugin.manager.config_translation.mapper')
    ->getMappers();
  $mapper = $mappers['system.site_information_settings'];
  $this
    ->assertNull($config_translation_service
    ->getConfigDocumentId($mapper), 'The system.site config mapper has been disassociated from its Lingotek Document ID');
  $this
    ->assertIdentical(Lingotek::STATUS_UNTRACKED, $config_translation_service
    ->getConfigSourceStatus($mapper));

  // Ensure the UIs show the right statuses.
  $this
    ->goToContentBulkManagementForm('node');
  $this
    ->assertSourceStatusStateCount(Lingotek::STATUS_UNTRACKED, 'EN', 1, 'The node shows as untracked');
  $this
    ->goToContentBulkManagementForm('taxonomy_term');
  $this
    ->assertSourceStatusStateCount(Lingotek::STATUS_UNTRACKED, 'EN', 1, 'The taxonomy term shows as untracked');
  $this
    ->goToConfigBulkManagementForm('config');

  // We have 4 configuration objects.
  $this
    ->assertSourceStatusStateCount(Lingotek::STATUS_UNTRACKED, 'EN', 4, 'The configuration shows as untracked');
  $this
    ->goToConfigBulkManagementForm('node_type');
  $this
    ->assertSourceStatusStateCount(Lingotek::STATUS_UNTRACKED, 'EN', 1, 'The article type shows as untracked');
}