Skip to content

Commit 4ccb965

Browse files
akaashakaash
authored andcommitted
PR Feedbacks
1 parent c220794 commit 4ccb965

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed

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

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,20 @@
77

88
namespace Magento\Customer\Model\AccountManagement;
99

10+
use Magento\Catalog\Helper\Data;
1011
use Magento\Customer\Api\AccountManagementInterface;
11-
use Magento\Customer\Api\CustomerRepositoryInterface;
1212
use Magento\Customer\Model\AccountManagement;
13+
use Magento\Customer\Test\Fixture\Customer;
14+
use Magento\Framework\Exception\LocalizedException;
1315
use Magento\Framework\ObjectManagerInterface;
1416
use Magento\Store\Model\StoreManagerInterface;
17+
use Magento\Store\Test\Fixture\Group as StoreGroupFixture;
18+
use Magento\Store\Test\Fixture\Store as StoreFixture;
19+
use Magento\Store\Test\Fixture\Website as WebsiteFixture;
20+
use Magento\TestFramework\Fixture\Config;
21+
use Magento\TestFramework\Fixture\DataFixture;
22+
use Magento\TestFramework\Fixture\DataFixtureStorage;
23+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
1524
use Magento\TestFramework\Helper\Bootstrap;
1625
use Magento\TestFramework\Helper\Xpath;
1726
use Magento\TestFramework\Mail\Template\TransportBuilderMock;
@@ -40,8 +49,8 @@ class ForgotPasswordTest extends TestCase
4049
/** @var StoreManagerInterface */
4150
private $storeManager;
4251

43-
/** @var CustomerRepositoryInterface */
44-
private $customerRepository;
52+
/** @var DataFixtureStorage */
53+
private $fixtures;
4554

4655
/**
4756
* @inheritdoc
@@ -54,7 +63,7 @@ protected function setUp(): void
5463
$this->accountManagement = $this->objectManager->get(AccountManagementInterface::class);
5564
$this->transportBuilder = $this->objectManager->get(TransportBuilderMock::class);
5665
$this->storeManager = $this->objectManager->get(StoreManagerInterface::class);
57-
$this->customerRepository = $this->objectManager->get(CustomerRepositoryInterface::class);
66+
$this->fixtures = $this->objectManager->get(DataFixtureStorageManager::class)->getStorage();
5867
}
5968

6069
/**
@@ -73,29 +82,46 @@ public function testForgotPassword(): void
7382
}
7483

7584
/**
76-
* @magentoDataFixture Magento/Customer/_files/customer.php
77-
*
7885
* @return void
86+
* @throws LocalizedException
7987
*/
88+
#[
89+
Config(Data::XML_PATH_PRICE_SCOPE, Data::PRICE_SCOPE_WEBSITE),
90+
DataFixture(WebsiteFixture::class, as: 'website2'),
91+
DataFixture(StoreGroupFixture::class, ['website_id' => '$website2.id$'], 'store_group2'),
92+
DataFixture(StoreFixture::class, ['store_group_id' => '$store_group2.id$'], 'store2'),
93+
DataFixture(StoreFixture::class, ['store_group_id' => '$store_group2.id$'], 'store3'),
94+
DataFixture(
95+
Customer::class,
96+
[
97+
'store_id' => '$store2.id$',
98+
'website_id' => '1',
99+
'addresses' => [[]]
100+
],
101+
as: 'customer'
102+
)
103+
]
80104
public function testResetPasswordFlowStorefront(): void
81105
{
82-
// Forgot password section
83-
$email = 'customer@example.com';
84-
$customerId = (int)$this->customerRepository->get($email)->getId();
106+
// Forgot password section;
107+
$customer = $this->fixtures->get('customer');
108+
$email = $customer->getEmail();
109+
$customer->getId();
110+
$customerId = (int)$customer->getId();
85111
$result = $this->accountManagement->initiatePasswordReset($email, AccountManagement::EMAIL_RESET);
86112
$message = $this->transportBuilder->getSentMessage();
87113
$messageContent = $message->getBody()->getParts()[0]->getRawContent();
88114
$this->assertTrue($result);
89115
$this->assertEquals(1, Xpath::getElementsCountForXpath($this->newPasswordLinkPath, $messageContent));
90116

91117
// Send reset password link
92-
$websiteId = (int)$this->storeManager->getWebsite('base')->getId();
93-
$this->accountManagement->initiatePasswordReset($email, AccountManagement::EMAIL_RESET, $websiteId);
118+
$defaultWebsiteId = (int)$this->storeManager->getWebsite('base')->getId();
119+
$this->accountManagement->initiatePasswordReset($email, AccountManagement::EMAIL_RESET, $defaultWebsiteId);
94120

95121
// login with old credentials
96122
$this->assertEquals(
97123
$customerId,
98-
$this->accountManagement->authenticate($email, 'password')->getId()
124+
(int)$this->accountManagement->authenticate($email, 'password')->getId()
99125
);
100126

101127
// Change password

0 commit comments

Comments
 (0)