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 */
66declare (strict_types=1 );
77
88namespace 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 ;
1014use Magento \Backend \Helper \Data ;
1115use Magento \Backend \Model \Menu ;
1216use Magento \Backend \Model \Menu \Config ;
1317use Magento \Backend \Model \Menu \Item ;
14- use Magento \Backend \Model \Url ;
1518use Magento \Config \Model \Config \Structure ;
1619use Magento \Config \Model \Config \Structure \Element \Field ;
1720use Magento \Config \Model \Config \Structure \Element \Group ;
1821use Magento \Config \Model \Config \Structure \Element \Section ;
1922use Magento \Email \Block \Adminhtml \Template \Edit ;
2023use Magento \Email \Model \BackendTemplate ;
24+ use Magento \Framework \App \Config \ScopeConfigInterface ;
2125use Magento \Framework \App \Filesystem \DirectoryList ;
26+ use Magento \Framework \App \State ;
27+ use Magento \Framework \Event \ManagerInterface ;
2228use Magento \Framework \Filesystem ;
2329use 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 ;
2537use Magento \Framework \View \FileSystem as FilesystemView ;
2638use Magento \Framework \View \Layout ;
39+ use Magento \Store \Model \StoreManagerInterface ;
2740use PHPUnit \Framework \MockObject \MockObject ;
2841use PHPUnit \Framework \TestCase ;
2942use 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 ],
0 commit comments