You are here

public function UploadFlowTest::testRequestTranslationFailFlowErrorWhileUploading in TMGMT Translator Smartling 8.4

Same name and namespace in other branches
  1. 8.3 tests/src/Kernel/UploadFlowTest.php \Drupal\Tests\tmgmt_smartling\Kernel\UploadFlowTest::testRequestTranslationFailFlowErrorWhileUploading()

Upload fail flow: error while uploading.

File

tests/src/Kernel/UploadFlowTest.php, line 256

Class

UploadFlowTest
Tests file upload flow.

Namespace

Drupal\Tests\tmgmt_smartling\Kernel

Code

public function testRequestTranslationFailFlowErrorWhileUploading() {
  $exception = new \Exception("Test");
  $translation_request = [
    'translationRequestUid' => 'test',
  ];
  $translate_job = $this
    ->createJobWithItems([
    'batch_uid' => 'uid',
    'batch_execute_on_job' => 1,
  ]);
  $this->translationRequestManagerMock
    ->expects($this
    ->once())
    ->method('upsertTranslationRequest')
    ->with($translate_job)
    ->willReturn($translation_request);
  $this->apiWrapperMock
    ->expects($this
    ->once())
    ->method('getApi')
    ->with('batch')
    ->willReturn($this->batchApiMock);
  $this->apiWrapperMock
    ->expects($this
    ->once())
    ->method('createAuditLogRecord')
    ->with($translate_job, NULL, \Drupal::currentUser(), CreateRecordParameters::ACTION_TYPE_UPLOAD);
  $this->apiWrapperMock
    ->expects($this
    ->once())
    ->method('executeBatch')
    ->with('uid')
    ->will($this
    ->throwException($exception));
  $this->translationRequestManagerMock
    ->expects($this
    ->never())
    ->method('commitSuccessfulUpload');
  $this->apiWrapperMock
    ->expects($this
    ->at(2))
    ->method('createFirebaseRecord')
    ->with('tmgmt_smartling', 'notifications', 10, [
    "message" => 'File uploaded. Job id: 1, file name: JobID1_en_de.xml.',
    "type" => "status",
  ]);
  $this->apiWrapperMock
    ->expects($this
    ->at(4))
    ->method('createFirebaseRecord')
    ->with('tmgmt_smartling', 'notifications', 10, [
    "message" => 'Error while uploading public://tmgmt_sources/JobID1_en_de.xml. Please see logs for more info.',
    "type" => "error",
  ]);
  $this->translationRequestManagerMock
    ->expects($this
    ->once())
    ->method('commitError')
    ->with($translate_job, $translation_request, $exception);
  $translate_job
    ->requestTranslation();
}