Skip to content

Commit 09ce2c0

Browse files
committed
Merge branch 'MAGETWO-71179' into MAGETWO-71289
2 parents e7102aa + cc42dd8 commit 09ce2c0

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

app/code/Magento/Newsletter/Model/Subscriber.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,9 @@ protected function _updateCustomerSubscription($customerId, $subscribe)
554554
} elseif ($isConfirmNeed) {
555555
$status = self::STATUS_NOT_ACTIVE;
556556
}
557+
} elseif (($this->getStatus() == self::STATUS_UNCONFIRMED) && ($customerData->getConfirmation() === null)) {
558+
$status = self::STATUS_SUBSCRIBED;
559+
$sendInformationEmail = true;
557560
} else {
558561
$status = self::STATUS_UNSUBSCRIBED;
559562
}

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,35 @@ public function testSubscribeCustomerById1()
273273
$this->assertEquals(\Magento\Newsletter\Model\Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->getStatus());
274274
}
275275

276+
public function testSubscribeCustomerByIdAfterConfirmation()
277+
{
278+
$customerId = 1;
279+
$customerDataMock = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class)
280+
->getMock();
281+
$this->customerRepository->expects($this->atLeastOnce())
282+
->method('getById')
283+
->with($customerId)->willReturn($customerDataMock);
284+
$this->resource->expects($this->atLeastOnce())
285+
->method('loadByCustomerData')
286+
->with($customerDataMock)
287+
->willReturn(
288+
[
289+
'subscriber_id' => 1,
290+
'subscriber_status' => 4
291+
]
292+
);
293+
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
294+
$this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf();
295+
$customerDataMock->expects($this->once())->method('getStoreId')->willReturn('store_id');
296+
$customerDataMock->expects($this->once())->method('getEmail')->willReturn('email');
297+
$this->sendEmailCheck();
298+
$this->customerAccountManagement->expects($this->never())->method('getConfirmationStatus');
299+
$this->scopeConfig->expects($this->atLeastOnce())->method('getValue')->with()->willReturn(true);
300+
301+
$this->subscriber->updateSubscription($customerId);
302+
$this->assertEquals(\Magento\Newsletter\Model\Subscriber::STATUS_SUBSCRIBED, $this->subscriber->getStatus());
303+
}
304+
276305
public function testUnsubscribe()
277306
{
278307
$this->resource->expects($this->once())->method('save')->willReturnSelf();

0 commit comments

Comments
 (0)