Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DownloadsTest.php
Go to the documentation of this file.
1 <?php
8 
12 
14 {
18  protected $downloads;
19 
23  protected $dateMock;
24 
28  protected function setUp()
29  {
30  parent::setUp();
31 
32  $this->dateMock = $this->getMockBuilder(\Magento\Framework\Stdlib\DateTime\Filter\Date::class)
33  ->disableOriginalConstructor()
34  ->getMock();
35 
36  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
37  $this->downloads = $objectManager->getObject(
38  \Magento\Reports\Controller\Adminhtml\Report\Product\Downloads::class,
39  [
40  'context' => $this->contextMock,
41  'fileFactory' => $this->fileFactoryMock,
42  'dateFilter' => $this->dateMock,
43  ]
44  );
45  }
46 
50  public function testExecute()
51  {
52  $titleMock = $this->getMockBuilder(\Magento\Framework\View\Page\Title::class)
53  ->disableOriginalConstructor()
54  ->getMock();
55 
56  $titleMock
57  ->expects($this->once())
58  ->method('prepend')
59  ->with(new Phrase('Downloads Report'));
60 
61  $this->viewMock
62  ->expects($this->once())
63  ->method('getPage')
64  ->willReturn(
65  new DataObject(
66  ['config' => new DataObject(
67  ['title' => $titleMock]
68  )]
69  )
70  );
71 
72  $this->menuBlockMock
73  ->expects($this->once())
74  ->method('setActive')
75  ->with('Magento_Downloadable::report_products_downloads');
76 
77  $this->breadcrumbsBlockMock
78  ->expects($this->exactly(3))
79  ->method('addLink')
80  ->withConsecutive(
81  [new Phrase('Reports'), new Phrase('Reports')],
82  [new Phrase('Products'), new Phrase('Products')],
83  [new Phrase('Downloads'), new Phrase('Downloads')]
84  );
85 
86  $this->layoutMock
87  ->expects($this->once())
88  ->method('createBlock')
89  ->with(\Magento\Reports\Block\Adminhtml\Product\Downloads::class)
90  ->willReturn($this->abstractBlockMock);
91 
92  $this->downloads->execute();
93  }
94 }
$objectManager
Definition: bootstrap.php:17