@@ -17,109 +17,76 @@ class GuestShippingAddressManagementTest extends \PHPUnit_Framework_TestCase
17
17
/**
18
18
* @var \PHPUnit_Framework_MockObject_MockObject
19
19
*/
20
- protected $ quoteRepositoryMock ;
20
+ protected $ quoteAddressMock ;
21
21
22
22
/**
23
23
* @var \PHPUnit_Framework_MockObject_MockObject
24
24
*/
25
- protected $ quoteAddressMock ;
25
+ protected $ quoteIdMaskFactoryMock ;
26
26
27
27
/**
28
28
* @var \PHPUnit_Framework_MockObject_MockObject
29
29
*/
30
- protected $ validatorMock ;
30
+ protected $ quoteIdMaskMock ;
31
31
32
32
/**
33
33
* @var \PHPUnit_Framework_MockObject_MockObject
34
34
*/
35
- protected $ quoteIdMaskFactoryMock ;
35
+ protected $ shippingAddressManagementMock ;
36
36
37
37
/**
38
- * @var \PHPUnit_Framework_MockObject_MockObject
38
+ * @var string
39
39
*/
40
- protected $ quoteIdMaskMock ;
40
+ protected $ maskedCartId ;
41
+
42
+ /**
43
+ * @var int
44
+ */
45
+ protected $ cartId ;
41
46
42
47
protected function setUp ()
43
48
{
44
49
$ objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
45
50
46
- $ this ->quoteRepositoryMock = $ this ->getMock ('\Magento\Quote\Model\QuoteRepository ' , [], [], '' , false );
47
- $ this ->quoteAddressMock = $ this ->getMock ( '\Magento\Quote\Model\Quote\Address ' , [], [], '' , false );
48
- $ this ->validatorMock = $ this ->getMock ( 'Magento\Quote\Model\QuoteAddressValidator ' , [], [], '' , false );
49
- $ this ->quoteIdMaskFactoryMock = $ this ->getMock ('Magento\Quote\Model\QuoteIdMaskFactory ' , [], [], '' , false );
50
- $ this ->quoteIdMaskMock = $ this ->getMock ('Magento\Quote\Model\QuoteIdMask ' , [], [], '' , false );
51
+ $ this ->shippingAddressManagementMock = $ this ->getMock (
52
+ 'Magento\Quote\Model\ShippingAddressManagement ' ,
53
+ [],
54
+ [],
55
+ '' ,
56
+ false
57
+ );
58
+ $ this ->quoteAddressMock = $ this ->getMock ('Magento\Quote\Model\Quote\Address ' , [], [], '' , false );
59
+
60
+ $ this ->maskedCartId = 'f216207248d65c789b17be8545e0aa73 ' ;
61
+ $ this ->cartId = 123 ;
62
+
63
+ $ guestCartTestHelper = new GuestCartTestHelper ($ this );
64
+ list ($ this ->quoteIdMaskFactoryMock , $ this ->quoteIdMaskMock ) = $ guestCartTestHelper ->mockQuoteIdMask (
65
+ $ this ->maskedCartId ,
66
+ $ this ->cartId
67
+ );
68
+
51
69
$ this ->model = $ objectManager ->getObject (
52
70
'Magento\Quote\Model\GuestCart\GuestShippingAddressManagement ' ,
53
71
[
54
- 'quoteRepository ' => $ this ->quoteRepositoryMock ,
55
- 'addressValidator ' => $ this ->validatorMock ,
56
- 'logger ' => $ this ->getMock ('\Psr\Log\LoggerInterface ' ),
72
+ 'shippingAddressManagement ' => $ this ->shippingAddressManagementMock ,
57
73
'quoteIdMaskFactory ' => $ this ->quoteIdMaskFactoryMock
58
74
]
59
75
);
60
76
}
61
77
62
- public function testAssignAddress ()
78
+ public function testAssign ()
63
79
{
64
- $ maskedCartId = 'f216207248d65c789b17be8545e0aa73 ' ;
65
- $ cartId = 867 ;
66
-
67
- $ this ->quoteIdMaskFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->quoteIdMaskMock );
68
- $ this ->quoteIdMaskMock ->expects ($ this ->once ())
69
- ->method ('load ' )
70
- ->with ($ maskedCartId , 'masked_id ' )
71
- ->willReturn ($ this ->quoteIdMaskMock );
72
- $ this ->quoteIdMaskMock ->expects ($ this ->once ())
73
- ->method ('getId ' )
74
- ->willReturn ($ cartId );
75
-
76
- $ quoteMock = $ this ->getMock ('\Magento\Quote\Model\Quote ' , [], [], '' , false );
77
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())
78
- ->method ('getActive ' )
79
- ->with ($ cartId )
80
- ->will ($ this ->returnValue ($ quoteMock ));
81
- $ quoteMock ->expects ($ this ->once ())->method ('isVirtual ' )->will ($ this ->returnValue (false ));
82
-
83
-
84
- $ this ->validatorMock ->expects ($ this ->once ())->method ('validate ' )
85
- ->with ($ this ->quoteAddressMock )
86
- ->will ($ this ->returnValue (true ));
87
-
88
- $ quoteMock ->expects ($ this ->once ())->method ('setShippingAddress ' )->with ($ this ->quoteAddressMock );
89
- $ quoteMock ->expects ($ this ->once ())->method ('setDataChanges ' )->with (true );
90
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('save ' )->with ($ quoteMock );
91
-
92
80
$ addressId = 1 ;
93
- $ shippingAddressMock = $ this ->getMock ('\Magento\Quote\Model\Quote\Address ' , [], [], '' , false );
94
- $ shippingAddressMock ->expects ($ this ->once ())->method ('getId ' )->will ($ this ->returnValue ($ addressId ));
95
- $ quoteMock ->expects ($ this ->once ())->method ('getShippingAddress ' )
96
- ->will ($ this ->returnValue ($ shippingAddressMock ));
97
-
98
- $ this ->assertEquals ($ addressId , $ this ->model ->assign ($ maskedCartId , $ this ->quoteAddressMock ));
81
+ $ this ->shippingAddressManagementMock ->expects ($ this ->once ())->method ('assign ' )->willReturn ($ addressId );
82
+ $ this ->assertEquals ($ addressId , $ this ->model ->assign ($ this ->maskedCartId , $ this ->quoteAddressMock ));
99
83
}
100
84
101
- public function testGetAddress ()
85
+ public function testGet ()
102
86
{
103
- $ maskedCartId = 'f216207248d65c789b17be8545e0aa73 ' ;
104
- $ cartId = 867 ;
105
-
106
- $ this ->quoteIdMaskFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->quoteIdMaskMock );
107
- $ this ->quoteIdMaskMock ->expects ($ this ->once ())
108
- ->method ('load ' )
109
- ->with ($ maskedCartId , 'masked_id ' )
110
- ->willReturn ($ this ->quoteIdMaskMock );
111
- $ this ->quoteIdMaskMock ->expects ($ this ->once ())
112
- ->method ('getId ' )
113
- ->willReturn ($ cartId );
114
-
115
- $ quoteMock = $ this ->getMock ('\Magento\Quote\Model\Quote ' , [], [], '' , false );
116
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('getActive ' )->with ($ cartId )->will (
117
- $ this ->returnValue ($ quoteMock )
87
+ $ this ->shippingAddressManagementMock ->expects ($ this ->once ())->method ('get ' )->willReturn (
88
+ $ this ->quoteAddressMock
118
89
);
119
-
120
- $ addressMock = $ this ->getMock ('\Magento\Quote\Model\Quote\Address ' , [], [], '' , false );
121
- $ quoteMock ->expects ($ this ->any ())->method ('getShippingAddress ' )->will ($ this ->returnValue ($ addressMock ));
122
- $ quoteMock ->expects ($ this ->any ())->method ('isVirtual ' )->will ($ this ->returnValue (false ));
123
- $ this ->assertEquals ($ addressMock , $ this ->model ->get ($ maskedCartId ));
90
+ $ this ->assertEquals ($ this ->quoteAddressMock , $ this ->model ->get ($ this ->maskedCartId ));
124
91
}
125
92
}
0 commit comments