Skip to content

Commit 7d7d9e3

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

File tree

6 files changed

+211
-18
lines changed

6 files changed

+211
-18
lines changed

app/code/Magento/OfflineShipping/Model/Config/Backend/Tablerate.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public function __construct(
4646
*/
4747
public function afterSave()
4848
{
49-
$this->_tablerateFactory->create()->uploadAndImport($this);
49+
/** @var \Magento\OfflineShipping\Model\Resource\Carrier\Tablerate $tableRate */
50+
$tableRate = $this->_tablerateFactory->create();
51+
$tableRate->uploadAndImport($this);
5052
}
5153
}

app/code/Magento/OfflineShipping/Model/Observer/SalesRule/ActionsTab.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,24 @@ public function prepareForm($observer)
2424
$form = $observer->getForm();
2525
foreach ($form->getElements() as $element) {
2626
/** @var \Magento\Framework\Data\Form\Element\AbstractElement $element */
27-
if ($element->getId() == 'action_fieldset') {
28-
$element->addField(
29-
'simple_free_shipping',
30-
'select',
31-
[
32-
'label' => __('Free Shipping'),
33-
'title' => __('Free Shipping'),
34-
'name' => 'simple_free_shipping',
35-
'options' => [
36-
0 => __('No'),
37-
Rule::FREE_SHIPPING_ITEM => __('For matching items only'),
38-
Rule::FREE_SHIPPING_ADDRESS => __('For shipment with matching items'),
39-
]
40-
]
41-
);
27+
if ($element->getId() != 'action_fieldset') {
28+
continue;
4229
}
30+
31+
$element->addField(
32+
'simple_free_shipping',
33+
'select',
34+
[
35+
'label' => __('Free Shipping'),
36+
'title' => __('Free Shipping'),
37+
'name' => 'simple_free_shipping',
38+
'options' => [
39+
0 => __('No'),
40+
Rule::FREE_SHIPPING_ITEM => __('For matching items only'),
41+
Rule::FREE_SHIPPING_ADDRESS => __('For shipment with matching items'),
42+
]
43+
]
44+
);
4345
}
4446
}
4547
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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+
/**
21+
* @var \Magento\Backend\Helper\Data|\PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
protected $backendHelperMock;
24+
25+
/**
26+
* @var \Magento\OfflineShipping\Model\Resource\Carrier\Tablerate\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
protected $tablerateMock;
29+
30+
/**
31+
* @var \Magento\Backend\Block\Template\Context|\PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
protected $context;
34+
35+
/**
36+
* @var \Magento\OfflineShipping\Model\Resource\Carrier\Tablerate\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
protected $collectionFactoryMock;
39+
40+
protected function setUp()
41+
{
42+
$objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
43+
44+
$this->storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManagerInterface')
45+
->disableOriginalConstructor()
46+
->getMock();
47+
48+
$this->context = $objectManager->getObject('Magento\Backend\Block\Template\Context', [
49+
'storeManager' => $this->storeManagerMock
50+
]);
51+
52+
$this->backendHelperMock = $this->getMockBuilder('\Magento\Backend\Helper\Data')
53+
->disableOriginalConstructor()
54+
->getMock();
55+
56+
$this->collectionFactoryMock = $this->getMockBuilder('\Magento\OfflineShipping\Model\Resource\Carrier\Tablerate\CollectionFactory')
57+
->disableOriginalConstructor()
58+
->getMock();
59+
60+
$this->tablerateMock = $this->getMockBuilder('Magento\OfflineShipping\Model\Carrier\Tablerate')
61+
->disableOriginalConstructor()
62+
->getMock();
63+
64+
$this->model = new \Magento\OfflineShipping\Block\Adminhtml\Carrier\Tablerate\Grid(
65+
$this->context,
66+
$this->backendHelperMock,
67+
$this->collectionFactoryMock,
68+
$this->tablerateMock
69+
);
70+
}
71+
72+
public function testSetWebsiteId()
73+
{
74+
$websiteId = 1;
75+
76+
$websiteMock = $this->getMockBuilder('Magento\Store\Model\Website')
77+
->setMethods(['getId'])
78+
->disableOriginalConstructor()
79+
->getMock();
80+
81+
$this->storeManagerMock->expects($this->once())
82+
->method('getWebsite')
83+
->with($websiteId)
84+
->willReturn($websiteMock);
85+
86+
$websiteMock->expects($this->once())
87+
->method('getId')
88+
->willReturn($websiteId);
89+
90+
$this->assertSame($this->model, $this->model->setWebsiteId($websiteId));
91+
$this->assertEquals($websiteId, $this->model->getWebsiteId());
92+
}
93+
94+
public function testGetWebsiteId()
95+
{
96+
$websiteId = 10;
97+
98+
$websiteMock = $this->getMockBuilder('Magento\Store\Model\Website')
99+
->disableOriginalConstructor()
100+
->setMethods(['getId'])
101+
->getMock();
102+
103+
$websiteMock->expects($this->once())
104+
->method('getId')
105+
->willReturn($websiteId);
106+
107+
$this->storeManagerMock->expects($this->once())
108+
->method('getWebsite')
109+
->willReturn($websiteMock);
110+
111+
$this->assertEquals($websiteId, $this->model->getWebsiteId());
112+
113+
$this->storeManagerMock->expects($this->never())
114+
->method('getWebsite')
115+
->willReturn($websiteMock);
116+
117+
$this->assertEquals($websiteId, $this->model->getWebsiteId());
118+
}
119+
120+
public function testSetAndGetConditionName()
121+
{
122+
$conditionName = 'someName';
123+
$this->assertEquals($this->model, $this->model->setConditionName($conditionName));
124+
$this->assertEquals($conditionName, $this->model->getConditionName());
125+
}
126+
}
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+
}

dev/tests/unit/testsuite/Magento/OfflineShipping/Model/Observer/SalesRule/ActionsTabTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\OfflineShipping\Model\Observer\SalesRule;
77

8+
use Magento\OfflineShipping\Model\SalesRule\Rule;
9+
810
class ActionsTabTest extends \PHPUnit_Framework_TestCase
911
{
1012
/**
@@ -39,7 +41,21 @@ public function testPrepareForm()
3941
->willReturn('action_fieldset');
4042

4143
$elementMock->expects($this->once())
42-
->method('addField');
44+
->method('addField')
45+
->with(
46+
'simple_free_shipping',
47+
'select',
48+
[
49+
'label' => __('Free Shipping'),
50+
'title' => __('Free Shipping'),
51+
'name' => 'simple_free_shipping',
52+
'options' => [
53+
0 => __('No'),
54+
Rule::FREE_SHIPPING_ITEM => __('For matching items only'),
55+
Rule::FREE_SHIPPING_ADDRESS => __('For shipment with matching items'),
56+
]
57+
]
58+
);
4359

4460
$formMock->expects($this->once())
4561
->method('getElements')

dev/tests/unit/testsuite/Magento/OfflineShipping/Model/Plugin/Checkout/Block/Cart/ShippingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function testAfterGetStateActive($scopeConfigMockReturnValue, $result, $a
4848
->method('getValue')
4949
->willReturn($scopeConfigMockReturnValue);
5050

51-
$this->assertEquals($this->model->afterGetStateActive($subjectMock, $result), $assertResult);
51+
$this->assertEquals($assertResult, $this->model->afterGetStateActive($subjectMock, $result));
5252
}
5353

5454
public function afterGetStateActiveDataProvider()

0 commit comments

Comments
 (0)