Skip to content

Commit 7ceb72f

Browse files
committed
MAGETWO-39296: UnitTest Coverage Magento\Reports\Controller\Adminhtml\Report\Customer*
1 parent 140595d commit 7ceb72f

File tree

10 files changed

+655
-0
lines changed

10 files changed

+655
-0
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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;
8+
9+
abstract class AbstractControllerTest extends \PHPUnit_Framework_TestCase
10+
{
11+
/**
12+
* @var \Magento\Backend\App\Action\Context|\PHPUnit_Framework_MockObject_MockObject
13+
*/
14+
protected $contextMock;
15+
16+
/**
17+
* @var \Magento\Framework\App\Response\Http\FileFactory|\PHPUnit_Framework_MockObject_MockObject
18+
*/
19+
protected $fileFactoryMock;
20+
21+
/**
22+
* @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject
23+
*/
24+
protected $requestMock;
25+
26+
/**
27+
* @var \Magento\Framework\App\ViewInterface|\PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
protected $viewMock;
30+
31+
/**
32+
* @var \Magento\Framework\View\LayoutInterface|\PHPUnit_Framework_MockObject_MockObject
33+
*/
34+
protected $layoutMock;
35+
36+
/**
37+
* @var \Magento\Framework\View\Element\BlockInterface|\PHPUnit_Framework_MockObject_MockObject
38+
*/
39+
protected $breadcrumbsBlockMock;
40+
41+
/**
42+
* @var \Magento\Framework\View\Element\BlockInterface|\PHPUnit_Framework_MockObject_MockObject
43+
*/
44+
protected $menuBlockMock;
45+
46+
/**
47+
* @var \Magento\Framework\View\Element\BlockInterface|\PHPUnit_Framework_MockObject_MockObject
48+
*/
49+
protected $switcherBlockMock;
50+
51+
/**
52+
* @var \Magento\Backend\Model\Menu|\PHPUnit_Framework_MockObject_MockObject
53+
*/
54+
protected $menuModelMock;
55+
56+
/**
57+
* @var \Magento\Framework\View\Element\AbstractBlock|\PHPUnit_Framework_MockObject_MockObject
58+
*/
59+
protected $abstractBlockMock;
60+
61+
/**
62+
* {@inheritDoc}
63+
*/
64+
protected function setUp()
65+
{
66+
$this->requestMock = $this->getMockForAbstractClassBuilder(
67+
'Magento\Framework\App\RequestInterface',
68+
['isDispatched', 'initForward', 'setDispatched', 'isForwarded']
69+
);
70+
$this->breadcrumbsBlockMock = $this->getMockForAbstractClassBuilder(
71+
'Magento\Framework\View\Element\BlockInterface',
72+
['addLink']
73+
);
74+
$this->menuBlockMock = $this->getMockForAbstractClassBuilder(
75+
'Magento\Framework\View\Element\BlockInterface',
76+
['setActive', 'getMenuModel']
77+
);
78+
$this->viewMock = $this->getMockForAbstractClassBuilder(
79+
'Magento\Framework\App\ViewInterface'
80+
);
81+
82+
$this->layoutMock = $this->getMockBuilder('Magento\Framework\View\LayoutInterface')
83+
->disableOriginalConstructor()
84+
->getMock();
85+
$this->switcherBlockMock = $this->getMockBuilder('Magento\Framework\View\Element\BlockInterface')
86+
->disableOriginalConstructor()
87+
->getMock();
88+
$this->contextMock = $this->getMockBuilder('Magento\Backend\App\Action\Context')
89+
->disableOriginalConstructor()
90+
->getMock();
91+
$this->fileFactoryMock = $this->getMockBuilder('Magento\Framework\App\Response\Http\FileFactory')
92+
->disableOriginalConstructor()
93+
->getMock();
94+
$this->menuModelMock = $this->getMockBuilder('Magento\Backend\Model\Menu')
95+
->disableOriginalConstructor()
96+
->getMock();
97+
$this->abstractBlockMock = $this->getMockBuilder('Magento\Framework\View\Element\AbstractBlock')
98+
->setMethods(['getCsvFile', 'getExcelFile'])
99+
->disableOriginalConstructor()
100+
->getMock();
101+
102+
$this->menuModelMock->expects($this->any())->method('getParentItems')->willReturn([]);
103+
$this->menuBlockMock->expects($this->any())->method('getMenuModel')->willReturn($this->menuModelMock);
104+
$this->viewMock->expects($this->any())->method('getLayout')->willReturn($this->layoutMock);
105+
$this->contextMock->expects($this->any())->method('getRequest')->willReturn($this->requestMock);
106+
$this->contextMock->expects($this->any())->method('getView')->willReturn($this->viewMock);
107+
108+
$this->layoutMock->expects($this->any())->method('getBlock')->will(
109+
$this->returnValueMap(
110+
[
111+
['breadcrumbs', $this->breadcrumbsBlockMock],
112+
['menu', $this->menuBlockMock],
113+
['store_switcher', $this->switcherBlockMock]
114+
]
115+
)
116+
);
117+
$this->layoutMock->expects($this->any())->method('getChildBlock')->willReturn($this->abstractBlockMock);
118+
}
119+
120+
/**
121+
* Custom mock for abstract class
122+
* @param string $className
123+
* @param array $mockedMethods
124+
* @return \PHPUnit_Framework_MockObject_MockObject
125+
*/
126+
protected function getMockForAbstractClassBuilder($className, $mockedMethods = [])
127+
{
128+
return $this->getMockForAbstractClass($className, [], '', false, false, true, $mockedMethods);
129+
}
130+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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\Customer;
8+
9+
use Magento\Reports\Controller\Adminhtml\Report\Customer\Accounts;
10+
use Magento\Framework\Object;
11+
use Magento\Framework\Phrase;
12+
13+
class AccountsTest extends \Magento\Reports\Test\Unit\Controller\Adminhtml\Report\AbstractControllerTest
14+
{
15+
/**
16+
* @var \Magento\Reports\Controller\Adminhtml\Report\Customer\Accounts
17+
*/
18+
protected $accounts;
19+
20+
/**
21+
* {@inheritDoc}
22+
*/
23+
protected function setUp()
24+
{
25+
parent::setUp();
26+
27+
$this->accounts = new Accounts(
28+
$this->contextMock,
29+
$this->fileFactoryMock
30+
);
31+
}
32+
33+
/**
34+
* @return void
35+
*/
36+
public function testExecute()
37+
{
38+
$titleMock = $this->getMockBuilder('Magento\Framework\View\Page\Title')
39+
->disableOriginalConstructor()
40+
->getMock();
41+
$titleMock
42+
->expects($this->once())
43+
->method('prepend')
44+
->with(new Phrase('New Accounts Report'));
45+
46+
$this->viewMock
47+
->expects($this->any())
48+
->method('getPage')
49+
->willReturn(
50+
new Object(
51+
['config' => new Object(
52+
['title' => $titleMock]
53+
)]
54+
)
55+
);
56+
57+
$this->menuBlockMock
58+
->expects($this->once())
59+
->method('setActive')
60+
->with('Magento_Reports::report_customers_accounts');
61+
$this->breadcrumbsBlockMock
62+
->expects($this->at(0))
63+
->method('addLink')
64+
->with(new Phrase('Reports'), new Phrase('Reports'));
65+
$this->breadcrumbsBlockMock
66+
->expects($this->at(1))
67+
->method('addLink')
68+
->with(new Phrase('Customers'), new Phrase('Customers'));
69+
$this->breadcrumbsBlockMock
70+
->expects($this->at(2))
71+
->method('addLink')
72+
->with(new Phrase('New Accounts'), new Phrase('New Accounts'));
73+
$this->accounts->execute();
74+
}
75+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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\Customer;
8+
9+
use Magento\Reports\Controller\Adminhtml\Report\Customer\ExportAccountsCsv;
10+
11+
class ExportAccountsCsvTest extends \Magento\Reports\Test\Unit\Controller\Adminhtml\Report\AbstractControllerTest
12+
{
13+
/**
14+
* @var \Magento\Reports\Controller\Adminhtml\Report\Customer\ExportAccountsCsv
15+
*/
16+
protected $exportAccountsCsv;
17+
18+
/**
19+
* {@inheritDoc}
20+
*/
21+
protected function setUp()
22+
{
23+
parent::setUp();
24+
25+
$this->exportAccountsCsv = new ExportAccountsCsv(
26+
$this->contextMock,
27+
$this->fileFactoryMock
28+
);
29+
}
30+
31+
/**
32+
* @return void
33+
*/
34+
public function testExecute()
35+
{
36+
$this->abstractBlockMock
37+
->expects($this->once())
38+
->method('getCsvFile')
39+
->willReturn(['export']);
40+
$this->layoutMock
41+
->expects($this->once())
42+
->method('getChildBlock')
43+
->with('adminhtml.report.grid', 'grid.export');
44+
$this->fileFactoryMock
45+
->expects($this->once())
46+
->method('create')
47+
->with('new_accounts.csv', ['export'], \Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR);
48+
$this->exportAccountsCsv->execute();
49+
}
50+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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\Customer;
8+
9+
use Magento\Reports\Controller\Adminhtml\Report\Customer\ExportAccountsExcel;
10+
11+
class ExportAccountsExcelTest extends \Magento\Reports\Test\Unit\Controller\Adminhtml\Report\AbstractControllerTest
12+
{
13+
/**
14+
* @var \Magento\Reports\Controller\Adminhtml\Report\Customer\ExportAccountsExcel
15+
*/
16+
protected $exportAccountsExcel;
17+
18+
/**
19+
* {@inheritDoc}
20+
*/
21+
protected function setUp()
22+
{
23+
parent::setUp();
24+
25+
$this->exportAccountsExcel = new ExportAccountsExcel(
26+
$this->contextMock,
27+
$this->fileFactoryMock
28+
);
29+
}
30+
31+
/**
32+
* @return void
33+
*/
34+
public function testExecute()
35+
{
36+
$this->abstractBlockMock
37+
->expects($this->once())
38+
->method('getExcelFile')
39+
->willReturn(['export']);
40+
$this->layoutMock
41+
->expects($this->once())
42+
->method('getChildBlock')
43+
->with('adminhtml.report.grid', 'grid.export');
44+
$this->fileFactoryMock
45+
->expects($this->once())
46+
->method('create')
47+
->with('new_accounts.xml', ['export'], \Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR);
48+
$this->exportAccountsExcel->execute();
49+
}
50+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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\Customer;
8+
9+
use Magento\Reports\Controller\Adminhtml\Report\Customer\ExportOrdersCsv;
10+
11+
class ExportOrdersCsvTest extends \Magento\Reports\Test\Unit\Controller\Adminhtml\Report\AbstractControllerTest
12+
{
13+
/**
14+
* @var \Magento\Reports\Controller\Adminhtml\Report\Customer\ExportOrdersCsv
15+
*/
16+
protected $exportOrdersCsv;
17+
18+
/**
19+
* {@inheritDoc}
20+
*/
21+
protected function setUp()
22+
{
23+
parent::setUp();
24+
25+
$this->exportOrdersCsv = new ExportOrdersCsv(
26+
$this->contextMock,
27+
$this->fileFactoryMock
28+
);
29+
}
30+
31+
/**
32+
* @return void
33+
*/
34+
public function testExecute()
35+
{
36+
$this->abstractBlockMock
37+
->expects($this->once())
38+
->method('getCsvFile')
39+
->willReturn(['export']);
40+
$this->layoutMock
41+
->expects($this->once())
42+
->method('getChildBlock')
43+
->with('adminhtml.report.grid', 'grid.export');
44+
$this->fileFactoryMock
45+
->expects($this->once())
46+
->method('create')
47+
->with('customers_orders.csv', ['export'], \Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR);
48+
$this->exportOrdersCsv->execute();
49+
}
50+
}

0 commit comments

Comments
 (0)