Skip to content

Commit 5eb3481

Browse files
Merge remote-tracking branch '36769/patch-2' into comm_voted_v2
2 parents 83b7f30 + 56d755b commit 5eb3481

File tree

2 files changed

+60
-5
lines changed

2 files changed

+60
-5
lines changed

app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Newsletter.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ class Newsletter extends Generic implements TabInterface
4646
protected $customerAccountManagement;
4747

4848
/**
49-
* Core registry
50-
*
5149
* @var Registry
5250
*/
5351
protected $_coreRegistry = null;
@@ -414,7 +412,7 @@ protected function updateFromSession(Form $form, $customerId)
414412
*/
415413
public function getStatusChangedDate()
416414
{
417-
$customer = $this->getCurrentCustomerId();
415+
$customer = $this->getCurrentCustomer();
418416
if ($customer === null) {
419417
return '';
420418
}

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

Lines changed: 59 additions & 2 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;
@@ -50,8 +51,6 @@ class NewsletterTest extends TestCase
5051
private $contextMock;
5152

5253
/**
53-
* Store manager
54-
*
5554
* @var StoreManagerInterface|MockObject
5655
*/
5756
private $storeManager;
@@ -101,12 +100,20 @@ class NewsletterTest extends TestCase
101100
*/
102101
private $shareConfig;
103102

103+
/** @var TimezoneInterface|MockObject */
104+
protected $localeDateMock;
105+
104106
/**
105107
* @inheritdoc
106108
*/
107109
protected function setUp(): void
108110
{
109111
$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);
110117
$this->registryMock = $this->createMock(Registry::class);
111118
$this->formFactoryMock = $this->createMock(FormFactory::class);
112119
$this->subscriberFactoryMock = $this->createPartialMock(
@@ -161,6 +168,56 @@ public function testInitFormCanNotShowTab()
161168
$this->assertSame($this->model, $this->model->initForm());
162169
}
163170

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+
164221
/**
165222
* Test to initialize the form
166223
*/

0 commit comments

Comments
 (0)