Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExportDownloadsExcelTest.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->exportDownloadsExcel = $objectManager->getObject(
36  \Magento\Reports\Controller\Adminhtml\Report\Product\ExportDownloadsExcel::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  $fileName = 'products_downloads.xml';
52 
53  $this->abstractBlockMock
54  ->expects($this->once())
55  ->method('setSaveParametersInSession')
56  ->willReturnSelf();
57 
58  $this->abstractBlockMock
59  ->expects($this->once())
60  ->method('getExcel')
61  ->with($fileName)
62  ->willReturn($content);
63 
64  $this->layoutMock
65  ->expects($this->once())
66  ->method('createBlock')
67  ->with(\Magento\Reports\Block\Adminhtml\Product\Downloads\Grid::class)
68  ->willReturn($this->abstractBlockMock);
69 
70  $this->fileFactoryMock
71  ->expects($this->once())
72  ->method('create')
73  ->with($fileName, $content);
74 
75  $this->exportDownloadsExcel->execute();
76  }
77 }
$objectManager
Definition: bootstrap.php:17
$fileName
Definition: translate.phtml:15