Skip to content

Commit acdec2c

Browse files
author
Serhiy Shkolyarenko
committed
MAGETWO-45672: Broken checkout flow
added unit test
1 parent f3bb402 commit acdec2c

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Persistent\Test\Unit\Model\Checkout;
7+
8+
class ConfigProviderPluginTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \PHPUnit_Framework_MockObject_MockObject
12+
*/
13+
protected $persistentHelperMock;
14+
15+
/**
16+
* @var \PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
protected $persistentSessionMock;
19+
20+
/**
21+
* @var \PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
protected $checkoutSessionMock;
24+
25+
/**
26+
* @var \PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
protected $maskFactoryMock;
29+
30+
/**
31+
* @var \PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
protected $customerSessionMock;
34+
35+
/**
36+
* @var \Magento\Persistent\Model\Checkout\ConfigProviderPlugin
37+
*/
38+
protected $plugin;
39+
40+
/**
41+
* @var \PHPUnit_Framework_MockObject_MockObject
42+
*/
43+
protected $subjectMock;
44+
45+
protected function setUp()
46+
{
47+
$this->persistentHelperMock = $this->getMock('Magento\Persistent\Helper\Data', [], [], '', false);
48+
$this->persistentSessionMock = $this->getMock('Magento\Persistent\Helper\Session', [], [], '', false);
49+
$this->checkoutSessionMock = $this->getMock('Magento\Checkout\Model\Session', [], [], '', false);
50+
$this->maskFactoryMock = $this->getMock(
51+
'Magento\Quote\Model\QuoteIdMaskFactory',
52+
['create', '__wakeup'],
53+
[],
54+
'',
55+
false
56+
);
57+
$this->customerSessionMock = $this->getMock('Magento\Customer\Model\Session', [], [], '', false);
58+
$this->subjectMock = $this->getMock('\Magento\Checkout\Model\DefaultConfigProvider', [], [], '', false);
59+
60+
$this->plugin = new \Magento\Persistent\Model\Checkout\ConfigProviderPlugin(
61+
$this->persistentHelperMock,
62+
$this->persistentSessionMock,
63+
$this->checkoutSessionMock,
64+
$this->maskFactoryMock,
65+
$this->customerSessionMock
66+
);
67+
}
68+
69+
/**
70+
* @dataProvider configDataProvider
71+
*/
72+
public function testAfterGetConfigNegative($persitenceEnabled, $isPersistent, $isLoggedIn)
73+
{
74+
$result = [40, 30, 50];
75+
76+
$this->persistentHelperMock->expects($this->once())->method('isEnabled')->willReturn($persitenceEnabled);
77+
$this->persistentSessionMock->expects($this->any())->method('isPersistent')->willReturn($isPersistent);
78+
$this->customerSessionMock->expects($this->any())->method('isLoggedIn')->willReturn($isLoggedIn);
79+
$this->maskFactoryMock->expects($this->never())->method('create');
80+
$this->assertEquals($result, $this->plugin->afterGetConfig($this->subjectMock, $result));
81+
}
82+
83+
public function configDataProvider()
84+
{
85+
return [
86+
[false, true, true], //disabled persistence case
87+
[true, false, true], //persistence enabled but not persistent session
88+
[true, true, true], //logged in user
89+
];
90+
}
91+
92+
public function testAfterGetConfigPositive()
93+
{
94+
$maskedId = 3005;
95+
$result = [40, 30, 50];
96+
$expectedResult = $result;
97+
$expectedResult['quoteData']['entity_id'] = $maskedId;
98+
99+
$this->persistentHelperMock->expects($this->once())->method('isEnabled')->willReturn(true);
100+
$this->persistentSessionMock->expects($this->once())->method('isPersistent')->willReturn(true);
101+
$this->customerSessionMock->expects($this->once())->method('isLoggedIn')->willReturn(false);
102+
103+
$quoteMaskMock = $this->getMock(
104+
'Magento\Quote\Model\QuoteIdMask',
105+
['load', 'getMaskedId'],
106+
[],
107+
'',
108+
false
109+
);
110+
$this->maskFactoryMock->expects($this->once())->method('create')->willReturn($quoteMaskMock);
111+
$quoteMock = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false);
112+
113+
$this->checkoutSessionMock->expects($this->once())->method('getQuote')->willReturn($quoteMock);
114+
$quoteMaskMock->expects($this->once())->method('load')->willReturnSelf();
115+
$quoteMaskMock->expects($this->once())->method('getMaskedId')->willReturn($maskedId);
116+
$this->assertEquals($expectedResult, $this->plugin->afterGetConfig($this->subjectMock, $result));
117+
}
118+
}

0 commit comments

Comments
 (0)