|
8 | 8 | namespace Magento\GraphQl\Newsletter\Customer; |
9 | 9 |
|
10 | 10 | use Exception; |
| 11 | +use Magento\Customer\Model\AccountManagement; |
11 | 12 | use Magento\Customer\Model\CustomerAuthUpdate; |
12 | 13 | use Magento\Customer\Model\CustomerRegistry; |
| 14 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
13 | 15 | use Magento\Framework\Exception\AuthenticationException; |
14 | 16 | use Magento\Integration\Api\CustomerTokenServiceInterface; |
15 | 17 | use Magento\Newsletter\Model\ResourceModel\Subscriber as SubscriberResourceModel; |
| 18 | +use Magento\Store\Model\ScopeInterface; |
16 | 19 | use Magento\TestFramework\Helper\Bootstrap; |
17 | 20 | use Magento\TestFramework\TestCase\GraphQlAbstract; |
18 | 21 |
|
@@ -40,13 +43,18 @@ class SubscribeEmailToNewsletterTest extends GraphQlAbstract |
40 | 43 | * @var SubscriberResourceModel |
41 | 44 | */ |
42 | 45 | private $subscriberResource; |
| 46 | + /** |
| 47 | + * @var ScopeConfigInterface |
| 48 | + */ |
| 49 | + private $scopeConfig; |
43 | 50 |
|
44 | 51 | /** |
45 | 52 | * @inheritDoc |
46 | 53 | */ |
47 | 54 | protected function setUp(): void |
48 | 55 | { |
49 | 56 | $objectManager = Bootstrap::getObjectManager(); |
| 57 | + $this->scopeConfig = $objectManager->get(ScopeConfigInterface::class); |
50 | 58 | $this->customerAuthUpdate = Bootstrap::getObjectManager()->get(CustomerAuthUpdate::class); |
51 | 59 | $this->customerRegistry = Bootstrap::getObjectManager()->get(CustomerRegistry::class); |
52 | 60 | $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); |
@@ -146,10 +154,17 @@ public function testNewsletterSubscriptionWithAnotherCustomerEmail() |
146 | 154 | { |
147 | 155 | $query = $this->getQuery('customer2@search.example.com'); |
148 | 156 |
|
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 | + } |
153 | 168 | } |
154 | 169 |
|
155 | 170 | /** |
|
0 commit comments