Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
AccountTest Class Reference
Inheritance diagram for AccountTest:
AbstractController

Public Member Functions

 testIndexAction ()
 
 testCreateAction ()
 
 testLogoutAction ()
 
 testNoFormKeyCreatePostAction ()
 
 testExistingEmailCreatePostAction ()
 
 testInactiveUserConfirmationAction ()
 
 testActiveUserConfirmationAction ()
 
 testForgotPasswordPostAction ()
 
 testForgotPasswordPostWithBadEmailAction ()
 
 testResetPasswordPostNoTokenAction ()
 
 testResetPasswordPostAction ()
 
 testEditAction ()
 
 testChangePasswordEditAction ()
 
 testMissingDataEditPostAction ()
 
 testWrongPasswordEditPostAction ()
 
 testWrongConfirmationEditPostAction ()
 
 testLoginPostRedirect ($redirectDashboard, string $redirectUrl)
 
 loginPostRedirectDataProvider ()
 
- Public Member Functions inherited from AbstractController
 getRequest ()
 
 getResponse ()
 
 assert404NotFound ()
 
 assertHeaderPcre ($headerName, $valueRegex)
 
 assertRedirect (\PHPUnit\Framework\Constraint\Constraint $urlConstraint=null)
 

Additional Inherited Members

- Protected Member Functions inherited from AbstractController
 _getBootstrap ()
 
 setUp ()
 
 tearDown ()
 
 assertPostConditions ()
 
 getMessages ( $messageType=null, $messageManagerClass=\Magento\Framework\Message\Manager::class)
 
- Protected Attributes inherited from AbstractController
 $_runCode = ''
 
 $_runScope = 'store'
 
 $_runOptions = []
 
 $_request
 
 $_response
 
 $_objectManager
 
 $_assertSessionErrors = false
 

Detailed Description

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 30 of file AccountTest.php.

Member Function Documentation

◆ loginPostRedirectDataProvider()

loginPostRedirectDataProvider ( )

Data provider for testLoginPostRedirect.

Returns
array

Definition at line 709 of file AccountTest.php.

710  {
711  return [
712  [null, 'index.php/'],
713  [0, 'index.php/'],
714  [1, 'index.php/customer/account/'],
715  ];
716  }

◆ testActiveUserConfirmationAction()

testActiveUserConfirmationAction ( )

@magentoDataFixture Magento/Customer/_files/customer.php

Definition at line 350 of file AccountTest.php.

351  {
352  $this->getRequest()
353  ->setMethod('POST')
354  ->setPostValue([
355  'email' => '[email protected]',
356  ]);
357 
358  $this->dispatch('customer/account/confirmation');
359  $this->assertRedirect($this->stringContains('customer/account/index'));
360  $this->assertSessionMessages(
361  $this->equalTo(['This email does not require confirmation.']),
363  );
364  }
assertRedirect(\PHPUnit\Framework\Constraint\Constraint $urlConstraint=null)

◆ testChangePasswordEditAction()

testChangePasswordEditAction ( )

@magentoDataFixture Magento/Customer/_files/customer.php

Definition at line 479 of file AccountTest.php.

480  {
481  $this->login(1);
482 
483  $this->dispatch('customer/account/edit/changepass/1');
484 
485  $body = $this->getResponse()->getBody();
486  $this->assertEquals(200, $this->getResponse()->getHttpResponseCode(), $body);
487  $this->assertContains('<div class="field field-name-firstname required">', $body);
488  // Verify the password check box is checked
489  $this->assertContains(
490  '<input type="checkbox" name="change_password" id="change-password" '
491  . 'data-role="change-password" value="1" title="Change&#x20;Password" checked="checked" '
492  . 'class="checkbox" />',
493  $body
494  );
495  }

◆ testCreateAction()

testCreateAction ( )

Test sign up form displaying.

Definition at line 62 of file AccountTest.php.

63  {
64  $this->dispatch('customer/account/create');
65  $body = $this->getResponse()->getBody();
66 
67  $this->assertRegExp('~<input type="text"[^>]*id="firstname"~', $body);
68  $this->assertRegExp('~<input type="text"[^>]*id="lastname"~', $body);
69  $this->assertRegExp('~<input type="checkbox"[^>]*id="is_subscribed"~', $body);
70  $this->assertRegExp('~<input type="email"[^>]*id="email_address"~', $body);
71  $this->assertRegExp('~<input type="password"[^>]*id="password"~', $body);
72  $this->assertRegExp('~<input type="password"[^>]*id="password-confirmation"~', $body);
73  }

