1
1
<?php
2
2
/**
3
3
* Copyright 2024 Adobe
4
- * All rights reserved.
5
- * See COPYING.txt for license details.
4
+ * All Rights Reserved.
6
5
*/
7
6
declare (strict_types=1 );
8
7
15
14
use Magento \Catalog \Model \Product \Price \Validation \TierPriceValidator ;
16
15
use Magento \Catalog \Model \Product \Type ;
17
16
use Magento \Catalog \Model \ProductIdLocatorInterface ;
18
- use Magento \Customer \Api \Data \GroupInterface ;
19
- use Magento \Customer \Api \Data \GroupSearchResultsInterface ;
20
- use Magento \Customer \Api \GroupRepositoryInterface ;
21
- use Magento \Framework \Api \AbstractSimpleObject ;
22
- use Magento \Framework \Api \FilterBuilder ;
23
- use Magento \Framework \Api \Search \SearchCriteriaInterface ;
24
- use Magento \Framework \Api \SearchCriteriaBuilder ;
17
+ use Magento \Framework \App \ResourceConnection ;
18
+ use Magento \Framework \DB \Adapter \AdapterInterface ;
19
+ use Magento \Framework \DB \Select ;
25
20
use Magento \Framework \Exception \NoSuchEntityException ;
26
21
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
27
22
use Magento \Store \Api \Data \WebsiteInterface ;
28
23
use Magento \Store \Api \WebsiteRepositoryInterface ;
29
24
use PHPUnit \Framework \MockObject \MockObject ;
30
25
use PHPUnit \Framework \TestCase ;
31
- use Magento \Framework \App \ResourceConnection ;
32
- use Magento \Framework \DB \Adapter \AdapterInterface ;
33
- use Magento \Framework \DB \Select ;
34
26
35
27
/**
36
28
* Test for \Magento\Catalog\Model\Product\Price\Validation\TierPriceValidator.
@@ -92,15 +84,6 @@ protected function setUp(): void
92
84
$ this ->productIdLocator = $ this ->getMockBuilder (ProductIdLocatorInterface::class)
93
85
->disableOriginalConstructor ()
94
86
->getMockForAbstractClass ();
95
- $ this ->searchCriteriaBuilder = $ this ->getMockBuilder (SearchCriteriaBuilder::class)
96
- ->disableOriginalConstructor ()
97
- ->getMock ();
98
- $ this ->filterBuilder = $ this ->getMockBuilder (FilterBuilder::class)
99
- ->disableOriginalConstructor ()
100
- ->getMock ();
101
- $ this ->customerGroupRepository = $ this ->getMockBuilder (GroupRepositoryInterface::class)
102
- ->disableOriginalConstructor ()
103
- ->getMockForAbstractClass ();
104
87
$ this ->websiteRepository = $ this ->getMockBuilder (WebsiteRepositoryInterface::class)
105
88
->disableOriginalConstructor ()
106
89
->getMockForAbstractClass ();
@@ -130,9 +113,6 @@ protected function setUp(): void
130
113
TierPriceValidator::class,
131
114
[
132
115
'productIdLocator ' => $ this ->productIdLocator ,
133
- 'searchCriteriaBuilder ' => $ this ->searchCriteriaBuilder ,
134
- 'filterBuilder ' => $ this ->filterBuilder ,
135
- 'customerGroupRepository ' => $ this ->customerGroupRepository ,
136
116
'websiteRepository ' => $ this ->websiteRepository ,
137
117
'validationResult ' => $ this ->validationResult ,
138
118
'invalidSkuProcessor ' => $ this ->invalidSkuProcessor ,
@@ -145,10 +125,9 @@ protected function setUp(): void
145
125
/**
146
126
* Prepare CustomerGroupRepository mock.
147
127
*
148
- * @param array $returned
149
128
* @return void
150
129
*/
151
- private function prepareCustomerGroupRepositoryMock (array $ returned )
130
+ private function prepareCustomerGroupRepositoryMock ()
152
131
{
153
132
$ select = $ this ->createMock (Select::class);
154
133
$ select ->expects ($ this ->once ())
@@ -257,11 +236,6 @@ public function testValidateSkus()
257
236
*/
258
237
public function testRetrieveValidationResult (array $ returned )
259
238
{
260
- if (!empty ($ returned ['customerGroupSearchResults_getItems ' ])) {
261
- $ groupSearchResult = $ returned ['customerGroupSearchResults_getItems ' ][0 ];
262
- $ returned ['customerGroupSearchResults_getItems ' ][0 ] = $ groupSearchResult ($ this );
263
- }
264
-
265
239
$ sku = 'ASDF234234 ' ;
266
240
$ prices = [$ this ->tierPrice ];
267
241
$ existingPrices = [$ this ->tierPrice ];
@@ -270,26 +244,14 @@ public function testRetrieveValidationResult(array $returned)
270
244
->disableOriginalConstructor ()
271
245
->getMockForAbstractClass ();
272
246
$ this ->websiteRepository ->expects ($ this ->atLeastOnce ())->method ('getById ' )->willReturn ($ website );
273
- $ this ->prepareCustomerGroupRepositoryMock ($ returned );
247
+ $ this ->prepareCustomerGroupRepositoryMock ();
274
248
275
249
$ this ->assertEquals (
276
250
$ this ->validationResult ,
277
251
$ this ->tierPriceValidator ->retrieveValidationResult ($ prices , $ existingPrices )
278
252
);
279
253
}
280
254
281
- protected function getMockForCustomerGroup ($ customerGroupName )
282
- {
283
- $ customerGroup = $ this ->getMockBuilder (GroupInterface::class)
284
- ->onlyMethods (['getCode ' , 'getId ' ])
285
- ->disableOriginalConstructor ()
286
- ->getMockForAbstractClass ();
287
- $ customerGroup ->expects ($ this ->atLeastOnce ())->method ('getCode ' )->willReturn ($ customerGroupName );
288
- $ customerGroupId = 23 ;
289
- $ customerGroup ->expects ($ this ->atLeastOnce ())->method ('getId ' )->willReturn ($ customerGroupId );
290
- return $ customerGroup ;
291
- }
292
-
293
255
/**
294
256
* Data provider for retrieveValidationResult() test.
295
257
*
@@ -298,21 +260,17 @@ protected function getMockForCustomerGroup($customerGroupName)
298
260
public static function retrieveValidationResultDataProvider ()
299
261
{
300
262
$ customerGroupName = 'test_Group ' ;
301
- $ customerGroup = static fn (self $ testCase ) => $ testCase ->getMockForCustomerGroup ($ customerGroupName );
302
-
303
263
return [
304
264
[
305
265
[
306
266
'tierPrice_getCustomerGroup ' => $ customerGroupName ,
307
- 'tierPrice_getPriceType ' => TierPriceInterface::PRICE_TYPE_DISCOUNT ,
308
- 'customerGroupSearchResults_getItems ' => [$ customerGroup ]
267
+ 'tierPrice_getPriceType ' => TierPriceInterface::PRICE_TYPE_DISCOUNT
309
268
]
310
269
],
311
270
[
312
271
[
313
272
'tierPrice_getCustomerGroup ' => $ customerGroupName ,
314
- 'tierPrice_getPriceType ' => TierPriceInterface::PRICE_TYPE_FIXED ,
315
- 'customerGroupSearchResults_getItems ' => []
273
+ 'tierPrice_getPriceType ' => TierPriceInterface::PRICE_TYPE_FIXED
316
274
]
317
275
]
318
276
];
@@ -331,13 +289,12 @@ public function testRetrieveValidationResultWithException()
331
289
$ existingPrices = [$ this ->tierPrice ];
332
290
$ returned = [
333
291
'tierPrice_getPriceType ' => TierPriceInterface::PRICE_TYPE_DISCOUNT ,
334
- 'customerGroupSearchResults_getItems ' => [],
335
292
'tierPrice_getCustomerGroup ' => $ customerGroupName ,
336
293
];
337
294
$ this ->prepareRetrieveValidationResultMethod ($ sku , $ returned );
338
295
$ exception = new NoSuchEntityException ();
339
296
$ this ->websiteRepository ->expects ($ this ->atLeastOnce ())->method ('getById ' )->willThrowException ($ exception );
340
- $ this ->prepareCustomerGroupRepositoryMock ($ returned );
297
+ $ this ->prepareCustomerGroupRepositoryMock ();
341
298
342
299
$ this ->assertEquals (
343
300
$ this ->validationResult ,
0 commit comments