Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExportDownloadsCsvTest.php
Go to the documentation of this file.
1 <?php
8 
10 
12 {
17 
21  protected $dateMock;
22 
26  protected function setUp()
27  {
28  parent::setUp();
29 
30  $this->dateMock = $this->getMockBuilder(\Magento\Framework\Stdlib\DateTime\Filter\Date::class)
31  ->disableOriginalConstructor()
32  ->getMock();
33 
34  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
35  $this->exportDownloadsCsv = $objectManager->getObject(
36  \Magento\Reports\Controller\Adminhtml\Report\Product\ExportDownloadsCsv::class,
37  [
38  'context' => $this->contextMock,
39  'fileFactory' => $this->fileFactoryMock,
40  'dateFilter' => $this->dateMock,
41  ]
42  );
43  }
44 
48  public function testExecute()
49  {
50  $content = ['export'];
51 
52  $this->abstractBlockMock
53  ->expects($this->once())
54  ->method('setSaveParametersInSession')
55  ->willReturnSelf();
56 
57  $this->abstractBlockMock
58  ->expects($this->once())
59  ->method('getCsv')
60  ->willReturn($content);
61 
62  $this->layoutMock
63  ->expects($this->once())
64  ->method('createBlock')
65  ->with(\Magento\Reports\Block\Adminhtml\Product\Downloads\Grid::class)
66  ->willReturn($this->abstractBlockMock);
67 
68  $this->fileFactoryMock
69  ->expects($this->once())
70  ->method('create')
71  ->with('products_downloads.csv', $content);
72 
73  $this->exportDownloadsCsv->execute();
74  }
75 }
$objectManager
Definition: bootstrap.php:17