Skip to content

Commit d6129f0

Browse files
authored
Merge pull request #5345 from magento-tsg/2.4.0-develop-pr14
[TSG] Fixes for 2.4 (pr14) (2.4.0-develop)
2 parents 286fd52 + d0a9a3d commit d6129f0

File tree

3 files changed

+56
-24
lines changed

3 files changed

+56
-24
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public function execute()
221221
return $this->returnResult('catalog/*/', [], ['error' => true]);
222222
}
223223
// entity type check
224-
if ($model->getEntityTypeId() != $this->_entityTypeId) {
224+
if ($model->getEntityTypeId() != $this->_entityTypeId || array_key_exists('backend_model', $data)) {
225225
$this->messageManager->addErrorMessage(__('We can\'t update the attribute.'));
226226
$this->_session->setAttributeData($data);
227227
return $this->returnResult('catalog/*/', [], ['error' => true]);

app/code/Magento/Newsletter/Block/Adminhtml/Queue/Preview.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class Preview extends \Magento\Newsletter\Block\Adminhtml\Template\Preview
2626
/**
2727
* @param \Magento\Backend\Block\Template\Context $context
2828
* @param \Magento\Newsletter\Model\TemplateFactory $templateFactory
29-
* @param \Magento\Newsletter\Model\QueueFactory $queueFactory
3029
* @param \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory
30+
* @param \Magento\Newsletter\Model\QueueFactory $queueFactory
3131
* @param array $data
3232
*/
3333
public function __construct(
@@ -42,6 +42,8 @@ public function __construct(
4242
}
4343

4444
/**
45+
* Return template.
46+
*
4547
* @param \Magento\Newsletter\Model\Template $template
4648
* @param string $id
4749
* @return $this
@@ -50,9 +52,11 @@ protected function loadTemplate(\Magento\Newsletter\Model\Template $template, $i
5052
{
5153
/** @var \Magento\Newsletter\Model\Queue $queue */
5254
$queue = $this->_queueFactory->create()->load($id);
55+
$template->setId($queue->getTemplateId());
5356
$template->setTemplateType($queue->getNewsletterType());
5457
$template->setTemplateText($queue->getNewsletterText());
5558
$template->setTemplateStyles($queue->getNewsletterStyles());
59+
5660
return $this;
5761
}
5862
}

app/code/Magento/Newsletter/Test/Unit/Block/Adminhtml/Queue/PreviewTest.php

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@ protected function setUp()
4949
{
5050
$context = $this->createMock(\Magento\Backend\Block\Template\Context::class);
5151
$eventManager = $this->createMock(\Magento\Framework\Event\ManagerInterface::class);
52-
$context->expects($this->once())->method('getEventManager')->will($this->returnValue($eventManager));
52+
$context->expects($this->once())->method('getEventManager')->willReturn($eventManager);
5353
$scopeConfig = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
54-
$context->expects($this->once())->method('getScopeConfig')->will($this->returnValue($scopeConfig));
54+
$context->expects($this->once())->method('getScopeConfig')->willReturn($scopeConfig);
5555
$this->request = $this->createMock(\Magento\Framework\App\Request\Http::class);
56-
$context->expects($this->once())->method('getRequest')->will($this->returnValue($this->request));
56+
$context->expects($this->once())->method('getRequest')->willReturn($this->request);
5757
$this->storeManager = $this->createPartialMock(
5858
\Magento\Store\Model\StoreManager::class,
5959
['getStores', 'getDefaultStoreView']
6060
);
61-
$context->expects($this->once())->method('getStoreManager')->will($this->returnValue($this->storeManager));
61+
$context->expects($this->once())->method('getStoreManager')->willReturn($this->storeManager);
6262
$appState = $this->createMock(\Magento\Framework\App\State::class);
63-
$context->expects($this->once())->method('getAppState')->will($this->returnValue($appState));
63+
$context->expects($this->once())->method('getAppState')->willReturn($appState);
6464

6565
$backendSession = $this->getMockBuilder(\Magento\Backend\Model\Session::class)
6666
->disableOriginalConstructor()
@@ -69,16 +69,34 @@ protected function setUp()
6969
$context->expects($this->once())->method('getBackendSession')->willReturn($backendSession);
7070

7171
$templateFactory = $this->createPartialMock(\Magento\Newsletter\Model\TemplateFactory::class, ['create']);
72-
$this->template = $this->createMock(\Magento\Newsletter\Model\Template::class);
73-
$templateFactory->expects($this->once())->method('create')->will($this->returnValue($this->template));
72+
$this->template = $this->createPartialMock(
73+
\Magento\Newsletter\Model\Template::class,
74+
[
75+
'isPlain',
76+
'setId',
77+
'setTemplateType',
78+
'setTemplateText',
79+
'setTemplateStyles',
80+
]
81+
);
82+
$templateFactory->expects($this->once())->method('create')->willReturn($this->template);
7483

7584
$subscriberFactory = $this->createPartialMock(\Magento\Newsletter\Model\SubscriberFactory::class, ['create']);
7685
$this->subscriber = $this->createMock(\Magento\Newsletter\Model\Subscriber::class);
77-
$subscriberFactory->expects($this->once())->method('create')->will($this->returnValue($this->subscriber));
86+
$subscriberFactory->expects($this->once())->method('create')->willReturn($this->subscriber);
7887

7988
$queueFactory = $this->createPartialMock(\Magento\Newsletter\Model\QueueFactory::class, ['create']);
80-
$this->queue = $this->createPartialMock(\Magento\Newsletter\Model\Queue::class, ['load']);
81-
$queueFactory->expects($this->any())->method('create')->will($this->returnValue($this->queue));
89+
$this->queue = $this->createPartialMock(
90+
\Magento\Newsletter\Model\Queue::class,
91+
[
92+
'load',
93+
'getTemplateId',
94+
'getNewsletterType',
95+
'getNewsletterText',
96+
'getNewsletterStyles',
97+
]
98+
);
99+
$queueFactory->expects($this->any())->method('create')->willReturn($this->queue);
82100

83101
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
84102

@@ -100,27 +118,37 @@ public function testToHtmlEmpty()
100118
{
101119
/** @var \Magento\Store\Model\Store $store */
102120
$store = $this->createPartialMock(\Magento\Store\Model\Store::class, ['getId']);
103-
$this->storeManager->expects($this->once())->method('getDefaultStoreView')->will($this->returnValue($store));
121+
$this->storeManager->expects($this->once())->method('getDefaultStoreView')->willReturn($store);
104122
$result = $this->preview->toHtml();
105123
$this->assertEquals('', $result);
106124
}
107125

108126
public function testToHtmlWithId()
109127
{
110-
$this->request->expects($this->any())->method('getParam')->will(
111-
$this->returnValueMap(
112-
[
113-
['id', null, 1],
114-
['store_id', null, 0]
115-
]
116-
)
128+
$templateId = 1;
129+
$newsletterType = 2;
130+
$newsletterText = 'newsletter text';
131+
$newsletterStyle = 'style';
132+
$this->request->expects($this->any())->method('getParam')->willReturnMap(
133+
[
134+
['id', null, 1],
135+
['store_id', null, 0],
136+
]
117137
);
118-
$this->queue->expects($this->once())->method('load')->will($this->returnSelf());
119-
$this->template->expects($this->any())->method('isPlain')->will($this->returnValue(true));
138+
$this->queue->expects($this->once())->method('load')->willReturnSelf();
139+
$this->queue->expects($this->once())->method('getTemplateId')->willReturn($templateId);
140+
$this->queue->expects($this->once())->method('getNewsletterType')->willReturn($newsletterType);
141+
$this->queue->expects($this->once())->method('getNewsletterText')->willReturn($newsletterText);
142+
$this->queue->expects($this->once())->method('getNewsletterStyles')->willReturn($newsletterStyle);
143+
$this->template->expects($this->any())->method('isPlain')->willReturn(true);
144+
$this->template->expects($this->once())->method('setId')->willReturn($templateId);
145+
$this->template->expects($this->once())->method('setTemplateType')->willReturn($newsletterType);
146+
$this->template->expects($this->once())->method('setTemplateText')->willReturn($newsletterText);
147+
$this->template->expects($this->once())->method('setTemplateStyles')->willReturn($newsletterStyle);
120148
/** @var \Magento\Store\Model\Store $store */
121-
$this->storeManager->expects($this->once())->method('getDefaultStoreView')->will($this->returnValue(null));
149+
$this->storeManager->expects($this->once())->method('getDefaultStoreView')->willReturn(null);
122150
$store = $this->createPartialMock(\Magento\Store\Model\Store::class, ['getId']);
123-
$this->storeManager->expects($this->once())->method('getStores')->will($this->returnValue([0 => $store]));
151+
$this->storeManager->expects($this->once())->method('getStores')->willReturn([0 => $store]);
124152
$result = $this->preview->toHtml();
125153
$this->assertEquals('<pre></pre>', $result);
126154
}

0 commit comments

Comments
 (0)