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