39 private $accountManagement;
44 private $searchCriteriaBuilder;
49 private $sortOrderBuilder;
54 private $filterGroupBuilder;
59 private $customerHelper;
64 private $currentCustomerId;
72 private $dataObjectProcessor;
90 \
Magento\Customer\Api\AccountManagementInterface::class
93 \
Magento\Framework\Api\SearchCriteriaBuilder::class
96 \
Magento\Framework\Api\SortOrderBuilder::class
99 \
Magento\Framework\Api\Search\FilterGroupBuilder::class
101 $this->customerHelper =
new CustomerHelper();
104 \
Magento\Framework\Reflection\DataObjectProcessor::class
109 $this->initSubscriber();
111 if ($this->config->getConfigDataValue(
115 $this->configValue = $this->config
116 ->getConfigDataValue(
120 $this->config->setDataByPath(
124 $this->config->save();
130 if (!empty($this->currentCustomerId)) {
131 foreach ($this->currentCustomerId as
$customerId) {
134 'resourcePath' => self::RESOURCE_PATH .
'/' .
$customerId,
149 $this->config->setDataByPath(
153 $this->config->save();
154 $this->accountManagement =
null;
155 $this->subscriber =
null;
158 private function initSubscriber()
161 \
Magento\Newsletter\Model\Subscriber::class
180 'operation' => self::SERVICE_NAME .
'CreateAccount',
184 $customerDataArray = $this->dataObjectProcessor->buildOutputDataArray(
185 $this->customerHelper->createSampleCustomerDataObject(),
186 \Magento\Customer\Api\Data\CustomerInterface::class
188 $invalidEmail =
'invalid';
189 $customerDataArray[
'email'] = $invalidEmail;
190 $requestData = [
'customer' => $customerDataArray,
'password' => CustomerHelper::PASSWORD];
193 $this->fail(
'Expected exception did not occur.');
194 }
catch (\Exception $e) {
195 if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) {
197 $expectedException->addError(
__(
'"Email" is not a valid email address.'));
198 $this->assertInstanceOf(
'SoapFault', $e);
201 $expectedException->getRawMessage(),
203 $expectedException->getParameters()
206 $this->assertEquals(HTTPExceptionCodes::HTTP_BAD_REQUEST, $e->getCode());
208 $expectedExceptionData = [
209 'message' =>
'"Email" is not a valid email address.',
211 $this->assertEquals($expectedExceptionData, $exceptionData);
225 'operation' => self::SERVICE_NAME .
'CreateAccount',
229 $customerDataArray = $this->dataObjectProcessor->buildOutputDataArray(
230 $this->customerHelper->createSampleCustomerDataObject(),
231 \Magento\Customer\Api\Data\CustomerInterface::class
233 unset($customerDataArray[
'store_id']);
234 unset($customerDataArray[
'website_id']);
235 $requestData = [
'customer' => $customerDataArray,
'password' => CustomerHelper::PASSWORD];
239 }
catch (\Exception $e) {
240 $this->fail(
'Customer should be created without optional fields.');
252 $this->assertNotNull(
$customerData[Customer::CONFIRMATION],
'Customer activation is not required');
256 'resourcePath' => self::RESOURCE_PATH .
'/' .
$customerData[Customer::EMAIL] .
'/activate',
262 'operation' => self::SERVICE_NAME .
'Activate',
275 !isset(
$result[Customer::CONFIRMATION]) ||
$result[Customer::CONFIRMATION] ===
null,
276 'Customer is not activated!' 286 'resourcePath' => self::RESOURCE_PATH .
'/' .
$customerData[Customer::EMAIL] .
'/activate',
292 'operation' => self::SERVICE_NAME .
'Activate',
302 $this->assertEquals(
$customerData[Customer::ID], $customerResponseData[Customer::ID]);
304 $this->assertFalse(isset($customerResponseData[Customer::CONFIRMATION]));
307 public function testValidateResetPasswordLinkToken()
314 $rpToken =
'lsdj579slkj5987slkj595lkj';
315 $customerModel->setRpToken(
'lsdj579slkj5987slkj595lkj');
316 $customerModel->setRpTokenCreatedAt(date(
'Y-m-d H:i:s'));
317 $customerModel->save();
318 $path = self::RESOURCE_PATH .
'/' .
$customerData[Customer::ID] .
'/password/resetLinkToken/' . $rpToken;
321 'resourcePath' =>
$path,
327 'operation' => self::SERVICE_NAME .
'ValidateResetPasswordLinkToken',
333 [
'customerId' =>
$customerData[
'id'],
'resetPasswordLinkToken' => $rpToken]
340 $invalidToken =
'fjjkafjie';
341 $path = self::RESOURCE_PATH .
'/' .
$customerData[Customer::ID] .
'/password/resetLinkToken/' . $invalidToken;
344 'resourcePath' =>
$path,
350 'operation' => self::SERVICE_NAME .
'ValidateResetPasswordLinkToken',
354 $expectedMessage =
'The password token is mismatched. Reset and try again.';
357 if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) {
360 [
'customerId' =>
$customerData[
'id'],
'resetPasswordLinkToken' =>
'invalid']
365 $this->fail(
"Expected exception to be thrown.");
366 }
catch (\SoapFault $e) {
367 $this->assertContains(
370 "Exception message does not match" 372 }
catch (\Exception $e) {
374 $this->assertEquals($expectedMessage, $errorObj[
'message']);
375 $this->assertEquals(HTTPExceptionCodes::HTTP_BAD_REQUEST, $e->getCode());
381 $this->
_markTestAsRestOnly(
'Soap clients explicitly check for required fields based on WSDL.');
384 'resourcePath' => self::RESOURCE_PATH .
'/password',
391 }
catch (\Exception $e) {
392 $this->assertEquals(\
Magento\Framework\Webapi\Exception::HTTP_BAD_REQUEST, $e->getCode());
394 $expectedExceptionData = [
395 'message' =>
'One or more input exceptions have occurred.',
398 'message' =>
'"%fieldName" is required. Enter and try again.',
400 'fieldName' =>
'email',
404 'message' =>
'"%fieldName" is required. Enter and try again.',
406 'fieldName' =>
'template',
411 $this->assertEquals($expectedExceptionData, $exceptionData);
421 'resourcePath' => self::RESOURCE_PATH .
'/password',
427 'operation' => self::SERVICE_NAME .
'InitiatePasswordReset',
445 'resourcePath' => self::RESOURCE_PATH .
'/password',
451 'operation' => self::SERVICE_NAME .
'InitiatePasswordReset',
461 }
catch (\Exception $e) {
462 $expectedErrorParameters =
464 'fieldName' =>
'email',
466 'field2Name' =>
'websiteId',
470 if (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) {
473 'No such entity with %fieldName = %fieldValue, %field2Name = %field2Value',
476 $this->assertEquals($expectedErrorParameters, $errorObj[
'parameters']);
477 $this->assertEquals(HTTPExceptionCodes::HTTP_NOT_FOUND, $e->getCode());
479 $this->assertInstanceOf(
'SoapFault', $e);
482 'No such entity with %fieldName = %fieldValue, %field2Name = %field2Value',
484 $expectedErrorParameters
496 'resourcePath' => self::RESOURCE_PATH .
'/' .
$customerData[Customer::ID] .
'/confirm',
502 'operation' => self::SERVICE_NAME .
'GetConfirmationStatus',
517 'resourcePath' => self::RESOURCE_PATH .
'/confirm',
523 'operation' => self::SERVICE_NAME .
'ResendConfirmation',
540 'resourcePath' => self::RESOURCE_PATH .
'/confirm',
546 'operation' => self::SERVICE_NAME .
'ResendConfirmation',
555 }
catch (\Exception $e) {
556 $expectedErrorParameters =
558 'fieldName' =>
'email',
560 'field2Name' =>
'websiteId',
563 if (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) {
566 'No such entity with %fieldName = %fieldValue, %field2Name = %field2Value',
569 $this->assertEquals($expectedErrorParameters, $errorObj[
'parameters']);
570 $this->assertEquals(HTTPExceptionCodes::HTTP_NOT_FOUND, $e->getCode());
572 $this->assertInstanceOf(
'SoapFault', $e);
575 'No such entity with %fieldName = %fieldValue, %field2Name = %field2Value',
577 $expectedErrorParameters
585 $customerData = $this->customerHelper->createSampleCustomerDataObject();
590 'resourcePath' => self::RESOURCE_PATH .
'/validate',
596 'operation' => self::SERVICE_NAME .
'Validate',
599 $customerData = $this->dataObjectProcessor->buildOutputDataArray(
601 \
Magento\Customer\Api\Data\CustomerInterface::class
605 $this->assertFalse($validationResponse[
'valid']);
608 'The "First Name" attribute value is empty. Set the attribute and try again.',
609 $validationResponse[
'messages'][0]
612 'The "Last Name" attribute value is empty. Set the attribute and try again.',
613 $validationResponse[
'messages'][1]
623 'resourcePath' => self::RESOURCE_PATH .
'/' .
$customerData[Customer::ID] .
'/permissions/readonly',
629 'operation' => self::SERVICE_NAME .
'IsReadonly',
644 'resourcePath' => self::RESOURCE_PATH .
'/isEmailAvailable',
650 'operation' => self::SERVICE_NAME .
'IsEmailAvailable',
664 'resourcePath' => self::RESOURCE_PATH .
'/isEmailAvailable',
670 'operation' => self::SERVICE_NAME .
'IsEmailAvailable',
674 'customerEmail' =>
'invalid',
687 $customerData = $this->customerHelper->createSampleCustomerDataObject();
689 $fixtureAddressAttributeCode =
'address_user_attribute';
691 $fixtureCustomerAttributeCode =
'user_attribute';
693 $address1CustomAttributeValue =
'value1';
694 $address2CustomAttributeValue =
'value2';
695 $customerCustomAttributeValue =
'value3';
698 $addresses[0]->setCustomAttribute($fixtureAddressAttributeCode, $address1CustomAttributeValue);
699 $addresses[1]->setCustomAttribute($fixtureAddressAttributeCode, $address2CustomAttributeValue);
701 $customerData->setCustomAttribute($fixtureCustomerAttributeCode, $customerCustomAttributeValue);
710 'operation' => self::SERVICE_NAME .
'CreateAccount',
714 $customerDataArray = $this->dataObjectProcessor->buildOutputDataArray(
716 \
Magento\Customer\Api\Data\CustomerInterface::class
718 $requestData = [
'customer' => $customerDataArray,
'password' => CustomerHelper::PASSWORD];
726 'resourcePath' => self::RESOURCE_PATH .
'/' .
$customerId ,
746 $fixtureCustomerId = 1;
749 'resourcePath' => self::RESOURCE_PATH .
"/$fixtureCustomerId/billingAddress",
755 'operation' => self::SERVICE_NAME .
'GetDefaultBillingAddress',
763 "Default billing address data is invalid." 773 $fixtureCustomerId = 1;
776 'resourcePath' => self::RESOURCE_PATH .
"/$fixtureCustomerId/shippingAddress",
782 'operation' => self::SERVICE_NAME .
'GetDefaultShippingAddress',
790 "Default shipping address data is invalid." 799 $customerData = $this->customerHelper->createSampleCustomer();
812 'firstname' =>
'John',
813 'lastname' =>
'Smith',
815 'country_id' =>
'US',
816 'company' =>
'CompanyName',
817 'postcode' =>
'75477',
818 'telephone' =>
'3468676',
819 'street' => [
'Green str, 67'],
821 'default_billing' =>
true,
822 'default_shipping' =>
true,
823 'customer_id' =>
'1',
824 'region' => [
'region' =>
'Alabama',
'region_id' => 1,
'region_code' =>
'AL'],
832 [
"extension_attributes" => [
"is_subscribed" =>
true]]
839 $this->assertNotNull($this->subscriber->getId());
840 $this->assertEquals(
$customerData[
'id'], $this->subscriber->getCustomerId());
847 [
"extension_attributes" => [
"is_subscribed" =>
true]]
852 $subscriptionId = $this->subscriber->getId();
854 $this->assertNotNull($subscriptionId);
855 $this->assertEquals(
$customerData[
'id'], $this->subscriber->getCustomerId());
857 $this->customerHelper->updateSampleCustomer(
861 [
"extension_attributes" => [
"is_subscribed" =>
false]]
864 $this->initSubscriber();
const XML_PATH_FRONTEND_AREA
testGetDefaultShippingAddress()
testCreateCustomerWithErrors()
testValidateResetPasswordLinkTokenInvalidToken()
_markTestAsRestOnly($message=null)
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
testCreateCustomerWithSubscription()
testValidateCustomerData()
const ACCOUNT_CONFIRMATION_NOT_REQUIRED
testResendConfirmationBadEmailOrWebsite()
testEmailAvailableInvalidEmail()
getFirstFixtureAddressData()
const XML_PATH_PASSWORD_RESET_PROTECTION_TYPE
testCreateCustomerWithoutOptionalFields()
testUnsubscribeCustomer()
testGetConfirmationStatus()
checkSoapFault( $soapFault, $expectedMessage, $expectedFaultCode, $expectedErrorParams=[], $expectedWrappedErrors=[], $traceString=null)
testSendPasswordResetLinkBadEmailOrWebsite()
testInitiatePasswordReset()
testGetDefaultBillingAddress()
testInitiatePasswordMissingRequiredFields()
processRestExceptionResult(\Exception $e)
const STATUS_UNSUBSCRIBED
testGetCustomerActivateCustomer()
static getObjectManager()