Skip to content

Commit 9672c74

Browse files
author
Stanislav Idolov
committed
MAGETWO-84686: MAGETWO-84525 Send newsletter subscription success email after confirmation #12478
- Merge Pull Request #12478 from RhodriOwainDavies/magento2:MAGETWO-84525 - Merged commits: 1. 7b88103 2. 5140041
2 parents aa950c8 + 5140041 commit 9672c74

File tree

2 files changed

+39
-16
lines changed

2 files changed

+39
-16
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,8 @@ public function confirm($code)
621621
$this->setStatus(self::STATUS_SUBSCRIBED)
622622
->setStatusChanged(true)
623623
->save();
624+
625+
$this->sendConfirmationSuccessEmail();
624626
return true;
625627
}
626628

dev/tests/integration/testsuite/Magento/Newsletter/Model/SubscriberTest.php

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ class SubscriberTest extends \PHPUnit\Framework\TestCase
1212
/**
1313
* @var Subscriber
1414
*/
15-
protected $_model;
15+
private $model;
1616

1717
protected function setUp()
1818
{
19-
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
19+
$this->model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
2020
\Magento\Newsletter\Model\Subscriber::class
2121
);
2222
}
@@ -27,26 +27,26 @@ protected function setUp()
2727
*/
2828
public function testEmailConfirmation()
2929
{
30-
$this->_model->subscribe('customer_confirm@example.com');
30+
$this->model->subscribe('customer_confirm@example.com');
3131
/** @var TransportBuilderMock $transportBuilder */
3232
$transportBuilder = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
3333
->get(\Magento\TestFramework\Mail\Template\TransportBuilderMock::class);
3434
// confirmationCode 'ysayquyajua23iq29gxwu2eax2qb6gvy' is taken from fixture
3535
$this->assertContains(
36-
'/newsletter/subscriber/confirm/id/' . $this->_model->getSubscriberId()
36+
'/newsletter/subscriber/confirm/id/' . $this->model->getSubscriberId()
3737
. '/code/ysayquyajua23iq29gxwu2eax2qb6gvy',
3838
$transportBuilder->getSentMessage()->getRawMessage()
3939
);
40-
$this->assertEquals(Subscriber::STATUS_NOT_ACTIVE, $this->_model->getSubscriberStatus());
40+
$this->assertEquals(Subscriber::STATUS_NOT_ACTIVE, $this->model->getSubscriberStatus());
4141
}
4242

4343
/**
4444
* @magentoDataFixture Magento/Newsletter/_files/subscribers.php
4545
*/
4646
public function testLoadByCustomerId()
4747
{
48-
$this->assertSame($this->_model, $this->_model->loadByCustomerId(1));
49-
$this->assertEquals('customer@example.com', $this->_model->getSubscriberEmail());
48+
$this->assertSame($this->model, $this->model->loadByCustomerId(1));
49+
$this->assertEquals('customer@example.com', $this->model->getSubscriberEmail());
5050
}
5151

5252
/**
@@ -56,13 +56,13 @@ public function testLoadByCustomerId()
5656
public function testUnsubscribeSubscribe()
5757
{
5858
// Unsubscribe and verify
59-
$this->assertSame($this->_model, $this->_model->loadByCustomerId(1));
60-
$this->assertEquals($this->_model, $this->_model->unsubscribe());
61-
$this->assertEquals(Subscriber::STATUS_UNSUBSCRIBED, $this->_model->getSubscriberStatus());
59+
$this->assertSame($this->model, $this->model->loadByCustomerId(1));
60+
$this->assertEquals($this->model, $this->model->unsubscribe());
61+
$this->assertEquals(Subscriber::STATUS_UNSUBSCRIBED, $this->model->getSubscriberStatus());
6262

6363
// Subscribe and verify
64-
$this->assertEquals(Subscriber::STATUS_SUBSCRIBED, $this->_model->subscribe('customer@example.com'));
65-
$this->assertEquals(Subscriber::STATUS_SUBSCRIBED, $this->_model->getSubscriberStatus());
64+
$this->assertEquals(Subscriber::STATUS_SUBSCRIBED, $this->model->subscribe('customer@example.com'));
65+
$this->assertEquals(Subscriber::STATUS_SUBSCRIBED, $this->model->getSubscriberStatus());
6666
}
6767

6868
/**
@@ -72,11 +72,32 @@ public function testUnsubscribeSubscribe()
7272
public function testUnsubscribeSubscribeByCustomerId()
7373
{
7474
// Unsubscribe and verify
75-
$this->assertSame($this->_model, $this->_model->unsubscribeCustomerById(1));
76-
$this->assertEquals(Subscriber::STATUS_UNSUBSCRIBED, $this->_model->getSubscriberStatus());
75+
$this->assertSame($this->model, $this->model->unsubscribeCustomerById(1));
76+
$this->assertEquals(Subscriber::STATUS_UNSUBSCRIBED, $this->model->getSubscriberStatus());
7777

7878
// Subscribe and verify
79-
$this->assertSame($this->_model, $this->_model->subscribeCustomerById(1));
80-
$this->assertEquals(Subscriber::STATUS_SUBSCRIBED, $this->_model->getSubscriberStatus());
79+
$this->assertSame($this->model, $this->model->subscribeCustomerById(1));
80+
$this->assertEquals(Subscriber::STATUS_SUBSCRIBED, $this->model->getSubscriberStatus());
81+
}
82+
83+
/**
84+
* @magentoDataFixture Magento/Newsletter/_files/subscribers.php
85+
* @magentoConfigFixture current_store newsletter/subscription/confirm 1
86+
*/
87+
public function testConfirm()
88+
{
89+
$customerEmail = 'customer_confirm@example.com';
90+
$this->model->subscribe($customerEmail);
91+
$this->model->loadByEmail($customerEmail);
92+
$this->model->confirm($this->model->getSubscriberConfirmCode());
93+
94+
$transportBuilder = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
95+
\Magento\TestFramework\Mail\Template\TransportBuilderMock::class
96+
);
97+
98+
$this->assertContains(
99+
'You have been successfully subscribed to our newsletter.',
100+
$transportBuilder->getSentMessage()->getRawMessage()
101+
);
81102
}
82103
}

0 commit comments

Comments
 (0)