Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExportViewedExcelTest.php
Go to the documentation of this file.
1 <?php
8 
10 
12 {
16  protected $exportViewedExcel;
17 
21  protected $dateMock;
22 
26  protected $objectManagerMock;
27 
31  protected $helperMock;
32 
36  protected function setUp()
37  {
38  parent::setUp();
39 
40  $this->dateMock = $this->getMockBuilder(\Magento\Framework\Stdlib\DateTime\Filter\Date::class)
41  ->disableOriginalConstructor()
42  ->getMock();
43 
44  $this->helperMock = $this->getMockBuilder(\Magento\Backend\Helper\Data::class)
45  ->disableOriginalConstructor()
46  ->getMock();
47 
48  $this->objectManagerMock = $this->getMockBuilder(\Magento\Framework\ObjectManagerInterface::class)
49  ->disableOriginalConstructor()
50  ->getMock();
51  $this->objectManagerMock
52  ->expects($this->any())
53  ->method('get')
54  ->willReturn($this->helperMock);
55 
56  $this->contextMock->expects($this->any())->method('getObjectManager')->willReturn($this->objectManagerMock);
57 
58  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
59  $this->exportViewedExcel = $objectManager->getObject(
60  \Magento\Reports\Controller\Adminhtml\Report\Product\ExportViewedExcel::class,
61  [
62  'context' => $this->contextMock,
63  'fileFactory' => $this->fileFactoryMock,
64  'dateFilter' => $this->dateMock,
65  ]
66  );
67  }
68 
72  public function testExecute()
73  {
74  $content = ['export'];
75  $fileName = 'products_mostviewed.xml';
76 
77  $this->abstractBlockMock
78  ->expects($this->once())
79  ->method('getExcelFile')
80  ->with($fileName)
81  ->willReturn($content);
82 
83  $this->layoutMock
84  ->expects($this->once())
85  ->method('createBlock')
86  ->with(\Magento\Reports\Block\Adminhtml\Product\Viewed\Grid::class)
87  ->willReturn($this->abstractBlockMock);
88 
89  $this->fileFactoryMock
90  ->expects($this->once())
91  ->method('create')
92  ->with($fileName, $content, \Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR);
93 
94  $this->exportViewedExcel->execute();
95  }
96 }
$objectManager
Definition: bootstrap.php:17
$fileName
Definition: translate.phtml:15