You are here

public function LingotekFieldBodyBulkCancelTest::testFieldCancel in Lingotek Translation 3.6.x

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/LingotekFieldBodyBulkCancelTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyBulkCancelTest::testFieldCancel()
  2. 4.0.x tests/src/Functional/LingotekFieldBodyBulkCancelTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyBulkCancelTest::testFieldCancel()
  3. 3.0.x tests/src/Functional/LingotekFieldBodyBulkCancelTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyBulkCancelTest::testFieldCancel()
  4. 3.1.x tests/src/Functional/LingotekFieldBodyBulkCancelTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyBulkCancelTest::testFieldCancel()
  5. 3.2.x tests/src/Functional/LingotekFieldBodyBulkCancelTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyBulkCancelTest::testFieldCancel()
  6. 3.3.x tests/src/Functional/LingotekFieldBodyBulkCancelTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyBulkCancelTest::testFieldCancel()
  7. 3.4.x tests/src/Functional/LingotekFieldBodyBulkCancelTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyBulkCancelTest::testFieldCancel()
  8. 3.5.x tests/src/Functional/LingotekFieldBodyBulkCancelTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyBulkCancelTest::testFieldCancel()
  9. 3.7.x tests/src/Functional/LingotekFieldBodyBulkCancelTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyBulkCancelTest::testFieldCancel()
  10. 3.8.x tests/src/Functional/LingotekFieldBodyBulkCancelTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyBulkCancelTest::testFieldCancel()

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

File

tests/src/Functional/LingotekFieldBodyBulkCancelTest.php, line 50

Class

LingotekFieldBodyBulkCancelTest
Tests cancelling a field using the bulk management form.

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testFieldCancel() {
  $assert_session = $this
    ->assertSession();

  // Login as admin.
  $this
    ->drupalLogin($this->rootUser);
  $this
    ->createAndTranslateFieldWithLinks();

  // Mark the first for cancelling.
  $edit = [
    'table[node.article.body]' => 'node.article.body',
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForCancel('node_fields'),
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());

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

  // Assert that The document has been cancelled remotely.
  $cancelled_docs = \Drupal::state()
    ->get('lingotek.cancelled_docs', []);
  $this
    ->assertEqual(1, count($cancelled_docs), 'The document has been cancelled remotely.');

  // Assert that no document has been deleted remotely.
  $deleted_docs = \Drupal::state()
    ->get('lingotek.deleted_docs', []);
  $this
    ->assertEqual(0, count($deleted_docs), 'No document has been deleted remotely.');
  $this
    ->assertNull($config_translation_service
    ->getDocumentId($entity));
  $this
    ->assertSourceStatus('EN', Lingotek::STATUS_CANCELLED);
  $this
    ->assertTargetStatus('ES', Lingotek::STATUS_CANCELLED);
  \Drupal::entityTypeManager()
    ->getStorage('field_config')
    ->resetCache();
  $entity = \Drupal::entityTypeManager()
    ->getStorage('field_config')
    ->load('node.article.body');
  $this
    ->assertIdentical(Lingotek::STATUS_CANCELLED, $config_translation_service
    ->getSourceStatus($entity));
  $this
    ->assertIdentical(Lingotek::STATUS_CANCELLED, $config_translation_service
    ->getTargetStatus($entity, 'es'));

  // We cannot request again.
  $basepath = \Drupal::request()
    ->getBasePath();
  $assert_session
    ->linkByHrefExists($basepath . '/admin/lingotek/config/upload/field_config/node.article.body?destination=' . $basepath . '/admin/lingotek/config/manage');
  $assert_session
    ->linkByHrefNotExists($basepath . '/admin/lingotek/config/request/field_config/node.article.body/es_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
  $this
    ->createAndTranslateFieldWithLinks();
}