/** * Returns XML file * * @return array * @throws LocalizedException */ public function getXmlFile() { $component = $this->filter->getComponent(); $name = md5(microtime()); $file = 'export/' . $component->getName() . $name . '.xml'; $this->filter->prepareComponent($component); $this->filter->applySelectionOnTargetProvider(); $component->getContext()->getDataProvider()->setLimit(0, 0); /** @var SearchResultInterface $searchResult */ $searchResult = $component->getContext()->getDataProvider()->getSearchResult(); /** @var DocumentInterface[] $searchResultItems */ $searchResultItems = $searchResult->getItems(); $this->prepareItems($component->getName(), $searchResultItems); /** @var SearchResultIterator $searchResultIterator */ $searchResultIterator = $this->iteratorFactory->create(['items' => $searchResultItems]); /** @var Excel $excel */ $excel = $this->excelFactory->create(['iterator' => $searchResultIterator, 'rowCallback' => [$this, 'getRowData']]); $this->directory->create('export'); $stream = $this->directory->openFile($file, 'w+'); $stream->lock(); $excel->setDataHeader($this->metadataProvider->getHeaders($component)); $excel->write($stream, $component->getName() . '.xml'); $stream->unlock(); $stream->close(); return ['type' => 'filename', 'value' => $file, 'rm' => true]; }
public function testCreate() { $excel = $this->getMockBuilder('Magento\\Framework\\Convert\\Excel')->disableOriginalConstructor()->getMock(); $this->objectManager->expects($this->once())->method('create')->with('\\Magento\\Framework\\Convert\\Excel', [])->willReturn($excel); $this->assertInstanceOf('Magento\\Framework\\Convert\\Excel', $this->model->create()); }