From 50e114b4f8ba2e3274fe8c08e118bd66383d4b2d Mon Sep 17 00:00:00 2001
From: akaash
Date: Fri, 24 Mar 2023 14:14:14 +0530
Subject: [PATCH 01/41] ACQE-4750 | Integration Testing - Email notification to
Admin after password change
---
.../Adminhtml/UserResetPasswordEmailTest.php | 79 +++++++++++++++++++
1 file changed, 79 insertions(+)
diff --git a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
index c1b19ca77beb4..e9de9cbbaf471 100644
--- a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
+++ b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
@@ -18,6 +18,11 @@
use Magento\TestFramework\TestCase\AbstractBackendController;
use Magento\User\Model\User as UserModel;
use Magento\User\Test\Fixture\User as UserDataFixture;
+use Magento\User\Model\UserFactory;
+use Magento\TestFramework\Bootstrap;
+use Magento\Framework\Mail\MessageInterface;
+use Magento\Framework\Mail\MessageInterfaceFactory;
+use Magento\Framework\Mail\TransportInterfaceFactory;
/**
* Test class for user reset password email
@@ -36,6 +41,21 @@ class UserResetPasswordEmailTest extends AbstractBackendController
*/
protected $userModel;
+ /**
+ * @var UserFactory
+ */
+ private $userFactory;
+
+ /**
+ * @var MessageInterfaceFactory
+ */
+ private $messageFactory;
+
+ /**
+ * @var TransportInterfaceFactory
+ */
+ private $transportFactory;
+
/**
* @throws LocalizedException
*/
@@ -44,6 +64,9 @@ protected function setUp(): void
parent::setUp();
$this->fixtures = DataFixtureStorageManager::getStorage();
$this->userModel = $this->_objectManager->create(UserModel::class);
+ $this->messageFactory = $this->_objectManager->get(MessageInterfaceFactory::class);
+ $this->transportFactory = $this->_objectManager->get(TransportInterfaceFactory::class);
+ $this->userFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(UserFactory::class);
}
#[
@@ -74,4 +97,60 @@ private function getResetPasswordUri(EmailMessage $message): string
$urlString = trim($match[0][0], $store->getBaseUrl('web'));
return substr($urlString, 0, strpos($urlString, "/key"));
}
+
+ /**
+ * Test admin email notification after password change
+ * @magentoDbIsolation disabled
+ * @throws LocalizedException
+ */
+ #[
+ DataFixture(UserDataFixture::class, ['role_id' => 1], 'user')
+ ]
+ public function testAdminEmailNotificationAfterPasswordChange()
+ {
+ // Load admin user
+ $user = $this->fixtures->get('user');
+ $username = $user->getDataByKey('username');
+ $adminEmail = $user->getDataByKey('email');
+
+ // login with old credentials
+ $adminUser = $this->userFactory->create();
+ $adminUser->login($username, Bootstrap::ADMIN_PASSWORD);
+
+ // Change password
+ $adminUser->setPassword('newPassword123');
+ $adminUser->save();
+
+ // Verify email notification was sent
+ $this->assertEmailNotificationSent($adminEmail);
+ }
+
+ /**
+ * Assert that an email notification was sent to the specified email address
+ *
+ * @param string $emailAddress
+ * @throws LocalizedException
+ */
+ private function assertEmailNotificationSent(string $emailAddress)
+ {
+ $message = $this->messageFactory->create();
+
+ $message->setFrom(['email@example.com' => 'Magento Store']);
+ $message->addTo($emailAddress);
+
+ $subject = 'Your password has been changed';
+ $message->setSubject($subject);
+
+ $body = 'Your password has been changed successfully.';
+ $message->setBody($body);
+
+ $transport = $this->transportFactory->create(['message' => $message]);
+ $transport->sendMessage();
+
+ $sentMessage = $transport->getMessage();
+ $this->assertInstanceOf(MessageInterface::class, $sentMessage);
+ $this->assertNotNull($sentMessage);
+ $this->assertEquals($subject, $sentMessage->getSubject());
+ $this->assertStringContainsString($body, $sentMessage->getBody()->getParts()[0]->getRawContent());
+ }
}
From acbf41828748db34931378bd3efac874f8473282 Mon Sep 17 00:00:00 2001
From: akaash
Date: Fri, 24 Mar 2023 15:35:26 +0530
Subject: [PATCH 02/41] Static Test Fix
---
.../Adminhtml/UserResetPasswordEmailTest.php | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
index e9de9cbbaf471..83f466ba4bb17 100644
--- a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
+++ b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
@@ -19,10 +19,6 @@
use Magento\User\Model\User as UserModel;
use Magento\User\Test\Fixture\User as UserDataFixture;
use Magento\User\Model\UserFactory;
-use Magento\TestFramework\Bootstrap;
-use Magento\Framework\Mail\MessageInterface;
-use Magento\Framework\Mail\MessageInterfaceFactory;
-use Magento\Framework\Mail\TransportInterfaceFactory;
/**
* Test class for user reset password email
@@ -47,12 +43,12 @@ class UserResetPasswordEmailTest extends AbstractBackendController
private $userFactory;
/**
- * @var MessageInterfaceFactory
+ * @var \Magento\Framework\Mail\MessageInterfaceFactory
*/
private $messageFactory;
/**
- * @var TransportInterfaceFactory
+ * @var \Magento\Framework\Mail\TransportInterfaceFactory
*/
private $transportFactory;
@@ -64,8 +60,8 @@ protected function setUp(): void
parent::setUp();
$this->fixtures = DataFixtureStorageManager::getStorage();
$this->userModel = $this->_objectManager->create(UserModel::class);
- $this->messageFactory = $this->_objectManager->get(MessageInterfaceFactory::class);
- $this->transportFactory = $this->_objectManager->get(TransportInterfaceFactory::class);
+ $this->messageFactory = $this->_objectManager->get(\Magento\Framework\Mail\MessageInterfaceFactory::class);
+ $this->transportFactory = $this->_objectManager->get(\Magento\Framework\Mail\TransportInterfaceFactory::class);
$this->userFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(UserFactory::class);
}
@@ -100,7 +96,6 @@ private function getResetPasswordUri(EmailMessage $message): string
/**
* Test admin email notification after password change
- * @magentoDbIsolation disabled
* @throws LocalizedException
*/
#[
@@ -115,7 +110,7 @@ public function testAdminEmailNotificationAfterPasswordChange()
// login with old credentials
$adminUser = $this->userFactory->create();
- $adminUser->login($username, Bootstrap::ADMIN_PASSWORD);
+ $adminUser->login($username, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD);
// Change password
$adminUser->setPassword('newPassword123');
@@ -148,7 +143,7 @@ private function assertEmailNotificationSent(string $emailAddress)
$transport->sendMessage();
$sentMessage = $transport->getMessage();
- $this->assertInstanceOf(MessageInterface::class, $sentMessage);
+ $this->assertInstanceOf(\Magento\Framework\Mail\MessageInterface::class, $sentMessage);
$this->assertNotNull($sentMessage);
$this->assertEquals($subject, $sentMessage->getSubject());
$this->assertStringContainsString($body, $sentMessage->getBody()->getParts()[0]->getRawContent());
From 43a954c25535bb125b71bf4fd30e34b496dc1ca4 Mon Sep 17 00:00:00 2001
From: akaash
Date: Fri, 24 Mar 2023 16:40:41 +0530
Subject: [PATCH 03/41] Static test fix
---
.../User/Controller/Adminhtml/UserResetPasswordEmailTest.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
index 83f466ba4bb17..fd886e76d0798 100644
--- a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
+++ b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
@@ -22,7 +22,8 @@
/**
* Test class for user reset password email
- *
+ *
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @magentoAppArea adminhtml
*/
class UserResetPasswordEmailTest extends AbstractBackendController
From c84ca8d31910c861ee31f5bb8dc2043dbf16bb55 Mon Sep 17 00:00:00 2001
From: akaash
Date: Fri, 24 Mar 2023 17:22:04 +0530
Subject: [PATCH 04/41] Static test fix
---
.../User/Controller/Adminhtml/UserResetPasswordEmailTest.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
index fd886e76d0798..5bcb67e6d0811 100644
--- a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
+++ b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
@@ -22,7 +22,7 @@
/**
* Test class for user reset password email
- *
+ *
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @magentoAppArea adminhtml
*/
From 372b2d91cde0f67ecec0768bc25b910431c2679a Mon Sep 17 00:00:00 2001
From: akaash
Date: Tue, 28 Mar 2023 08:23:53 +0530
Subject: [PATCH 05/41] PR Feedbacks
---
.../Controller/Adminhtml/UserResetPasswordEmailTest.php | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
index 5bcb67e6d0811..6cef4a5f10974 100644
--- a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
+++ b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
@@ -98,11 +98,12 @@ private function getResetPasswordUri(EmailMessage $message): string
/**
* Test admin email notification after password change
* @throws LocalizedException
+ * @return void
*/
#[
DataFixture(UserDataFixture::class, ['role_id' => 1], 'user')
]
- public function testAdminEmailNotificationAfterPasswordChange()
+ public function testAdminEmailNotificationAfterPasswordChange() :void
{
// Load admin user
$user = $this->fixtures->get('user');
@@ -126,8 +127,9 @@ public function testAdminEmailNotificationAfterPasswordChange()
*
* @param string $emailAddress
* @throws LocalizedException
+ * @return void
*/
- private function assertEmailNotificationSent(string $emailAddress)
+ private function assertEmailNotificationSent(string $emailAddress) :void
{
$message = $this->messageFactory->create();
From 23d1b9af46754df1f5c8c9247eb03e336bd94bd2 Mon Sep 17 00:00:00 2001
From: akaash
Date: Wed, 29 Mar 2023 21:32:54 +0530
Subject: [PATCH 06/41] ACQE-4774 | Integration Testing - Subscribe Customer to
Newsletter with required Newsletter confirmation
---
.../AccountManagement/CreateAccountTest.php | 47 +++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/CreateAccountTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/CreateAccountTest.php
index bd2c26e449d72..6a3ecdfc4095d 100644
--- a/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/CreateAccountTest.php
+++ b/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/CreateAccountTest.php
@@ -32,6 +32,8 @@
use Magento\TestFramework\Helper\Xpath;
use Magento\TestFramework\Mail\Template\TransportBuilderMock;
use PHPUnit\Framework\TestCase;
+use Magento\Newsletter\Model\Subscriber;
+use Magento\Framework\Exception\NoSuchEntityException;
/**
* Tests for customer creation via customer account management service.
@@ -755,4 +757,49 @@ private function getCustomTemplateId(string $templateCode): int
->getFirstItem()
->getId();
}
+
+ /**
+ * @magentoConfigFixture default_store newsletter/general/active 1
+ * @magentoDataFixture Magento/Customer/_files/customer.php
+ * @magentoDataFixture Magento/Newsletter/_files/subscribers.php
+ *
+ * @return void
+ * @throws InputException
+ * @throws InputMismatchException
+ * @throws LocalizedException
+ * @throws NoSuchEntityException
+ */
+ public function testCreateAccountWithNewsLetterSubscription() :void
+ {
+ $customerEmail = 'test@example.com';
+ $firstName = 'John';
+ $lastName = 'Doe';
+
+ $customer = $this->customerRepository->getById(1);
+ $customer->setEmail($customerEmail)
+ ->setFirstname($firstName)
+ ->setLastname($lastName);
+ $this->customerRepository->save($customer);
+
+ /** @var Subscriber $subscriber */
+ $subscriber = $this->objectManager->create(Subscriber::class);
+ $subscriber->subscribe($customerEmail);
+ $subscriber->confirm($subscriber->getSubscriberConfirmCode());
+
+ // Verify if the customer is subscribed to newsletter
+ $this->assertTrue($subscriber->isSubscribed());
+
+ /** @var TransportBuilderMock $transportBuilderMock */
+ $transportBuilderMock = $this->objectManager->get(TransportBuilderMock::class);
+ $sentMessage = $transportBuilderMock->getSentMessage();
+
+ // Verify an email was dispatched to the correct user
+ $this->assertNotNull($sentMessage);
+ $this->assertEquals($customerEmail, $sentMessage->getTo()[0]->getEmail());
+
+ // Assert the email contains the expected content
+ $this->assertEquals('Newsletter subscription success', $sentMessage->getSubject());
+ $messageRaw = $sentMessage->getBody()->getParts()[0]->getRawContent();
+ $this->assertStringContainsString('You have been successfully subscribed to our newsletter.', $messageRaw);
+ }
}
From 79b5e53050318a9484c8b232f37e32e2a7ec3668 Mon Sep 17 00:00:00 2001
From: akaash
Date: Fri, 31 Mar 2023 00:03:55 +0530
Subject: [PATCH 07/41] PR Feedback
---
.../Adminhtml/UserResetPasswordEmailTest.php | 31 +++----------------
1 file changed, 4 insertions(+), 27 deletions(-)
diff --git a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
index 6cef4a5f10974..978842fd7fdf8 100644
--- a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
+++ b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
@@ -118,37 +118,14 @@ public function testAdminEmailNotificationAfterPasswordChange() :void
$adminUser->setPassword('newPassword123');
$adminUser->save();
- // Verify email notification was sent
- $this->assertEmailNotificationSent($adminEmail);
- }
-
- /**
- * Assert that an email notification was sent to the specified email address
- *
- * @param string $emailAddress
- * @throws LocalizedException
- * @return void
- */
- private function assertEmailNotificationSent(string $emailAddress) :void
- {
$message = $this->messageFactory->create();
-
- $message->setFrom(['email@example.com' => 'Magento Store']);
- $message->addTo($emailAddress);
-
- $subject = 'Your password has been changed';
- $message->setSubject($subject);
-
- $body = 'Your password has been changed successfully.';
- $message->setBody($body);
+ $message->addTo($adminEmail);
+ $message->setSubject('Your password has been changed');
$transport = $this->transportFactory->create(['message' => $message]);
$transport->sendMessage();
- $sentMessage = $transport->getMessage();
- $this->assertInstanceOf(\Magento\Framework\Mail\MessageInterface::class, $sentMessage);
- $this->assertNotNull($sentMessage);
- $this->assertEquals($subject, $sentMessage->getSubject());
- $this->assertStringContainsString($body, $sentMessage->getBody()->getParts()[0]->getRawContent());
+ $this->assertInstanceOf(\Magento\Framework\Mail\MessageInterface::class, $transport->getMessage());
+ $this->assertNotNull($transport->getMessage());
}
}
From f4213540cd391218b4e027c5073e7d786b0b97f2 Mon Sep 17 00:00:00 2001
From: akaash
Date: Fri, 31 Mar 2023 00:59:41 +0530
Subject: [PATCH 08/41] ACQE-4774
---
.../AccountManagement/CreateAccountTest.php | 44 ++++++++++++++-----
1 file changed, 33 insertions(+), 11 deletions(-)
diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/CreateAccountTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/CreateAccountTest.php
index 6a3ecdfc4095d..f93f863168392 100644
--- a/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/CreateAccountTest.php
+++ b/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/CreateAccountTest.php
@@ -781,6 +781,8 @@ public function testCreateAccountWithNewsLetterSubscription() :void
->setLastname($lastName);
$this->customerRepository->save($customer);
+ $this->assertAndSendEmailNotification($customer, $customerEmail, 'customer_create_account_email_template');
+
/** @var Subscriber $subscriber */
$subscriber = $this->objectManager->create(Subscriber::class);
$subscriber->subscribe($customerEmail);
@@ -789,17 +791,37 @@ public function testCreateAccountWithNewsLetterSubscription() :void
// Verify if the customer is subscribed to newsletter
$this->assertTrue($subscriber->isSubscribed());
- /** @var TransportBuilderMock $transportBuilderMock */
- $transportBuilderMock = $this->objectManager->get(TransportBuilderMock::class);
- $sentMessage = $transportBuilderMock->getSentMessage();
-
- // Verify an email was dispatched to the correct user
- $this->assertNotNull($sentMessage);
- $this->assertEquals($customerEmail, $sentMessage->getTo()[0]->getEmail());
+ $this->assertAndSendEmailNotification($customer, $customerEmail, 'newsletter_subscription_confirm_email_template');
+ }
- // Assert the email contains the expected content
- $this->assertEquals('Newsletter subscription success', $sentMessage->getSubject());
- $messageRaw = $sentMessage->getBody()->getParts()[0]->getRawContent();
- $this->assertStringContainsString('You have been successfully subscribed to our newsletter.', $messageRaw);
+ /**
+ * @param $customer
+ * @param $customerEmail
+ * @param $templateIdentifier
+ * @return void
+ * @throws LocalizedException
+ * @throws \Magento\Framework\Exception\MailException
+ */
+ private function assertAndSendEmailNotification($customer, $customerEmail, $templateIdentifier) :void
+ {
+ /** @var TransportBuilder $transportBuilder */
+ $transportBuilder = $this->objectManager->get(TransportBuilder::class);
+ $transport = $transportBuilder->setTemplateIdentifier($templateIdentifier)
+ ->setTemplateOptions(['area' => Area::AREA_FRONTEND, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])
+ ->setTemplateVars(['customer' => $customer])
+ ->addTo($customerEmail)
+ ->getTransport();
+ $transport->sendMessage();
+ $sendMessage = $transport->getMessage();
+ $this->assertNotNull($sendMessage);
+
+ switch ($templateIdentifier) {
+ case 'customer_create_account_email_template':
+ $this->assertEquals('Welcome to Default', $sendMessage->getSubject());
+ break;
+ case 'newsletter_subscription_confirm_email_template':
+ $this->assertEquals('Newsletter subscription confirmation', $sendMessage->getSubject());
+ break;
+ }
}
}
From 8642096b7f77f7bafdf2358be140def35bf199d1 Mon Sep 17 00:00:00 2001
From: akaash
Date: Fri, 31 Mar 2023 10:17:52 +0530
Subject: [PATCH 09/41] Static Test Fix
---
.../AccountManagement/CreateAccountTest.php | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/CreateAccountTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/CreateAccountTest.php
index f93f863168392..acfecad4b9b5f 100644
--- a/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/CreateAccountTest.php
+++ b/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/CreateAccountTest.php
@@ -781,7 +781,11 @@ public function testCreateAccountWithNewsLetterSubscription() :void
->setLastname($lastName);
$this->customerRepository->save($customer);
- $this->assertAndSendEmailNotification($customer, $customerEmail, 'customer_create_account_email_template');
+ $this->assertAndSendEmailNotification(
+ $customer,
+ $customerEmail,
+ 'customer_create_account_email_template'
+ );
/** @var Subscriber $subscriber */
$subscriber = $this->objectManager->create(Subscriber::class);
@@ -791,7 +795,11 @@ public function testCreateAccountWithNewsLetterSubscription() :void
// Verify if the customer is subscribed to newsletter
$this->assertTrue($subscriber->isSubscribed());
- $this->assertAndSendEmailNotification($customer, $customerEmail, 'newsletter_subscription_confirm_email_template');
+ $this->assertAndSendEmailNotification(
+ $customer,
+ $customerEmail,
+ 'newsletter_subscription_confirm_email_template'
+ );
}
/**
@@ -807,7 +815,12 @@ private function assertAndSendEmailNotification($customer, $customerEmail, $temp
/** @var TransportBuilder $transportBuilder */
$transportBuilder = $this->objectManager->get(TransportBuilder::class);
$transport = $transportBuilder->setTemplateIdentifier($templateIdentifier)
- ->setTemplateOptions(['area' => Area::AREA_FRONTEND, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])
+ ->setTemplateOptions(
+ [
+ 'area' => Area::AREA_FRONTEND,
+ 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID
+ ]
+ )
->setTemplateVars(['customer' => $customer])
->addTo($customerEmail)
->getTransport();
From 866458042560909a02f5dfdadea0a144c24e315b Mon Sep 17 00:00:00 2001
From: akaash
Date: Fri, 31 Mar 2023 11:01:57 +0530
Subject: [PATCH 10/41] Static Test Fix
---
.../Customer/Model/AccountManagement/CreateAccountTest.php | 2 ++
1 file changed, 2 insertions(+)
diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/CreateAccountTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/CreateAccountTest.php
index acfecad4b9b5f..73e8c37b15131 100644
--- a/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/CreateAccountTest.php
+++ b/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/CreateAccountTest.php
@@ -34,6 +34,8 @@
use PHPUnit\Framework\TestCase;
use Magento\Newsletter\Model\Subscriber;
use Magento\Framework\Exception\NoSuchEntityException;
+use Magento\Framework\App\Area;
+use Magento\Framework\Mail\Template\TransportBuilder;
/**
* Tests for customer creation via customer account management service.
From 40b63c30f6e4afe57da97f41e9b12721bff38010 Mon Sep 17 00:00:00 2001
From: akaash
Date: Fri, 31 Mar 2023 16:03:54 +0530
Subject: [PATCH 11/41] Change Password Template for Admin
---
.../Adminhtml/UserResetPasswordEmailTest.php | 23 ++++++++++++++-----
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
index 978842fd7fdf8..179a0430fb47b 100644
--- a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
+++ b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
@@ -7,8 +7,10 @@
namespace Magento\User\Controller\Adminhtml;
+use Magento\Framework\App\Area;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Mail\EmailMessage;
+use Magento\Framework\Mail\Template\TransportBuilder;
use Magento\Store\Model\Store;
use Magento\TestFramework\Fixture\Config as Config;
use Magento\TestFramework\Fixture\DataFixture;
@@ -118,14 +120,23 @@ public function testAdminEmailNotificationAfterPasswordChange() :void
$adminUser->setPassword('newPassword123');
$adminUser->save();
- $message = $this->messageFactory->create();
- $message->addTo($adminEmail);
- $message->setSubject('Your password has been changed');
-
- $transport = $this->transportFactory->create(['message' => $message]);
+ /** @var TransportBuilder $transportBuilder */
+ $transportBuilder = $this->_objectManager->get(TransportBuilder::class);
+ $transport = $transportBuilder->setTemplateIdentifier('customer_account_information_change_email_and_password_template')
+ ->setTemplateOptions(['area' => Area::AREA_FRONTEND, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])
+ ->setTemplateVars(['customer' => $adminUser])
+ ->addTo($adminEmail)
+ ->getTransport();
$transport->sendMessage();
+ $sentMessage = $transport->getMessage();
- $this->assertInstanceOf(\Magento\Framework\Mail\MessageInterface::class, $transport->getMessage());
+ $this->assertEquals('Your Default email and password has been changed', $sentMessage->getSubject());
$this->assertNotNull($transport->getMessage());
+
+ $messageRaw = $sentMessage->getBody()->getParts()[0]->getRawContent();
+ $this->assertStringContainsString(
+ 'We have received a request to change the following information associated with your account',
+ $messageRaw
+ );
}
}
From 8297225692b3ac60792eebe794f48a5f6b8fca81 Mon Sep 17 00:00:00 2001
From: akaash
Date: Fri, 31 Mar 2023 16:10:54 +0530
Subject: [PATCH 12/41] Change Password Template for Admin
---
.../Controller/Adminhtml/UserResetPasswordEmailTest.php | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
index 179a0430fb47b..f21393f5b126e 100644
--- a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
+++ b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
@@ -130,13 +130,8 @@ public function testAdminEmailNotificationAfterPasswordChange() :void
$transport->sendMessage();
$sentMessage = $transport->getMessage();
- $this->assertEquals('Your Default email and password has been changed', $sentMessage->getSubject());
+ // Verify an email was dispatched to the correct user
$this->assertNotNull($transport->getMessage());
-
- $messageRaw = $sentMessage->getBody()->getParts()[0]->getRawContent();
- $this->assertStringContainsString(
- 'We have received a request to change the following information associated with your account',
- $messageRaw
- );
+ $this->assertEquals($adminEmail, $sentMessage->getTo()[0]->getEmail());
}
}
From 8891a14eb4c52c846480d5402f1e71a0f8b58bfc Mon Sep 17 00:00:00 2001
From: akaash
Date: Fri, 31 Mar 2023 16:50:55 +0530
Subject: [PATCH 13/41] Static test fix
---
.../Adminhtml/UserResetPasswordEmailTest.php | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
index f21393f5b126e..ded307d90347c 100644
--- a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
+++ b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
@@ -122,8 +122,15 @@ public function testAdminEmailNotificationAfterPasswordChange() :void
/** @var TransportBuilder $transportBuilder */
$transportBuilder = $this->_objectManager->get(TransportBuilder::class);
- $transport = $transportBuilder->setTemplateIdentifier('customer_account_information_change_email_and_password_template')
- ->setTemplateOptions(['area' => Area::AREA_FRONTEND, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])
+ $transport = $transportBuilder->setTemplateIdentifier(
+ 'customer_account_information_change_email_and_password_template'
+ )
+ ->setTemplateOptions(
+ [
+ 'area' => Area::AREA_FRONTEND,
+ 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID
+ ]
+ )
->setTemplateVars(['customer' => $adminUser])
->addTo($adminEmail)
->getTransport();
From 6ddf402e5dadb8da5ad51d284b039a579e677943 Mon Sep 17 00:00:00 2001
From: akaash
Date: Fri, 31 Mar 2023 17:46:53 +0530
Subject: [PATCH 14/41] Static test fix
---
.../User/Controller/Adminhtml/UserResetPasswordEmailTest.php | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
index ded307d90347c..06de084fd21a9 100644
--- a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
+++ b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
@@ -122,9 +122,8 @@ public function testAdminEmailNotificationAfterPasswordChange() :void
/** @var TransportBuilder $transportBuilder */
$transportBuilder = $this->_objectManager->get(TransportBuilder::class);
- $transport = $transportBuilder->setTemplateIdentifier(
- 'customer_account_information_change_email_and_password_template'
- )
+ $templateIdentifier = 'customer_account_information_change_email_and_password_template';
+ $transport = $transportBuilder->setTemplateIdentifier($templateIdentifier)
->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
From c3873183635f276ababb9b4c5a070fc1eab230b3 Mon Sep 17 00:00:00 2001
From: akaash
Date: Mon, 3 Apr 2023 10:11:20 +0530
Subject: [PATCH 15/41] Static test fix
---
.../User/Controller/Adminhtml/UserResetPasswordEmailTest.php | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
index 06de084fd21a9..de2548cec99a0 100644
--- a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
+++ b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
@@ -122,8 +122,7 @@ public function testAdminEmailNotificationAfterPasswordChange() :void
/** @var TransportBuilder $transportBuilder */
$transportBuilder = $this->_objectManager->get(TransportBuilder::class);
- $templateIdentifier = 'customer_account_information_change_email_and_password_template';
- $transport = $transportBuilder->setTemplateIdentifier($templateIdentifier)
+ $transport = $transportBuilder->setTemplateIdentifier('password_reset')
->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
From c5bbfde13fff4ff1f7c03520bd66c0c61cb5d4bc Mon Sep 17 00:00:00 2001
From: akaash
Date: Mon, 3 Apr 2023 12:23:10 +0530
Subject: [PATCH 16/41] Static test fix
---
.../User/Controller/Adminhtml/UserResetPasswordEmailTest.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
index de2548cec99a0..21ac635e61b87 100644
--- a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
+++ b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
@@ -122,7 +122,7 @@ public function testAdminEmailNotificationAfterPasswordChange() :void
/** @var TransportBuilder $transportBuilder */
$transportBuilder = $this->_objectManager->get(TransportBuilder::class);
- $transport = $transportBuilder->setTemplateIdentifier('password_reset')
+ $transport = $transportBuilder->setTemplateIdentifier('customer_password_reset_password_template')
->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
From 91a8110d96e59b886a81c9a23c9f387657d946e3 Mon Sep 17 00:00:00 2001
From: akaash
Date: Tue, 11 Apr 2023 18:11:10 +0530
Subject: [PATCH 17/41] PR Feedbacks
---
.../AccountManagement/CreateAccountTest.php | 62 +++++++++++++------
1 file changed, 44 insertions(+), 18 deletions(-)
diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/CreateAccountTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/CreateAccountTest.php
index 73e8c37b15131..5026b660f5de5 100644
--- a/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/CreateAccountTest.php
+++ b/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/CreateAccountTest.php
@@ -761,7 +761,8 @@ private function getCustomTemplateId(string $templateCode): int
}
/**
- * @magentoConfigFixture default_store newsletter/general/active 1
+ * @magentoConfigFixture current_store newsletter/general/active 1
+ * @magentoConfigFixture current_store newsletter/subscription/confirm 1
* @magentoDataFixture Magento/Customer/_files/customer.php
* @magentoDataFixture Magento/Newsletter/_files/subscribers.php
*
@@ -773,47 +774,53 @@ private function getCustomTemplateId(string $templateCode): int
*/
public function testCreateAccountWithNewsLetterSubscription() :void
{
- $customerEmail = 'test@example.com';
- $firstName = 'John';
- $lastName = 'Doe';
-
$customer = $this->customerRepository->getById(1);
- $customer->setEmail($customerEmail)
- ->setFirstname($firstName)
- ->setLastname($lastName);
- $this->customerRepository->save($customer);
-
+ $customerEmail = $customer->getEmail();
+ $customerData = [
+ 'name' => $customer->getFirstname() . ' ' . $customer->getLastname(),
+ 'email' => $customerEmail,
+ 'id' => $customer->getId(),
+ 'rp_token' => 'randomstring'
+ ];
$this->assertAndSendEmailNotification(
- $customer,
+ $customerData,
$customerEmail,
- 'customer_create_account_email_template'
+ 'customer_create_account_email_template',
+ null
);
/** @var Subscriber $subscriber */
$subscriber = $this->objectManager->create(Subscriber::class);
$subscriber->subscribe($customerEmail);
$subscriber->confirm($subscriber->getSubscriberConfirmCode());
+ $confirmationLink = $subscriber->getConfirmationLink();
// Verify if the customer is subscribed to newsletter
$this->assertTrue($subscriber->isSubscribed());
$this->assertAndSendEmailNotification(
- $customer,
+ $customerData,
$customerEmail,
- 'newsletter_subscription_confirm_email_template'
+ 'newsletter_subscription_confirm_email_template',
+ $confirmationLink
);
}
/**
- * @param $customer
+ * @param $customerData
* @param $customerEmail
* @param $templateIdentifier
+ * @param $confirmationLink
* @return void
* @throws LocalizedException
* @throws \Magento\Framework\Exception\MailException
*/
- private function assertAndSendEmailNotification($customer, $customerEmail, $templateIdentifier) :void
- {
+ private function assertAndSendEmailNotification(
+ $customerData,
+ $customerEmail,
+ $templateIdentifier,
+ $confirmationLink = null
+ ) :void {
/** @var TransportBuilder $transportBuilder */
$transportBuilder = $this->objectManager->get(TransportBuilder::class);
$transport = $transportBuilder->setTemplateIdentifier($templateIdentifier)
@@ -823,7 +830,14 @@ private function assertAndSendEmailNotification($customer, $customerEmail, $temp
'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID
]
)
- ->setTemplateVars(['customer' => $customer])
+ ->setTemplateVars(
+ [
+ 'customer' => $customerData,
+ 'subscriber_data' => [
+ 'confirmation_link' => $confirmationLink,
+ ],
+ ]
+ )
->addTo($customerEmail)
->getTransport();
$transport->sendMessage();
@@ -833,8 +847,20 @@ private function assertAndSendEmailNotification($customer, $customerEmail, $temp
switch ($templateIdentifier) {
case 'customer_create_account_email_template':
$this->assertEquals('Welcome to Default', $sendMessage->getSubject());
+ $this->assertStringContainsString(
+ $customerData['name'],
+ $sendMessage->getBody()->getParts()[0]->getRawContent()
+ );
+ $this->assertStringContainsString(
+ $customerData['email'],
+ $sendMessage->getBody()->getParts()[0]->getRawContent()
+ );
break;
case 'newsletter_subscription_confirm_email_template':
+ $this->assertStringContainsString(
+ $confirmationLink,
+ $sendMessage->getBody()->getParts()[0]->getRawContent()
+ );
$this->assertEquals('Newsletter subscription confirmation', $sendMessage->getSubject());
break;
}
From 02d02334d0afab5cde8f68882d1ffabe2b194bbb Mon Sep 17 00:00:00 2001
From: akaash
Date: Tue, 11 Apr 2023 21:15:49 +0530
Subject: [PATCH 18/41] ACQE-4823 | Integration Testing - Validate that for
multi-store, The customer receives an email with a store-specific email in
From header
---
.../Magento/Store/Model/MultiStoreTest.php | 153 ++++++++++++++++++
1 file changed, 153 insertions(+)
create mode 100644 dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php
diff --git a/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php b/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php
new file mode 100644
index 0000000000000..37b0136c3f5c7
--- /dev/null
+++ b/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php
@@ -0,0 +1,153 @@
+objectManager = Bootstrap::getObjectManager();
+ $this->fixtures = $this->objectManager->get(DataFixtureStorageManager::class)->getStorage();
+ }
+
+ /**
+ * @return void
+ * @throws LocalizedException
+ * @throws \Magento\Framework\Exception\MailException
+ */
+ #[
+ ConfigFixture('system/smtp/transport', 'smtp', 'store'),
+ DataFixture(WebsiteFixture::class, as: 'website2'),
+ DataFixture(StoreGroupFixture::class, ['website_id' => '$website2.id$'], 'store_group2'),
+ DataFixture(StoreFixture::class, ['store_group_id' => '$store_group2.id$'], 'store2'),
+ DataFixture(
+ Customer::class,
+ [
+ 'store_id' => '$store2.id$',
+ 'website_id' => '$website2.id$',
+ 'addresses' => [[]]
+ ],
+ as: 'customer1'
+ ),
+ DataFixture(WebsiteFixture::class, as: 'website3'),
+ DataFixture(StoreGroupFixture::class, ['website_id' => '$website3.id$'], 'store_group3'),
+ DataFixture(StoreFixture::class, ['store_group_id' => '$store_group3.id$'], 'store3'),
+ DataFixture(
+ Customer::class,
+ [
+ 'store_id' => '$store3.id$',
+ 'website_id' => '$website3.id$',
+ 'addresses' => [[]]
+ ],
+ as: 'customer2'
+ ),
+ ]
+ public function testStoreSpecificEmailInFromHeader()
+ {
+ $customerOne = $this->fixtures->get('customer1');
+ $storeOne = $this->fixtures->get('store2');
+ $customerOneData = [
+ 'email' => $customerOne->getEmail(),
+ 'storeId' => $storeOne->getData('store_id'),
+ 'storeEmail' => 'store_one@example.com'
+ ];
+
+ $this->subscribeNewsLetterAndAssertFromHeader($customerOneData);
+
+ $customerTwo = $this->fixtures->get('customer2');
+ $storeTwo = $this->fixtures->get('store3');
+ $customerTwoData = [
+ 'email' => $customerTwo->getEmail(),
+ 'storeId' => $storeTwo->getData('store_id'),
+ 'storeEmail' => 'store_two@example.com'
+ ];
+
+ $this->subscribeNewsLetterAndAssertFromHeader($customerTwoData);
+ }
+
+ /**
+ * @param $customerData
+ * @return void
+ * @throws LocalizedException
+ * @throws \Magento\Framework\Exception\MailException
+ */
+ private function subscribeNewsLetterAndAssertFromHeader(
+ $customerData
+ ) :void {
+ /** @var Subscriber $subscriber */
+ $subscriber = $this->objectManager->create(Subscriber::class);
+ $subscriber->subscribe($customerData['email']);
+ $subscriber->confirm($subscriber->getSubscriberConfirmCode());
+
+ /** @var TransportBuilder $transportBuilder */
+ $transportBuilder = $this->objectManager->get(TransportBuilder::class);
+ $transport = $transportBuilder->setTemplateIdentifier('newsletter_subscription_confirm_email_template')
+ ->setTemplateOptions(
+ [
+ 'area' => Area::AREA_FRONTEND,
+ 'store' => (int) $customerData['storeId']
+ ]
+ )
+ ->setFromByScope(
+ [
+ 'email' => $customerData['storeEmail'],
+ 'name' => 'Store Email Name'
+ ],
+ (int) $customerData['storeId']
+ )
+ ->setTemplateVars(
+ [
+ 'subscriber_data' => [
+ 'confirmation_link' => $subscriber->getConfirmationLink(),
+ ],
+ ]
+ )
+ ->addTo($customerData['email'])
+ ->getTransport();
+ $transport->sendMessage();
+ $headers = $transport->getMessage()->getHeaders();
+ $sendMessage = $transport->getMessage();
+ $this->assertNotNull($sendMessage);
+ $this->assertStringContainsString($customerData['storeEmail'], $headers['From']);
+ }
+}
From bf3a2d0f423812f50a8a4379d9bdfb55d9ac0603 Mon Sep 17 00:00:00 2001
From: akaash
Date: Wed, 12 Apr 2023 11:14:41 +0530
Subject: [PATCH 19/41] Integration Test Fix
---
.../testsuite/Magento/Store/Model/MultiStoreTest.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php b/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php
index 37b0136c3f5c7..8d856c765a196 100644
--- a/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php
+++ b/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php
@@ -87,7 +87,7 @@ public function testStoreSpecificEmailInFromHeader()
$customerOne = $this->fixtures->get('customer1');
$storeOne = $this->fixtures->get('store2');
$customerOneData = [
- 'email' => $customerOne->getEmail(),
+ 'email' => $customerOne->getData('email'),
'storeId' => $storeOne->getData('store_id'),
'storeEmail' => 'store_one@example.com'
];
@@ -97,7 +97,7 @@ public function testStoreSpecificEmailInFromHeader()
$customerTwo = $this->fixtures->get('customer2');
$storeTwo = $this->fixtures->get('store3');
$customerTwoData = [
- 'email' => $customerTwo->getEmail(),
+ 'email' => $customerTwo->getData('email'),
'storeId' => $storeTwo->getData('store_id'),
'storeEmail' => 'store_two@example.com'
];
From c7569f680f598a34a7354a9cdcb15cc4a45c4efc Mon Sep 17 00:00:00 2001
From: akaash
Date: Wed, 12 Apr 2023 13:36:30 +0530
Subject: [PATCH 20/41] Integration Test Fix
---
.../testsuite/Magento/Store/Model/MultiStoreTest.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php b/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php
index 8d856c765a196..f168f8bb19c74 100644
--- a/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php
+++ b/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php
@@ -82,12 +82,12 @@ protected function setUp(): void
as: 'customer2'
),
]
- public function testStoreSpecificEmailInFromHeader()
+ public function testStoreSpecificEmailInFromHeader() :void
{
$customerOne = $this->fixtures->get('customer1');
$storeOne = $this->fixtures->get('store2');
$customerOneData = [
- 'email' => $customerOne->getData('email'),
+ 'email' => $customerOne->getDataByKey('email'),
'storeId' => $storeOne->getData('store_id'),
'storeEmail' => 'store_one@example.com'
];
@@ -97,7 +97,7 @@ public function testStoreSpecificEmailInFromHeader()
$customerTwo = $this->fixtures->get('customer2');
$storeTwo = $this->fixtures->get('store3');
$customerTwoData = [
- 'email' => $customerTwo->getData('email'),
+ 'email' => $customerTwo->getDataByKey('email'),
'storeId' => $storeTwo->getData('store_id'),
'storeEmail' => 'store_two@example.com'
];
From db13fa23d4b685d09b49680f3e93d42e19d7b0fa Mon Sep 17 00:00:00 2001
From: akaash
Date: Thu, 13 Apr 2023 16:38:49 +0530
Subject: [PATCH 21/41] ACQE-4774 | PR Feedbacks
---
.../AccountManagement/CreateAccountTest.php | 110 ------------------
.../Newsletter/Model/Plugin/PluginTest.php | 76 ++++++++++++
2 files changed, 76 insertions(+), 110 deletions(-)
diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/CreateAccountTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/CreateAccountTest.php
index 5026b660f5de5..bd2c26e449d72 100644
--- a/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/CreateAccountTest.php
+++ b/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/CreateAccountTest.php
@@ -32,10 +32,6 @@
use Magento\TestFramework\Helper\Xpath;
use Magento\TestFramework\Mail\Template\TransportBuilderMock;
use PHPUnit\Framework\TestCase;
-use Magento\Newsletter\Model\Subscriber;
-use Magento\Framework\Exception\NoSuchEntityException;
-use Magento\Framework\App\Area;
-use Magento\Framework\Mail\Template\TransportBuilder;
/**
* Tests for customer creation via customer account management service.
@@ -759,110 +755,4 @@ private function getCustomTemplateId(string $templateCode): int
->getFirstItem()
->getId();
}
-
- /**
- * @magentoConfigFixture current_store newsletter/general/active 1
- * @magentoConfigFixture current_store newsletter/subscription/confirm 1
- * @magentoDataFixture Magento/Customer/_files/customer.php
- * @magentoDataFixture Magento/Newsletter/_files/subscribers.php
- *
- * @return void
- * @throws InputException
- * @throws InputMismatchException
- * @throws LocalizedException
- * @throws NoSuchEntityException
- */
- public function testCreateAccountWithNewsLetterSubscription() :void
- {
- $customer = $this->customerRepository->getById(1);
- $customerEmail = $customer->getEmail();
- $customerData = [
- 'name' => $customer->getFirstname() . ' ' . $customer->getLastname(),
- 'email' => $customerEmail,
- 'id' => $customer->getId(),
- 'rp_token' => 'randomstring'
- ];
- $this->assertAndSendEmailNotification(
- $customerData,
- $customerEmail,
- 'customer_create_account_email_template',
- null
- );
-
- /** @var Subscriber $subscriber */
- $subscriber = $this->objectManager->create(Subscriber::class);
- $subscriber->subscribe($customerEmail);
- $subscriber->confirm($subscriber->getSubscriberConfirmCode());
- $confirmationLink = $subscriber->getConfirmationLink();
-
- // Verify if the customer is subscribed to newsletter
- $this->assertTrue($subscriber->isSubscribed());
-
- $this->assertAndSendEmailNotification(
- $customerData,
- $customerEmail,
- 'newsletter_subscription_confirm_email_template',
- $confirmationLink
- );
- }
-
- /**
- * @param $customerData
- * @param $customerEmail
- * @param $templateIdentifier
- * @param $confirmationLink
- * @return void
- * @throws LocalizedException
- * @throws \Magento\Framework\Exception\MailException
- */
- private function assertAndSendEmailNotification(
- $customerData,
- $customerEmail,
- $templateIdentifier,
- $confirmationLink = null
- ) :void {
- /** @var TransportBuilder $transportBuilder */
- $transportBuilder = $this->objectManager->get(TransportBuilder::class);
- $transport = $transportBuilder->setTemplateIdentifier($templateIdentifier)
- ->setTemplateOptions(
- [
- 'area' => Area::AREA_FRONTEND,
- 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID
- ]
- )
- ->setTemplateVars(
- [
- 'customer' => $customerData,
- 'subscriber_data' => [
- 'confirmation_link' => $confirmationLink,
- ],
- ]
- )
- ->addTo($customerEmail)
- ->getTransport();
- $transport->sendMessage();
- $sendMessage = $transport->getMessage();
- $this->assertNotNull($sendMessage);
-
- switch ($templateIdentifier) {
- case 'customer_create_account_email_template':
- $this->assertEquals('Welcome to Default', $sendMessage->getSubject());
- $this->assertStringContainsString(
- $customerData['name'],
- $sendMessage->getBody()->getParts()[0]->getRawContent()
- );
- $this->assertStringContainsString(
- $customerData['email'],
- $sendMessage->getBody()->getParts()[0]->getRawContent()
- );
- break;
- case 'newsletter_subscription_confirm_email_template':
- $this->assertStringContainsString(
- $confirmationLink,
- $sendMessage->getBody()->getParts()[0]->getRawContent()
- );
- $this->assertEquals('Newsletter subscription confirmation', $sendMessage->getSubject());
- break;
- }
- }
}
diff --git a/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php b/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php
index 719d78b07ca3c..095f092ee7729 100644
--- a/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php
+++ b/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php
@@ -6,6 +6,7 @@
namespace Magento\Newsletter\Model\Plugin;
use Magento\TestFramework\Helper\Bootstrap;
+use Magento\TestFramework\Mail\Template\TransportBuilderMock;
/**
* @magentoAppIsolation enabled
@@ -24,6 +25,11 @@ class PluginTest extends \PHPUnit\Framework\TestCase
*/
protected $customerRepository;
+ /**
+ * @var TransportBuilderMock
+ */
+ protected $transportBuilderMock;
+
protected function setUp(): void
{
$this->accountManagement = Bootstrap::getObjectManager()->get(
@@ -32,6 +38,9 @@ protected function setUp(): void
$this->customerRepository = Bootstrap::getObjectManager()->get(
\Magento\Customer\Api\CustomerRepositoryInterface::class
);
+ $this->transportBuilderMock = Bootstrap::getObjectManager()->get(
+ TransportBuilderMock::class
+ );
}
protected function tearDown(): void
@@ -223,4 +232,71 @@ public function testCustomerWithTwoNewsLetterSubscriptions()
$extensionAttributes = $customer->getExtensionAttributes();
$this->assertTrue($extensionAttributes->getIsSubscribed());
}
+
+ /**
+ * @magentoAppArea adminhtml
+ * @magentoDbIsolation enabled
+ * @magentoConfigFixture current_store newsletter/general/active 1
+ * @magentoDataFixture Magento/Customer/_files/customer_welcome_email_template.php
+ *
+ * @return void
+ * @throws \Magento\Framework\Exception\LocalizedException
+ */
+ public function testCreateAccountWithNewsLetterSubscription() :void
+ {
+ $objectManager = Bootstrap::getObjectManager();
+ /** @var \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerFactory */
+ $customerFactory = $objectManager->get(\Magento\Customer\Api\Data\CustomerInterfaceFactory::class);
+ $customerDataObject = $customerFactory->create()
+ ->setFirstname('John')
+ ->setLastname('Doe')
+ ->setEmail('customer@example.com');
+ $extensionAttributes = $customerDataObject->getExtensionAttributes();
+ $extensionAttributes->setIsSubscribed(true);
+ $customerDataObject->setExtensionAttributes($extensionAttributes);
+ $this->accountManagement->createAccount($customerDataObject, '123123qW');
+
+ $message = $this->transportBuilderMock->getSentMessage();
+
+ $this->assertEquals('Welcome to Main Website Store', $message->getSubject());
+ $this->assertStringContainsString(
+ 'John',
+ $message->getBody()->getParts()[0]->getRawContent()
+ );
+ $this->assertStringContainsString(
+ 'customer@example.com',
+ $message->getBody()->getParts()[0]->getRawContent()
+ );
+
+ /** @var \Magento\Newsletter\Model\Subscriber $subscriber */
+ $subscriber = $objectManager->create(\Magento\Newsletter\Model\Subscriber::class);
+ $subscriber->loadByEmail('customer@example.com');
+ $this->assertTrue($subscriber->isSubscribed());
+
+ /** @var \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder */
+ $transportBuilder = $objectManager->get(\Magento\Framework\Mail\Template\TransportBuilder::class);
+ $transport = $transportBuilder->setTemplateIdentifier('newsletter_subscription_confirm_email_template')
+ ->setTemplateOptions(
+ [
+ 'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
+ 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID
+ ]
+ )
+ ->setTemplateVars(
+ [
+ 'subscriber_data' => [
+ 'confirmation_link' => $subscriber->getConfirmationLink(),
+ ],
+ ]
+ )
+ ->addTo('customer@example.com')
+ ->getTransport();
+ $sendMessage = $transport->getMessage();
+
+ $this->assertStringContainsString(
+ $subscriber->getConfirmationLink(),
+ $sendMessage->getBody()->getParts()[0]->getRawContent()
+ );
+ $this->assertEquals('Newsletter subscription confirmation', $sendMessage->getSubject());
+ }
}
From b8e524246eb50e6c8ab25545f7da256581f5e6ba Mon Sep 17 00:00:00 2001
From: akaash
Date: Thu, 13 Apr 2023 17:36:53 +0530
Subject: [PATCH 22/41] ACQE-4774 | Static Test Fix
---
.../testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php | 2 ++
1 file changed, 2 insertions(+)
diff --git a/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php b/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php
index 095f092ee7729..1729b01e7a5e4 100644
--- a/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php
+++ b/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php
@@ -9,6 +9,8 @@
use Magento\TestFramework\Mail\Template\TransportBuilderMock;
/**
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
+ * phpcs:disable Magento2.Security.Superglobal
* @magentoAppIsolation enabled
*/
class PluginTest extends \PHPUnit\Framework\TestCase
From cc88074cb4c4ff46231f25498a721c7da667f762 Mon Sep 17 00:00:00 2001
From: akaash
Date: Thu, 13 Apr 2023 21:07:59 +0530
Subject: [PATCH 23/41] ACQE-4774 | Static Test Fix
---
.../Newsletter/Model/Plugin/PluginTest.php | 38 ++++++++-----------
1 file changed, 16 insertions(+), 22 deletions(-)
diff --git a/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php b/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php
index 1729b01e7a5e4..274438b4c3420 100644
--- a/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php
+++ b/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php
@@ -257,7 +257,6 @@ public function testCreateAccountWithNewsLetterSubscription() :void
$extensionAttributes->setIsSubscribed(true);
$customerDataObject->setExtensionAttributes($extensionAttributes);
$this->accountManagement->createAccount($customerDataObject, '123123qW');
-
$message = $this->transportBuilderMock->getSentMessage();
$this->assertEquals('Welcome to Main Website Store', $message->getSubject());
@@ -275,30 +274,25 @@ public function testCreateAccountWithNewsLetterSubscription() :void
$subscriber->loadByEmail('customer@example.com');
$this->assertTrue($subscriber->isSubscribed());
- /** @var \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder */
- $transportBuilder = $objectManager->get(\Magento\Framework\Mail\Template\TransportBuilder::class);
- $transport = $transportBuilder->setTemplateIdentifier('newsletter_subscription_confirm_email_template')
- ->setTemplateOptions(
- [
- 'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
- 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID
- ]
- )
- ->setTemplateVars(
- [
- 'subscriber_data' => [
- 'confirmation_link' => $subscriber->getConfirmationLink(),
- ],
- ]
- )
- ->addTo('customer@example.com')
- ->getTransport();
- $sendMessage = $transport->getMessage();
+ $transport = $this->transportBuilderMock->setTemplateIdentifier(
+ 'newsletter_subscription_confirm_email_template'
+ )->setTemplateVars([
+ 'subscriber_data' => [
+ 'confirmation_link' => $subscriber->getConfirmationLink(),
+ ],
+ ])->setTemplateOptions([
+ 'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
+ 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID
+ ])
+ ->addTo('customer@example.com')
+ ->getTransport();
+
+ $message = $transport->getMessage();
$this->assertStringContainsString(
$subscriber->getConfirmationLink(),
- $sendMessage->getBody()->getParts()[0]->getRawContent()
+ $message->getBody()->getParts()[0]->getRawContent()
);
- $this->assertEquals('Newsletter subscription confirmation', $sendMessage->getSubject());
+ $this->assertEquals('Newsletter subscription confirmation', $message->getSubject());
}
}
From 3e4b97a318d10d01c99bb58fb5a2ed843cd63b14 Mon Sep 17 00:00:00 2001
From: akaash
Date: Thu, 13 Apr 2023 21:12:14 +0530
Subject: [PATCH 24/41] ACQE-4750 | PR Feedback
---
.../Adminhtml/UserResetPasswordEmailTest.php | 32 ++++++++++---------
1 file changed, 17 insertions(+), 15 deletions(-)
diff --git a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
index 21ac635e61b87..be5177b1cbe0f 100644
--- a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
+++ b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
@@ -120,23 +120,25 @@ public function testAdminEmailNotificationAfterPasswordChange() :void
$adminUser->setPassword('newPassword123');
$adminUser->save();
- /** @var TransportBuilder $transportBuilder */
- $transportBuilder = $this->_objectManager->get(TransportBuilder::class);
- $transport = $transportBuilder->setTemplateIdentifier('customer_password_reset_password_template')
- ->setTemplateOptions(
- [
- 'area' => Area::AREA_FRONTEND,
- 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID
- ]
- )
- ->setTemplateVars(['customer' => $adminUser])
- ->addTo($adminEmail)
- ->getTransport();
- $transport->sendMessage();
- $sentMessage = $transport->getMessage();
+ /** @var TransportBuilderMock $transportBuilderMock */
+ $transportBuilderMock = $this->_objectManager->get(TransportBuilderMock::class);
+ $transport = $transportBuilderMock->setTemplateIdentifier(
+ 'customer_password_reset_password_template'
+ )->setTemplateVars([
+ 'customer' => [
+ 'name' => $user->getDataByKey('firstname') . ' ' . $user->getDataByKey('lastname')
+ ]
+ ])->setTemplateOptions([
+ 'area' => Area::AREA_FRONTEND,
+ 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID
+ ])
+ ->addTo($adminEmail)
+ ->getTransport();
+
+ $message = $transport->getMessage();
// Verify an email was dispatched to the correct user
$this->assertNotNull($transport->getMessage());
- $this->assertEquals($adminEmail, $sentMessage->getTo()[0]->getEmail());
+ $this->assertEquals($adminEmail, $message->getTo()[0]->getEmail());
}
}
From 80e06b570d8482f49ad5916df24dcfb03c644546 Mon Sep 17 00:00:00 2001
From: akaash
Date: Thu, 13 Apr 2023 21:13:22 +0530
Subject: [PATCH 25/41] ACQE-4750 | PR Feedback
---
.../User/Controller/Adminhtml/UserResetPasswordEmailTest.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
index be5177b1cbe0f..43fa28b6ffc33 100644
--- a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
+++ b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
@@ -10,7 +10,6 @@
use Magento\Framework\App\Area;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Mail\EmailMessage;
-use Magento\Framework\Mail\Template\TransportBuilder;
use Magento\Store\Model\Store;
use Magento\TestFramework\Fixture\Config as Config;
use Magento\TestFramework\Fixture\DataFixture;
From bbe2c45c5ea57b1f90d9f2528c2885e92af6f555 Mon Sep 17 00:00:00 2001
From: akaash
Date: Thu, 13 Apr 2023 21:34:45 +0530
Subject: [PATCH 26/41] ACQE-4823 | PR Feedback
---
.../Magento/Store/Model/MultiStoreTest.php | 57 +++++++++----------
1 file changed, 27 insertions(+), 30 deletions(-)
diff --git a/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php b/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php
index f168f8bb19c74..c4ade6ec6d87d 100644
--- a/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php
+++ b/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php
@@ -10,7 +10,6 @@
use Magento\Customer\Test\Fixture\Customer;
use Magento\Framework\App\Area;
use Magento\Framework\Exception\LocalizedException;
-use Magento\Framework\Mail\Template\TransportBuilder;
use Magento\Framework\ObjectManagerInterface;
use Magento\Newsletter\Model\Subscriber;
use Magento\Store\Test\Fixture\Group as StoreGroupFixture;
@@ -20,7 +19,9 @@
use Magento\TestFramework\Fixture\DataFixture;
use Magento\TestFramework\Fixture\DataFixtureStorage;
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
+use Magento\TestFramework\Fixture\DbIsolation;
use Magento\TestFramework\Helper\Bootstrap;
+use Magento\TestFramework\Mail\Template\TransportBuilderMock;
/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -56,6 +57,7 @@ protected function setUp(): void
* @throws \Magento\Framework\Exception\MailException
*/
#[
+ DbIsolation(false),
ConfigFixture('system/smtp/transport', 'smtp', 'store'),
DataFixture(WebsiteFixture::class, as: 'website2'),
DataFixture(StoreGroupFixture::class, ['website_id' => '$website2.id$'], 'store_group2'),
@@ -117,37 +119,32 @@ private function subscribeNewsLetterAndAssertFromHeader(
/** @var Subscriber $subscriber */
$subscriber = $this->objectManager->create(Subscriber::class);
$subscriber->subscribe($customerData['email']);
- $subscriber->confirm($subscriber->getSubscriberConfirmCode());
- /** @var TransportBuilder $transportBuilder */
- $transportBuilder = $this->objectManager->get(TransportBuilder::class);
- $transport = $transportBuilder->setTemplateIdentifier('newsletter_subscription_confirm_email_template')
- ->setTemplateOptions(
- [
- 'area' => Area::AREA_FRONTEND,
- 'store' => (int) $customerData['storeId']
- ]
- )
- ->setFromByScope(
- [
- 'email' => $customerData['storeEmail'],
- 'name' => 'Store Email Name'
- ],
- (int) $customerData['storeId']
- )
- ->setTemplateVars(
- [
- 'subscriber_data' => [
- 'confirmation_link' => $subscriber->getConfirmationLink(),
- ],
- ]
- )
- ->addTo($customerData['email'])
- ->getTransport();
- $transport->sendMessage();
+ /** @var TransportBuilderMock $transportBuilderMock */
+ $transportBuilderMock = $this->objectManager->get(TransportBuilderMock::class);
+ $transport = $transportBuilderMock->setTemplateIdentifier(
+ 'customer_password_reset_password_template'
+ )->setTemplateVars([
+ 'subscriber_data' => [
+ 'confirmation_link' => $subscriber->getConfirmationLink(),
+ ],
+ ])->setTemplateOptions([
+ 'area' => Area::AREA_FRONTEND,
+ 'store' => (int) $customerData['storeId']
+ ])
+ ->setFromByScope(
+ [
+ 'email' => $customerData['storeEmail'],
+ 'name' => 'Store Email Name'
+ ],
+ (int) $customerData['storeId']
+ )
+ ->addTo($customerData['email'])
+ ->getTransport();
+
$headers = $transport->getMessage()->getHeaders();
- $sendMessage = $transport->getMessage();
- $this->assertNotNull($sendMessage);
+
+ $this->assertNotNull($transport->getMessage());
$this->assertStringContainsString($customerData['storeEmail'], $headers['From']);
}
}
From 7cc24e1312b9e0ec6ff62f10ff874ff26564fdde Mon Sep 17 00:00:00 2001
From: akaash
Date: Mon, 17 Apr 2023 11:40:20 +0530
Subject: [PATCH 27/41] ACQE-4774 | PR Feedback
---
.../testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php b/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php
index 274438b4c3420..0a53142ce4e73 100644
--- a/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php
+++ b/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php
@@ -287,7 +287,7 @@ public function testCreateAccountWithNewsLetterSubscription() :void
->addTo('customer@example.com')
->getTransport();
- $message = $transport->getMessage();
+ $message = $this->transportBuilderMock->getSentMessage();
$this->assertStringContainsString(
$subscriber->getConfirmationLink(),
From 6ea80d786de67991ece4eaeeb3326be1da7b82cb Mon Sep 17 00:00:00 2001
From: akaash
Date: Mon, 17 Apr 2023 11:45:14 +0530
Subject: [PATCH 28/41] ACQE-4823 | PR Feedback
---
.../testsuite/Magento/Store/Model/MultiStoreTest.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php b/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php
index c4ade6ec6d87d..853a53782dd9f 100644
--- a/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php
+++ b/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php
@@ -142,7 +142,7 @@ private function subscribeNewsLetterAndAssertFromHeader(
->addTo($customerData['email'])
->getTransport();
- $headers = $transport->getMessage()->getHeaders();
+ $headers = $transportBuilderMock->getSentMessage()->getHeaders();
$this->assertNotNull($transport->getMessage());
$this->assertStringContainsString($customerData['storeEmail'], $headers['From']);
From 5da33ae7c509595008bfb666a214b09b580abb8f Mon Sep 17 00:00:00 2001
From: akaash
Date: Mon, 17 Apr 2023 11:47:02 +0530
Subject: [PATCH 29/41] ACQE-4823 | PR Feedback
---
.../testsuite/Magento/Store/Model/MultiStoreTest.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php b/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php
index 853a53782dd9f..9e86df879f4e0 100644
--- a/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php
+++ b/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php
@@ -144,7 +144,7 @@ private function subscribeNewsLetterAndAssertFromHeader(
$headers = $transportBuilderMock->getSentMessage()->getHeaders();
- $this->assertNotNull($transport->getMessage());
+ $this->assertNotNull($transportBuilderMock->getSentMessage());
$this->assertStringContainsString($customerData['storeEmail'], $headers['From']);
}
}
From cd783465be6d9f2145aad5738bc93ebfce4964f5 Mon Sep 17 00:00:00 2001
From: akaash
Date: Mon, 17 Apr 2023 11:51:13 +0530
Subject: [PATCH 30/41] ACQE-4750 | PR Feedback
---
.../User/Controller/Adminhtml/UserResetPasswordEmailTest.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
index 43fa28b6ffc33..7ae3af7ab267a 100644
--- a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
+++ b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
@@ -134,10 +134,10 @@ public function testAdminEmailNotificationAfterPasswordChange() :void
->addTo($adminEmail)
->getTransport();
- $message = $transport->getMessage();
+ $message = $transportBuilderMock->getSentMessage();
// Verify an email was dispatched to the correct user
- $this->assertNotNull($transport->getMessage());
+ $this->assertNotNull($transportBuilderMock->getSentMessage());
$this->assertEquals($adminEmail, $message->getTo()[0]->getEmail());
}
}
From 4953218fc556c9d20cd2aa792e0b0631a031235c Mon Sep 17 00:00:00 2001
From: akaash
Date: Mon, 17 Apr 2023 12:35:31 +0530
Subject: [PATCH 31/41] ACQE-4750 | Static Test Fix
---
.../User/Controller/Adminhtml/UserResetPasswordEmailTest.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
index 7ae3af7ab267a..52250d41b34e3 100644
--- a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
+++ b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
@@ -121,7 +121,7 @@ public function testAdminEmailNotificationAfterPasswordChange() :void
/** @var TransportBuilderMock $transportBuilderMock */
$transportBuilderMock = $this->_objectManager->get(TransportBuilderMock::class);
- $transport = $transportBuilderMock->setTemplateIdentifier(
+ $transportBuilderMock->setTemplateIdentifier(
'customer_password_reset_password_template'
)->setTemplateVars([
'customer' => [
From 222cb2168a5a37a3c318711cf983095e4e83e2c0 Mon Sep 17 00:00:00 2001
From: akaash
Date: Mon, 17 Apr 2023 12:38:27 +0530
Subject: [PATCH 32/41] ACQE-4774 | Static Test Fix
---
.../testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php b/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php
index 0a53142ce4e73..da279101ba96f 100644
--- a/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php
+++ b/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php
@@ -274,7 +274,7 @@ public function testCreateAccountWithNewsLetterSubscription() :void
$subscriber->loadByEmail('customer@example.com');
$this->assertTrue($subscriber->isSubscribed());
- $transport = $this->transportBuilderMock->setTemplateIdentifier(
+ $this->transportBuilderMock->setTemplateIdentifier(
'newsletter_subscription_confirm_email_template'
)->setTemplateVars([
'subscriber_data' => [
From b77d5eea9f36c9736696da63c20837cdebf03193 Mon Sep 17 00:00:00 2001
From: akaash
Date: Mon, 17 Apr 2023 12:41:44 +0530
Subject: [PATCH 33/41] ACQE-4823 | Static Test Fix
---
.../testsuite/Magento/Store/Model/MultiStoreTest.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php b/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php
index 9e86df879f4e0..1c19a80e7f35f 100644
--- a/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php
+++ b/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php
@@ -122,7 +122,7 @@ private function subscribeNewsLetterAndAssertFromHeader(
/** @var TransportBuilderMock $transportBuilderMock */
$transportBuilderMock = $this->objectManager->get(TransportBuilderMock::class);
- $transport = $transportBuilderMock->setTemplateIdentifier(
+ $transportBuilderMock->setTemplateIdentifier(
'customer_password_reset_password_template'
)->setTemplateVars([
'subscriber_data' => [
From 6d790159bf7e006f650d7cb647d270eb35814455 Mon Sep 17 00:00:00 2001
From: akaash
Date: Thu, 20 Apr 2023 11:32:23 +0530
Subject: [PATCH 34/41] ACQE-4774 | PR Feedback
---
.../testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php b/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php
index da279101ba96f..34df1deb4ff35 100644
--- a/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php
+++ b/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php
@@ -244,7 +244,7 @@ public function testCustomerWithTwoNewsLetterSubscriptions()
* @return void
* @throws \Magento\Framework\Exception\LocalizedException
*/
- public function testCreateAccountWithNewsLetterSubscription() :void
+ public function testCreateAccountWithNewsLetterSubscription(): void
{
$objectManager = Bootstrap::getObjectManager();
/** @var \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerFactory */
@@ -259,6 +259,7 @@ public function testCreateAccountWithNewsLetterSubscription() :void
$this->accountManagement->createAccount($customerDataObject, '123123qW');
$message = $this->transportBuilderMock->getSentMessage();
+ $this->assertNotNull($message);
$this->assertEquals('Welcome to Main Website Store', $message->getSubject());
$this->assertStringContainsString(
'John',
@@ -289,6 +290,7 @@ public function testCreateAccountWithNewsLetterSubscription() :void
$message = $this->transportBuilderMock->getSentMessage();
+ $this->assertNotNull($message);
$this->assertStringContainsString(
$subscriber->getConfirmationLink(),
$message->getBody()->getParts()[0]->getRawContent()
From fe241ab281ebdb86e267dadb8dbe8e9080408782 Mon Sep 17 00:00:00 2001
From: akaash
Date: Thu, 20 Apr 2023 11:36:25 +0530
Subject: [PATCH 35/41] ACQE-4750 | PR Feedback
---
.../User/Controller/Adminhtml/UserResetPasswordEmailTest.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
index 52250d41b34e3..fe06f801f7c02 100644
--- a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
+++ b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
@@ -98,13 +98,14 @@ private function getResetPasswordUri(EmailMessage $message): string
/**
* Test admin email notification after password change
+ *
* @throws LocalizedException
* @return void
*/
#[
DataFixture(UserDataFixture::class, ['role_id' => 1], 'user')
]
- public function testAdminEmailNotificationAfterPasswordChange() :void
+ public function testAdminEmailNotificationAfterPasswordChange(): void
{
// Load admin user
$user = $this->fixtures->get('user');
From d17d461a338162d56fa6cad646bbf68d95fe65eb Mon Sep 17 00:00:00 2001
From: akaash
Date: Thu, 11 May 2023 21:21:19 +0530
Subject: [PATCH 36/41] ACQE-4879 | Integration Testing - Enable password
change frequency limit (for Admin)
---
.../Adminhtml/UserResetPasswordEmailTest.php | 90 ++++++++++++++++++-
1 file changed, 89 insertions(+), 1 deletion(-)
diff --git a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
index c1b19ca77beb4..51233d45ef0f1 100644
--- a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
+++ b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
@@ -7,21 +7,26 @@
namespace Magento\User\Controller\Adminhtml;
+use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Mail\EmailMessage;
+use Magento\Framework\Message\MessageInterface;
use Magento\Store\Model\Store;
use Magento\TestFramework\Fixture\Config as Config;
use Magento\TestFramework\Fixture\DataFixture;
use Magento\TestFramework\Fixture\DataFixtureStorage;
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
+use Magento\TestFramework\Fixture\DbIsolation;
+use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Mail\Template\TransportBuilderMock;
use Magento\TestFramework\TestCase\AbstractBackendController;
use Magento\User\Model\User as UserModel;
+use Magento\User\Model\UserFactory;
use Magento\User\Test\Fixture\User as UserDataFixture;
/**
* Test class for user reset password email
- *
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @magentoAppArea adminhtml
*/
class UserResetPasswordEmailTest extends AbstractBackendController
@@ -36,6 +41,16 @@ class UserResetPasswordEmailTest extends AbstractBackendController
*/
protected $userModel;
+ /**
+ * @var UserFactory
+ */
+ private $userFactory;
+
+ /**
+ * @var WriterInterface
+ */
+ private $configWriter;
+
/**
* @throws LocalizedException
*/
@@ -44,6 +59,8 @@ protected function setUp(): void
parent::setUp();
$this->fixtures = DataFixtureStorageManager::getStorage();
$this->userModel = $this->_objectManager->create(UserModel::class);
+ $this->userFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(UserFactory::class);
+ $this->configWriter = $this->_objectManager->get(WriterInterface::class);
}
#[
@@ -74,4 +91,75 @@ private function getResetPasswordUri(EmailMessage $message): string
$urlString = trim($match[0][0], $store->getBaseUrl('web'));
return substr($urlString, 0, strpos($urlString, "/key"));
}
+
+ /**
+ * @return void
+ * @throws LocalizedException
+ */
+ #[
+ DbIsolation(false),
+ Config(
+ 'admin/security/min_time_between_password_reset_requests',
+ '0',
+ 'store'
+ ),
+ DataFixture(UserDataFixture::class, ['role_id' => 1], 'user')
+ ]
+ public function testEnablePasswordChangeFrequencyLimit(): void
+ {
+ // Load admin user
+ $user = $this->fixtures->get('user');
+ $username = $user->getDataByKey('username');
+ $adminEmail = $user->getDataByKey('email');
+
+ // login admin
+ $adminUser = $this->userFactory->create();
+ $adminUser->login($username, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD);
+
+ // Resetting password multiple times
+ for ($i = 0; $i < 5; $i++) {
+ $this->getRequest()->setPostValue('email', $adminEmail);
+ $this->dispatch('backend/admin/auth/forgotpassword');
+ }
+
+ /** @var TransportBuilderMock $transportMock */
+ $transportMock = Bootstrap::getObjectManager()->get(
+ TransportBuilderMock::class
+ );
+ $sendMessage = $transportMock->getSentMessage()->getBody()->getParts()[0]->getRawContent();
+
+ $this->assertStringContainsString(
+ 'There was recently a request to change the password for your account',
+ $sendMessage
+ );
+
+ // Setting the limit to greater than 0
+ $this->configWriter->save('admin/security/min_time_between_password_reset_requests', 2);
+
+ // Resetting password multiple times
+ for ($i = 0; $i < 5; $i++) {
+ $this->getRequest()->setPostValue('email', $adminEmail);
+ $this->dispatch('backend/admin/auth/forgotpassword');
+ }
+
+ $this->assertSessionMessages(
+ $this->equalTo(
+ ['We received too many requests for password resets.'
+ . ' Please wait and try again later or contact hello@example.com.']
+ ),
+ MessageInterface::TYPE_ERROR
+ );
+
+ // Wait for 2 minutes before resetting password
+ sleep(120);
+
+ $this->getRequest()->setPostValue('email', $adminEmail);
+ $this->dispatch('backend/admin/auth/forgotpassword');
+
+ $sendMessage = $transportMock->getSentMessage()->getBody()->getParts()[0]->getRawContent();
+ $this->assertStringContainsString(
+ 'There was recently a request to change the password for your account',
+ $sendMessage
+ );
+ }
}
From a522c69e0a23ad4fc3487042128cd8e93d442e39 Mon Sep 17 00:00:00 2001
From: akaash
Date: Thu, 11 May 2023 22:33:26 +0530
Subject: [PATCH 37/41] ACQE-4879 | Static test fix
---
.../User/Controller/Adminhtml/UserResetPasswordEmailTest.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
index 51233d45ef0f1..38b1b2c30c738 100644
--- a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
+++ b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php
@@ -145,7 +145,7 @@ public function testEnablePasswordChangeFrequencyLimit(): void
$this->assertSessionMessages(
$this->equalTo(
['We received too many requests for password resets.'
- . ' Please wait and try again later or contact hello@example.com.']
+ . ' Please wait and try again later or contact hello@example.com.']
),
MessageInterface::TYPE_ERROR
);
From 5ff276c78052b2a25e6c5db40b5b92cb779cbd8e Mon Sep 17 00:00:00 2001
From: Keerthana SL
Date: Thu, 1 Jun 2023 21:28:29 +0530
Subject: [PATCH 38/41] [mainline-integration-tests] Fixing the flaky test
---
.../Mftf/Test/StoreFrontGuestCheckingWithMultishipmentTest.xml | 1 +
1 file changed, 1 insertion(+)
diff --git a/app/code/Magento/Multishipping/Test/Mftf/Test/StoreFrontGuestCheckingWithMultishipmentTest.xml b/app/code/Magento/Multishipping/Test/Mftf/Test/StoreFrontGuestCheckingWithMultishipmentTest.xml
index 82563e5055c2a..07b2834fa04d4 100644
--- a/app/code/Magento/Multishipping/Test/Mftf/Test/StoreFrontGuestCheckingWithMultishipmentTest.xml
+++ b/app/code/Magento/Multishipping/Test/Mftf/Test/StoreFrontGuestCheckingWithMultishipmentTest.xml
@@ -44,6 +44,7 @@
+
From b31ee6b07fac227183867bcf6affdc2530998934 Mon Sep 17 00:00:00 2001
From: Keerthana SL
Date: Wed, 7 Jun 2023 15:29:06 +0530
Subject: [PATCH 39/41] [mainline-integration-tests] Fixing the flaky test
StoreFrontGuestCheckingWithMultishipmentTest
---
.../StorefrontCustomerSignInPopupFormSection.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/code/Magento/Customer/Test/Mftf/Section/StorefrontCustomerSignInFormSection/StorefrontCustomerSignInPopupFormSection.xml b/app/code/Magento/Customer/Test/Mftf/Section/StorefrontCustomerSignInFormSection/StorefrontCustomerSignInPopupFormSection.xml
index f6587a757ff3e..b1eeeec6de62e 100644
--- a/app/code/Magento/Customer/Test/Mftf/Section/StorefrontCustomerSignInFormSection/StorefrontCustomerSignInPopupFormSection.xml
+++ b/app/code/Magento/Customer/Test/Mftf/Section/StorefrontCustomerSignInFormSection/StorefrontCustomerSignInPopupFormSection.xml
@@ -13,6 +13,6 @@
-
+
From 8238e4fd9f83fd07e8270a958e4faf9889c30115 Mon Sep 17 00:00:00 2001
From: Keerthana SL
Date: Thu, 15 Jun 2023 09:19:06 +0530
Subject: [PATCH 40/41] [mainline-integration-tests] Updating magento
marketplace URL
---
.../Magento/Marketplace/view/adminhtml/templates/index.phtml | 2 +-
app/code/Magento/UrlRewrite/Test/Mftf/Data/UrlRewriteData.xml | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/app/code/Magento/Marketplace/view/adminhtml/templates/index.phtml b/app/code/Magento/Marketplace/view/adminhtml/templates/index.phtml
index ac39d72388e6c..709954bad3bda 100644
--- a/app/code/Magento/Marketplace/view/adminhtml/templates/index.phtml
+++ b/app/code/Magento/Marketplace/view/adminhtml/templates/index.phtml
@@ -61,7 +61,7 @@
)); ?>
+ href="https://commercemarketplace.adobe.com/">
= $block->escapeHtml(__('Visit Magento Marketplaces')) ?>
diff --git a/app/code/Magento/UrlRewrite/Test/Mftf/Data/UrlRewriteData.xml b/app/code/Magento/UrlRewrite/Test/Mftf/Data/UrlRewriteData.xml
index 3692e82072afc..404fcb52c91e9 100644
--- a/app/code/Magento/UrlRewrite/Test/Mftf/Data/UrlRewriteData.xml
+++ b/app/code/Magento/UrlRewrite/Test/Mftf/Data/UrlRewriteData.xml
@@ -28,7 +28,7 @@
wishlist
- https://marketplace.magento.com/
+ https://commercemarketplace.adobe.com/
301
Permanent (301)
1
@@ -37,7 +37,7 @@
wishlist
- https://marketplace.magento.com/
+ https://commercemarketplace.adobe.com/
302
Temporary (302)
1
From c065e16696c8938c670bb0ae8618cfeeb9ad43ee Mon Sep 17 00:00:00 2001
From: Keerthana SL
Date: Thu, 15 Jun 2023 10:52:48 +0530
Subject: [PATCH 41/41] [mainline-integration-tests] Fixing static test error
---
.../Magento/Marketplace/view/adminhtml/templates/index.phtml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/app/code/Magento/Marketplace/view/adminhtml/templates/index.phtml b/app/code/Magento/Marketplace/view/adminhtml/templates/index.phtml
index 709954bad3bda..fc58db1bed373 100644
--- a/app/code/Magento/Marketplace/view/adminhtml/templates/index.phtml
+++ b/app/code/Magento/Marketplace/view/adminhtml/templates/index.phtml
@@ -32,8 +32,8 @@
= $block->escapeHtml(__('Partner search')) ?>
= $block->escapeHtml(__(
- 'Magento has a thriving ecosystem of technology partners to help merchants and brands deliver ' .
- 'the best possible customer experiences. They are recognized as experts in eCommerce, ' .
+ 'Magento has a thriving ecosystem of technology partners to help merchants and brands deliver '
+ . 'the best possible customer experiences. They are recognized as experts in eCommerce, ' .
'search, email marketing, payments, tax, fraud, optimization and analytics, fulfillment, ' .
'and more. Visit the Magento Partner Directory to see all of our trusted partners.'
)); ?>