Skip to content

Commit faa16c5

Browse files
committed
Merge remote-tracking branch 'adobe-commerce-tier-4/ACP2E-3998' into PR_2025_06_25_muntianu
2 parents 4616bca + db800a7 commit faa16c5

File tree

7 files changed

+100
-38
lines changed

7 files changed

+100
-38
lines changed

app/code/Magento/Backend/Block/Template.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ public function __construct(
8080
$this->formKey = $context->getFormKey();
8181
$this->nameBuilder = $context->getNameBuilder();
8282
$data['jsonHelper'] = $jsonHelper ?? ObjectManager::getInstance()->get(JsonHelper::class);
83-
$data['directoryHelper']= $directoryHelper ?? ObjectManager::getInstance()->get(DirectoryHelper::class);
83+
if (empty($data['directoryHelper'])) {
84+
$data['directoryHelper'] = $directoryHelper ?? ObjectManager::getInstance()->get(DirectoryHelper::class);
85+
}
8486
parent::__construct($context, $data);
8587
}
8688

@@ -107,6 +109,7 @@ public function getFormKey()
107109
* not be used in future development. Module design should explicitly state dependencies to avoid requiring output
108110
* disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity
109111
* issues that will be addressed in future releases.
112+
* @see no alternatives
110113
*/
111114
public function isOutputEnabled($moduleName = null)
112115
{

app/code/Magento/CatalogWidget/Test/Unit/Block/Product/Widget/ConditionsTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
use Magento\Framework\View\TemplateEngineInterface;
2626
use Magento\Framework\View\TemplateEnginePool;
2727
use Magento\Rule\Model\Condition\Combine;
28+
use Magento\Store\Api\Data\StoreInterface;
29+
use Magento\Store\Model\StoreManagerInterface;
2830
use Magento\Widget\Model\Widget\Instance;
31+
use PHPUnit\Framework\MockObject\Exception;
2932
use PHPUnit\Framework\MockObject\MockObject;
3033
use PHPUnit\Framework\TestCase;
3134

@@ -196,9 +199,9 @@ public function testConstructWithParamsFromBlock()
196199

197200
/**
198201
* @return void
199-
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
202+
* @throws Exception
200203
*/
201-
public function testRender()
204+
public function testRender(): void
202205
{
203206
$data = ['area' => 'backend'];
204207
$abstractElementMock = $this->getMockBuilder(AbstractElement::class)
@@ -226,6 +229,10 @@ public function testRender()
226229
$templateEngineMock->expects($this->once())->method('render')->willReturn('html');
227230
$resolverMock->method('getTemplateFileName')->willReturn('');
228231

232+
$storeMock = $this->createMock(StoreInterface::class);
233+
$storeManager = $this->createMock(StoreManagerInterface::class);
234+
$storeManager->expects($this->once())->method('getStore')->willReturn($storeMock);
235+
$this->contextMock->expects($this->any())->method('getStoreManager')->willReturn($storeManager);
229236
$this->widgetConditions = $this->objectManagerHelper->getObject(
230237
Conditions::class,
231238
[

app/code/Magento/Email/Block/Adminhtml/Template/Edit.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2011 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\Email\Block\Adminhtml\Template;
77

@@ -100,7 +100,7 @@ public function __construct(
100100
$this->_emailConfig = $emailConfig;
101101
$this->buttonList = $buttonList;
102102
$this->toolbar = $toolbar;
103-
parent::__construct($context, $data);
103+
parent::__construct($context, $data, $jsonHelper);
104104
}
105105

106106
/**

app/code/Magento/Email/Test/Unit/Block/Adminhtml/Template/EditTest.php

Lines changed: 73 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,42 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2013 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

88
namespace Magento\Email\Test\Unit\Block\Adminhtml\Template;
99

10+
use Magento\Backend\Block\Template\Context;
11+
use Magento\Backend\Block\Widget\Button\ButtonList;
12+
use Magento\Backend\Block\Widget\Button\ToolbarInterface;
13+
use Magento\Backend\Model\Menu\Item\Factory;
1014
use Magento\Backend\Helper\Data;
1115
use Magento\Backend\Model\Menu;
1216
use Magento\Backend\Model\Menu\Config;
1317
use Magento\Backend\Model\Menu\Item;
14-
use Magento\Backend\Model\Url;
1518
use Magento\Config\Model\Config\Structure;
1619
use Magento\Config\Model\Config\Structure\Element\Field;
1720
use Magento\Config\Model\Config\Structure\Element\Group;
1821
use Magento\Config\Model\Config\Structure\Element\Section;
1922
use Magento\Email\Block\Adminhtml\Template\Edit;
2023
use Magento\Email\Model\BackendTemplate;
24+
use Magento\Framework\App\Config\ScopeConfigInterface;
2125
use Magento\Framework\App\Filesystem\DirectoryList;
26+
use Magento\Framework\App\State;
27+
use Magento\Framework\Event\ManagerInterface;
2228
use Magento\Framework\Filesystem;
2329
use Magento\Framework\Filesystem\Directory\Read;
24-
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
30+
use Magento\Framework\Json\EncoderInterface;
31+
use Magento\Framework\Json\Helper\Data as JsonHelper;
32+
use Magento\Framework\Registry;
33+
use Magento\Framework\Serialize\SerializerInterface;
34+
use Magento\Framework\UrlInterface;
35+
use Magento\Framework\View\Element\Template\File\Resolver;
36+
use Magento\Framework\View\Element\Template\File\Validator;
2537
use Magento\Framework\View\FileSystem as FilesystemView;
2638
use Magento\Framework\View\Layout;
39+
use Magento\Store\Model\StoreManagerInterface;
2740
use PHPUnit\Framework\MockObject\MockObject;
2841
use PHPUnit\Framework\TestCase;
2942
use Psr\Log\LoggerInterface;
@@ -62,20 +75,29 @@ class EditTest extends TestCase
6275
*/
6376
protected $filesystemMock;
6477

78+
/**
79+
* @var Context|MockObject
80+
*/
81+
private Context $context;
82+
6583
protected function setUp(): void
6684
{
67-
$objectManager = new ObjectManager($this);
6885
$layoutMock = $this->getMockBuilder(Layout::class)
6986
->addMethods(['helper'])
7087
->disableOriginalConstructor()
7188
->getMock();
7289
$helperMock = $this->createMock(Data::class);
7390
$menuConfigMock = $this->createMock(Config::class);
7491
$menuMock = $this->getMockBuilder(Menu::class)
75-
->setConstructorArgs([$this->getMockForAbstractClass(LoggerInterface::class)])
76-
->getMock();
92+
->setConstructorArgs(
93+
[
94+
$this->getMockForAbstractClass(LoggerInterface::class),
95+
'',
96+
$this->createMock(Factory::class),
97+
$this->createMock(SerializerInterface::class)
98+
]
99+
)->getMock();
77100
$menuItemMock = $this->createMock(Item::class);
78-
$urlBuilder = $this->createMock(Url::class);
79101
$this->_configStructureMock = $this->createMock(Structure::class);
80102
$this->_emailConfigMock = $this->createMock(\Magento\Email\Model\Template\Config::class);
81103

@@ -96,20 +118,29 @@ protected function setUp(): void
96118
)->willReturn(
97119
DirectoryList::ROOT . '/custom/filename.phtml'
98120
);
99-
100-
$params = [
101-
'urlBuilder' => $urlBuilder,
102-
'layout' => $layoutMock,
103-
'menuConfig' => $menuConfigMock,
104-
'configStructure' => $this->_configStructureMock,
105-
'emailConfig' => $this->_emailConfigMock,
106-
'filesystem' => $this->filesystemMock,
107-
'viewFileSystem' => $viewFilesystem,
108-
];
109-
$arguments = $objectManager->getConstructArguments(
110-
Edit::class,
111-
$params
112-
);
121+
$this->context = $this->createMock(Context::class);
122+
$this->context->expects($this->any())->method('getStoreManager')
123+
->willReturn($this->createMock(StoreManagerInterface::class));
124+
$urlBuilder = $this->createMock(UrlInterface::class);
125+
$this->context->expects($this->any())->method('getUrlBuilder')->willReturn($urlBuilder);
126+
$eventManager = $this->createMock(ManagerInterface::class);
127+
$this->context->expects($this->any())->method('getEventManager')->willReturn($eventManager);
128+
$scopeConfig = $this->createMock(ScopeConfigInterface::class);
129+
$this->context->expects($this->any())->method('getScopeConfig')->willReturn($scopeConfig);
130+
$appState = $this->createMock(State::class);
131+
$this->context->expects($this->any())->method('getAppState')->willReturn($appState);
132+
$resolver = $this->createMock(Resolver::class);
133+
$this->context->expects($this->any())->method('getResolver')->willReturn($resolver);
134+
$fileSystem = $this->createMock(Filesystem::class);
135+
$fileSystem->expects($this->any())
136+
->method('getDirectoryRead')
137+
->willReturn($this->createMock(Read::class));
138+
$this->context->expects($this->any())->method('getFilesystem')->willReturn($fileSystem);
139+
$validator = $this->createMock(Validator::class);
140+
$this->context->expects($this->any())->method('getValidator')->willReturn($validator);
141+
$this->context->expects($this->any())
142+
->method('getLogger')
143+
->willReturn($this->createMock(LoggerInterface::class));
113144

114145
$urlBuilder->expects($this->any())->method('getUrl')->willReturnArgument(0);
115146
$menuConfigMock->expects($this->any())->method('getMenu')->willReturn($menuMock);
@@ -118,7 +149,25 @@ protected function setUp(): void
118149

119150
$layoutMock->expects($this->any())->method('helper')->willReturn($helperMock);
120151

121-
$this->_block = $objectManager->getObject(Edit::class, $arguments);
152+
$encoder = $this->createMock(EncoderInterface::class);
153+
$registry = $this->createMock(Registry::class);
154+
$jsonHelper = $this->createMock(JsonHelper::class);
155+
$buttonList = $this->createMock(ButtonList::class);
156+
$toolbar = $this->createMock(ToolbarInterface::class);
157+
$this->_block = new Edit(
158+
$this->context,
159+
$encoder,
160+
$registry,
161+
$menuConfigMock,
162+
$this->_configStructureMock,
163+
$this->_emailConfigMock,
164+
$jsonHelper,
165+
$buttonList,
166+
$toolbar,
167+
[
168+
'directoryHelper' => $this->createMock(\Magento\Directory\Helper\Data::class)
169+
]
170+
);
122171
}
123172

124173
/**
@@ -148,6 +197,7 @@ public function testGetCurrentlyUsedForPaths()
148197
['getLabel']
149198
);
150199
$map = [
200+
[['section1'], $sectionMock],
151201
[['section1', 'group1'], $groupMock1],
152202
[['section1', 'group1', 'group2'], $groupMock2],
153203
[['section1', 'group1', 'group2', 'group3'], $groupMock3],

app/code/Magento/Theme/Test/Unit/Block/Html/TopmenuTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -213,7 +213,7 @@ public function testGetCacheKeyInfo(): void
213213
->onlyMethods(['getCode'])
214214
->getMock();
215215
$store->expects($this->once())->method('getCode')->willReturn('321');
216-
$this->storeManager->expects($this->once())->method('getStore')->willReturn($store);
216+
$this->storeManager->expects($this->exactly(2))->method('getStore')->willReturn($store);
217217

218218
$this->assertEquals(
219219
['BLOCK_TPL', '321', null, 'base_url' => 'baseUrl', 'template' => null],

lib/internal/Magento/Framework/View/Element/Template.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2011 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\Framework\View\Element;
77

@@ -35,7 +35,7 @@ class Template extends AbstractBlock
3535
/**
3636
* Config path to 'Allow Symlinks' template settings
3737
*/
38-
const XML_PATH_TEMPLATE_ALLOW_SYMLINK = 'dev/template/allow_symlink';
38+
public const XML_PATH_TEMPLATE_ALLOW_SYMLINK = 'dev/template/allow_symlink';
3939

4040
/**
4141
* Assigned variables for view
@@ -211,6 +211,7 @@ public function getTemplateFile($template = null)
211211
if ($area) {
212212
$params['area'] = $area;
213213
}
214+
$params['store_id'] = $this->_storeManager->getStore()?->getId();
214215
return $this->resolver->getTemplateFileName($template ?: $this->getTemplate(), $params);
215216
}
216217

lib/internal/Magento/Framework/View/Test/Unit/Element/TemplateTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2013 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -107,6 +107,7 @@ protected function setUp(): void
107107
$storeMock->expects($this->any())
108108
->method('getCode')
109109
->willReturn('storeCode');
110+
$storeMock->expects($this->any())->method('getId')->willReturn(1);
110111
$urlBuilderMock = $this->getMockForAbstractClass(UrlInterface::class);
111112
$urlBuilderMock->expects($this->any())
112113
->method('getBaseUrl')
@@ -130,7 +131,7 @@ protected function setUp(): void
130131

131132
public function testGetTemplateFile()
132133
{
133-
$params = ['module' => 'Fixture_Module', 'area' => 'frontend'];
134+
$params = ['module' => 'Fixture_Module', 'area' => 'frontend', 'store_id' => 1];
134135
$this->resolver->expects($this->once())->method('getTemplateFileName')->with('template.phtml', $params);
135136
$this->block->getTemplateFile();
136137
}

0 commit comments

Comments
 (0)