Skip to content

Commit 2a7e00f

Browse files
committed
Update newsletter module
Fix unit tests according to new logic Add integration tests for case when customer have store_id = 0
1 parent 8718a60 commit 2a7e00f

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ public function testSubscribeNotLoggedIn()
211211

212212
public function testUpdateSubscription()
213213
{
214+
$storeId = 2;
214215
$customerId = 1;
215216
$customerDataMock = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class)
216217
->getMock();
@@ -232,7 +233,7 @@ public function testUpdateSubscription()
232233
->method('getConfirmationStatus')
233234
->with($customerId)
234235
->willReturn('account_confirmation_required');
235-
$customerDataMock->expects($this->once())->method('getStoreId')->willReturn('store_id');
236+
$customerDataMock->expects($this->exactly(2))->method('getStoreId')->willReturn($storeId);
236237
$customerDataMock->expects($this->once())->method('getEmail')->willReturn('email');
237238

238239
$storeModel = $this->getMockBuilder(\Magento\Store\Model\Store::class)
@@ -246,6 +247,7 @@ public function testUpdateSubscription()
246247

247248
public function testUnsubscribeCustomerById()
248249
{
250+
$storeId = 2;
249251
$customerId = 1;
250252
$customerDataMock = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class)
251253
->getMock();
@@ -263,7 +265,7 @@ public function testUnsubscribeCustomerById()
263265
);
264266
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
265267
$this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf();
266-
$customerDataMock->expects($this->once())->method('getStoreId')->willReturn('store_id');
268+
$customerDataMock->expects($this->exactly(2))->method('getStoreId')->willReturn($storeId);
267269
$customerDataMock->expects($this->once())->method('getEmail')->willReturn('email');
268270
$this->sendEmailCheck();
269271

@@ -272,6 +274,7 @@ public function testUnsubscribeCustomerById()
272274

273275
public function testSubscribeCustomerById()
274276
{
277+
$storeId = 2;
275278
$customerId = 1;
276279
$customerDataMock = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class)
277280
->getMock();
@@ -289,7 +292,7 @@ public function testSubscribeCustomerById()
289292
);
290293
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
291294
$this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf();
292-
$customerDataMock->expects($this->once())->method('getStoreId')->willReturn('store_id');
295+
$customerDataMock->expects($this->exactly(2))->method('getStoreId')->willReturn($storeId);
293296
$customerDataMock->expects($this->once())->method('getEmail')->willReturn('email');
294297
$this->sendEmailCheck();
295298

@@ -298,6 +301,7 @@ public function testSubscribeCustomerById()
298301

299302
public function testSubscribeCustomerById1()
300303
{
304+
$storeId = 2;
301305
$customerId = 1;
302306
$customerDataMock = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class)
303307
->getMock();
@@ -315,7 +319,7 @@ public function testSubscribeCustomerById1()
315319
);
316320
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
317321
$this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf();
318-
$customerDataMock->expects($this->once())->method('getStoreId')->willReturn('store_id');
322+
$customerDataMock->expects($this->exactly(2))->method('getStoreId')->willReturn($storeId);
319323
$customerDataMock->expects($this->once())->method('getEmail')->willReturn('email');
320324
$this->sendEmailCheck();
321325
$this->customerAccountManagement->expects($this->once())
@@ -329,6 +333,7 @@ public function testSubscribeCustomerById1()
329333

330334
public function testSubscribeCustomerByIdAfterConfirmation()
331335
{
336+
$storeId = 2;
332337
$customerId = 1;
333338
$customerDataMock = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class)
334339
->getMock();
@@ -346,7 +351,7 @@ public function testSubscribeCustomerByIdAfterConfirmation()
346351
);
347352
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
348353
$this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf();
349-
$customerDataMock->expects($this->once())->method('getStoreId')->willReturn('store_id');
354+
$customerDataMock->expects($this->exactly(2))->method('getStoreId')->willReturn($storeId);
350355
$customerDataMock->expects($this->once())->method('getEmail')->willReturn('email');
351356
$this->sendEmailCheck();
352357
$this->customerAccountManagement->expects($this->never())->method('getConfirmationStatus');

dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,42 @@ private function verifySubscriptionNotExist($email)
167167
$this->assertEquals(0, (int)$subscriber->getId());
168168
return $subscriber;
169169
}
170+
171+
/**
172+
* @magentoAppArea adminhtml
173+
* @magentoDbIsolation enabled
174+
*/
175+
public function testCustomerWithZeroStoreIdIsSubscribed()
176+
{
177+
$objectManager = Bootstrap::getObjectManager();
178+
179+
$currentStore = $objectManager->get(
180+
\Magento\Store\Model\StoreManagerInterface::class
181+
)->getStore()->getId();
182+
183+
$subscriber = $objectManager->create(\Magento\Newsletter\Model\Subscriber::class);
184+
/** @var \Magento\Newsletter\Model\Subscriber $subscriber */
185+
$subscriber->setStoreId($currentStore)
186+
->setCustomerId(0)
187+
->setSubscriberEmail('[email protected]')
188+
->setSubscriberStatus(\Magento\Newsletter\Model\Subscriber::STATUS_SUBSCRIBED)
189+
->save();
190+
191+
/** @var \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerFactory */
192+
$customerFactory = $objectManager->get(\Magento\Customer\Api\Data\CustomerInterfaceFactory::class);
193+
$customerDataObject = $customerFactory->create()
194+
->setFirstname('Firstname')
195+
->setLastname('Lastname')
196+
->setStoreId(0)
197+
->setEmail('[email protected]');
198+
/** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
199+
$customer = $this->accountManagement->createAccount($customerDataObject);
200+
201+
$this->customerRepository->save($customer);
202+
203+
$subscriber->loadByEmail('[email protected]');
204+
205+
$this->assertEquals($customer->getId(), (int)$subscriber->getCustomerId());
206+
$this->assertEquals($currentStore, (int)$subscriber->getStoreId());
207+
}
170208
}

0 commit comments

Comments
 (0)