Skip to content

Commit 65daac8

Browse files
AC-6695: Guest Checkout Fix
1 parent 7252681 commit 65daac8

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Newsletter/Customer/SubscribeEmailToNewsletterTest.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
namespace Magento\GraphQl\Newsletter\Customer;
99

1010
use Exception;
11+
use Magento\Customer\Model\AccountManagement;
1112
use Magento\Customer\Model\CustomerAuthUpdate;
1213
use Magento\Customer\Model\CustomerRegistry;
14+
use Magento\Framework\App\Config\ScopeConfigInterface;
1315
use Magento\Framework\Exception\AuthenticationException;
1416
use Magento\Integration\Api\CustomerTokenServiceInterface;
1517
use Magento\Newsletter\Model\ResourceModel\Subscriber as SubscriberResourceModel;
18+
use Magento\Store\Model\ScopeInterface;
1619
use Magento\TestFramework\Helper\Bootstrap;
1720
use Magento\TestFramework\TestCase\GraphQlAbstract;
1821

@@ -40,13 +43,18 @@ class SubscribeEmailToNewsletterTest extends GraphQlAbstract
4043
* @var SubscriberResourceModel
4144
*/
4245
private $subscriberResource;
46+
/**
47+
* @var ScopeConfigInterface
48+
*/
49+
private $scopeConfig;
4350

4451
/**
4552
* @inheritDoc
4653
*/
4754
protected function setUp(): void
4855
{
4956
$objectManager = Bootstrap::getObjectManager();
57+
$this->scopeConfig = $objectManager->get(ScopeConfigInterface::class);
5058
$this->customerAuthUpdate = Bootstrap::getObjectManager()->get(CustomerAuthUpdate::class);
5159
$this->customerRegistry = Bootstrap::getObjectManager()->get(CustomerRegistry::class);
5260
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
@@ -146,10 +154,17 @@ public function testNewsletterSubscriptionWithAnotherCustomerEmail()
146154
{
147155
$query = $this->getQuery('customer2@search.example.com');
148156

149-
$this->expectException(Exception::class);
150-
$this->expectExceptionMessage('Cannot create a newsletter subscription.' . "\n");
151-
152-
$this->graphQlMutation($query, [], '', $this->getHeaderMap('customer@search.example.com'));
157+
$guestLoginConfig = $this->scopeConfig->getValue(
158+
AccountManagement::GUEST_CHECKOUT_LOGIN_OPTION_SYS_CONFIG,
159+
ScopeInterface::SCOPE_WEBSITE,
160+
1
161+
);
162+
163+
if ($guestLoginConfig) {
164+
$this->expectException(Exception::class);
165+
$this->expectExceptionMessage('Cannot create a newsletter subscription.' . "\n");
166+
$this->graphQlMutation($query, [], '', $this->getHeaderMap('customer@search.example.com'));
167+
}
153168
}
154169

155170
/**

dev/tests/integration/testsuite/Magento/Newsletter/Controller/Subscriber/NewActionTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
namespace Magento\Newsletter\Controller\Subscriber;
99

1010
use Magento\Customer\Api\CustomerRepositoryInterface;
11+
use Magento\Customer\Model\AccountManagement;
1112
use Magento\Customer\Model\Session;
1213
use Magento\Customer\Model\Url;
14+
use Magento\Framework\App\Config\ScopeConfigInterface;
1315
use Magento\Framework\App\Request\Http as HttpRequest;
1416
use Magento\Newsletter\Model\ResourceModel\Subscriber as SubscriberResource;
1517
use Magento\Newsletter\Model\ResourceModel\Subscriber\CollectionFactory;
1618
use Magento\Newsletter\Model\ResourceModel\Subscriber\Grid\Collection as GridCollection;
19+
use Magento\Store\Model\ScopeInterface;
1720
use Magento\TestFramework\TestCase\AbstractController;
1821
use Laminas\Stdlib\Parameters;
1922

@@ -222,8 +225,18 @@ public function testWithEmailAssignedToAnotherCustomer(): void
222225
$this->session->loginById(1);
223226
$this->prepareRequest('customer2@search.example.com');
224227
$this->dispatch('newsletter/subscriber/new');
228+
$scopeConfig = $this->_objectManager->get(ScopeConfigInterface::class);
229+
$guestLoginConfig = $scopeConfig->getValue(
230+
AccountManagement::GUEST_CHECKOUT_LOGIN_OPTION_SYS_CONFIG,
231+
ScopeInterface::SCOPE_WEBSITE,
232+
1
233+
);
225234

226-
$this->performAsserts('This email address is already assigned to another user.');
235+
if ($guestLoginConfig) {
236+
$this->performAsserts('This email address is already assigned to another user.');
237+
} else {
238+
$this->performAsserts('This email address is already subscribed.');
239+
}
227240
}
228241

229242
/**

0 commit comments

Comments
 (0)