◆ testEditAction()

testEditAction ( )

@magentoDataFixture Magento/Customer/_files/customer.php

Definition at line 462 of file AccountTest.php.

463  {
464  $this->login(1);
465 
466  $this->dispatch('customer/account/edit');
467 
468  $body = $this->getResponse()->getBody();
469  $this->assertEquals(200, $this->getResponse()->getHttpResponseCode(), $body);
470  $this->assertContains('<div class="field field-name-firstname required">', $body);
471  // Verify the password check box is not checked
472  $this->assertContains('<input type="checkbox" name="change_password" id="change-password" '
473  . 'data-role="change-password" value="1" title="Change&#x20;Password" class="checkbox" />', $body);
474  }

◆ testExistingEmailCreatePostAction()

testExistingEmailCreatePostAction ( )

@magentoDataFixture Magento/Customer/_files/customer.php

Definition at line 316 of file AccountTest.php.

317  {
318  $this->fillRequestWithAccountDataAndFormKey('[email protected]');
319  $this->dispatch('customer/account/createPost');
320  $this->assertRedirect($this->stringContains('customer/account/create/'));
321  $this->assertSessionMessages(
322  $this->equalTo(['There is already an account with this email address. ' .
323  'If you are sure that it is your email address, ' .
324  '<a href="http://localhost/index.php/customer/account/forgotpassword/">click here</a>' .
325  ' to get your password and access your account.', ]),
327  );
328  }
assertRedirect(\PHPUnit\Framework\Constraint\Constraint $urlConstraint=null)

◆ testForgotPasswordPostAction()

testForgotPasswordPostAction ( )

@codingStandardsIgnoreStart @magentoConfigFixture current_store customer/password/limit_password_reset_requests_method 0 @magentoConfigFixture current_store customer/password/forgot_email_template customer_password_forgot_email_template @magentoConfigFixture current_store customer/password/forgot_email_identity support @magentoConfigFixture current_store customer/captcha/enable 0 @magentoDataFixture Magento/Customer/_files/customer.php @codingStandardsIgnoreEnd

Definition at line 375 of file AccountTest.php.

376  {
378 
379  $this->getRequest()->setMethod(HttpRequest::METHOD_POST);
380  $this->getRequest()->setPostValue(['email' => $email]);
381 
382  $this->dispatch('customer/account/forgotPasswordPost');
383  $this->assertRedirect($this->stringContains('customer/account/'));
384 
385  $message = __(
386  'If there is an account associated with %1 you will receive an email with a link to reset your password.',
387  $email
388  );
389  $this->assertSessionMessages(
390  $this->equalTo([$message]),
392  );
393  }
assertRedirect(\PHPUnit\Framework\Constraint\Constraint $urlConstraint=null)
$email
Definition: details.phtml:13
__()
Definition: __.php:13
$message

◆ testForgotPasswordPostWithBadEmailAction()

testForgotPasswordPostWithBadEmailAction ( )

@magentoConfigFixture current_store customer/captcha/enable 0

Definition at line 398 of file AccountTest.php.

399  {
400  $this->getRequest()->setMethod(HttpRequest::METHOD_POST);
401  $this->getRequest()
402  ->setPostValue([
403  'email' => 'bad@email',
404  ]);
405 
406  $this->dispatch('customer/account/forgotPasswordPost');
407  $this->assertRedirect($this->stringContains('customer/account/forgotpassword'));
408  $this->assertSessionMessages(
409  $this->equalTo(['The email address is incorrect. Verify the email address and try again.']),
411  );
412  }
assertRedirect(\PHPUnit\Framework\Constraint\Constraint $urlConstraint=null)

◆ testInactiveUserConfirmationAction()

testInactiveUserConfirmationAction ( )

@magentoDataFixture Magento/Customer/_files/inactive_customer.php

Definition at line 333 of file AccountTest.php.

