Skip to content

Commit ad2e876

Browse files
akaashakaash
authored andcommitted
ACQE-4501 | Integration Testing - Reset password flow
1 parent 1c874bd commit ad2e876

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/ForgotPasswordTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Customer\Api\AccountManagementInterface;
1111
use Magento\Customer\Model\AccountManagement;
1212
use Magento\Framework\ObjectManagerInterface;
13+
use Magento\Store\Model\StoreManagerInterface;
1314
use Magento\TestFramework\Helper\Bootstrap;
1415
use Magento\TestFramework\Helper\Xpath;
1516
use Magento\TestFramework\Mail\Template\TransportBuilderMock;
@@ -35,6 +36,9 @@ class ForgotPasswordTest extends TestCase
3536
private $newPasswordLinkPath = "//a[contains(@href, 'customer/account/createPassword') "
3637
. "and contains(text(), 'Set a New Password')]";
3738

39+
/** @var StoreManagerInterface */
40+
private $storeManager;
41+
3842
/**
3943
* @inheritdoc
4044
*/
@@ -45,6 +49,7 @@ protected function setUp(): void
4549
$this->objectManager = Bootstrap::getObjectManager();
4650
$this->accountManagement = $this->objectManager->get(AccountManagementInterface::class);
4751
$this->transportBuilder = $this->objectManager->get(TransportBuilderMock::class);
52+
$this->storeManager = $this->objectManager->get(StoreManagerInterface::class);
4853
}
4954

5055
/**
@@ -61,4 +66,44 @@ public function testForgotPassword(): void
6166
$this->assertTrue($result);
6267
$this->assertEquals(1, Xpath::getElementsCountForXpath($this->newPasswordLinkPath, $messageContent));
6368
}
69+
70+
/**
71+
* @magentoDataFixture Magento/Customer/_files/customer.php
72+
*
73+
* @return void
74+
*/
75+
public function testResetPasswordFlowStorefront(): void
76+
{
77+
// Forgot password section
78+
$email = 'customer@example.com';
79+
$result = $this->accountManagement->initiatePasswordReset($email, AccountManagement::EMAIL_RESET);
80+
$message = $this->transportBuilder->getSentMessage();
81+
$messageContent = $message->getBody()->getParts()[0]->getRawContent();
82+
$this->assertTrue($result);
83+
$this->assertEquals(1, Xpath::getElementsCountForXpath($this->newPasswordLinkPath, $messageContent));
84+
85+
// Send reset password link
86+
$websiteId = (int)$this->storeManager->getWebsite('base')->getId();
87+
$this->accountManagement->initiatePasswordReset($email, AccountManagement::EMAIL_RESET, $websiteId);
88+
89+
// login with old credentials
90+
$customer = $this->accountManagement->authenticate('customer@example.com', 'password');
91+
92+
$this->assertEquals(
93+
$customer->getId(),
94+
$this->accountManagement->authenticate('customer@example.com', 'password')->getId()
95+
);
96+
97+
// Change password
98+
$this->accountManagement->changePassword('customer@example.com', 'password', 'new_Password123');
99+
100+
// Login with new credentials
101+
$this->accountManagement->authenticate('customer@example.com', 'new_Password123');
102+
103+
$this->assertEquals(
104+
$customer->getId(),
105+
$this->accountManagement->authenticate('customer@example.com', 'new_Password123')->getId()
106+
);
107+
108+
}
64109
}

0 commit comments

Comments
 (0)