Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions
AccountManagementTest Class Reference
Inheritance diagram for AccountManagementTest:
WebapiAbstract

Public Member Functions

 setUp ()
 
 tearDown ()
 
 testCreateCustomer ()
 
 testCreateCustomerWithErrors ()
 
 testCreateCustomerWithoutOptionalFields ()
 
 testActivateCustomer ()
 
 testGetCustomerActivateCustomer ()
 
 testValidateResetPasswordLinkTokenInvalidToken ()
 
 testInitiatePasswordMissingRequiredFields ()
 
 testInitiatePasswordReset ()
 
 testSendPasswordResetLinkBadEmailOrWebsite ()
 
 testGetConfirmationStatus ()
 
 testResendConfirmation ()
 
 testResendConfirmationBadEmailOrWebsite ()
 
 testValidateCustomerData ()
 
 testIsReadonly ()
 
 testEmailAvailable ()
 
 testEmailAvailableInvalidEmail ()
 
 testCustomAttributes ()
 
 testGetDefaultBillingAddress ()
 
 testGetDefaultShippingAddress ()
 
 testCreateCustomerWithSubscription ()
 
 testUnsubscribeCustomer ()
 
- Public Member Functions inherited from WebapiAbstract
 addModelToDelete ($model, $secure=false)
 
 processRestExceptionResult (\Exception $e)
 

Data Fields

const SERVICE_VERSION = 'V1'
 
const SERVICE_NAME = 'customerAccountManagementV1'
 
const RESOURCE_PATH = '/V1/customers'
 
const ATTRIBUTE_CODE = 'attribute_code'
 
const ATTRIBUTE_VALUE = 'attribute_value'
 
- Data Fields inherited from WebapiAbstract
const AUTO_TEAR_DOWN_DISABLED = 0
 
const AUTO_TEAR_DOWN_AFTER_METHOD = 1
 
const AUTO_TEAR_DOWN_AFTER_CLASS = 2
 
const ADAPTER_SOAP = 'soap'
 
const ADAPTER_REST = 'rest'
 

Protected Member Functions

 _createCustomer ()
 
 getFirstFixtureAddressData ()
 
