|
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; |
@@ -50,8 +51,6 @@ class NewsletterTest extends TestCase |
50 | 51 | private $contextMock; |
51 | 52 |
|
52 | 53 | /** |
53 | | - * Store manager |
54 | | - * |
55 | 54 | * @var StoreManagerInterface|MockObject |
56 | 55 | */ |
57 | 56 | private $storeManager; |
@@ -101,12 +100,20 @@ class NewsletterTest extends TestCase |
101 | 100 | */ |
102 | 101 | private $shareConfig; |
103 | 102 |
|
| 103 | + /** @var TimezoneInterface|MockObject */ |
| 104 | + protected $localeDateMock; |
| 105 | + |
104 | 106 | /** |
105 | 107 | * @inheritdoc |
106 | 108 | */ |
107 | 109 | protected function setUp(): void |
108 | 110 | { |
109 | 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); |
110 | 117 | $this->registryMock = $this->createMock(Registry::class); |
111 | 118 | $this->formFactoryMock = $this->createMock(FormFactory::class); |
112 | 119 | $this->subscriberFactoryMock = $this->createPartialMock( |
@@ -161,6 +168,56 @@ public function testInitFormCanNotShowTab() |
161 | 168 | $this->assertSame($this->model, $this->model->initForm()); |
162 | 169 | } |
163 | 170 |
|
| 171 | + /** |
| 172 | + * Test getSubscriberStatusChangedDate |
| 173 | + * |
| 174 | + * @dataProvider getChangeStatusAtDataProvider |
| 175 | + */ |
| 176 | + public function testGetSubscriberStatusChangedDate($statusDate, $dateExpected) |
| 177 | + { |
| 178 | + $customerId = 999; |
| 179 | + $websiteId = 1; |
| 180 | + $storeId = 1; |
| 181 | + $isSubscribed = true; |
| 182 | + |
| 183 | + $this->registryMock->method('registry')->with(RegistryConstants::CURRENT_CUSTOMER_ID) |
| 184 | + ->willReturn($customerId); |
| 185 | + |
| 186 | + $customer = $this->getMockForAbstractClass(CustomerInterface::class); |
| 187 | + $customer->method('getWebsiteId')->willReturn($websiteId); |
| 188 | + $customer->method('getStoreId')->willReturn($storeId); |
| 189 | + $customer->method('getId')->willReturn($customerId); |
| 190 | + $this->customerRepository->method('getById')->with($customerId)->willReturn($customer); |
| 191 | + |
| 192 | + $subscriberMock = $this->getMockBuilder(Subscriber::class) |
| 193 | + ->disableOriginalConstructor() |
| 194 | + ->setMethods(['loadByCustomer', 'getChangeStatusAt', 'isSubscribed', 'getData']) |
| 195 | + ->getMock(); |
| 196 | + $statusDate = new \DateTime($statusDate); |
| 197 | + $this->localeDateMock->method('formatDateTime')->with($statusDate)->willReturn($dateExpected); |
| 198 | + |
| 199 | + $subscriberMock->method('loadByCustomer')->with($customerId, $websiteId)->willReturnSelf(); |
| 200 | + $subscriberMock->method('getChangeStatusAt')->willReturn($statusDate); |
| 201 | + $subscriberMock->method('isSubscribed')->willReturn($isSubscribed); |
| 202 | + $subscriberMock->method('getData')->willReturn([]); |
| 203 | + $this->subscriberFactoryMock->expects($this->any())->method('create')->willReturn($subscriberMock); |
| 204 | + $this->assertEquals($dateExpected, $this->model->getStatusChangedDate()); |
| 205 | + } |
| 206 | + |
| 207 | + /** |
| 208 | + * Data provider for testGetSubscriberStatusChangedDate |
| 209 | + * |
| 210 | + * @return array |
| 211 | + */ |
| 212 | + public function getChangeStatusAtDataProvider() |
| 213 | + { |
| 214 | + return |
| 215 | + [ |
| 216 | + ['',''], |
| 217 | + ['Nov 22, 2023, 1:00:00 AM','Nov 23, 2023, 2:00:00 AM'] |
| 218 | + ]; |
| 219 | + } |
| 220 | + |
164 | 221 | /** |
165 | 222 | * Test to initialize the form |
166 | 223 | */ |
|
0 commit comments