@@ -12,11 +12,11 @@ class SubscriberTest extends \PHPUnit\Framework\TestCase
12
12
/**
13
13
* @var Subscriber
14
14
*/
15
- protected $ _model ;
15
+ private $ model ;
16
16
17
17
protected function setUp ()
18
18
{
19
- $ this ->_model = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
19
+ $ this ->model = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
20
20
\Magento \Newsletter \Model \Subscriber::class
21
21
);
22
22
}
@@ -27,26 +27,26 @@ protected function setUp()
27
27
*/
28
28
public function testEmailConfirmation ()
29
29
{
30
- $ this ->_model ->subscribe ('customer_confirm@example.com ' );
30
+ $ this ->model ->subscribe ('customer_confirm@example.com ' );
31
31
/** @var TransportBuilderMock $transportBuilder */
32
32
$ transportBuilder = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()
33
33
->get (\Magento \TestFramework \Mail \Template \TransportBuilderMock::class);
34
34
// confirmationCode 'ysayquyajua23iq29gxwu2eax2qb6gvy' is taken from fixture
35
35
$ this ->assertContains (
36
- '/newsletter/subscriber/confirm/id/ ' . $ this ->_model ->getSubscriberId ()
36
+ '/newsletter/subscriber/confirm/id/ ' . $ this ->model ->getSubscriberId ()
37
37
. '/code/ysayquyajua23iq29gxwu2eax2qb6gvy ' ,
38
38
$ transportBuilder ->getSentMessage ()->getRawMessage ()
39
39
);
40
- $ this ->assertEquals (Subscriber::STATUS_NOT_ACTIVE , $ this ->_model ->getSubscriberStatus ());
40
+ $ this ->assertEquals (Subscriber::STATUS_NOT_ACTIVE , $ this ->model ->getSubscriberStatus ());
41
41
}
42
42
43
43
/**
44
44
* @magentoDataFixture Magento/Newsletter/_files/subscribers.php
45
45
*/
46
46
public function testLoadByCustomerId ()
47
47
{
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 ());
50
50
}
51
51
52
52
/**
@@ -56,13 +56,13 @@ public function testLoadByCustomerId()
56
56
public function testUnsubscribeSubscribe ()
57
57
{
58
58
// 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 ());
62
62
63
63
// 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 ());
66
66
}
67
67
68
68
/**
@@ -72,11 +72,32 @@ public function testUnsubscribeSubscribe()
72
72
public function testUnsubscribeSubscribeByCustomerId ()
73
73
{
74
74
// 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 ());
77
77
78
78
// 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
+ );
81
102
}
82
103
}
0 commit comments