1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2013 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
declare (strict_types=1 );
7
7
8
8
namespace Magento \Email \Test \Unit \Block \Adminhtml \Template ;
9
9
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 ;
10
14
use Magento \Backend \Helper \Data ;
11
15
use Magento \Backend \Model \Menu ;
12
16
use Magento \Backend \Model \Menu \Config ;
13
17
use Magento \Backend \Model \Menu \Item ;
14
- use Magento \Backend \Model \Url ;
15
18
use Magento \Config \Model \Config \Structure ;
16
19
use Magento \Config \Model \Config \Structure \Element \Field ;
17
20
use Magento \Config \Model \Config \Structure \Element \Group ;
18
21
use Magento \Config \Model \Config \Structure \Element \Section ;
19
22
use Magento \Email \Block \Adminhtml \Template \Edit ;
20
23
use Magento \Email \Model \BackendTemplate ;
24
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
21
25
use Magento \Framework \App \Filesystem \DirectoryList ;
26
+ use Magento \Framework \App \State ;
27
+ use Magento \Framework \Event \ManagerInterface ;
22
28
use Magento \Framework \Filesystem ;
23
29
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 ;
25
37
use Magento \Framework \View \FileSystem as FilesystemView ;
26
38
use Magento \Framework \View \Layout ;
39
+ use Magento \Store \Model \StoreManagerInterface ;
27
40
use PHPUnit \Framework \MockObject \MockObject ;
28
41
use PHPUnit \Framework \TestCase ;
29
42
use Psr \Log \LoggerInterface ;
@@ -62,20 +75,29 @@ class EditTest extends TestCase
62
75
*/
63
76
protected $ filesystemMock ;
64
77
78
+ /**
79
+ * @var Context|MockObject
80
+ */
81
+ private Context $ context ;
82
+
65
83
protected function setUp (): void
66
84
{
67
- $ objectManager = new ObjectManager ($ this );
68
85
$ layoutMock = $ this ->getMockBuilder (Layout::class)
69
86
->addMethods (['helper ' ])
70
87
->disableOriginalConstructor ()
71
88
->getMock ();
72
89
$ helperMock = $ this ->createMock (Data::class);
73
90
$ menuConfigMock = $ this ->createMock (Config::class);
74
91
$ 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 ();
77
100
$ menuItemMock = $ this ->createMock (Item::class);
78
- $ urlBuilder = $ this ->createMock (Url::class);
79
101
$ this ->_configStructureMock = $ this ->createMock (Structure::class);
80
102
$ this ->_emailConfigMock = $ this ->createMock (\Magento \Email \Model \Template \Config::class);
81
103
@@ -96,20 +118,29 @@ protected function setUp(): void
96
118
)->willReturn (
97
119
DirectoryList::ROOT . '/custom/filename.phtml '
98
120
);
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));
113
144
114
145
$ urlBuilder ->expects ($ this ->any ())->method ('getUrl ' )->willReturnArgument (0 );
115
146
$ menuConfigMock ->expects ($ this ->any ())->method ('getMenu ' )->willReturn ($ menuMock );
@@ -118,7 +149,25 @@ protected function setUp(): void
118
149
119
150
$ layoutMock ->expects ($ this ->any ())->method ('helper ' )->willReturn ($ helperMock );
120
151
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
+ );
122
171
}
123
172
124
173
/**
@@ -148,6 +197,7 @@ public function testGetCurrentlyUsedForPaths()
148
197
['getLabel ' ]
149
198
);
150
199
$ map = [
200
+ [['section1 ' ], $ sectionMock ],
151
201
[['section1 ' , 'group1 ' ], $ groupMock1 ],
152
202
[['section1 ' , 'group1 ' , 'group2 ' ], $ groupMock2 ],
153
203
[['section1 ' , 'group1 ' , 'group2 ' , 'group3 ' ], $ groupMock3 ],
0 commit comments