Skip to content

Commit 5020752

Browse files
webapi test
1 parent c9f9d71 commit 5020752

File tree

1 file changed

+45
-7
lines changed

1 file changed

+45
-7
lines changed

dev/tests/api-functional/testsuite/Magento/Customer/Api/CustomerRepositoryTest.php

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
use Magento\Customer\Api\Data\CustomerInterface as Customer;
1010
use Magento\Customer\Api\Data\AddressInterface as Address;
11+
use Magento\Framework\Api\FilterBuilder;
12+
use Magento\Framework\Api\SearchCriteriaInterface;
1113
use Magento\Framework\Api\SortOrder;
1214
use Magento\Framework\Exception\InputException;
1315
use Magento\Framework\Exception\LocalizedException;
@@ -482,25 +484,31 @@ public function testCreateCustomerWithoutAddressRequiresException()
482484

483485
/**
484486
* Test with a single filter
487+
*
488+
* @param bool $subscribeStatus
489+
* @return void
490+
*
491+
* @dataProvider subscriptionDataProvider
485492
*/
486-
public function testSearchCustomers()
493+
public function testSearchCustomers(bool $subscribeStatus): void
487494
{
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);
490498
$filter = $builder
491499
->setField(Customer::EMAIL)
492500
->setValue($customerData[Customer::EMAIL])
493501
->create();
494502
$this->searchCriteriaBuilder->addFilters([$filter]);
495503
$searchData = $this->dataObjectProcessor->buildOutputDataArray(
496504
$this->searchCriteriaBuilder->create(),
497-
\Magento\Framework\Api\SearchCriteriaInterface::class
505+
SearchCriteriaInterface::class
498506
);
499507
$requestData = ['searchCriteria' => $searchData];
500508
$serviceInfo = [
501509
'rest' => [
502510
'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,
504512
],
505513
'soap' => [
506514
'service' => self::SERVICE_NAME,
@@ -511,6 +519,35 @@ public function testSearchCustomers()
511519
$searchResults = $this->_webApiCall($serviceInfo, $requestData);
512520
$this->assertEquals(1, $searchResults['total_count']);
513521
$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+
];
514551
}
515552

516553
/**
@@ -857,11 +894,12 @@ protected function _getCustomerData($customerId)
857894
}
858895

859896
/**
897+
* @param array|null $additionalData
860898
* @return array|bool|float|int|string
861899
*/
862-
protected function _createCustomer()
900+
protected function _createCustomer(?array $additionalData = [])
863901
{
864-
$customerData = $this->customerHelper->createSampleCustomer();
902+
$customerData = $this->customerHelper->createSampleCustomer($additionalData);
865903
$this->currentCustomerId[] = $customerData['id'];
866904
return $customerData;
867905
}

0 commit comments

Comments
 (0)