21
21
use Magento \Framework \Data \Form \Element \Select ;
22
22
use Magento \Framework \Data \FormFactory ;
23
23
use Magento \Framework \Registry ;
24
+ use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
24
25
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
25
26
use Magento \Framework \UrlInterface ;
26
27
use Magento \Newsletter \Model \Subscriber ;
@@ -99,12 +100,20 @@ class NewsletterTest extends TestCase
99
100
*/
100
101
private $ shareConfig ;
101
102
103
+ /** @var TimezoneInterface|MockObject */
104
+ protected $ localeDateMock ;
105
+
102
106
/**
103
107
* @inheritdoc
104
108
*/
105
109
protected function setUp (): void
106
110
{
107
111
$ this ->contextMock = $ this ->createMock (Context::class);
112
+ $ this ->localeDateMock = $ this ->getMockBuilder (TimezoneInterface::class)
113
+ ->disableOriginalConstructor ()
114
+ ->setMethods (['formatDateTime ' ])
115
+ ->getMockForAbstractClass ();
116
+ $ this ->contextMock ->expects ($ this ->any ())->method ('getLocaleDate ' )->willReturn ($ this ->localeDateMock );
108
117
$ this ->registryMock = $ this ->createMock (Registry::class);
109
118
$ this ->formFactoryMock = $ this ->createMock (FormFactory::class);
110
119
$ this ->subscriberFactoryMock = $ this ->createPartialMock (
@@ -158,11 +167,13 @@ public function testInitFormCanNotShowTab()
158
167
159
168
$ this ->assertSame ($ this ->model , $ this ->model ->initForm ());
160
169
}
161
-
170
+
162
171
/**
163
172
* Test getSubscriberStatusChangedDate
173
+ *
174
+ * @dataProvider getChangeStatusAtDataProvider
164
175
*/
165
- public function testGetSubscriberStatusChangedDate ()
176
+ public function testGetSubscriberStatusChangedDate ($ statusDate , $ dateExpected )
166
177
{
167
178
$ customerId = 999 ;
168
179
$ websiteId = 1 ;
@@ -182,14 +193,28 @@ public function testGetSubscriberStatusChangedDate()
182
193
->disableOriginalConstructor ()
183
194
->setMethods (['loadByCustomer ' , 'getChangeStatusAt ' , 'isSubscribed ' , 'getData ' ])
184
195
->getMock ();
196
+ $ this ->localeDateMock ->method ('formatDateTime ' )->willReturn ($ statusDate );
185
197
186
198
$ subscriberMock ->method ('loadByCustomer ' )->with ($ customerId , $ websiteId )->willReturnSelf ();
187
- $ subscriberMock ->method ('getChangeStatusAt ' )->willReturn ('' );
199
+ $ subscriberMock ->method ('getChangeStatusAt ' )->willReturn ($ statusDate );
188
200
$ subscriberMock ->method ('isSubscribed ' )->willReturn ($ isSubscribed );
189
201
$ subscriberMock ->method ('getData ' )->willReturn ([]);
190
- $ this ->subscriberFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ subscriberMock );
202
+ $ this ->subscriberFactoryMock ->expects ($ this ->any ())->method ('create ' )->willReturn ($ subscriberMock );
203
+ $ this ->assertEquals ($ dateExpected , $ this ->model ->getStatusChangedDate ());
204
+ }
191
205
192
- $ this ->assertEquals ('' , $ this ->model ->getStatusChangedDate ());
206
+ /**
207
+ * Data provider for testGetSubscriberStatusChangedDate
208
+ *
209
+ * @return array
210
+ */
211
+ public function getChangeStatusAtDataProvider ()
212
+ {
213
+ return
214
+ [
215
+ ['' ,'' ],
216
+ ['Nov 22, 2023, 1:00:00 AM ' ,'Nov 22, 2023, 1:00:00 AM ' ]
217
+ ];
193
218
}
194
219
195
220
/**
0 commit comments