@@ -17,149 +17,72 @@ class GuestCouponManagementTest extends \PHPUnit_Framework_TestCase
17
17
/**
18
18
* @var \PHPUnit_Framework_MockObject_MockObject
19
19
*/
20
- protected $ quoteRepositoryMock ;
20
+ protected $ quoteIdMaskFactoryMock ;
21
21
22
22
/**
23
23
* @var \PHPUnit_Framework_MockObject_MockObject
24
24
*/
25
- protected $ quoteMock ;
25
+ protected $ quoteIdMaskMock ;
26
26
27
27
/**
28
28
* @var \PHPUnit_Framework_MockObject_MockObject
29
29
*/
30
- protected $ quoteAddressMock ;
30
+ protected $ couponManagementMock ;
31
31
32
32
/**
33
- * @var \PHPUnit_Framework_MockObject_MockObject
33
+ * @var string
34
34
*/
35
- protected $ quoteIdMaskFactoryMock ;
35
+ protected $ maskedCartId ;
36
36
37
37
/**
38
- * @var \PHPUnit_Framework_MockObject_MockObject
38
+ * @var int
39
39
*/
40
- protected $ quoteIdMaskMock ;
40
+ protected $ cartId ;
41
+
42
+ /**
43
+ * @var string
44
+ */
45
+ protected $ couponCode ;
41
46
42
47
protected function setUp ()
43
48
{
44
49
$ objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
50
+ $ this ->couponManagementMock = $ this ->getMock ( 'Magento\Quote\Model\CouponManagement ' , [], [], '' , false );
45
51
46
- $ this ->quoteRepositoryMock = $ this ->getMock ('Magento\Quote\Model\QuoteRepository ' , [], [], '' , false );
47
- $ this ->quoteMock = $ this ->getMock (
48
- 'Magento\Quote\Model\Quote ' ,
49
- [
50
- 'getItemsCount ' ,
51
- 'setCouponCode ' ,
52
- 'collectTotals ' ,
53
- 'save ' ,
54
- 'getShippingAddress ' ,
55
- 'getCouponCode '
56
- ],
57
- [],
58
- '' ,
59
- false
60
- );
61
- $ this ->quoteAddressMock = $ this ->getMock (
62
- 'Magento\Quote\Model\Quote\Address ' ,
63
- [
64
- 'setCollectShippingRates '
65
- ],
66
- [],
67
- '' ,
68
- false );
52
+ $ this ->couponCode = 'test_coupon_code ' ;
53
+ $ this ->maskedCartId = 'f216207248d65c789b17be8545e0aa73 ' ;
54
+ $ this ->cartId = 123 ;
69
55
70
- $ this ->quoteIdMaskFactoryMock = $ this ->getMock ('Magento\Quote\Model\QuoteIdMaskFactory ' , [], [], '' , false );
71
- $ this ->quoteIdMaskMock = $ this ->getMock ('Magento\Quote\Model\QuoteIdMask ' , [], [], '' , false );
56
+ $ guestCartTestHelper = new GuestCartTestHelper ($ this );
57
+ list ($ this ->quoteIdMaskFactoryMock , $ this ->quoteIdMaskMock ) = $ guestCartTestHelper ->mockQuoteIdMask (
58
+ $ this ->maskedCartId ,
59
+ $ this ->cartId
60
+ );
72
61
73
62
$ this ->model = $ objectManager ->getObject (
74
63
'Magento\Quote\Model\GuestCart\GuestCouponManagement ' ,
75
64
[
76
- 'quoteRepository ' => $ this ->quoteRepositoryMock ,
65
+ 'couponManagement ' => $ this ->couponManagementMock ,
77
66
'quoteIdMaskFactory ' => $ this ->quoteIdMaskFactoryMock
78
67
]
79
68
);
80
69
}
81
70
82
- public function testGetCoupon ()
71
+ public function testGet ()
83
72
{
84
- $ maskedCartId = 'f216207248d65c789b17be8545e0aa73 ' ;
85
- $ cartId = 11 ;
86
- $ couponCode = 'test_coupon_code ' ;
87
-
88
- $ this ->quoteIdMaskFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->quoteIdMaskMock );
89
- $ this ->quoteIdMaskMock ->expects ($ this ->once ())
90
- ->method ('load ' )
91
- ->with ($ maskedCartId , 'masked_id ' )
92
- ->willReturn ($ this ->quoteIdMaskMock );
93
- $ this ->quoteIdMaskMock ->expects ($ this ->once ())
94
- ->method ('getId ' )
95
- ->willReturn ($ cartId );
96
-
97
- $ quoteMock = $ this ->getMock ('Magento\Quote\Model\Quote ' , ['getCouponCode ' , '__wakeup ' ], [], '' , false );
98
- $ quoteMock ->expects ($ this ->any ())->method ('getCouponCode ' )->will ($ this ->returnValue ($ couponCode ));
99
-
100
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())
101
- ->method ('getActive ' )
102
- ->with ($ cartId )
103
- ->will ($ this ->returnValue ($ quoteMock ));
104
-
105
- $ this ->assertEquals ($ couponCode , $ this ->model ->get ($ maskedCartId ));
73
+ $ this ->couponManagementMock ->expects ($ this ->once ())->method ('get ' )->willReturn ($ this ->couponCode );
74
+ $ this ->assertEquals ($ this ->couponCode , $ this ->model ->get ($ this ->maskedCartId ));
106
75
}
107
76
108
77
public function testSet ()
109
78
{
110
- $ maskedCartId = 'f216207248d65c789b17be8545e0aa73 ' ;
111
- $ cartId = 33 ;
112
- $ couponCode = '153a-ABC ' ;
113
-
114
- $ this ->quoteIdMaskFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->quoteIdMaskMock );
115
- $ this ->quoteIdMaskMock ->expects ($ this ->once ())
116
- ->method ('load ' )
117
- ->with ($ maskedCartId , 'masked_id ' )
118
- ->willReturn ($ this ->quoteIdMaskMock );
119
- $ this ->quoteIdMaskMock ->expects ($ this ->once ())
120
- ->method ('getId ' )
121
- ->willReturn ($ cartId );
122
-
123
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())
124
- ->method ('getActive ' )->with ($ cartId )->will ($ this ->returnValue ($ this ->quoteMock ));
125
- $ this ->quoteMock ->expects ($ this ->once ())->method ('getItemsCount ' )->will ($ this ->returnValue (12 ));
126
- $ this ->quoteMock ->expects ($ this ->once ())
127
- ->method ('getShippingAddress ' )->will ($ this ->returnValue ($ this ->quoteAddressMock ));
128
- $ this ->quoteAddressMock ->expects ($ this ->once ())->method ('setCollectShippingRates ' )->with (true );
129
- $ this ->quoteMock ->expects ($ this ->once ())->method ('setCouponCode ' )->with ($ couponCode );
130
- $ this ->quoteMock ->expects ($ this ->once ())->method ('collectTotals ' )->will ($ this ->returnValue ($ this ->quoteMock ));
131
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('save ' )->with ($ this ->quoteMock );
132
- $ this ->quoteMock ->expects ($ this ->once ())->method ('getCouponCode ' )->will ($ this ->returnValue ($ couponCode ));
133
-
134
- $ this ->assertTrue ($ this ->model ->set ($ maskedCartId , $ couponCode ));
79
+ $ this ->couponManagementMock ->expects ($ this ->once ())->method ('set ' )->willReturn (true );
80
+ $ this ->assertTrue ($ this ->model ->set ($ this ->maskedCartId , $ this ->couponCode ));
135
81
}
136
82
137
- public function testDelete ()
83
+ public function testRemove ()
138
84
{
139
- $ maskedCartId = 'f216207248d65c789b17be8545e0aa73 ' ;
140
- $ cartId = 65 ;
141
-
142
- $ this ->quoteIdMaskFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->quoteIdMaskMock );
143
- $ this ->quoteIdMaskMock ->expects ($ this ->once ())
144
- ->method ('load ' )
145
- ->with ($ maskedCartId , 'masked_id ' )
146
- ->willReturn ($ this ->quoteIdMaskMock );
147
- $ this ->quoteIdMaskMock ->expects ($ this ->once ())
148
- ->method ('getId ' )
149
- ->willReturn ($ cartId );
150
-
151
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())
152
- ->method ('getActive ' )->with ($ cartId )->will ($ this ->returnValue ($ this ->quoteMock ));
153
- $ this ->quoteMock ->expects ($ this ->once ())->method ('getItemsCount ' )->will ($ this ->returnValue (12 ));
154
- $ this ->quoteMock ->expects ($ this ->once ())
155
- ->method ('getShippingAddress ' )->will ($ this ->returnValue ($ this ->quoteAddressMock ));
156
- $ this ->quoteAddressMock ->expects ($ this ->once ())->method ('setCollectShippingRates ' )->with (true );
157
- $ this ->quoteMock ->expects ($ this ->once ())->method ('setCouponCode ' )->with ('' );
158
- $ this ->quoteMock ->expects ($ this ->once ())->method ('collectTotals ' )->will ($ this ->returnValue ($ this ->quoteMock ));
159
- $ this ->quoteMock ->expects ($ this ->once ())->method ('collectTotals ' )->will ($ this ->returnValue ($ this ->quoteMock ));
160
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('save ' )->with ($ this ->quoteMock );
161
- $ this ->quoteMock ->expects ($ this ->once ())->method ('getCouponCode ' )->will ($ this ->returnValue ('' ));
162
-
163
- $ this ->assertTrue ($ this ->model ->remove ($ maskedCartId ));
85
+ $ this ->couponManagementMock ->expects ($ this ->once ())->method ('remove ' )->willReturn (true );
86
+ $ this ->assertTrue ($ this ->model ->remove ($ this ->maskedCartId ));
164
87
}
165
88
}
0 commit comments