2121use Magento \Framework \Data \Form \Element \Select ;
2222use Magento \Framework \Data \FormFactory ;
2323use Magento \Framework \Registry ;
24+ use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
2425use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
2526use Magento \Framework \UrlInterface ;
2627use Magento \Newsletter \Model \Subscriber ;
@@ -99,12 +100,20 @@ class NewsletterTest extends TestCase
99100 */
100101 private $ shareConfig ;
101102
103+ /** @var TimezoneInterface|MockObject */
104+ protected $ localeDateMock ;
105+
102106 /**
103107 * @inheritdoc
104108 */
105109 protected function setUp (): void
106110 {
107111 $ 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 );
108117 $ this ->registryMock = $ this ->createMock (Registry::class);
109118 $ this ->formFactoryMock = $ this ->createMock (FormFactory::class);
110119 $ this ->subscriberFactoryMock = $ this ->createPartialMock (
@@ -158,11 +167,13 @@ public function testInitFormCanNotShowTab()
158167
159168 $ this ->assertSame ($ this ->model , $ this ->model ->initForm ());
160169 }
161-
170+
162171 /**
163172 * Test getSubscriberStatusChangedDate
173+ *
174+ * @dataProvider getChangeStatusAtDataProvider
164175 */
165- public function testGetSubscriberStatusChangedDate ()
176+ public function testGetSubscriberStatusChangedDate ($ statusDate , $ dateExpected )
166177 {
167178 $ customerId = 999 ;
168179 $ websiteId = 1 ;
@@ -182,14 +193,28 @@ public function testGetSubscriberStatusChangedDate()
182193 ->disableOriginalConstructor ()
183194 ->setMethods (['loadByCustomer ' , 'getChangeStatusAt ' , 'isSubscribed ' , 'getData ' ])
184195 ->getMock ();
196+ $ this ->localeDateMock ->method ('formatDateTime ' )->willReturn ($ statusDate );
185197
186198 $ subscriberMock ->method ('loadByCustomer ' )->with ($ customerId , $ websiteId )->willReturnSelf ();
187- $ subscriberMock ->method ('getChangeStatusAt ' )->willReturn ('' );
199+ $ subscriberMock ->method ('getChangeStatusAt ' )->willReturn ($ statusDate );
188200 $ subscriberMock ->method ('isSubscribed ' )->willReturn ($ isSubscribed );
189201 $ 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+ }
191205
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+ ];
193218 }
194219
195220 /**
0 commit comments