- Protected Member Functions inherited from WebapiAbstract
 tearDown ()
 
 _webApiCall ( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
 
 _markTestAsSoapOnly ($message=null)
 
 _markTestAsRestOnly ($message=null)
 
 _getWebApiAdapter ($webApiAdapterCode)
 
 _assertMessagesEqual ($expectedMessages, $receivedMessages)
 
 _cleanAppConfigCache ()
 
 _restoreAppConfig ()
 
 checkSoapFault ( $soapFault, $expectedMessage, $expectedFaultCode, $expectedErrorParams=[], $expectedWrappedErrors=[], $traceString=null)
 
 _checkFaultParams ($expectedErrorParams, $errorDetails)
 
 _checkWrappedErrors ($expectedWrappedErrors, $errorDetails)
 

Additional Inherited Members

- Static Public Member Functions inherited from WebapiAbstract
static setUpBeforeClass ()
 
static tearDownAfterClass ()
 
static setFixture ($key, $fixture, $tearDown=self::AUTO_TEAR_DOWN_AFTER_METHOD)
 
static getFixture ($key)
 
static callModelDelete ($model, $secure=false)
 
static deleteFixture ($key, $secure=false)
 
- Static Protected Member Functions inherited from WebapiAbstract
static _setFixtureNamespace ()
 
static _unsetFixtureNamespace ()
 
static _getFixtureNamespace ()
 
static _deleteFixtures ($fixtures)
 
- Protected Attributes inherited from WebapiAbstract
 $_appCache
 
 $_modelsToDelete = []
 
 $_origConfigValues = []
 
 $_webApiAdapters
 
 $_webApiAdaptersMap
 
- Static Protected Attributes inherited from WebapiAbstract
static $_fixturesNamespace
 
static $_fixtures = []
 
static $_methodLevelFixtures = []
 
static $_classLevelFixtures = []
 

Detailed Description

Test class for Magento\Customer\Api\AccountManagementInterface

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 24 of file AccountManagementTest.php.

Member Function Documentation

◆ _createCustomer()

_createCustomer ( )
protected
Returns
array|bool|float|int|string

Definition at line 797 of file AccountManagementTest.php.

798  {
799  $customerData = $this->customerHelper->createSampleCustomer();
800  $this->currentCustomerId[] = $customerData['id'];
801  return $customerData;
802  }
$customerData

◆ getFirstFixtureAddressData()

getFirstFixtureAddressData ( )
protected

Retrieve data of the first fixture address.

Returns
array

Definition at line 809 of file AccountManagementTest.php.

810  {
811  return [
812  'firstname' => 'John',
813  'lastname' => 'Smith',
814  'city' => 'CityM',
815  'country_id' => 'US',
816  'company' => 'CompanyName',
817  'postcode' => '75477',
818  'telephone' => '3468676',
819  'street' => ['Green str, 67'],
820  'id' => 1,
821  'default_billing' => true,
822  'default_shipping' => true,
823  'customer_id' => '1',
824  'region' => ['region' => 'Alabama', 'region_id' => 1, 'region_code' => 'AL'],
825  'region_id' => 1,
826  ];
827  }

◆ setUp()

setUp ( )

Execute per test initialization.

Definition at line 87 of file AccountManagementTest.php.

88  {
89  $this->accountManagement = Bootstrap::getObjectManager()->get(
90  \Magento\Customer\Api\AccountManagementInterface::class
91  );
92  $this->searchCriteriaBuilder = Bootstrap::getObjectManager()->create(
93  \Magento\Framework\Api\SearchCriteriaBuilder::class
94  );
95  $this->sortOrderBuilder = Bootstrap::getObjectManager()->create(
96  \Magento\Framework\Api\SortOrderBuilder::class
97  );
98  $this->filterGroupBuilder = Bootstrap::getObjectManager()->create(
99  \Magento\Framework\Api\Search\FilterGroupBuilder::class
100  );
101  $this->customerHelper = new CustomerHelper();
102 
103  $this->dataObjectProcessor = Bootstrap::getObjectManager()->create(
104  \Magento\Framework\Reflection\DataObjectProcessor::class
105  );
106  $this->config = Bootstrap::getObjectManager()->create(
107  \Magento\Config\Model\Config::class
108  );
109  $this->initSubscriber();
110 
111  if ($this->config->getConfigDataValue(
114  ) != 0) {
115  $this->configValue = $this->config
116  ->getConfigDataValue(
119  );
120  $this->config->setDataByPath(
122  0
123  );
124  $this->config->save();
125  }
126  }
const XML_PATH_PASSWORD_RESET_PROTECTION_TYPE
Definition: Config.php:47

◆ tearDown()

tearDown ( )

Clean up shared dependencies

Definition at line 128 of file AccountManagementTest.php.

129  {
130  if (!empty($this->currentCustomerId)) {
131  foreach ($this->currentCustomerId as $customerId) {
132  $serviceInfo = [
133  'rest' => [
134  'resourcePath' => self::RESOURCE_PATH . '/' . $customerId,
136  ],
137  'soap' => [
139  'serviceVersion' => self::SERVICE_VERSION,
140  'operation' => CustomerRepositoryTest::SERVICE_NAME . 'DeleteById',
141  ],
142  ];
143 
144  $response = $this->_webApiCall($serviceInfo, ['customerId' => $customerId]);
145 
146  $this->assertTrue($response);
147  }
148  }
149  $this->config->setDataByPath(
151  $this->configValue
152  );
153  $this->config->save();
154  $this->accountManagement = null;
155  $this->subscriber = null;
156  }
$response
Definition: 404.php:11
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
const XML_PATH_PASSWORD_RESET_PROTECTION_TYPE
Definition: Config.php:47

◆ testActivateCustomer()

testActivateCustomer ( )

Test customer activation when it is required

@magentoConfigFixture default_store customer/create_account/confirm 0

Definition at line 249 of file AccountManagementTest.php.

250  {
251  $customerData = $this->_createCustomer();
252  $this->assertNotNull($customerData[Customer::CONFIRMATION], 'Customer activation is not required');
253 
254  $serviceInfo = [
255  'rest' => [
256  'resourcePath' => self::RESOURCE_PATH . '/' . $customerData[Customer::EMAIL] . '/activate',
258  ],
259  'soap' => [
260  'service' => self::SERVICE_NAME,
261  'serviceVersion' => self::SERVICE_VERSION,
262  'operation' => self::SERVICE_NAME . 'Activate',
263  ],
264  ];
265 
266  $requestData = [
267  'email' => $customerData[Customer::EMAIL],
268  'confirmationKey' => $customerData[Customer::CONFIRMATION],
269  ];
270 
271  $result = $this->_webApiCall($serviceInfo, $requestData);
272 
273  $this->assertEquals($customerData[Customer::ID], $result[Customer::ID], 'Wrong customer!');
274  $this->assertTrue(
275  !isset($result[Customer::CONFIRMATION]) || $result[Customer::CONFIRMATION] === null,
276  'Customer is not activated!'
277  );
278  }
$customerData
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testCreateCustomer()

testCreateCustomer ( )

Definition at line 165 of file AccountManagementTest.php.

166  {
167  $customerData = $this->_createCustomer();
168  $this->assertNotNull($customerData['id']);
169  }
$customerData

◆ testCreateCustomerWithErrors()

testCreateCustomerWithErrors ( )

Definition at line 171 of file AccountManagementTest.php.

172  {
173  $serviceInfo = [
174  'rest' => [
175  'resourcePath' => self::RESOURCE_PATH,
177  'soap' => [
178  'service' => self::SERVICE_NAME,
179  'serviceVersion' => self::SERVICE_VERSION,
180  'operation' => self::SERVICE_NAME . 'CreateAccount',
181  ],
182  ];
183 
184  $customerDataArray = $this->dataObjectProcessor->buildOutputDataArray(
185  $this->customerHelper->createSampleCustomerDataObject(),
186  \Magento\Customer\Api\Data\CustomerInterface::class
187  );
188  $invalidEmail = 'invalid';
189  $customerDataArray['email'] = $invalidEmail;
190  $requestData = ['customer' => $customerDataArray, 'password' => CustomerHelper::PASSWORD];
191  try {
192  $this->_webApiCall($serviceInfo, $requestData);
193  $this->fail('Expected exception did not occur.');
194  } catch (\Exception $e) {
195  if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) {
196  $expectedException = new InputException();
197  $expectedException->addError(__('"Email" is not a valid email address.'));
198  $this->assertInstanceOf('SoapFault', $e);
199  $this->checkSoapFault(
200  $e,
201  $expectedException->getRawMessage(),
202  'env:Sender',
203  $expectedException->getParameters() // expected error parameters
204  );
205  } else {
206  $this->assertEquals(HTTPExceptionCodes::HTTP_BAD_REQUEST, $e->getCode());
207  $exceptionData = $this->processRestExceptionResult($e);
208  $expectedExceptionData = [
209  'message' => '"Email" is not a valid email address.',
210  ];
211  $this->assertEquals($expectedExceptionData, $exceptionData);
212  }
213  }
214  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
__()
Definition: __.php:13
checkSoapFault( $soapFault, $expectedMessage, $expectedFaultCode, $expectedErrorParams=[], $expectedWrappedErrors=[], $traceString=null)

◆ testCreateCustomerWithoutOptionalFields()

testCreateCustomerWithoutOptionalFields ( )

Definition at line 216 of file AccountManagementTest.php.

217  {
218  $serviceInfo = [
219  'rest' => [
220  'resourcePath' => self::RESOURCE_PATH,
222  'soap' => [
223  'service' => self::SERVICE_NAME,
224  'serviceVersion' => self::SERVICE_VERSION,
225  'operation' => self::SERVICE_NAME . 'CreateAccount',
226  ],
227  ];
228 
229  $customerDataArray = $this->dataObjectProcessor->buildOutputDataArray(
230  $this->customerHelper->createSampleCustomerDataObject(),
231  \Magento\Customer\Api\Data\CustomerInterface::class
232  );
233  unset($customerDataArray['store_id']);
234  unset($customerDataArray['website_id']);
235  $requestData = ['customer' => $customerDataArray, 'password' => CustomerHelper::PASSWORD];
236  try {
237  $customerData = $this->_webApiCall($serviceInfo, $requestData, null, 'all');
238  $this->assertNotNull($customerData['id']);
239  } catch (\Exception $e) {
240  $this->fail('Customer should be created without optional fields.');
241  }
242  }
$customerData
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testCreateCustomerWithSubscription()

testCreateCustomerWithSubscription ( )

Definition at line 829 of file AccountManagementTest.php.

830  {
831  $customerData = $this->customerHelper->createSampleCustomer(
832  ["extension_attributes" => ["is_subscribed" => true]]
833  );
834 
835  $this->assertNotNull($customerData['id']);
836 
837  $this->subscriber->loadByCustomerId($customerData['id']);
838 
839  $this->assertNotNull($this->subscriber->getId());
840  $this->assertEquals($customerData['id'], $this->subscriber->getCustomerId());
841  }
$customerData

◆ testCustomAttributes()

testCustomAttributes ( )

@magentoApiDataFixture Magento/Customer/_files/attribute_user_defined_address.php @magentoApiDataFixture Magento/Customer/_files/attribute_user_defined_customer.php

Definition at line 684 of file AccountManagementTest.php.

685  {
686  //Sample customer data comes with the disable_auto_group_change custom attribute
687  $customerData = $this->customerHelper->createSampleCustomerDataObject();
688  //address attribute code from fixture
689  $fixtureAddressAttributeCode = 'address_user_attribute';
690  //customer attribute code from fixture
691  $fixtureCustomerAttributeCode = 'user_attribute';
692  //Custom Attribute Values
693  $address1CustomAttributeValue = 'value1';
694  $address2CustomAttributeValue = 'value2';
695  $customerCustomAttributeValue = 'value3';
696 
697  $addresses = $customerData->getAddresses();
698  $addresses[0]->setCustomAttribute($fixtureAddressAttributeCode, $address1CustomAttributeValue);
699  $addresses[1]->setCustomAttribute($fixtureAddressAttributeCode, $address2CustomAttributeValue);
700  $customerData->setAddresses($addresses);
701  $customerData->setCustomAttribute($fixtureCustomerAttributeCode, $customerCustomAttributeValue);
702  $serviceInfo = [
703  'rest' => [
704  'resourcePath' => self::RESOURCE_PATH,
706  ],
707  'soap' => [
708  'service' => self::SERVICE_NAME,
709  'serviceVersion' => self::SERVICE_VERSION,
710  'operation' => self::SERVICE_NAME . 'CreateAccount',
711  ],
712  ];
713 
714  $customerDataArray = $this->dataObjectProcessor->buildOutputDataArray(
716  \Magento\Customer\Api\Data\CustomerInterface::class
717  );
718  $requestData = ['customer' => $customerDataArray, 'password' => CustomerHelper::PASSWORD];
719  $customerData = $this->_webApiCall($serviceInfo, $requestData);
720  $customerId = $customerData['id'];
721  //TODO: Fix assertions to verify custom attributes
722  $this->assertNotNull($customerData);
723 
724  $serviceInfo = [
725  'rest' => [
726  'resourcePath' => self::RESOURCE_PATH . '/' . $customerId ,
728  ],
729  'soap' => [
731  'serviceVersion' => self::SERVICE_VERSION,
732  'operation' => CustomerRepositoryTest::SERVICE_NAME . 'DeleteById',
733  ],
734  ];
735 
736  $response = $this->_webApiCall($serviceInfo, ['customerId' => $customerId]);
737  $this->assertTrue($response);
738  }
$response
Definition: 404.php:11
$customerData
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
$addresses
Definition: address_list.php:7

◆ testEmailAvailable()

testEmailAvailable ( )

Definition at line 638 of file AccountManagementTest.php.

639  {
640  $customerData = $this->_createCustomer();
641 
642  $serviceInfo = [
643  'rest' => [
644  'resourcePath' => self::RESOURCE_PATH . '/isEmailAvailable',
646  ],
647  'soap' => [
648  'service' => self::SERVICE_NAME,
649  'serviceVersion' => self::SERVICE_VERSION,
650  'operation' => self::SERVICE_NAME . 'IsEmailAvailable',
651  ],
652  ];
653  $requestData = [
654  'customerEmail' => $customerData[Customer::EMAIL],
655  'websiteId' => $customerData[Customer::WEBSITE_ID],
656  ];
657  $this->assertFalse($this->_webApiCall($serviceInfo, $requestData));
658  }
$customerData
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testEmailAvailableInvalidEmail()

testEmailAvailableInvalidEmail ( )

Definition at line 660 of file AccountManagementTest.php.

661  {
662  $serviceInfo = [
663  'rest' => [
664  'resourcePath' => self::RESOURCE_PATH . '/isEmailAvailable',
666  ],
667  'soap' => [
668  'service' => self::SERVICE_NAME,
669  'serviceVersion' => self::SERVICE_VERSION,
670  'operation' => self::SERVICE_NAME . 'IsEmailAvailable',
671  ],
672  ];
673  $requestData = [
674  'customerEmail' => 'invalid',
675  'websiteId' => 0,
676  ];
677  $this->assertTrue($this->_webApiCall($serviceInfo, $requestData));
678  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testGetConfirmationStatus()

testGetConfirmationStatus ( )

Definition at line 490 of file AccountManagementTest.php.

491  {
492  $customerData = $this->_createCustomer();
493 
494  $serviceInfo = [
495  'rest' => [
496  'resourcePath' => self::RESOURCE_PATH . '/' . $customerData[Customer::ID] . '/confirm',
498  ],
499  'soap' => [
500  'service' => self::SERVICE_NAME,
501  'serviceVersion' => self::SERVICE_VERSION,
502  'operation' => self::SERVICE_NAME . 'GetConfirmationStatus',
503  ],
504  ];
505 
506  $confirmationResponse = $this->_webApiCall($serviceInfo, ['customerId' => $customerData['id']]);
507 
508  $this->assertEquals(AccountManagement::ACCOUNT_CONFIRMATION_NOT_REQUIRED, $confirmationResponse);
509  }
$customerData
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testGetCustomerActivateCustomer()

testGetCustomerActivateCustomer ( )

Definition at line 280 of file AccountManagementTest.php.

281  {
282  $customerData = $this->_createCustomer();
283 
284  $serviceInfo = [
285  'rest' => [
286  'resourcePath' => self::RESOURCE_PATH . '/' . $customerData[Customer::EMAIL] . '/activate',
288  ],
289  'soap' => [
290  'service' => self::SERVICE_NAME,
291  'serviceVersion' => self::SERVICE_VERSION,
292  'operation' => self::SERVICE_NAME . 'Activate',
293  ],
294  ];
295  $requestData = [
296  'email' => $customerData[Customer::EMAIL],
297  'confirmationKey' => $customerData[Customer::CONFIRMATION],
298  ];
299 
300  $customerResponseData = $this->_webApiCall($serviceInfo, $requestData);
301 
302  $this->assertEquals($customerData[Customer::ID], $customerResponseData[Customer::ID]);
303  // Confirmation key is removed after confirmation
304  $this->assertFalse(isset($customerResponseData[Customer::CONFIRMATION]));
305  }
$customerData
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testGetDefaultBillingAddress()

testGetDefaultBillingAddress ( )

@magentoApiDataFixture Magento/Customer/_files/customer.php @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php

Definition at line 744 of file AccountManagementTest.php.

745  {
746  $fixtureCustomerId = 1;
747  $serviceInfo = [
748  'rest' => [
749  'resourcePath' => self::RESOURCE_PATH . "/$fixtureCustomerId/billingAddress",
751  ],
752  'soap' => [
753  'service' => self::SERVICE_NAME,
754  'serviceVersion' => self::SERVICE_VERSION,
755  'operation' => self::SERVICE_NAME . 'GetDefaultBillingAddress',
756  ],
757  ];
758  $requestData = ['customerId' => $fixtureCustomerId];
759  $addressData = $this->_webApiCall($serviceInfo, $requestData);
760  $this->assertEquals(
762  $addressData,
763  "Default billing address data is invalid."
764  );
765  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
$addressData
Definition: order.php:19

◆ testGetDefaultShippingAddress()

testGetDefaultShippingAddress ( )

@magentoApiDataFixture Magento/Customer/_files/customer.php @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php

Definition at line 771 of file AccountManagementTest.php.

772  {
773  $fixtureCustomerId = 1;
774  $serviceInfo = [
775  'rest' => [
776  'resourcePath' => self::RESOURCE_PATH . "/$fixtureCustomerId/shippingAddress",
778  ],
779  'soap' => [
780  'service' => self::SERVICE_NAME,
781  'serviceVersion' => self::SERVICE_VERSION,
782  'operation' => self::SERVICE_NAME . 'GetDefaultShippingAddress',
783  ],
784  ];
785  $requestData = ['customerId' => $fixtureCustomerId];
786  $addressData = $this->_webApiCall($serviceInfo, $requestData);
787  $this->assertEquals(
789  $addressData,
790  "Default shipping address data is invalid."
791  );
792  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
$addressData
Definition: order.php:19

◆ testInitiatePasswordMissingRequiredFields()

testInitiatePasswordMissingRequiredFields ( )

Definition at line 379 of file AccountManagementTest.php.

380  {
381  $this->_markTestAsRestOnly('Soap clients explicitly check for required fields based on WSDL.');
382  $serviceInfo = [
383  'rest' => [
384  'resourcePath' => self::RESOURCE_PATH . '/password',
386  ]
387  ];
388 
389  try {
390  $this->_webApiCall($serviceInfo);
391  } catch (\Exception $e) {
392  $this->assertEquals(\Magento\Framework\Webapi\Exception::HTTP_BAD_REQUEST, $e->getCode());
393  $exceptionData = $this->processRestExceptionResult($e);
394  $expectedExceptionData = [
395  'message' => 'One or more input exceptions have occurred.',
396  'errors' => [
397  [
398  'message' => '"%fieldName" is required. Enter and try again.',
399  'parameters' => [
400  'fieldName' => 'email',
401  ],
402  ],
403  [
404  'message' => '"%fieldName" is required. Enter and try again.',
405  'parameters' => [
406  'fieldName' => 'template',
407  ]
408  ],
409  ],
410  ];
411  $this->assertEquals($expectedExceptionData, $exceptionData);
412  }
413  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testInitiatePasswordReset()

testInitiatePasswordReset ( )

Definition at line 415 of file AccountManagementTest.php.

416  {
417  $customerData = $this->_createCustomer();
418 
419  $serviceInfo = [
420  'rest' => [
421  'resourcePath' => self::RESOURCE_PATH . '/password',
423  ],
424  'soap' => [
425  'service' => self::SERVICE_NAME,
426  'serviceVersion' => self::SERVICE_VERSION,
427  'operation' => self::SERVICE_NAME . 'InitiatePasswordReset',
428  ],
429  ];
430  $requestData = [
431  'email' => $customerData[Customer::EMAIL],
432  'template' => AccountManagement::EMAIL_RESET,
433  'websiteId' => $customerData[Customer::WEBSITE_ID],
434  ];
435  // This api doesn't return any response.
436  // No exception or response means the request was processed successfully.
437  // The webapi framework does not return the header information as yet. A check for HTTP 200 would be ideal here
438  $this->_webApiCall($serviceInfo, $requestData);
439  }
$customerData
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testIsReadonly()

testIsReadonly ( )

Definition at line 617 of file AccountManagementTest.php.

618  {
619  $customerData = $this->_createCustomer();
620 
621  $serviceInfo = [
622  'rest' => [
623  'resourcePath' => self::RESOURCE_PATH . '/' . $customerData[Customer::ID] . '/permissions/readonly',
625  ],
626  'soap' => [
627  'service' => self::SERVICE_NAME,
628  'serviceVersion' => self::SERVICE_VERSION,
629  'operation' => self::SERVICE_NAME . 'IsReadonly',
630  ],
631  ];
632 
633  $response = $this->_webApiCall($serviceInfo, ['customerId' => $customerData['id']]);
634 
635  $this->assertFalse($response);
636  }
$response
Definition: 404.php:11
$customerData
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testResendConfirmation()

testResendConfirmation ( )

Definition at line 511 of file AccountManagementTest.php.

512  {
513  $customerData = $this->_createCustomer();
514 
515  $serviceInfo = [
516  'rest' => [
517  'resourcePath' => self::RESOURCE_PATH . '/confirm',
519  ],
520  'soap' => [
521  'service' => self::SERVICE_NAME,
522  'serviceVersion' => self::SERVICE_VERSION,
523  'operation' => self::SERVICE_NAME . 'ResendConfirmation',
524  ],
525  ];
526  $requestData = [
527  'email' => $customerData[Customer::EMAIL],
528  'websiteId' => $customerData[Customer::WEBSITE_ID],
529  ];
530  // This api doesn't return any response.
531  // No exception or response means the request was processed successfully.
532  // The webapi framework does not return the header information as yet. A check for HTTP 200 would be ideal here
533  $this->_webApiCall($serviceInfo, $requestData);
534  }
$customerData
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testResendConfirmationBadEmailOrWebsite()

testResendConfirmationBadEmailOrWebsite ( )

Definition at line 536 of file AccountManagementTest.php.

537  {
538  $serviceInfo = [
539  'rest' => [
540  'resourcePath' => self::RESOURCE_PATH . '/confirm',
542  ],
543  'soap' => [
544  'service' => self::SERVICE_NAME,
545  'serviceVersion' => self::SERVICE_VERSION,
546  'operation' => self::SERVICE_NAME . 'ResendConfirmation',
547  ],
548  ];
549  $requestData = [
550  'email' => '[email protected]',
551  'websiteId' => 0,
552  ];
553  try {
554  $this->_webApiCall($serviceInfo, $requestData);
555  } catch (\Exception $e) {
556  $expectedErrorParameters =
557  [
558  'fieldName' => 'email',
559  'fieldValue' => '[email protected]',
560  'field2Name' => 'websiteId',
561  'field2Value' => 0,
562  ];
563  if (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) {
564  $errorObj = $this->processRestExceptionResult($e);
565  $this->assertEquals(
566  'No such entity with %fieldName = %fieldValue, %field2Name = %field2Value',
567  $errorObj['message']
568  );
569  $this->assertEquals($expectedErrorParameters, $errorObj['parameters']);
570  $this->assertEquals(HTTPExceptionCodes::HTTP_NOT_FOUND, $e->getCode());
571  } else {
572  $this->assertInstanceOf('SoapFault', $e);
573  $this->checkSoapFault(
574  $e,
575  'No such entity with %fieldName = %fieldValue, %field2Name = %field2Value',
576  'env:Sender',
577  $expectedErrorParameters
578  );
579  }
580  }
581  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
checkSoapFault( $soapFault, $expectedMessage, $expectedFaultCode, $expectedErrorParams=[], $expectedWrappedErrors=[], $traceString=null)

◆ testSendPasswordResetLinkBadEmailOrWebsite()

testSendPasswordResetLinkBadEmailOrWebsite ( )

Definition at line 441 of file AccountManagementTest.php.

442  {
443  $serviceInfo = [
444  'rest' => [
445  'resourcePath' => self::RESOURCE_PATH . '/password',
447  ],
448  'soap' => [
449  'service' => self::SERVICE_NAME,
450  'serviceVersion' => self::SERVICE_VERSION,
451  'operation' => self::SERVICE_NAME . 'InitiatePasswordReset',
452  ],
453  ];
454  $requestData = [
455  'email' => '[email protected]',
456  'template' => AccountManagement::EMAIL_RESET,
457  'websiteId' => 0,
458  ];
459  try {
460  $this->_webApiCall($serviceInfo, $requestData);
461  } catch (\Exception $e) {
462  $expectedErrorParameters =
463  [
464  'fieldName' => 'email',
465  'fieldValue' => '[email protected]',
466  'field2Name' => 'websiteId',
467  'field2Value' => 0,
468  ];
469 
470  if (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) {
471  $errorObj = $this->processRestExceptionResult($e);
472  $this->assertEquals(
473  'No such entity with %fieldName = %fieldValue, %field2Name = %field2Value',
474  $errorObj['message']
475  );
476  $this->assertEquals($expectedErrorParameters, $errorObj['parameters']);
477  $this->assertEquals(HTTPExceptionCodes::HTTP_NOT_FOUND, $e->getCode());
478  } else {
479  $this->assertInstanceOf('SoapFault', $e);
480  $this->checkSoapFault(
481  $e,
482  'No such entity with %fieldName = %fieldValue, %field2Name = %field2Value',
483  'env:Sender',
484  $expectedErrorParameters
485  );
486  }
487  }
488  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
checkSoapFault( $soapFault, $expectedMessage, $expectedFaultCode, $expectedErrorParams=[], $expectedWrappedErrors=[], $traceString=null)

◆ testUnsubscribeCustomer()

testUnsubscribeCustomer ( )

Definition at line 843 of file AccountManagementTest.php.

844  {
845  //Creating customer and subscribe
846  $customerData = $this->customerHelper->createSampleCustomer(
847  ["extension_attributes" => ["is_subscribed" => true]]
848  );
849  $this->assertNotNull($customerData['id']);
850 
851  $this->subscriber->loadByCustomerId($customerData['id']);
852  $subscriptionId = $this->subscriber->getId();
853 
854  $this->assertNotNull($subscriptionId);
855  $this->assertEquals($customerData['id'], $this->subscriber->getCustomerId());
856  //Manage customer in order to unsubscribe
857  $this->customerHelper->updateSampleCustomer(
858  $customerData["id"],
859  array_merge(
861  ["extension_attributes" => ["is_subscribed" => false]]
862  )
863  );
864  $this->initSubscriber();
865 
866  $this->subscriber->loadByCustomerId($customerData['id']);
867  $this->assertEquals(Subscriber::STATUS_UNSUBSCRIBED, $this->subscriber->getStatus());
868  }
$customerData

◆ testValidateCustomerData()

testValidateCustomerData ( )

Definition at line 583 of file AccountManagementTest.php.

584  {
585  $customerData = $this->customerHelper->createSampleCustomerDataObject();
586  $customerData->setFirstname(null);
587  $customerData->setLastname(null);
588  $serviceInfo = [
589  'rest' => [
590  'resourcePath' => self::RESOURCE_PATH . '/validate',
592  ],
593  'soap' => [
594  'service' => self::SERVICE_NAME,
595  'serviceVersion' => self::SERVICE_VERSION,
596  'operation' => self::SERVICE_NAME . 'Validate',
597  ],
598  ];
599  $customerData = $this->dataObjectProcessor->buildOutputDataArray(
601  \Magento\Customer\Api\Data\CustomerInterface::class
602  );
603  $requestData = ['customer' => $customerData];
604  $validationResponse = $this->_webApiCall($serviceInfo, $requestData);
605  $this->assertFalse($validationResponse['valid']);
606 
607  $this->assertEquals(
608  'The "First Name" attribute value is empty. Set the attribute and try again.',
609  $validationResponse['messages'][0]
610  );
611  $this->assertEquals(
612  'The "Last Name" attribute value is empty. Set the attribute and try again.',
613  $validationResponse['messages'][1]
614  );
615  }
$customerData
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testValidateResetPasswordLinkTokenInvalidToken()

testValidateResetPasswordLinkTokenInvalidToken ( )

Definition at line 337 of file AccountManagementTest.php.

338  {
339  $customerData = $this->_createCustomer();
340  $invalidToken = 'fjjkafjie';
341  $path = self::RESOURCE_PATH . '/' . $customerData[Customer::ID] . '/password/resetLinkToken/' . $invalidToken;
342  $serviceInfo = [
343  'rest' => [
344  'resourcePath' => $path,
346  ],
347  'soap' => [
348  'service' => self::SERVICE_NAME,
349  'serviceVersion' => self::SERVICE_VERSION,
350  'operation' => self::SERVICE_NAME . 'ValidateResetPasswordLinkToken',
351  ],
352  ];
353 
354  $expectedMessage = 'The password token is mismatched. Reset and try again.';
355 
356  try {
357  if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) {
358  $this->_webApiCall(
359  $serviceInfo,
360  ['customerId' => $customerData['id'], 'resetPasswordLinkToken' => 'invalid']
361  );
362  } else {
363  $this->_webApiCall($serviceInfo);
364  }
365  $this->fail("Expected exception to be thrown.");
366  } catch (\SoapFault $e) {
367  $this->assertContains(
368  $expectedMessage,
369  $e->getMessage(),
370  "Exception message does not match"
371  );
372  } catch (\Exception $e) {
373  $errorObj = $this->processRestExceptionResult($e);
374  $this->assertEquals($expectedMessage, $errorObj['message']);
375  $this->assertEquals(HTTPExceptionCodes::HTTP_BAD_REQUEST, $e->getCode());
376  }
377  }
$customerData
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

Field Documentation

◆ ATTRIBUTE_CODE

const ATTRIBUTE_CODE = 'attribute_code'

Sample values for testing

Definition at line 33 of file AccountManagementTest.php.

◆ ATTRIBUTE_VALUE

const ATTRIBUTE_VALUE = 'attribute_value'

Definition at line 34 of file AccountManagementTest.php.

◆ RESOURCE_PATH

const RESOURCE_PATH = '/V1/customers'

Definition at line 28 of file AccountManagementTest.php.

◆ SERVICE_NAME

const SERVICE_NAME = 'customerAccountManagementV1'

Definition at line 27 of file AccountManagementTest.php.

◆ SERVICE_VERSION

const SERVICE_VERSION = 'V1'

Definition at line 26 of file AccountManagementTest.php.


The documentation for this class was generated from the following file: