@@ -59,22 +59,22 @@ class GiftMessageConfigProviderTest extends \PHPUnit_Framework_TestCase
59
59
60
60
protected function setUp ()
61
61
{
62
- $ this ->checkoutSessionMock = $ this ->getMock (' Magento\Checkout\Model\Session ' , [], [], '' , false );
63
- $ this ->httpContextMock = $ this ->getMock (' Magento\Framework\App\Http\Context ' , [], [], '' , false );
64
- $ this ->storeManagerMock = $ this ->getMock (' Magento\Store\Model\StoreManagerInterface ' , [], [], '' , false );
65
- $ this ->localeFormatMock = $ this ->getMock (' Magento\Framework\Locale\FormatInterface ' , [], [], '' , false );
66
- $ this ->formKeyMock = $ this ->getMock (' Magento\Framework\Data\Form\FormKey ' , [], [], '' , false );
67
- $ this ->scopeConfigMock = $ this ->getMock (' Magento\Framework\App\Config\ScopeConfigInterface ' , [], [], '' , false );
68
- $ contextMock = $ this ->getMock (' Magento\Framework\App\Helper\Context ' , [], [], '' , false );
62
+ $ this ->checkoutSessionMock = $ this ->getMock (\ Magento \Checkout \Model \Session::class , [], [], '' , false );
63
+ $ this ->httpContextMock = $ this ->getMock (\ Magento \Framework \App \Http \Context::class , [], [], '' , false );
64
+ $ this ->storeManagerMock = $ this ->getMock (\ Magento \Store \Model \StoreManagerInterface::class , [], [], '' , false );
65
+ $ this ->localeFormatMock = $ this ->getMock (\ Magento \Framework \Locale \FormatInterface::class , [], [], '' , false );
66
+ $ this ->formKeyMock = $ this ->getMock (\ Magento \Framework \Data \Form \FormKey::class , [], [], '' , false );
67
+ $ this ->scopeConfigMock = $ this ->getMock (\ Magento \Framework \App \Config \ScopeConfigInterface::class , [], [], '' , false );
68
+ $ contextMock = $ this ->getMock (\ Magento \Framework \App \Helper \Context::class , [], [], '' , false );
69
69
$ this ->cartRepositoryMock = $ this ->getMock (
70
- ' Magento\GiftMessage\Api\CartRepositoryInterface ' ,
70
+ \ Magento \GiftMessage \Api \CartRepositoryInterface::class ,
71
71
[],
72
72
[],
73
73
'' ,
74
74
false
75
75
);
76
76
$ this ->itemRepositoryMock = $ this ->getMock (
77
- ' Magento\GiftMessage\Api\ItemRepositoryInterface ' ,
77
+ \ Magento \GiftMessage \Api \ItemRepositoryInterface::class ,
78
78
[],
79
79
[],
80
80
'' ,
@@ -94,8 +94,17 @@ protected function setUp()
94
94
);
95
95
}
96
96
97
- public function testGetConfig ()
98
- {
97
+ /**
98
+ * @param $productMessageAvailable
99
+ * @param $messageData
100
+ * @param $expectedItemLevel
101
+ * @dataProvider getConfigDataProvider
102
+ */
103
+ public function testGetConfig (
104
+ $ productMessageAvailable ,
105
+ $ messageData ,
106
+ $ expectedItemLevel
107
+ ) {
99
108
$ orderLevel = true ;
100
109
$ itemLevel = true ;
101
110
$ isCustomerLoggedIn = true ;
@@ -104,34 +113,28 @@ public function testGetConfig()
104
113
$ currencyCode = 'EUR ' ;
105
114
$ priceFormat = [$ currencyCode ];
106
115
$ storeCode = 4 ;
107
- $ messageDataMock = ['from ' => 'John Doe ' , 'to ' => 'Jane Doe ' ];
108
116
$ formKey = 'ABCDEFGHIJKLMNOP ' ;
109
117
$ isFrontUrlSecure = true ;
110
118
$ baseUrl = 'https://magento.com/ ' ;
111
- $ quoteItemMock = $ this ->getMock (' Magento\Quote\Model\Quote\Item ' , [], [], '' , false );
119
+ $ quoteItemMock = $ this ->getMock (\ Magento \Quote \Model \Quote \Item::class , [], [], '' , false );
112
120
$ storeMock = $ this ->getMock (
113
- ' Magento\Store\Model\Store ' ,
121
+ \ Magento \Store \Model \Store::class ,
114
122
['isFrontUrlSecure ' , 'getBaseUrl ' , 'getCode ' ],
115
123
[],
116
124
'' ,
117
125
false
118
126
);
127
+ $ productMock = $ this ->getMock (\Magento \Catalog \Model \Product::class, [], [], '' , false );
119
128
$ quoteMock = $ this ->getMock (
120
- ' Magento\Quote\Model\Quote ' ,
121
- ['getQuoteCurrencyCode ' , 'getStore ' , 'getIsVirtual ' , 'getAllVisibleItems ' ],
129
+ \ Magento \Quote \Model \Quote::class ,
130
+ ['getQuoteCurrencyCode ' , 'getStore ' , 'getIsVirtual ' , 'getAllVisibleItems ' , ' getId ' ],
122
131
[],
123
132
'' ,
124
133
false
125
134
);
126
- $ messageMock = $ this ->getMockForAbstractClass (
127
- 'Magento\GiftMessage\Api\Data\MessageInterface ' ,
128
- [],
129
- '' ,
130
- false ,
131
- false ,
132
- false ,
133
- ['getData ' ]
134
- );
135
+ $ messageMock = $ this ->getMockBuilder (\Magento \GiftMessage \Api \Data \MessageInterface::class)
136
+ ->setMethods (['getData ' ])
137
+ ->getMockForAbstractClass ();
135
138
136
139
$ this ->scopeConfigMock ->expects ($ this ->atLeastOnce ())->method ('getValue ' )->willReturnMap (
137
140
[
@@ -140,17 +143,20 @@ public function testGetConfig()
140
143
]
141
144
);
142
145
146
+ $ quoteMock ->expects ($ this ->any ())->method ('getId ' )->willReturn ($ quoteId );
147
+
143
148
$ this ->checkoutSessionMock ->expects ($ this ->atLeastOnce ())->method ('getQuoteId ' )->willReturn ($ quoteId );
144
149
$ this ->cartRepositoryMock ->expects ($ this ->once ())->method ('get ' )->with ($ quoteId )->willReturn ($ messageMock );
145
150
146
151
$ this ->checkoutSessionMock ->expects ($ this ->once ())->method ('loadCustomerQuote ' )->willReturnSelf ();
147
152
$ this ->checkoutSessionMock ->expects ($ this ->atLeastOnce ())->method ('getQuote ' )->willReturn ($ quoteMock );
148
153
$ quoteMock ->expects ($ this ->once ())->method ('getIsVirtual ' )->willReturn (false );
149
154
150
- $ messageMock ->expects ($ this ->atLeastOnce ())->method ('getData ' )->willReturn ($ messageDataMock );
155
+ $ messageMock ->expects ($ this ->atLeastOnce ())->method ('getData ' )->willReturn ($ messageData );
151
156
152
157
$ quoteMock ->expects ($ this ->once ())->method ('getAllVisibleItems ' )->willReturn ([$ quoteItemMock ]);
153
158
$ quoteItemMock ->expects ($ this ->once ())->method ('getId ' )->willReturn ($ itemId );
159
+ $ quoteItemMock ->expects ($ this ->any ())->method ('getProduct ' )->willReturn ($ productMock );
154
160
$ this ->itemRepositoryMock ->expects ($ this ->once ())->method ('get ' )->with ($ quoteId , $ itemId )
155
161
->willReturn ($ messageMock );
156
162
@@ -168,11 +174,12 @@ public function testGetConfig()
168
174
$ storeMock ->expects ($ this ->once ())->method ('isFrontUrlSecure ' )->willReturn ($ isFrontUrlSecure );
169
175
$ storeMock ->expects ($ this ->once ())->method ('getBaseUrl ' )->with (UrlInterface::URL_TYPE_LINK , $ isFrontUrlSecure )
170
176
->willReturn ($ baseUrl );
177
+ $ productMock ->expects ($ this ->once ())->method ('getGiftMessageAvailable ' )->willReturn ($ productMessageAvailable );
171
178
172
179
$ expectedResult = [
173
180
'giftMessage ' => [
174
- 'orderLevel ' => $ messageDataMock ,
175
- 'itemLevel ' => [$ itemId => $ messageDataMock ]
181
+ 'orderLevel ' => $ messageData ,
182
+ 'itemLevel ' => [$ itemId => $ expectedItemLevel ]
176
183
],
177
184
'isOrderLevelGiftOptionsEnabled ' => $ orderLevel ,
178
185
'isItemLevelGiftOptionsEnabled ' => $ itemLevel ,
@@ -185,4 +192,37 @@ public function testGetConfig()
185
192
186
193
$ this ->assertSame ($ expectedResult , $ this ->model ->getConfig ());
187
194
}
195
+
196
+ /**
197
+ * @return array
198
+ */
199
+ public function getConfigDataProvider ()
200
+ {
201
+ $ messageData = ['from ' => 'John Doe ' , 'to ' => 'Jane Doe ' ];
202
+ return [
203
+ [
204
+ 'productMessageAvailable ' => null ,
205
+ 'messageData ' => $ messageData ,
206
+ 'expectedItemLevel ' => [
207
+ 'message ' => $ messageData
208
+ ]
209
+ ],
210
+ [
211
+ 'productMessageAvailable ' => '0 ' ,
212
+ 'messageData ' => $ messageData ,
213
+ 'expectedItemLevel ' => [
214
+ 'message ' => $ messageData ,
215
+ 'is_available ' => false
216
+ ]
217
+ ],
218
+ [
219
+ 'productMessageAvailable ' => '1 ' ,
220
+ 'messageData ' => $ messageData ,
221
+ 'expectedItemLevel ' => [
222
+ 'message ' => $ messageData ,
223
+ 'is_available ' => true
224
+ ]
225
+ ]
226
+ ];
227
+ }
188
228
}
0 commit comments