public function DownloadFlowTest::testDownloadFailFlow in TMGMT Translator Smartling 8.4
Same name and namespace in other branches
- 8.3 tests/src/Kernel/DownloadFlowTest.php \Drupal\Tests\tmgmt_smartling\Kernel\DownloadFlowTest::testDownloadFailFlow()
Download fail flow.
File
- tests/
src/ Kernel/ DownloadFlowTest.php, line 224
Class
- DownloadFlowTest
- Tests file download flow.
Namespace
Drupal\Tests\tmgmt_smartling\KernelCode
public function testDownloadFailFlow() {
$exception = new \Exception("Test");
$translation_request = [
'translationRequestUid' => 'test',
'fileUri' => 'test_file_uri.xml',
];
$translate_job = $this
->createJobWithItems([
'batch_uid' => 'uid',
'batch_execute_on_job' => 1,
]);
$this->translationRequestManagerMock
->expects($this
->once())
->method('getTranslationRequest')
->with($translate_job)
->willReturn($translation_request);
$this->apiWrapperMock
->expects($this
->once())
->method('getApi')
->with('file')
->willReturn($this->fileApiMock);
$this->apiWrapperMock
->expects($this
->once())
->method('createAuditLogRecord')
->with($translate_job, NULL, \Drupal::currentUser(), CreateRecordParameters::ACTION_TYPE_DOWNLOAD);
$this->fileApiMock
->expects($this
->once())
->method('downloadFile')
->with('test_file_uri.xml', 'de', $this
->callback(function ($subject) {
$params = $subject
->exportToArray();
return $params['retrievalType'] == 'published';
}))
->will($this
->throwException($exception));
$this->translationRequestManagerMock
->expects($this
->once())
->method('commitError')
->with($translate_job, $translation_request, $exception);
$this->translationRequestManagerMock
->expects($this
->never())
->method('commitSuccessfulDownload');
$this->pluginMock
->expects($this
->never())
->method('validateImport');
$this->pluginMock
->expects($this
->never())
->method('import');
$this->apiWrapperMock
->expects($this
->once())
->method('createFirebaseRecord')
->with('tmgmt_smartling', 'notifications', 10, [
"message" => 'File test_file_uri.xml (job id = 1) wasn\'t downloaded. Please see logs for more info.',
"type" => "error",
]);
tmgmt_smartling_download_file($translate_job);
}