334  {
335  $this->getRequest()
336  ->setMethod('POST')
337  ->setPostValue(['email' => '[email protected]']);
338 
339  $this->dispatch('customer/account/confirmation');
340  $this->assertRedirect($this->stringContains('customer/account/index'));
341  $this->assertSessionMessages(
342  $this->equalTo(['Please check your email for confirmation key.']),
344  );
345  }
assertRedirect(\PHPUnit\Framework\Constraint\Constraint $urlConstraint=null)

◆ testIndexAction()

testIndexAction ( )

@magentoDataFixture Magento/Customer/_files/customer.php @magentoDataFixture Magento/Customer/_files/customer_address.php

Definition at line 50 of file AccountTest.php.

51  {
52  $this->login(1);
53  $this->dispatch('customer/account/index');
54 
55  $body = $this->getResponse()->getBody();
56  $this->assertContains('Green str, 67', $body);
57  }

◆ testLoginPostRedirect()

testLoginPostRedirect (   $redirectDashboard,
string  $redirectUrl 
)

Test redirect customer to account dashboard after logging in.

Parameters
bool | null$redirectDashboard
string$redirectUrl@magentoDbIsolation enabled @magentoAppIsolation enabled @magentoDataFixture Magento/Customer/_files/customer.php @dataProvider loginPostRedirectDataProvider

Definition at line 685 of file AccountTest.php.

686  {
687  if (isset($redirectDashboard)) {
688  $this->_objectManager->get(ScopeConfigInterface::class)->setValue(
689  'customer/startup/redirect_dashboard',
690  $redirectDashboard
691  );
692  }
693  $this->_objectManager->get(Redirect::class)->setRedirectCookie('test');
694  $configValue = $this->_objectManager->create(Value::class);
695  $configValue->load('web/unsecure/base_url', 'path');
696  $baseUrl = $configValue->getValue() ?: 'http://localhost/';
697  $request = $this->prepareRequest();
698  $app = $this->_objectManager->create(Http::class, ['_request' => $request]);
699  $response = $app->launch();
700  $this->assertResponseRedirect($response, $baseUrl . $redirectUrl);
701  $this->assertTrue($this->_objectManager->get(Session::class)->isLoggedIn());
702  }
$response
Definition: 404.php:11
$app
Definition: index.php:38

◆ testLogoutAction()

testLogoutAction ( )

@magentoDataFixture Magento/Customer/_files/customer.php

Definition at line 78 of file AccountTest.php.

79  {
80  $this->login(1);
81  $this->dispatch('customer/account/logout');
82  $this->assertRedirect($this->stringContains('customer/account/logoutSuccess'));
83  }
assertRedirect(\PHPUnit\Framework\Constraint\Constraint $urlConstraint=null)

◆ testMissingDataEditPostAction()

testMissingDataEditPostAction ( )

@magentoDataFixture Magento/Customer/_files/customer.php

Definition at line 591 of file AccountTest.php.

592  {
593  $this->login(1);
594  $this->getRequest()
595  ->setMethod('POST')
596  ->setPostValue(
597  [
598  'form_key' => $this->_objectManager->get(FormKey::class)->getFormKey(),
599  'firstname' => 'John',
600  'lastname' => 'Doe',
601  'change_email' => 1,
602  'current_password' => 'password',
603  'email' => 'bad-email',
604  ]
605  );
606 
607  $this->dispatch('customer/account/editPost');
608 
609  $this->assertRedirect($this->stringContains('customer/account/edit/'));
610  $this->assertSessionMessages(
611  $this->equalTo(['&quot;Email&quot; is not a valid email address.']),
613  );
614  }
assertRedirect(\PHPUnit\Framework\Constraint\Constraint $urlConstraint=null)

◆ testNoFormKeyCreatePostAction()

testNoFormKeyCreatePostAction ( )

Tests that without form key user account won't be created and user will be redirected on account creation page again.

Definition at line 221 of file AccountTest.php.

222  {
223  $this->fillRequestWithAccountData('[email protected]');
224  $this->getRequest()->setPostValue('form_key', null);
225  $this->dispatch('customer/account/createPost');
226 
227  $this->assertNull($this->getCustomerByEmail('[email protected]'));
228  $this->assertRedirect($this->stringEndsWith('customer/account/create/'));
229  }
assertRedirect(\PHPUnit\Framework\Constraint\Constraint $urlConstraint=null)

