public function testGetCsvFile() { $componentName = 'component_name'; $data = ['data_value']; $document = $this->getMockBuilder('Magento\\Framework\\Api\\Search\\DocumentInterface')->getMockForAbstractClass(); $this->mockComponent($componentName, [$document]); $this->mockFilter(); $this->mockDirectory(); $this->stream->expects($this->once())->method('lock')->willReturnSelf(); $this->stream->expects($this->once())->method('unlock')->willReturnSelf(); $this->stream->expects($this->once())->method('close')->willReturnSelf(); $this->stream->expects($this->any())->method('writeCsv')->with($data)->willReturnSelf(); $this->metadataProvider->expects($this->once())->method('getOptions')->willReturn([]); $this->metadataProvider->expects($this->once())->method('getHeaders')->with($this->component)->willReturn($data); $this->metadataProvider->expects($this->once())->method('getFields')->with($this->component)->willReturn([]); $this->metadataProvider->expects($this->once())->method('getRowData')->with($document, [], [])->willReturn($data); $this->metadataProvider->expects($this->once())->method('convertDate')->with($document, $componentName); $result = $this->model->getCsvFile(); $this->assertTrue(is_array($result)); $this->assertArrayHasKey('type', $result); $this->assertArrayHasKey('value', $result); $this->assertArrayHasKey('rm', $result); $this->assertContains($componentName, $result); $this->assertContains('.csv', $result); }
/** * Export data provider to CSV * * @throws \Magento\Framework\Exception\LocalizedException * @return \Magento\Framework\App\ResponseInterface */ public function execute() { return $this->fileFactory->create('export.csv', $this->converter->getCsvFile(), 'var'); }