8
8
namespace Magento \Newsletter \Model ;
9
9
10
10
use Magento \Customer \Api \CustomerRepositoryInterface ;
11
+ use Magento \Framework \Exception \LocalizedException ;
12
+ use Magento \Framework \Exception \NoSuchEntityException ;
11
13
use Magento \Framework \ObjectManagerInterface ;
12
14
use Magento \TestFramework \Helper \Bootstrap ;
13
15
use Magento \TestFramework \Mail \Template \TransportBuilderMock ;
@@ -89,18 +91,27 @@ public function testUnsubscribeSubscribe(): void
89
91
$ this ->assertEquals ($ subscriber , $ subscriber ->unsubscribe ());
90
92
$ this ->assertStringContainsString (
91
93
'You have been unsubscribed from the newsletter. ' ,
92
- $ this ->transportBuilder -> getSentMessage ()-> getBody ()-> getParts ()[ 0 ]-> getRawContent ( )
94
+ $ this ->getFilteredRawMessage ( $ this -> transportBuilder )
93
95
);
94
96
$ this ->assertEquals (Subscriber::STATUS_UNSUBSCRIBED , $ subscriber ->getSubscriberStatus ());
95
97
// Subscribe and verify
96
98
$ this ->assertEquals (Subscriber::STATUS_SUBSCRIBED , $ subscriber ->subscribe ('customer@example.com ' ));
97
99
$ this ->assertEquals (Subscriber::STATUS_SUBSCRIBED , $ subscriber ->getSubscriberStatus ());
98
100
$ this ->assertStringContainsString (
99
101
'You have been successfully subscribed to our newsletter. ' ,
100
- $ this ->transportBuilder -> getSentMessage ()-> getBody ()-> getParts ()[ 0 ]-> getRawContent ( )
102
+ $ this ->getFilteredRawMessage ( $ this -> transportBuilder )
101
103
);
102
104
}
103
105
106
+ /**
107
+ * @param TransportBuilderMock $transportBuilderMock
108
+ * @return string
109
+ */
110
+ private function getFilteredRawMessage (TransportBuilderMock $ transportBuilderMock ): string
111
+ {
112
+ return $ transportBuilderMock ->getSentMessage ()->getBody ()->getParts ()[0 ]->getRawContent ();
113
+ }
114
+
104
115
/**
105
116
* @magentoDataFixture Magento/Newsletter/_files/subscribers.php
106
117
*
@@ -116,14 +127,14 @@ public function testUnsubscribeSubscribeByCustomerId(): void
116
127
$ this ->assertEquals (Subscriber::STATUS_UNSUBSCRIBED , $ subscriber ->getSubscriberStatus ());
117
128
$ this ->assertStringContainsString (
118
129
'You have been unsubscribed from the newsletter. ' ,
119
- $ this ->transportBuilder -> getSentMessage ()-> getBody ()-> getParts ()[ 0 ]-> getRawContent ( )
130
+ $ this ->getFilteredRawMessage ( $ this -> transportBuilder )
120
131
);
121
132
// Subscribe and verify
122
133
$ this ->assertSame ($ subscriber , $ subscriber ->subscribeCustomerById (1 ));
123
134
$ this ->assertEquals (Subscriber::STATUS_SUBSCRIBED , $ subscriber ->getSubscriberStatus ());
124
135
$ this ->assertStringContainsString (
125
136
'You have been successfully subscribed to our newsletter. ' ,
126
- $ this ->transportBuilder -> getSentMessage ()-> getBody ()-> getParts ()[ 0 ]-> getRawContent ( )
137
+ $ this ->getFilteredRawMessage ( $ this -> transportBuilder )
127
138
);
128
139
}
129
140
@@ -143,7 +154,7 @@ public function testConfirm(): void
143
154
$ subscriber ->confirm ($ subscriber ->getSubscriberConfirmCode ());
144
155
$ this ->assertStringContainsString (
145
156
'You have been successfully subscribed to our newsletter. ' ,
146
- $ this ->transportBuilder -> getSentMessage ()-> getBody ()-> getParts ()[ 0 ]-> getRawContent ( )
157
+ $ this ->getFilteredRawMessage ( $ this -> transportBuilder )
147
158
);
148
159
}
149
160
@@ -152,6 +163,8 @@ public function testConfirm(): void
152
163
* @magentoDataFixture Magento/Newsletter/_files/newsletter_unconfirmed_customer.php
153
164
*
154
165
* @return void
166
+ * @throws LocalizedException
167
+ * @throws NoSuchEntityException
155
168
*/
156
169
public function testSubscribeUnconfirmedCustomerWithSubscription (): void
157
170
{
@@ -166,6 +179,8 @@ public function testSubscribeUnconfirmedCustomerWithSubscription(): void
166
179
* @magentoDataFixture Magento/Customer/_files/unconfirmed_customer.php
167
180
*
168
181
* @return void
182
+ * @throws LocalizedException
183
+ * @throws NoSuchEntityException
169
184
*/
170
185
public function testSubscribeUnconfirmedCustomerWithoutSubscription (): void
171
186
{
0 commit comments