Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExportViewedCsvTest.php
Go to the documentation of this file.
1 <?php
8 
10 
12 {
16  protected $exportViewedCsv;
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->exportViewedCsv = $objectManager->getObject(
60  \Magento\Reports\Controller\Adminhtml\Report\Product\ExportViewedCsv::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.csv';
76 
77  $this->abstractBlockMock
78  ->expects($this->once())
79  ->method('getCsvFile')
80  ->willReturn($content);
81 
82  $this->layoutMock
83  ->expects($this->once())
84  ->method('createBlock')
85  ->with(\Magento\Reports\Block\Adminhtml\Product\Viewed\Grid::class)
86  ->willReturn($this->abstractBlockMock);
87 
88  $this->fileFactoryMock
89  ->expects($this->once())
90  ->method('create')
91  ->with($fileName, $content, \Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR);
92 
93  $this->exportViewedCsv->execute();
94  }
95 }
$objectManager
Definition: bootstrap.php:17
$fileName
Definition: translate.phtml:15