Skip to content

Commit eda3772

Browse files
committed
Added dataprovider for different statuschange values
1 parent e093eff commit eda3772

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

app/code/Magento/Customer/Test/Unit/Block/Adminhtml/Edit/Tab/NewsletterTest.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Magento\Framework\Data\Form\Element\Select;
2222
use Magento\Framework\Data\FormFactory;
2323
use Magento\Framework\Registry;
24+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
2425
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
2526
use Magento\Framework\UrlInterface;
2627
use 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

Comments
 (0)