Skip to content

Commit 14a47b6

Browse files
author
Kostiantyn Poida
committed
MAGETWO-31363: Unit and Integration tests coverage
1 parent 1b9eb60 commit 14a47b6

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\OfflineShipping\Block\Adminhtml\Carrier\Tablerate;
7+
8+
class GridTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\OfflineShipping\Block\Adminhtml\Carrier\Tablerate\Grid
12+
*/
13+
protected $model;
14+
15+
/**
16+
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
protected $storeManagerMock;
19+
20+
protected function setUp()
21+
{
22+
$objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
23+
24+
$this->storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManagerInterface')
25+
->disableOriginalConstructor()
26+
->getMock();
27+
28+
$context = $objectManager->getObject('Magento\Backend\Block\Template\Context', [
29+
'storeManager' => $this->storeManagerMock
30+
]);
31+
32+
$this->model = $objectManager->getObject('Magento\OfflineShipping\Block\Adminhtml\Carrier\Tablerate\Grid', [
33+
'context' => $context,
34+
]);
35+
}
36+
37+
public function testSetWebsiteId()
38+
{
39+
$websiteMock = $this->getMockBuilder('Magento\Store\Model\Website')
40+
->disableOriginalConstructor()
41+
->getMock();
42+
43+
$this->storeManagerMock->expects($this->once())
44+
->method('getWebsite')
45+
->willReturn($websiteMock);
46+
47+
$this->model->setWebsiteId(1);
48+
}
49+
50+
public function testGetWebsiteId()
51+
{
52+
$websiteId = 10;
53+
54+
$websiteMock = $this->getMockBuilder('Magento\Store\Model\Website')
55+
->disableOriginalConstructor()
56+
->setMethods(['getId'])
57+
->getMock();
58+
59+
$websiteMock->expects($this->once())
60+
->method('getId')
61+
->willReturn($websiteId);
62+
63+
$this->storeManagerMock->expects($this->once())
64+
->method('getWebsite')
65+
->willReturn($websiteMock);
66+
67+
$this->assertEquals($websiteId, $this->model->getWebsiteId());
68+
}
69+
70+
public function testSetConditionName()
71+
{
72+
$this->assertEquals($this->model, $this->model->setConditionName('someName'));
73+
}
74+
75+
public function testGetConditionName()
76+
{
77+
$conditionName = 'someName';
78+
$this->assertEquals($conditionName, $this->model->setConditionName($conditionName)->getConditionName());
79+
}
80+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\OfflineShipping\Model\Config\Source;
7+
8+
class TablerateTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\OfflineShipping\Model\Config\Source\Tablerate
12+
*/
13+
protected $model;
14+
15+
/**
16+
* @var \Magento\OfflineShipping\Model\Carrier\Tablerate|\PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
protected $carrierTablerateMock;
19+
20+
protected function setUp()
21+
{
22+
$this->carrierTablerateMock = $this->getMockBuilder('\Magento\OfflineShipping\Model\Carrier\Tablerate')
23+
->disableOriginalConstructor()
24+
->setMethods(['getCode'])
25+
->getMock();
26+
27+
$helper = new \Magento\TestFramework\Helper\ObjectManager($this);
28+
$this->model = $helper->getObject('Magento\OfflineShipping\Model\Config\Source\Tablerate', [
29+
'carrierTablerate' => $this->carrierTablerateMock
30+
]);
31+
}
32+
33+
public function testToOptionArray()
34+
{
35+
$codes = [1, 2, 3, 4, 5];
36+
$expected = [];
37+
foreach ($codes as $k => $v) {
38+
$expected[] = ['value' => $k, 'label' => $v];
39+
}
40+
41+
$this->carrierTablerateMock->expects($this->once())
42+
->method('getCode')
43+
->willReturn($codes);
44+
45+
$this->assertEquals($expected, $this->model->toOptionArray());
46+
}
47+
}

0 commit comments

Comments
 (0)