Skip to content

Commit 91a8110

Browse files
akaashakaash
authored andcommitted
PR Feedbacks
1 parent 8664580 commit 91a8110

File tree

1 file changed

+44
-18
lines changed

1 file changed

+44
-18
lines changed

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

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,8 @@ private function getCustomTemplateId(string $templateCode): int
761761
}
762762

763763
/**
764-
* @magentoConfigFixture default_store newsletter/general/active 1
764+
* @magentoConfigFixture current_store newsletter/general/active 1
765+
* @magentoConfigFixture current_store newsletter/subscription/confirm 1
765766
* @magentoDataFixture Magento/Customer/_files/customer.php
766767
* @magentoDataFixture Magento/Newsletter/_files/subscribers.php
767768
*
@@ -773,47 +774,53 @@ private function getCustomTemplateId(string $templateCode): int
773774
*/
774775
public function testCreateAccountWithNewsLetterSubscription() :void
775776
{
776-
$customerEmail = 'test@example.com';
777-
$firstName = 'John';
778-
$lastName = 'Doe';
779-
780777
$customer = $this->customerRepository->getById(1);
781-
$customer->setEmail($customerEmail)
782-
->setFirstname($firstName)
783-
->setLastname($lastName);
784-
$this->customerRepository->save($customer);
785-
778+
$customerEmail = $customer->getEmail();
779+
$customerData = [
780+
'name' => $customer->getFirstname() . ' ' . $customer->getLastname(),
781+
'email' => $customerEmail,
782+
'id' => $customer->getId(),
783+
'rp_token' => 'randomstring'
784+
];
786785
$this->assertAndSendEmailNotification(
787-
$customer,
786+
$customerData,
788787
$customerEmail,
789-
'customer_create_account_email_template'
788+
'customer_create_account_email_template',
789+
null
790790
);
791791

792792
/** @var Subscriber $subscriber */
793793
$subscriber = $this->objectManager->create(Subscriber::class);
794794
$subscriber->subscribe($customerEmail);
795795
$subscriber->confirm($subscriber->getSubscriberConfirmCode());
796+
$confirmationLink = $subscriber->getConfirmationLink();
796797

797798
// Verify if the customer is subscribed to newsletter
798799
$this->assertTrue($subscriber->isSubscribed());
799800

800801
$this->assertAndSendEmailNotification(
801-
$customer,
802+
$customerData,
802803
$customerEmail,
803-
'newsletter_subscription_confirm_email_template'
804+
'newsletter_subscription_confirm_email_template',
805+
$confirmationLink
804806
);
805807
}
806808

807809
/**
808-
* @param $customer
810+
* @param $customerData
809811
* @param $customerEmail
810812
* @param $templateIdentifier
813+
* @param $confirmationLink
811814
* @return void
812815
* @throws LocalizedException
813816
* @throws \Magento\Framework\Exception\MailException
814817
*/
815-
private function assertAndSendEmailNotification($customer, $customerEmail, $templateIdentifier) :void
816-
{
818+
private function assertAndSendEmailNotification(
819+
$customerData,
820+
$customerEmail,
821+
$templateIdentifier,
822+
$confirmationLink = null
823+
) :void {
817824
/** @var TransportBuilder $transportBuilder */
818825
$transportBuilder = $this->objectManager->get(TransportBuilder::class);
819826
$transport = $transportBuilder->setTemplateIdentifier($templateIdentifier)
@@ -823,7 +830,14 @@ private function assertAndSendEmailNotification($customer, $customerEmail, $temp
823830
'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID
824831
]
825832
)
826-
->setTemplateVars(['customer' => $customer])
833+
->setTemplateVars(
834+
[
835+
'customer' => $customerData,
836+
'subscriber_data' => [
837+
'confirmation_link' => $confirmationLink,
838+
],
839+
]
840+
)
827841
->addTo($customerEmail)
828842
->getTransport();
829843
$transport->sendMessage();
@@ -833,8 +847,20 @@ private function assertAndSendEmailNotification($customer, $customerEmail, $temp
833847
switch ($templateIdentifier) {
834848
case 'customer_create_account_email_template':
835849
$this->assertEquals('Welcome to Default', $sendMessage->getSubject());
850+
$this->assertStringContainsString(
851+
$customerData['name'],
852+
$sendMessage->getBody()->getParts()[0]->getRawContent()
853+
);
854+
$this->assertStringContainsString(
855+
$customerData['email'],
856+
$sendMessage->getBody()->getParts()[0]->getRawContent()
857+
);
836858
break;
837859
case 'newsletter_subscription_confirm_email_template':
860+
$this->assertStringContainsString(
861+
$confirmationLink,
862+
$sendMessage->getBody()->getParts()[0]->getRawContent()
863+
);
838864
$this->assertEquals('Newsletter subscription confirmation', $sendMessage->getSubject());
839865
break;
840866
}

0 commit comments

Comments
 (0)