-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAGETWO-59090: [Github] Admin can't reset password for more than one …
…customer #5260
- Loading branch information
1 parent
aef25e7
commit 7a67ac9
Showing
5 changed files
with
157 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...s/integration/testsuite/Magento/Customer/Controller/Adminhtml/Index/ResetPasswordTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Customer\Controller\Adminhtml\Index; | ||
|
||
/** | ||
* ResetPassword controller test. | ||
* | ||
* @magentoAppArea adminhtml | ||
*/ | ||
class ResetPasswordTest extends \Magento\TestFramework\TestCase\AbstractBackendController | ||
{ | ||
/** | ||
* Base controller URL | ||
* | ||
* @var string | ||
*/ | ||
protected $baseControllerUrl = 'http://localhost/index.php/backend/customer/index/'; | ||
|
||
/** | ||
* Checks reset password functionality with default settings and customer reset request event. | ||
* | ||
* @magentoConfigFixture current_store admin/security/limit_password_reset_requests_method 1 | ||
* @magentoConfigFixture current_store admin/security/min_time_between_password_reset_requests 10 | ||
* @magentoDataFixture Magento/Customer/_files/customer.php | ||
*/ | ||
public function testResetPasswordSuccess() | ||
{ | ||
$this->passwordResetRequestEventCreate( | ||
\Magento\Security\Model\PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST | ||
); | ||
$this->getRequest()->setPostValue(['customer_id' => '1']); | ||
$this->dispatch('backend/customer/index/resetPassword'); | ||
$this->assertSessionMessages( | ||
$this->equalTo(['The customer will receive an email with a link to reset password.']), | ||
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS | ||
); | ||
$this->assertRedirect($this->stringStartsWith($this->baseControllerUrl . 'edit')); | ||
} | ||
|
||
/** | ||
* Checks reset password functionality with default settings, customer and admin reset request events. | ||
* | ||
* @magentoConfigFixture current_store admin/security/limit_password_reset_requests_method 1 | ||
* @magentoConfigFixture current_store admin/security/min_time_between_password_reset_requests 10 | ||
* @magentoConfigFixture current_store contact/email/recipient_email hello@example.com | ||
* @magentoDataFixture Magento/Customer/_files/customer.php | ||
*/ | ||
public function testResetPasswordWithSecurityViolationException() | ||
{ | ||
$this->passwordResetRequestEventCreate( | ||
\Magento\Security\Model\PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST | ||
); | ||
$this->passwordResetRequestEventCreate( | ||
\Magento\Security\Model\PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST | ||
); | ||
$this->getRequest()->setPostValue(['customer_id' => '1']); | ||
$this->dispatch('backend/customer/index/resetPassword'); | ||
$this->assertSessionMessages( | ||
$this->equalTo( | ||
['Too many password reset requests. Please wait and try again or contact hello@example.com.'] | ||
), | ||
\Magento\Framework\Message\MessageInterface::TYPE_ERROR | ||
); | ||
$this->assertRedirect($this->stringStartsWith($this->baseControllerUrl . 'edit')); | ||
} | ||
|
||
/** | ||
* Create and save reset request event with provided request type. | ||
* | ||
* @param int $requestType | ||
*/ | ||
private function passwordResetRequestEventCreate($requestType) | ||
{ | ||
$passwordResetRequestEventFactory = $this->_objectManager->get( | ||
\Magento\Security\Model\PasswordResetRequestEventFactory::class | ||
); | ||
$passwordResetRequestEvent = $passwordResetRequestEventFactory->create(); | ||
$passwordResetRequestEvent | ||
->setRequestType($requestType) | ||
->setAccountReference('customer@example.com') | ||
->setCreatedAt(strtotime('now')) | ||
->setIp('3232249856') | ||
->save(); | ||
} | ||
} |