7
7
namespace Magento \Customer \Model \Resource ;
8
8
9
9
use Magento \Customer \Api \Data \GroupInterface ;
10
+ use Magento \Framework \Api \SearchCriteria ;
10
11
11
12
/**
12
13
* Integration test for \Magento\Customer\Model\Resource\GroupRepository
@@ -28,12 +29,16 @@ class GroupRepositoryTest extends \PHPUnit_Framework_TestCase
28
29
/** @var \Magento\Framework\Api\SearchCriteriaBuilder */
29
30
private $ searchCriteriaBuilder ;
30
31
32
+ /** @var \Magento\Framework\Api\SortOrderBuilder */
33
+ private $ sortOrderBuilder ;
34
+
31
35
protected function setUp ()
32
36
{
33
37
$ this ->objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
34
38
$ this ->groupRepository = $ this ->objectManager ->create ('Magento\Customer\Api\GroupRepositoryInterface ' );
35
39
$ this ->groupFactory = $ this ->objectManager ->create ('Magento\Customer\Api\Data\GroupInterfaceFactory ' );
36
40
$ this ->searchCriteriaBuilder = $ this ->objectManager ->create ('Magento\Framework\Api\SearchCriteriaBuilder ' );
41
+ $ this ->sortOrderBuilder = $ this ->objectManager ->create ('Magento\Framework\Api\SortOrderBuilder ' );
37
42
}
38
43
39
44
/**
@@ -249,6 +254,95 @@ public function searchGroupsDataProvider()
249
254
3 => [GroupInterface::CODE => 'Retailer ' , GroupInterface::TAX_CLASS_ID => 3 ]
250
255
],
251
256
],
257
+ 'like_tax_name ' => [
258
+ [
259
+ $ builder ->setField (GroupInterface::TAX_CLASS_NAME )->setValue ('Retail Customer ' )
260
+ ->setConditionType ('like ' )
261
+ ->create (),
262
+ ],
263
+ [],
264
+ [
265
+ 0 => [GroupInterface::CODE => 'NOT LOGGED IN ' , GroupInterface::TAX_CLASS_ID => 3 ],
266
+ 1 => [GroupInterface::CODE => 'General ' , GroupInterface::TAX_CLASS_ID => 3 ],
267
+ 2 => [GroupInterface::CODE => 'Wholesale ' , GroupInterface::TAX_CLASS_ID => 3 ],
268
+ 3 => [GroupInterface::CODE => 'Retailer ' , GroupInterface::TAX_CLASS_ID => 3 ],
269
+ ],
270
+ ],
271
+ ];
272
+ }
273
+
274
+ /**
275
+ * @param string $field
276
+ * @param string, $direction
277
+ * @param string, $methodName
278
+ * @param array $expectedResult
279
+ *
280
+ * @dataProvider sortOrderDataProvider
281
+ */
282
+ public function testGetListSortOrder ($ field , $ direction , $ methodName , $ expectedResult )
283
+ {
284
+ /** @var \Magento\Framework\Api\SortOrder $sortOrder */
285
+ /** @var string $direction */
286
+ $ direction = ($ direction == 'ASC ' ) ? SearchCriteria::SORT_ASC : SearchCriteria::SORT_DESC ;
287
+ $ sortOrder = $ this ->sortOrderBuilder ->setField ($ field )->setDirection ($ direction )->create ();
288
+ $ this ->searchCriteriaBuilder ->addSortOrder ($ sortOrder );
289
+
290
+ $ searchResults = $ this ->groupRepository ->getList ($ this ->searchCriteriaBuilder ->create ());
291
+
292
+ /** @var \Magento\Customer\Api\Data\GroupInterface[] $resultItems */
293
+ $ resultItems = $ searchResults ->getItems ();
294
+ $ this ->assertTrue (count ($ resultItems ) > 0 );
295
+
296
+ $ result = [];
297
+ foreach ($ resultItems as $ item ) {
298
+ /** @var \Magento\Customer\Model\Data\Group $item */
299
+ $ result [] = $ item ->$ methodName ();
300
+ }
301
+ $ this ->assertEquals ($ expectedResult , $ result );
302
+ }
303
+
304
+ /**
305
+ * @return array
306
+ */
307
+ public function sortOrderDataProvider ()
308
+ {
309
+ return [
310
+ [
311
+ GroupInterface::ID ,
312
+ 'ASC ' ,
313
+ 'getId ' ,
314
+ [0 , 1 , 2 , 3 ],
315
+ ],
316
+ [
317
+ GroupInterface::ID ,
318
+ 'DESC ' ,
319
+ 'getId ' ,
320
+ [3 , 2 , 1 , 0 ],
321
+ ],
322
+ [
323
+ GroupInterface::CODE ,
324
+ 'ASC ' ,
325
+ 'getCode ' ,
326
+ ['General ' , 'NOT LOGGED IN ' , 'Retailer ' , 'Wholesale ' ],
327
+ ],
328
+ [
329
+ GroupInterface::CODE ,
330
+ 'DESC ' ,
331
+ 'getCode ' ,
332
+ ['Wholesale ' , 'Retailer ' , 'NOT LOGGED IN ' , 'General ' ],
333
+ ],
334
+ [
335
+ GroupInterface::TAX_CLASS_NAME ,
336
+ 'ASC ' ,
337
+ 'getTaxClassName ' ,
338
+ ['Retail Customer ' , 'Retail Customer ' , 'Retail Customer ' , 'Retail Customer ' ]
339
+ ],
340
+ [
341
+ GroupInterface::TAX_CLASS_NAME ,
342
+ 'DESC ' ,
343
+ 'getTaxClassName ' ,
344
+ ['Retail Customer ' , 'Retail Customer ' , 'Retail Customer ' , 'Retail Customer ' ]
345
+ ],
252
346
];
253
347
}
254
348
}
0 commit comments