Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AccountManagementTest.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Customer\Api;
8 
12 use Magento\Framework\Webapi\Exception as HTTPExceptionCodes;
16 use Magento\TestFramework\Helper\Customer as CustomerHelper;
18 
25 {
26  const SERVICE_VERSION = 'V1';
27  const SERVICE_NAME = 'customerAccountManagementV1';
28  const RESOURCE_PATH = '/V1/customers';
29 
33  const ATTRIBUTE_CODE = 'attribute_code';
34  const ATTRIBUTE_VALUE = 'attribute_value';
35 
39  private $accountManagement;
40 
44  private $searchCriteriaBuilder;
45 
49  private $sortOrderBuilder;
50 
54  private $filterGroupBuilder;
55 
59  private $customerHelper;
60 
64  private $currentCustomerId;
65 
67  private $subscriber;
68 
72  private $dataObjectProcessor;
73 
77  private $config;
78 
82  private $configValue;
83 
87  public function setUp()
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  }
127 
128  public function tearDown()
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  }
157 
158  private function initSubscriber()
159  {
160  $this->subscriber = Bootstrap::getObjectManager()->create(
161  \Magento\Newsletter\Model\Subscriber::class
162  );
163  }
164 
165  public function testCreateCustomer()
166  {
167  $customerData = $this->_createCustomer();
168  $this->assertNotNull($customerData['id']);
169  }
170 
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  }
215 
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  }
243 
249  public function testActivateCustomer()
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  }
279 
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  }
306 
307  public function testValidateResetPasswordLinkToken()
308  {
309  $customerData = $this->_createCustomer();
311  $customerModel = Bootstrap::getObjectManager()->create(\Magento\Customer\Model\CustomerFactory::class)
312  ->create();
313  $customerModel->load($customerData[Customer::ID]);
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;
319  $serviceInfo = [
320  'rest' => [
321  'resourcePath' => $path,
323  ],
324  'soap' => [
325  'service' => self::SERVICE_NAME,
326  'serviceVersion' => self::SERVICE_VERSION,
327  'operation' => self::SERVICE_NAME . 'ValidateResetPasswordLinkToken',
328  ],
329  ];
330 
331  $this->_webApiCall(
332  $serviceInfo,
333  ['customerId' => $customerData['id'], 'resetPasswordLinkToken' => $rpToken]
334  );
335  }
336 
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  }
378 
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  }
414 
415  public function testInitiatePasswordReset()
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  }
440 
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  }
489 
490  public function testGetConfirmationStatus()
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  }
510 
511  public function testResendConfirmation()
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  }
535 
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  }
582 
583  public function testValidateCustomerData()
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  }
616 
617  public function testIsReadonly()
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  }
637 
638  public function testEmailAvailable()
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  }
659 
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  }
679 
684  public function testCustomAttributes()
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  }
739 
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  }
766 
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  }
793 
797  protected function _createCustomer()
798  {
799  $customerData = $this->customerHelper->createSampleCustomer();
800  $this->currentCustomerId[] = $customerData['id'];
801  return $customerData;
802  }
803 
809  protected function getFirstFixtureAddressData()
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  }
828 
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  }
842 
843  public function testUnsubscribeCustomer()
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  }
869 }
$response
Definition: 404.php:11
$customerData
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
$addresses
Definition: address_list.php:7
__()
Definition: __.php:13
$addressData
Definition: order.php:19
const XML_PATH_PASSWORD_RESET_PROTECTION_TYPE
Definition: Config.php:47
checkSoapFault( $soapFault, $expectedMessage, $expectedFaultCode, $expectedErrorParams=[], $expectedWrappedErrors=[], $traceString=null)