Skip to content

Commit 49a7b12

Browse files
author
Ievgen Shakhsuvarov
committed
MAGETWO-37570: Unable to place order on frontend using secure urls
- Added unit test
1 parent 83e3ad9 commit 49a7b12

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Checkout\Test\Unit\Block;
7+
8+
class OnepageTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\Checkout\Block\Onepage
12+
*/
13+
protected $model;
14+
15+
/**
16+
* @var \PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
protected $configProviderMock;
19+
20+
/**
21+
* @var \PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
protected $storeManagerMock;
24+
25+
/**
26+
* @var \PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
protected $formKeyMock;
29+
30+
/**
31+
* @var \PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
protected $layoutProcessorMock;
34+
35+
protected function setUp()
36+
{
37+
$contextMock = $this->getMock('\Magento\Framework\View\Element\Template\Context', [], [], '', false);
38+
$directoryHelperMock = $this->getMock('\Magento\Directory\Helper\Data', [], [], '', false);
39+
$configCacheTypeMock = $this->getMock('\Magento\Framework\App\Cache\Type\Config', [], [], '', false);
40+
$customerSessionMock = $this->getMock('\Magento\Customer\Model\Session', [], [], '', false);
41+
$resourceSessionMock = $this->getMock('\Magento\Checkout\Model\Session', [], [], '', false);
42+
$addressConfigMock = $this->getMock('\Magento\Customer\Model\Address\Config', [], [], '', false);
43+
$httpContextMock = $this->getMock('\Magento\Framework\App\Http\Context', [], [], '', false);
44+
$addressMapperMock = $this->getMock('\Magento\Customer\Model\Address\Mapper', [], [], '', false);
45+
$this->formKeyMock = $this->getMock('\Magento\Framework\Data\Form\FormKey', [], [], '', false);
46+
$this->configProviderMock = $this->getMock(
47+
'\Magento\Checkout\Model\CompositeConfigProvider',
48+
[],
49+
[],
50+
'',
51+
false
52+
);
53+
$countryCollectionFactoryMock = $this->getMock(
54+
'\Magento\Directory\Model\Resource\Country\CollectionFactory',
55+
[],
56+
[],
57+
'',
58+
false
59+
);
60+
$regionCollectionFactoryMock = $this->getMock(
61+
'\Magento\Directory\Model\Resource\Region\CollectionFactory',
62+
[],
63+
[],
64+
'',
65+
false
66+
);
67+
$customerRepositoryMock = $this->getMock(
68+
'\Magento\Customer\Api\CustomerRepositoryInterface',
69+
[],
70+
[],
71+
'',
72+
false
73+
);
74+
75+
$this->storeManagerMock = $this->getMock('\Magento\Store\Model\StoreManagerInterface', [], [], '', false);
76+
$contextMock->expects($this->once())->method('getStoreManager')->willReturn($this->storeManagerMock);
77+
$this->layoutProcessorMock = $this->getMock(
78+
'\Magento\Checkout\Block\Checkout\LayoutProcessorInterface',
79+
[],
80+
[],
81+
'',
82+
false
83+
);
84+
85+
$this->model = new \Magento\Checkout\Block\Onepage(
86+
$contextMock,
87+
$directoryHelperMock,
88+
$configCacheTypeMock,
89+
$customerSessionMock,
90+
$resourceSessionMock,
91+
$countryCollectionFactoryMock,
92+
$regionCollectionFactoryMock,
93+
$customerRepositoryMock,
94+
$addressConfigMock,
95+
$httpContextMock,
96+
$addressMapperMock,
97+
$this->formKeyMock,
98+
$this->configProviderMock,
99+
[$this->layoutProcessorMock]
100+
);
101+
}
102+
103+
public function testGetBaseUrl()
104+
{
105+
$baseUrl = 'http://magento.com';
106+
$storeMock = $this->getMock('\Magento\Store\Model\Store', [], [], '', false);
107+
108+
$storeMock->expects($this->once())->method('getBaseUrl')->willReturn($baseUrl);
109+
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock);
110+
111+
$this->assertEquals($baseUrl, $this->model->getBaseUrl());
112+
}
113+
114+
public function testGetCheckoutConfig()
115+
{
116+
$checkoutConfig = ['checkout', 'config'];
117+
$this->configProviderMock->expects($this->once())->method('getConfig')->willReturn($checkoutConfig);
118+
119+
$this->assertEquals($checkoutConfig, $this->model->getCheckoutConfig());
120+
}
121+
122+
public function testGetFormKey()
123+
{
124+
$formKey = 'form_key';
125+
$this->formKeyMock->expects($this->once())->method('getFormKey')->willReturn($formKey);
126+
127+
$this->assertEquals($formKey, $this->model->getFormKey());
128+
}
129+
130+
public function testGetJsLayout()
131+
{
132+
$processedLayout = ['layout' => ['processed' => true]];
133+
$jsonLayout = '{"layout":{"processed":true}}';
134+
$this->layoutProcessorMock->expects($this->once())->method('process')->with([])->willReturn($processedLayout);
135+
136+
$this->assertEquals($jsonLayout, $this->model->getJsLayout());
137+
}
138+
}

0 commit comments

Comments
 (0)