8
8
9
9
use Magento \Customer \Api \Data \CustomerInterface as Customer ;
10
10
use Magento \Customer \Api \Data \AddressInterface as Address ;
11
+ use Magento \Framework \Api \FilterBuilder ;
12
+ use Magento \Framework \Api \SearchCriteriaInterface ;
11
13
use Magento \Framework \Api \SortOrder ;
12
14
use Magento \Framework \Exception \InputException ;
13
15
use Magento \Framework \Exception \LocalizedException ;
@@ -482,25 +484,31 @@ public function testCreateCustomerWithoutAddressRequiresException()
482
484
483
485
/**
484
486
* Test with a single filter
487
+ *
488
+ * @param bool $subscribeStatus
489
+ * @return void
490
+ *
491
+ * @dataProvider subscriptionDataProvider
485
492
*/
486
- public function testSearchCustomers ()
493
+ public function testSearchCustomers (bool $ subscribeStatus ): void
487
494
{
488
- $ builder = Bootstrap::getObjectManager ()->create (\Magento \Framework \Api \FilterBuilder::class);
489
- $ customerData = $ this ->_createCustomer ();
495
+ $ builder = Bootstrap::getObjectManager ()->create (FilterBuilder::class);
496
+ $ subscribeData = $ this ->buildSubscriptionData ($ subscribeStatus );
497
+ $ customerData = $ this ->_createCustomer ($ subscribeData );
490
498
$ filter = $ builder
491
499
->setField (Customer::EMAIL )
492
500
->setValue ($ customerData [Customer::EMAIL ])
493
501
->create ();
494
502
$ this ->searchCriteriaBuilder ->addFilters ([$ filter ]);
495
503
$ searchData = $ this ->dataObjectProcessor ->buildOutputDataArray (
496
504
$ this ->searchCriteriaBuilder ->create (),
497
- \ Magento \ Framework \ Api \ SearchCriteriaInterface::class
505
+ SearchCriteriaInterface::class
498
506
);
499
507
$ requestData = ['searchCriteria ' => $ searchData ];
500
508
$ serviceInfo = [
501
509
'rest ' => [
502
510
'resourcePath ' => self ::RESOURCE_PATH . '/search ' . '? ' . http_build_query ($ requestData ),
503
- 'httpMethod ' => \ Magento \ Framework \ Webapi \ Rest \ Request::HTTP_METHOD_GET ,
511
+ 'httpMethod ' => Request::HTTP_METHOD_GET ,
504
512
],
505
513
'soap ' => [
506
514
'service ' => self ::SERVICE_NAME ,
@@ -511,6 +519,35 @@ public function testSearchCustomers()
511
519
$ searchResults = $ this ->_webApiCall ($ serviceInfo , $ requestData );
512
520
$ this ->assertEquals (1 , $ searchResults ['total_count ' ]);
513
521
$ this ->assertEquals ($ customerData [Customer::ID ], $ searchResults ['items ' ][0 ][Customer::ID ]);
522
+ $ this ->assertEquals ($ subscribeStatus , $ searchResults ['items ' ][0 ]['extension_attributes ' ]['is_subscribed ' ]);
523
+ }
524
+
525
+ /**
526
+ * Build subscription extension attributes data
527
+ *
528
+ * @param bool $status
529
+ * @return array
530
+ */
531
+ private function buildSubscriptionData (bool $ status ): array
532
+ {
533
+ return [
534
+ 'extension_attributes ' => [
535
+ 'is_subscribed ' => $ status ,
536
+ ],
537
+ ];
538
+ }
539
+
540
+ /**
541
+ * Subscription customer data provider
542
+ *
543
+ * @return array
544
+ */
545
+ public function subscriptionDataProvider (): array
546
+ {
547
+ return [
548
+ 'subscribed user ' => [true ],
549
+ 'not subscribed user ' => [false ],
550
+ ];
514
551
}
515
552
516
553
/**
@@ -857,11 +894,12 @@ protected function _getCustomerData($customerId)
857
894
}
858
895
859
896
/**
897
+ * @param array|null $additionalData
860
898
* @return array|bool|float|int|string
861
899
*/
862
- protected function _createCustomer ()
900
+ protected function _createCustomer (? array $ additionalData = [] )
863
901
{
864
- $ customerData = $ this ->customerHelper ->createSampleCustomer ();
902
+ $ customerData = $ this ->customerHelper ->createSampleCustomer ($ additionalData );
865
903
$ this ->currentCustomerId [] = $ customerData ['id ' ];
866
904
return $ customerData ;
867
905
}
0 commit comments