◆ testResetPasswordPostAction()

testResetPasswordPostAction ( )

@magentoDataFixture Magento/Customer/_files/customer_rp_token.php @magentoConfigFixture customer/password/reset_link_expiration_period 10

Definition at line 440 of file AccountTest.php.

441  {
442  $this->getRequest()
443  ->setQueryValue('id', 1)
444  ->setQueryValue('token', '8ed8677e6c79e68b94e61658bd756ea5')
445  ->setMethod('POST')
446  ->setPostValue([
447  'password' => 'new-Password1',
448  'password_confirmation' => 'new-Password1',
449  ]);
450 
451  $this->dispatch('customer/account/resetPasswordPost');
452  $this->assertRedirect($this->stringContains('customer/account/login'));
453  $this->assertSessionMessages(
454  $this->equalTo(['You updated your password.']),
456  );
457  }
assertRedirect(\PHPUnit\Framework\Constraint\Constraint $urlConstraint=null)

◆ testResetPasswordPostNoTokenAction()

testResetPasswordPostNoTokenAction ( )

@magentoDataFixture Magento/Customer/_files/customer.php

Definition at line 417 of file AccountTest.php.

418  {
419  $this->getRequest()
420  ->setParam('id', 1)
421  ->setParam('token', '8ed8677e6c79e68b94e61658bd756ea5')
422  ->setMethod('POST')
423  ->setPostValue([
424  'password' => 'new-password',
425  'password_confirmation' => 'new-password',
426  ]);
427 
428  $this->dispatch('customer/account/resetPasswordPost');
429  $this->assertRedirect($this->stringContains('customer/account/'));
430  $this->assertSessionMessages(
431  $this->equalTo(['Something went wrong while saving the new password.']),
433  );
434  }
assertRedirect(\PHPUnit\Framework\Constraint\Constraint $urlConstraint=null)

◆ testWrongConfirmationEditPostAction()

testWrongConfirmationEditPostAction ( )

@magentoDataFixture Magento/Customer/_files/customer.php

Definition at line 650 of file AccountTest.php.

651  {
652  $this->login(1);
653  $this->getRequest()
654  ->setMethod('POST')
655  ->setPostValue([
656  'form_key' => $this->_objectManager->get(FormKey::class)->getFormKey(),
657  'firstname' => 'John',
658  'lastname' => 'Doe',
659  'email' => '[email protected]',
660  'change_password' => 1,
661  'current_password' => 'password',
662  'password' => 'new-password',
663  'password_confirmation' => 'new-password-no-match',
664  ]);
665 
666  $this->dispatch('customer/account/editPost');
667 
668  $this->assertRedirect($this->stringContains('customer/account/edit/'));
669  $this->assertSessionMessages(
670  $this->equalTo(['Password confirmation doesn&#039;t match entered password.']),
672  );
673  }
assertRedirect(\PHPUnit\Framework\Constraint\Constraint $urlConstraint=null)

◆ testWrongPasswordEditPostAction()

testWrongPasswordEditPostAction ( )

@magentoDataFixture Magento/Customer/_files/customer.php

Definition at line 619 of file AccountTest.php.

620  {
621  $this->login(1);
622  $this->getRequest()
623  ->setMethod('POST')
624  ->setPostValue(
625  [
626  'form_key' => $this->_objectManager->get(FormKey::class)->getFormKey(),
627  'firstname' => 'John',
628  'lastname' => 'Doe',
629  'email' => '[email protected]',
630  'change_password' => 1,
631  'current_password' => 'wrong-password',
632  'password' => 'new-password',
633  'password_confirmation' => 'new-password',
634  ]
635  );
636 
637  $this->dispatch('customer/account/editPost');
638 
639  $this->assertRedirect($this->stringContains('customer/account/edit/'));
640  // Not sure if its the most secure message. Not changing the behavior for now in the new AccountManagement APIs.
641  $this->assertSessionMessages(
642  $this->equalTo(["The password doesn&#039;t match this account. Verify the password and try again."]),
644  );
645  }
assertRedirect(\PHPUnit\Framework\Constraint\Constraint $urlConstraint=null)

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