You are here

public function LingotekContentTypeNotificationCallbackTest::testImportFailureWhileUploading in Lingotek Translation 3.4.x

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

Tests that an import_failure callback is handled after document upload.

File

tests/src/Functional/LingotekContentTypeNotificationCallbackTest.php, line 1549

Class

LingotekContentTypeNotificationCallbackTest
Tests translating a content type using the notification callback.

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testImportFailureWhileUploading() {

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

  // Enable translation for the current entity type and ensure the change is
  // picked up.
  $this
    ->saveLingotekConfigTranslationSettings([
    'node_type' => 'automatic',
  ]);

  // Create Article node types. We use the form at least once to ensure that
  // we don't break anything. E.g. see https://www.drupal.org/node/2645202.
  $this
    ->drupalPostForm('/admin/structure/types/add', [
    'type' => 'article',
    'name' => 'Article',
  ], 'Save content type');

  /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $node_storage */
  $node_storage = $this->container
    ->get('entity_type.manager')
    ->getStorage('node_type');

  /** @var \Drupal\lingotek\LingotekConfigTranslationServiceInterface $config_translation_service */
  $config_translation_service = \Drupal::service('lingotek.config_translation');
  $entity = $node_storage
    ->load('article');

  // Assert the content is importing.
  $this
    ->assertIdentical(Lingotek::STATUS_IMPORTING, $config_translation_service
    ->getSourceStatus($entity));
  $this
    ->assertIdentical($config_translation_service
    ->getDocumentId($entity), 'dummy-document-hash-id');
  $this
    ->goToConfigBulkManagementForm('node_type');

  // Simulate the notification of failed import document.
  $url = Url::fromRoute('lingotek.notify', [], [
    'query' => [
      'project_id' => 'test_project',
      'document_id' => 'dummy-document-hash-id',
      'type' => 'import_failure',
    ],
  ])
    ->setAbsolute()
    ->toString();
  $request = $this->client
    ->post($url, [
    'cookies' => $this->cookies,
    'headers' => [
      'Accept' => 'application/json',
      'Content-Type' => 'application/json',
    ],
    'http_errors' => FALSE,
  ]);
  $response = json_decode($request
    ->getBody(), TRUE);
  $this
    ->verbose($request);
  $this
    ->assertIdentical($response['messages'][0], 'Document import for entity Article failed. Reverting dummy-document-hash-id to previous id (NULL)');
  $this
    ->goToConfigBulkManagementForm('node_type');
  $entity = $node_storage
    ->load('article');
  $this
    ->assertNull($config_translation_service
    ->getDocumentId($entity));
  $this
    ->assertIdentical(Lingotek::STATUS_ERROR, $config_translation_service
    ->getSourceStatus($entity));
}