public function DownloadFlowTest::testDownloadByTmgmtJobAndTmgmtJobItem in TMGMT Translator Smartling 8.4
Download success full flow: download by TMGMT Job and TMGMT Job Item.
File
- tests/
src/ Kernel/ DownloadFlowTest.php, line 629
Class
- DownloadFlowTest
- Tests file download flow.
Namespace
Drupal\Tests\tmgmt_smartling\KernelCode
public function testDownloadByTmgmtJobAndTmgmtJobItem() {
$real_job = $this
->createJobWithItems([
'batch_uid' => 'uid',
'batch_execute_on_job' => 1,
]);
$field_item_list = $this
->getMockBuilder(FieldItemList::class)
->disableOriginalConstructor()
->setMethods([
'getValue',
])
->getMock();
$field_item_list
->expects($this
->any())
->method('getValue')
->willReturn([
0 => [
'value' => NULL,
],
]);
$job_item_mock_1 = $this
->getMockBuilder(JobItem::class)
->disableOriginalConstructor()
->setMethods([
'save',
'id',
'setState',
'addTranslatedData',
'getItemId',
'getItemType',
])
->getMock();
$job_item_mock_1
->expects($this
->any())
->method('id')
->willReturn(1);
$job_item_mock_1
->expects($this
->any())
->method('getItemId')
->willReturn(1);
$job_item_mock_1
->expects($this
->any())
->method('getItemType')
->willReturn('node');
$job_item_mock_1
->expects($this
->never())
->method('setState')
->with(JobItemInterface::STATE_ACTIVE);
$job_item_mock_1
->expects($this
->never())
->method('addTranslatedData');
$job_item_mock_2 = $this
->getMockBuilder(JobItem::class)
->disableOriginalConstructor()
->setMethods([
'id',
'setState',
'addTranslatedData',
'getItemId',
'getItemType',
])
->getMock();
$job_item_mock_2
->expects($this
->any())
->method('id')
->willReturn(2);
$job_item_mock_1
->expects($this
->any())
->method('getItemId')
->willReturn(1);
$job_item_mock_1
->expects($this
->any())
->method('getItemType')
->willReturn('node');
$job_item_mock_2
->expects($this
->once())
->method('setState')
->with(JobItemInterface::STATE_ACTIVE);
$job_item_mock_2
->expects($this
->once())
->method('addTranslatedData');
$translate_job = $this
->getMockBuilder(Job::class)
->disableOriginalConstructor()
->setMethods([
'id',
'getItems',
'getTranslator',
'getTranslatorPlugin',
'getSetting',
'getSourceLangcode',
'getTargetLangcode',
'save',
'set',
'get',
'addMessage',
'getFieldDefinitions',
])
->getMock();
$translate_job
->expects($this
->any())
->method('id')
->willReturn(1);
$translate_job
->expects($this
->any())
->method('getSetting')
->willReturn('public');
$translate_job
->expects($this
->any())
->method('getTranslator')
->willReturn($real_job
->getTranslator());
$translate_job
->expects($this
->any())
->method('getTranslatorPlugin')
->willReturn($real_job
->getTranslatorPlugin());
$translate_job
->expects($this
->any())
->method('getSourceLangcode')
->willReturn('en');
$translate_job
->expects($this
->any())
->method('getTargetLangcode')
->willReturn('de');
$translate_job
->expects($this
->any())
->method('get')
->willReturn($field_item_list);
$translate_job
->expects($this
->any())
->method('getFieldDefinitions')
->willReturn([]);
$translate_job
->expects($this
->once())
->method('getItems')
->willReturn([
1 => $job_item_mock_1,
2 => $job_item_mock_2,
]);
$this->translationRequestManagerMock
->expects($this
->never())
->method('commitError');
$this->translationRequestManagerMock
->expects($this
->once())
->method('getTranslationRequest')
->with($translate_job)
->willReturn([
'translationRequestUid' => 'test',
'fileUri' => 'test_file_uri.xml',
]);
$this->apiWrapperMock
->expects($this
->once())
->method('getApi')
->with('file')
->willReturn($this->fileApiMock);
$this->fileApiMock
->expects($this
->once())
->method('downloadFile')
->with('test_file_uri.xml', 'de', $this
->callback(function ($subject) {
$params = $subject
->exportToArray();
return $params['retrievalType'] == 'published';
}))
->willReturn('xml');
$this->pluginMock
->expects($this
->once())
->method('validateImport')
->with('public://tmgmt_smartling_translations/test_file_uri.xml', $translate_job)
->willReturn(TRUE);
$this->pluginMock
->expects($this
->once())
->method('import')
->with('public://tmgmt_smartling_translations/test_file_uri.xml', $translate_job)
->willReturn([
1 => [],
2 => [],
]);
$this->translationRequestManagerMock
->expects($this
->once())
->method('commitSuccessfulDownload')
->with($translate_job)
->willReturn(TRUE);
tmgmt_smartling_download_file($translate_job, $job_item_mock_2);
}