You are here

public function TranslationRequestManagerTest::testCommitError in TMGMT Translator Smartling 8.4

Test error flow.

File

tests/src/Kernel/TranslationRequestManagerTest.php, line 424

Class

TranslationRequestManagerTest
Tests TranslationRequestManagerTest class.

Namespace

Drupal\Tests\tmgmt_smartling\Kernel

Code

public function testCommitError() {
  $exception = new \Exception('Test');
  $translation_request = [
    'translationRequestUid' => 'test_translation_request_uid',
    'translationSubmissions' => [
      [
        'translationSubmissionUid' => 'test_translation_submission_uid',
      ],
    ],
  ];
  $translation_request_manager_mock = $this
    ->getMockBuilder(TranslationRequestManager::class)
    ->setConstructorArgs([
    $this->apiWrapperMock,
    $this->stateMock,
    $this->loggerMock,
  ])
    ->setMethods([
    'initApiWrapper',
  ])
    ->getMock();
  $translation_request_manager_mock
    ->expects($this
    ->once())
    ->method('initApiWrapper')
    ->with($this->job);
  $update_submission_params = new UpdateTranslationSubmissionParams();
  $update_submission_params
    ->setState(TranslationSubmissionStates::STATE_FAILED)
    ->setLastErrorMessage(mb_substr($exception
    ->getMessage() . ': ' . $exception
    ->getTraceAsString(), 0, 1024))
    ->setTranslationSubmissionUid($translation_request['translationSubmissions'][0]['translationSubmissionUid']);
  $update_request_params = new UpdateTranslationRequestParams();
  $update_request_params
    ->addTranslationSubmission($update_submission_params);
  $this->apiWrapperMock
    ->expects($this
    ->once())
    ->method('updateTranslationRequest')
    ->with('tmgmt_smartling_bucket', 'test_translation_request_uid', $update_request_params);
  $translation_request_manager_mock
    ->commitError($this->job, $translation_request, $exception);
}