|
9 | 9 | */
|
10 | 10 | namespace Magento\Paypal\Test\Unit\Helper;
|
11 | 11 |
|
| 12 | +use Magento\Checkout\Model\Session; |
| 13 | +use Magento\Paypal\Helper\Checkout; |
| 14 | +use Magento\Sales\Model\Order; |
| 15 | + |
12 | 16 | class CheckoutTest extends \PHPUnit_Framework_TestCase
|
13 | 17 | {
|
14 | 18 | /**
|
15 |
| - * @var \Magento\Checkout\Model\Session|\PHPUnit_Framework_MockObject_MockObject |
| 19 | + * @var Session|\PHPUnit_Framework_MockObject_MockObject |
16 | 20 | */
|
17 |
| - protected $_session; |
| 21 | + private $session; |
18 | 22 |
|
19 | 23 | /**
|
20 |
| - * @var \Magento\Quote\Model\QuoteFactory|\PHPUnit_Framework_MockObject_MockObject |
| 24 | + * @var Checkout |
21 | 25 | */
|
22 |
| - protected $_quoteFactory; |
| 26 | + private $checkout; |
23 | 27 |
|
24 |
| - /** |
25 |
| - * @var \Magento\Paypal\Helper\Checkout |
26 |
| - */ |
27 |
| - protected $_checkout; |
28 |
| - |
29 |
| - /** |
30 |
| - * Sets up the fixture, for example, opens a network connection. |
31 |
| - * This method is called before a test is executed. |
32 |
| - */ |
33 | 28 | protected function setUp()
|
34 | 29 | {
|
35 |
| - $this->_session = $this->getMockBuilder( |
36 |
| - 'Magento\Checkout\Model\Session' |
37 |
| - )->disableOriginalConstructor()->setMethods( |
38 |
| - ['getLastRealOrder', 'replaceQuote', 'unsLastRealOrderId', '__wakeup'] |
39 |
| - )->getMock(); |
40 |
| - $this->_quoteFactory = $this->getMockBuilder( |
41 |
| - 'Magento\Quote\Model\QuoteFactory' |
42 |
| - )->disableOriginalConstructor()->setMethods( |
43 |
| - ['create', '__wakeup'] |
44 |
| - )->getMock(); |
45 |
| - |
46 |
| - $this->_checkout = new \Magento\Paypal\Helper\Checkout($this->_session, $this->_quoteFactory); |
| 30 | + $this->session = $this->getMockBuilder(Session::class) |
| 31 | + ->disableOriginalConstructor() |
| 32 | + ->getMock(); |
| 33 | + |
| 34 | + $this->checkout = new Checkout($this->session); |
47 | 35 | }
|
48 | 36 |
|
49 |
| - /** |
50 |
| - * Get order mock |
51 |
| - * |
52 |
| - * @param bool $hasOrderId |
53 |
| - * @param array $mockMethods |
54 |
| - * @return \Magento\Sales\Model\Order|\PHPUnit_Framework_MockObject_MockObject |
55 |
| - */ |
56 |
| - protected function _getOrderMock($hasOrderId, $mockMethods = []) |
| 37 | + public function testCancelCurrentOrder() |
57 | 38 | {
|
58 |
| - $order = $this->getMockBuilder( |
59 |
| - 'Magento\Sales\Model\Order' |
60 |
| - )->disableOriginalConstructor()->setMethods( |
61 |
| - array_merge(['getId', '__wakeup'], $mockMethods) |
62 |
| - )->getMock(); |
63 |
| - $order->expects($this->once())->method('getId')->will($this->returnValue($hasOrderId ? 'order id' : null)); |
64 |
| - return $order; |
| 39 | + $id = 1; |
| 40 | + $state = Order::STATE_PENDING_PAYMENT; |
| 41 | + $comment = 'Bla Bla'; |
| 42 | + |
| 43 | + $order = $this->getMockBuilder(Order::class) |
| 44 | + ->disableOriginalConstructor() |
| 45 | + ->getMock(); |
| 46 | + |
| 47 | + $this->session->expects(static::once()) |
| 48 | + ->method('getLastRealOrder') |
| 49 | + ->willReturn($order); |
| 50 | + $order->expects(static::once()) |
| 51 | + ->method('getId') |
| 52 | + ->willReturn($id); |
| 53 | + $order->expects(static::once()) |
| 54 | + ->method('getState') |
| 55 | + ->willReturn($state); |
| 56 | + $order->expects(static::once()) |
| 57 | + ->method('registerCancellation') |
| 58 | + ->with($comment) |
| 59 | + ->willReturnSelf(); |
| 60 | + $order->expects(static::once()) |
| 61 | + ->method('save'); |
| 62 | + |
| 63 | + static::assertTrue($this->checkout->cancelCurrentOrder($comment)); |
65 | 64 | }
|
66 | 65 |
|
67 |
| - /** |
68 |
| - * @param bool $hasOrderId |
69 |
| - * @param bool $isOrderCancelled |
70 |
| - * @param bool $expectedResult |
71 |
| - * @dataProvider cancelCurrentOrderDataProvider |
72 |
| - */ |
73 |
| - public function testCancelCurrentOrder($hasOrderId, $isOrderCancelled, $expectedResult) |
| 66 | + public function testCancelCurrentOrderWhichIsCancelled() |
74 | 67 | {
|
75 |
| - $comment = 'Some test comment'; |
76 |
| - $order = $this->_getOrderMock($hasOrderId, ['registerCancellation', 'save']); |
77 |
| - $order->setData( |
78 |
| - 'state', |
79 |
| - $isOrderCancelled ? \Magento\Sales\Model\Order::STATE_CANCELED : 'some another state' |
80 |
| - ); |
81 |
| - if ($expectedResult) { |
82 |
| - $order->expects( |
83 |
| - $this->once() |
84 |
| - )->method( |
85 |
| - 'registerCancellation' |
86 |
| - )->with( |
87 |
| - $this->equalTo($comment) |
88 |
| - )->will( |
89 |
| - $this->returnSelf() |
90 |
| - ); |
91 |
| - $order->expects($this->once())->method('save'); |
92 |
| - } else { |
93 |
| - $order->expects($this->never())->method('registerCancellation'); |
94 |
| - $order->expects($this->never())->method('save'); |
95 |
| - } |
96 |
| - |
97 |
| - $this->_session->expects($this->any())->method('getLastRealOrder')->will($this->returnValue($order)); |
98 |
| - $this->assertEquals($expectedResult, $this->_checkout->cancelCurrentOrder($comment)); |
| 68 | + $id = 1; |
| 69 | + $state = Order::STATE_CANCELED; |
| 70 | + $comment = 'Bla Bla'; |
| 71 | + |
| 72 | + $order = $this->getMockBuilder(Order::class) |
| 73 | + ->disableOriginalConstructor() |
| 74 | + ->getMock(); |
| 75 | + |
| 76 | + $this->session->expects(static::once()) |
| 77 | + ->method('getLastRealOrder') |
| 78 | + ->willReturn($order); |
| 79 | + $order->expects(static::once()) |
| 80 | + ->method('getId') |
| 81 | + ->willReturn($id); |
| 82 | + $order->expects(static::once()) |
| 83 | + ->method('getState') |
| 84 | + ->willReturn($state); |
| 85 | + $order->expects(static::never()) |
| 86 | + ->method('registerCancellation') |
| 87 | + ->with($comment) |
| 88 | + ->willReturnSelf(); |
| 89 | + $order->expects(static::never()) |
| 90 | + ->method('save'); |
| 91 | + |
| 92 | + static::assertFalse($this->checkout->cancelCurrentOrder($comment)); |
99 | 93 | }
|
100 | 94 |
|
101 |
| - /** |
102 |
| - * @return array |
103 |
| - */ |
104 |
| - public function cancelCurrentOrderDataProvider() |
| 95 | + public function testRestoreQuote() |
105 | 96 | {
|
106 |
| - return [ |
107 |
| - [true, false, true], |
108 |
| - [true, true, false], |
109 |
| - [false, true, false], |
110 |
| - [false, false, false] |
111 |
| - ]; |
| 97 | + $this->session->expects(static::once()) |
| 98 | + ->method('restoreQuote') |
| 99 | + ->willReturn(true); |
| 100 | + |
| 101 | + static::assertTrue($this->checkout->restoreQuote()); |
112 | 102 | }
|
113 | 103 | }
|
0 commit comments