Skip to content

Commit abbd737

Browse files
committed
MAGETWO-39307: UnitTest Coverage Magento\Reports\Controller\Adminhtml\Report\Product*
1 parent 4404d29 commit abbd737

13 files changed

+1075
-1
lines changed

app/code/Magento/Reports/Test/Unit/Controller/Adminhtml/Report/AbstractControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ protected function setUp()
9595
->disableOriginalConstructor()
9696
->getMock();
9797
$this->abstractBlockMock = $this->getMockBuilder('Magento\Framework\View\Element\AbstractBlock')
98-
->setMethods(['getCsvFile', 'getExcelFile'])
98+
->setMethods(['getCsvFile', 'getExcelFile', 'setSaveParametersInSession', 'getCsv', 'getExcel'])
9999
->disableOriginalConstructor()
100100
->getMock();
101101

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Reports\Test\Unit\Controller\Adminhtml\Report\Product;
8+
9+
use Magento\Reports\Controller\Adminhtml\Report\Product\Downloads;
10+
use Magento\Framework\Object;
11+
use Magento\Framework\Phrase;
12+
13+
class DownloadsTest extends \Magento\Reports\Test\Unit\Controller\Adminhtml\Report\AbstractControllerTest
14+
{
15+
/**
16+
* @var \Magento\Reports\Controller\Adminhtml\Report\Product\Downloads
17+
*/
18+
protected $downloads;
19+
20+
/**
21+
* @var \Magento\Framework\Stdlib\DateTime\Filter\Date|\PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
protected $dateMock;
24+
25+
/**
26+
* {@inheritDoc}
27+
*/
28+
protected function setUp()
29+
{
30+
parent::setUp();
31+
32+
$this->dateMock = $this->getMockBuilder('Magento\Framework\Stdlib\DateTime\Filter\Date')
33+
->disableOriginalConstructor()
34+
->getMock();
35+
36+
$this->downloads = new Downloads(
37+
$this->contextMock,
38+
$this->fileFactoryMock,
39+
$this->dateMock
40+
);
41+
}
42+
43+
/**
44+
* @return void
45+
*/
46+
public function testExecute()
47+
{
48+
$titleMock = $this->getMockBuilder('Magento\Framework\View\Page\Title')
49+
->disableOriginalConstructor()
50+
->getMock();
51+
52+
$titleMock
53+
->expects($this->once())
54+
->method('prepend')
55+
->with(new Phrase('Downloads Report'));
56+
57+
$this->viewMock
58+
->expects($this->once())
59+
->method('getPage')
60+
->willReturn(
61+
new Object(
62+
['config' => new Object(
63+
['title' => $titleMock]
64+
)]
65+
)
66+
);
67+
68+
$this->menuBlockMock
69+
->expects($this->once())
70+
->method('setActive')
71+
->with('Magento_Downloadable::report_products_downloads');
72+
73+
$this->breadcrumbsBlockMock
74+
->expects($this->exactly(3))
75+
->method('addLink')
76+
->withConsecutive(
77+
[new Phrase('Reports'), new Phrase('Reports')],
78+
[new Phrase('Products'), new Phrase('Products')],
79+
[new Phrase('Downloads'), new Phrase('Downloads')]
80+
);
81+
82+
$this->layoutMock
83+
->expects($this->once())
84+
->method('createBlock')
85+
->with('Magento\Reports\Block\Adminhtml\Product\Downloads')
86+
->willReturn($this->abstractBlockMock);
87+
88+
$this->downloads->execute();
89+
}
90+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Reports\Test\Unit\Controller\Adminhtml\Report\Product;
8+
9+
use Magento\Reports\Controller\Adminhtml\Report\Product\ExportDownloadsCsv;
10+
11+
class ExportDownloadsCsvTest extends \Magento\Reports\Test\Unit\Controller\Adminhtml\Report\AbstractControllerTest
12+
{
13+
/**
14+
* @var \Magento\Reports\Controller\Adminhtml\Report\Product\ExportDownloadsCsv
15+
*/
16+
protected $exportDownloadsCsv;
17+
18+
/**
19+
* @var \Magento\Framework\Stdlib\DateTime\Filter\Date|\PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
protected $dateMock;
22+
23+
/**
24+
* {@inheritDoc}
25+
*/
26+
protected function setUp()
27+
{
28+
parent::setUp();
29+
30+
$this->dateMock = $this->getMockBuilder('Magento\Framework\Stdlib\DateTime\Filter\Date')
31+
->disableOriginalConstructor()
32+
->getMock();
33+
34+
$this->exportDownloadsCsv = new ExportDownloadsCsv(
35+
$this->contextMock,
36+
$this->fileFactoryMock,
37+
$this->dateMock
38+
);
39+
}
40+
41+
/**
42+
* @return void
43+
*/
44+
public function testExecute()
45+
{
46+
$content = ['export'];
47+
48+
$this->abstractBlockMock
49+
->expects($this->once())
50+
->method('setSaveParametersInSession')
51+
->willReturnSelf();
52+
53+
$this->abstractBlockMock
54+
->expects($this->once())
55+
->method('getCsv')
56+
->willReturn($content);
57+
58+
$this->layoutMock
59+
->expects($this->once())
60+
->method('createBlock')
61+
->with('Magento\Reports\Block\Adminhtml\Product\Downloads\Grid')
62+
->willReturn($this->abstractBlockMock);
63+
64+
$this->fileFactoryMock
65+
->expects($this->once())
66+
->method('create')
67+
->with('products_downloads.csv', $content);
68+
69+
$this->exportDownloadsCsv->execute();
70+
}
71+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Reports\Test\Unit\Controller\Adminhtml\Report\Product;
8+
9+
use Magento\Reports\Controller\Adminhtml\Report\Product\ExportDownloadsExcel;
10+
11+
class ExportDownloadsExcelTest extends \Magento\Reports\Test\Unit\Controller\Adminhtml\Report\AbstractControllerTest
12+
{
13+
/**
14+
* @var \Magento\Reports\Controller\Adminhtml\Report\Product\ExportDownloadsExcel
15+
*/
16+
protected $exportDownloadsExcel;
17+
18+
/**
19+
* @var \Magento\Framework\Stdlib\DateTime\Filter\Date|\PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
protected $dateMock;
22+
23+
/**
24+
* {@inheritDoc}
25+
*/
26+
protected function setUp()
27+
{
28+
parent::setUp();
29+
30+
$this->dateMock = $this->getMockBuilder('Magento\Framework\Stdlib\DateTime\Filter\Date')
31+
->disableOriginalConstructor()
32+
->getMock();
33+
34+
$this->exportDownloadsExcel = new ExportDownloadsExcel(
35+
$this->contextMock,
36+
$this->fileFactoryMock,
37+
$this->dateMock
38+
);
39+
}
40+
41+
/**
42+
* @return void
43+
*/
44+
public function testExecute()
45+
{
46+
$content = ['export'];
47+
$fileName = 'products_downloads.xml';
48+
49+
$this->abstractBlockMock
50+
->expects($this->once())
51+
->method('setSaveParametersInSession')
52+
->willReturnSelf();
53+
54+
$this->abstractBlockMock
55+
->expects($this->once())
56+
->method('getExcel')
57+
->with($fileName)
58+
->willReturn($content);
59+
60+
$this->layoutMock
61+
->expects($this->once())
62+
->method('createBlock')
63+
->with('Magento\Reports\Block\Adminhtml\Product\Downloads\Grid')
64+
->willReturn($this->abstractBlockMock);
65+
66+
$this->fileFactoryMock
67+
->expects($this->once())
68+
->method('create')
69+
->with($fileName, $content);
70+
71+
$this->exportDownloadsExcel->execute();
72+
}
73+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Reports\Test\Unit\Controller\Adminhtml\Report\Product;
8+
9+
use Magento\Reports\Controller\Adminhtml\Report\Product\ExportLowstockCsv;
10+
11+
class ExportLowstockCsvTest extends \Magento\Reports\Test\Unit\Controller\Adminhtml\Report\AbstractControllerTest
12+
{
13+
/**
14+
* @var \Magento\Reports\Controller\Adminhtml\Report\Product\ExportLowstockCsv
15+
*/
16+
protected $exportLowstockCsv;
17+
18+
/**
19+
* @var \Magento\Framework\Stdlib\DateTime\Filter\Date|\PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
protected $dateMock;
22+
23+
/**
24+
* {@inheritDoc}
25+
*/
26+
protected function setUp()
27+
{
28+
parent::setUp();
29+
30+
$this->dateMock = $this->getMockBuilder('Magento\Framework\Stdlib\DateTime\Filter\Date')
31+
->disableOriginalConstructor()
32+
->getMock();
33+
34+
$this->exportLowstockCsv = new ExportLowstockCsv(
35+
$this->contextMock,
36+
$this->fileFactoryMock,
37+
$this->dateMock
38+
);
39+
}
40+
41+
/**
42+
* @return void
43+
*/
44+
public function testExecute()
45+
{
46+
$content = ['export'];
47+
48+
$this->abstractBlockMock
49+
->expects($this->once())
50+
->method('getCsvFile')
51+
->willReturn($content);
52+
53+
$this->layoutMock
54+
->expects($this->once())
55+
->method('getChildBlock')
56+
->with('adminhtml.block.report.product.lowstock.grid', 'grid.export')
57+
->willReturn($this->abstractBlockMock);
58+
59+
$this->fileFactoryMock
60+
->expects($this->once())
61+
->method('create')
62+
->with('products_lowstock.csv', $content, \Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR);
63+
64+
$this->exportLowstockCsv->execute();
65+
}
66+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Reports\Test\Unit\Controller\Adminhtml\Report\Product;
8+
9+
use Magento\Reports\Controller\Adminhtml\Report\Product\ExportLowstockExcel;
10+
11+
class ExportLowstockExcelTest extends \Magento\Reports\Test\Unit\Controller\Adminhtml\Report\AbstractControllerTest
12+
{
13+
/**
14+
* @var \Magento\Reports\Controller\Adminhtml\Report\Product\ExportLowstockExcel
15+
*/
16+
protected $exportLowstockExcel;
17+
18+
/**
19+
* @var \Magento\Framework\Stdlib\DateTime\Filter\Date|\PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
protected $dateMock;
22+
23+
/**
24+
* {@inheritDoc}
25+
*/
26+
protected function setUp()
27+
{
28+
parent::setUp();
29+
30+
$this->dateMock = $this->getMockBuilder('Magento\Framework\Stdlib\DateTime\Filter\Date')
31+
->disableOriginalConstructor()
32+
->getMock();
33+
34+
$this->exportLowstockExcel = new ExportLowstockExcel(
35+
$this->contextMock,
36+
$this->fileFactoryMock,
37+
$this->dateMock
38+
);
39+
}
40+
41+
/**
42+
* @return void
43+
*/
44+
public function testExecute()
45+
{
46+
$content = ['export'];
47+
48+
$this->abstractBlockMock
49+
->expects($this->once())
50+
->method('getExcelFile')
51+
->willReturn($content);
52+
53+
$this->layoutMock
54+
->expects($this->once())
55+
->method('getChildBlock')
56+
->with('adminhtml.block.report.product.lowstock.grid', 'grid.export')
57+
->willReturn($this->abstractBlockMock);
58+
59+
$this->fileFactoryMock
60+
->expects($this->once())
61+
->method('create')
62+
->with('products_lowstock.xml', $content, \Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR);
63+
64+
$this->exportLowstockExcel->execute();
65+
}
66+
}

0 commit comments

Comments
 (0)