18 use Magento\Ui\Model\Export\SearchResultIteratorFactory;
76 $this->directory = $this->getMockBuilder(DirectoryWriteInterface::class)
77 ->getMockForAbstractClass();
79 $this->filesystem = $this->getMockBuilder(Filesystem::class)
80 ->disableOriginalConstructor()
82 $this->filesystem->expects($this->any())
83 ->method(
'getDirectoryWrite')
85 ->willReturn($this->directory);
87 $this->filter = $this->getMockBuilder(Filter::class)
88 ->disableOriginalConstructor()
91 $this->metadataProvider = $this->getMockBuilder(MetadataProvider::class)
92 ->disableOriginalConstructor()
95 $this->excelFactory = $this->getMockBuilder(ExcelFactory::class)
96 ->disableOriginalConstructor()
97 ->setMethods([
'create'])
100 $this->iteratorFactory = $this->getMockBuilder(\
Magento\Ui\Model\Export\SearchResultIteratorFactory::class)
101 ->disableOriginalConstructor()
102 ->setMethods([
'create'])
105 $this->component = $this->getMockBuilder(UiComponentInterface::class)
106 ->getMockForAbstractClass();
108 $this->stream = $this->getMockBuilder(FileWriteInterface::class)
114 ->getMockForAbstractClass();
119 $this->metadataProvider,
121 $this->iteratorFactory
125 public function testGetRowData()
127 $data = [
'data_value'];
130 $document = $this->getMockBuilder(DocumentInterface::class)
131 ->getMockForAbstractClass();
133 $this->metadataProvider->expects($this->once())
134 ->method(
'getRowData')
135 ->with($document, [], [])
137 $this->metadataProvider->expects($this->once())
138 ->method(
'getFields')
139 ->with($this->component)
141 $this->metadataProvider->expects($this->once())
142 ->method(
'getOptions')
145 $this->filter->expects($this->once())
146 ->method(
'getComponent')
147 ->willReturn($this->component);
149 $result = $this->model->getRowData($document);
153 public function testGetXmlFile()
155 $componentName =
'component_name';
158 $document = $this->getMockBuilder(DocumentInterface::class)
159 ->getMockForAbstractClass();
165 $this->
mockExcel($componentName, $document);
167 $this->metadataProvider->expects($this->once())
168 ->method(
'getHeaders')
169 ->with($this->component)
171 $this->metadataProvider->expects($this->once())
172 ->method(
'convertDate')
173 ->with($document, $componentName);
175 $result = $this->model->getXmlFile();
176 $this->assertTrue(is_array(
$result));
177 $this->assertArrayHasKey(
'type',
$result);
178 $this->assertArrayHasKey(
'value',
$result);
179 $this->assertArrayHasKey(
'rm',
$result);
180 $this->assertContains($componentName,
$result);
181 $this->assertContains(
'.xml',
$result);
186 $this->stream->expects($this->once())
189 $this->stream->expects($this->once())
192 $this->stream->expects($this->once())
203 $searchResultIterator = $this->getMockBuilder(SearchResultIterator::class)
204 ->disableOriginalConstructor()
207 $excel = $this->getMockBuilder(\
Magento\Framework\Convert\Excel::class)
208 ->disableOriginalConstructor()
211 $this->iteratorFactory->expects($this->once())
213 ->with([
'items' => [$document]])
214 ->willReturn($searchResultIterator);
216 $this->excelFactory->expects($this->once())
219 'iterator' => $searchResultIterator,
220 'rowCallback' => [$this->model,
'getRowData'],
222 ->willReturn($excel);
224 $excel->expects($this->once())
225 ->method(
'setDataHeader')
228 $excel->expects($this->once())
230 ->with($this->stream, $componentName .
'.xml')
240 $context = $this->getMockBuilder(ContextInterface::class)
241 ->setMethods([
'getDataProvider'])
242 ->getMockForAbstractClass();
244 $dataProvider = $this->getMockBuilder(DataProviderInterface::class)
245 ->setMethods([
'getSearchResult',
'setLimit'])
246 ->getMockForAbstractClass();
248 $searchResult = $this->getMockBuilder(SearchResultInterface::class)
249 ->setMethods([
'getItems'])
250 ->getMockForAbstractClass();
252 $this->component->expects($this->any())
254 ->willReturn($componentName);
255 $this->component->expects($this->exactly(2))
256 ->method(
'getContext')
257 ->willReturn($context);
259 $context->expects($this->exactly(2))
260 ->method(
'getDataProvider')
261 ->willReturn($dataProvider);
263 $dataProvider->expects($this->once())
264 ->method(
'getSearchResult')
265 ->willReturn($searchResult);
267 $dataProvider->expects($this->once())
272 $searchResult->expects($this->at(0))
274 ->willReturn([$document]);
276 $searchResult->expects($this->at(0))
284 $this->filter->expects($this->once())
285 ->method(
'getComponent')
286 ->willReturn($this->component);
287 $this->filter->expects($this->once())
288 ->method(
'prepareComponent')
289 ->with($this->component)
291 $this->filter->expects($this->once())
292 ->method(
'applySelectionOnTargetProvider')
298 $this->directory->expects($this->once())
302 $this->directory->expects($this->once())
304 ->willReturn($this->stream);
mockComponent($componentName, DocumentInterface $document=null)
mockExcel($componentName, DocumentInterface $document)