16
16
use Magento \Framework \Escaper ;
17
17
use Magento \Framework \Event \ManagerInterface ;
18
18
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
19
- use Magento \Newsletter \Block \Adminhtml \Queue \Preview ;
19
+ use Magento \Newsletter \Block \Adminhtml \Queue \Preview as QueuePreview ;
20
20
use Magento \Newsletter \Model \Queue ;
21
21
use Magento \Newsletter \Model \QueueFactory ;
22
22
use Magento \Newsletter \Model \Subscriber ;
32
32
/**
33
33
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
34
34
*/
35
- class PreviewTest extends TestCase
35
+ class PreviewTest extends \ PHPUnit \ Framework \ TestCase
36
36
{
37
37
/**
38
38
* @var ObjectManager
39
39
*/
40
- protected $ objectManager ;
40
+ private $ objectManager ;
41
41
42
42
/**
43
43
* @var Template|MockObject
44
44
*/
45
- protected $ template ;
45
+ private $ templateMock ;
46
46
47
47
/**
48
48
* @var RequestInterface|MockObject
49
49
*/
50
- protected $ request ;
50
+ private $ requestMock ;
51
51
52
52
/**
53
53
* @var Subscriber|MockObject
54
54
*/
55
- protected $ subscriber ;
55
+ private $ subscriberMock ;
56
56
57
57
/**
58
58
* @var Queue|MockObject
59
59
*/
60
- protected $ queue ;
60
+ private $ queueMock ;
61
61
62
62
/**
63
63
* @var StoreManagerInterface|MockObject
64
64
*/
65
- protected $ storeManager ;
65
+ private $ storeManagerMock ;
66
66
67
67
/**
68
- * @var Preview
68
+ * @var QueuePreview
69
69
*/
70
- protected $ preview ;
70
+ private $ preview ;
71
71
72
72
protected function setUp (): void
73
73
{
74
74
$ context = $ this ->createMock (Context::class);
75
75
$ eventManager = $ this ->createMock (ManagerInterface::class);
76
- $ context ->expects ($ this ->once ())->method ('getEventManager ' )->will ($ this ->returnValue ($ eventManager ));
76
+ $ context ->expects ($ this ->once ())->method ('getEventManager ' )
77
+ ->will ($ this ->returnValue ($ eventManager ));
77
78
$ scopeConfig = $ this ->createMock (ScopeConfigInterface::class);
78
- $ context ->expects ($ this ->once ())->method ('getScopeConfig ' )->will ($ this ->returnValue ($ scopeConfig ));
79
- $ this ->request = $ this ->createMock (Http::class);
80
- $ context ->expects ($ this ->once ())->method ('getRequest ' )->will ($ this ->returnValue ($ this ->request ));
81
- $ this ->storeManager = $ this ->createPartialMock (
79
+ $ context ->expects ($ this ->once ())->method ('getScopeConfig ' )
80
+ ->will ($ this ->returnValue ($ scopeConfig ));
81
+ $ this ->requestMock = $ this ->createMock (Http::class);
82
+ $ context ->expects ($ this ->once ())->method ('getRequest ' )
83
+ ->will ($ this ->returnValue ($ this ->requestMock ));
84
+ $ this ->storeManagerMock = $ this ->createPartialMock (
82
85
StoreManager::class,
83
86
['getStores ' , 'getDefaultStoreView ' ]
84
87
);
85
- $ context ->expects ($ this ->once ())->method ('getStoreManager ' )->will ($ this ->returnValue ($ this ->storeManager ));
88
+ $ context ->expects ($ this ->once ())->method ('getStoreManager ' )
89
+ ->will ($ this ->returnValue ($ this ->storeManagerMock ));
86
90
$ appState = $ this ->createMock (State::class);
87
- $ context ->expects ($ this ->once ())->method ('getAppState ' )->will ($ this ->returnValue ($ appState ));
91
+ $ context ->expects ($ this ->once ())->method ('getAppState ' )
92
+ ->will ($ this ->returnValue ($ appState ));
88
93
89
94
$ backendSession = $ this ->getMockBuilder (Session::class)
90
95
->disableOriginalConstructor ()
91
96
->getMock ();
92
97
93
- $ context ->expects ($ this ->once ())->method ('getBackendSession ' )->willReturn ($ backendSession );
98
+ $ context ->expects ($ this ->once ())
99
+ ->method ('getBackendSession ' )
100
+ ->willReturn ($ backendSession );
94
101
95
102
$ templateFactory = $ this ->createPartialMock (TemplateFactory::class, ['create ' ]);
96
- $ this ->template = $ this ->createMock (Template::class);
97
- $ templateFactory ->expects ($ this ->once ())->method ('create ' )->will ($ this ->returnValue ($ this ->template ));
103
+ $ this ->templateMock = $ this ->createMock (Template::class);
104
+ $ templateFactory ->expects ($ this ->once ())
105
+ ->method ('create ' )
106
+ ->will ($ this ->returnValue ($ this ->templateMock ));
98
107
99
108
$ subscriberFactory = $ this ->createPartialMock (SubscriberFactory::class, ['create ' ]);
100
- $ this ->subscriber = $ this ->createMock (Subscriber::class);
101
- $ subscriberFactory ->expects ($ this ->once ())->method ('create ' )->will ($ this ->returnValue ($ this ->subscriber ));
109
+ $ this ->subscriberMock = $ this ->createMock (Subscriber::class);
110
+ $ subscriberFactory ->expects ($ this ->once ())
111
+ ->method ('create ' )
112
+ ->will ($ this ->returnValue ($ this ->subscriberMock ));
102
113
103
114
$ queueFactory = $ this ->createPartialMock (QueueFactory::class, ['create ' ]);
104
- $ this ->queue = $ this ->createPartialMock (Queue::class, ['load ' ]);
105
- $ queueFactory ->expects ($ this ->any ())->method ('create ' )->will ($ this ->returnValue ($ this ->queue ));
115
+ $ this ->queueMock = $ this ->createPartialMock (Queue::class, ['load ' ]);
116
+ $ queueFactory ->expects ($ this ->any ())
117
+ ->method ('create ' )
118
+ ->will ($ this ->returnValue ($ this ->queueMock ));
106
119
107
120
$ this ->objectManager = new ObjectManager ($ this );
108
121
109
122
$ escaper = $ this ->objectManager ->getObject (Escaper::class);
110
- $ context ->expects ($ this ->once ())->method ('getEscaper ' )->willReturn ($ escaper );
123
+ $ context ->expects ($ this ->once ())
124
+ ->method ('getEscaper ' )
125
+ ->willReturn ($ escaper );
111
126
112
127
$ this ->preview = $ this ->objectManager ->getObject (
113
- Preview ::class,
128
+ QueuePreview ::class,
114
129
[
115
130
'context ' => $ context ,
116
131
'templateFactory ' => $ templateFactory ,
@@ -124,27 +139,37 @@ public function testToHtmlEmpty()
124
139
{
125
140
/** @var Store $store */
126
141
$ store = $ this ->createPartialMock (Store::class, ['getId ' ]);
127
- $ this ->storeManager ->expects ($ this ->once ())->method ('getDefaultStoreView ' )->will ($ this ->returnValue ($ store ));
142
+ $ this ->storeManagerMock ->expects ($ this ->once ())
143
+ ->method ('getDefaultStoreView ' )
144
+ ->will ($ this ->returnValue ($ store ));
128
145
$ result = $ this ->preview ->toHtml ();
129
146
$ this ->assertEquals ('' , $ result );
130
147
}
131
148
132
149
public function testToHtmlWithId ()
133
150
{
134
- $ this ->request ->expects ($ this ->any ())->method ('getParam ' )->will (
151
+ $ this ->requestMock ->expects ($ this ->any ())->method ('getParam ' )->will (
135
152
$ this ->returnValueMap (
136
153
[
137
154
['id ' , null , 1 ],
138
155
['store_id ' , null , 0 ]
139
156
]
140
157
)
141
158
);
142
- $ this ->queue ->expects ($ this ->once ())->method ('load ' )->will ($ this ->returnSelf ());
143
- $ this ->template ->expects ($ this ->any ())->method ('isPlain ' )->will ($ this ->returnValue (true ));
159
+ $ this ->queueMock ->expects ($ this ->once ())
160
+ ->method ('load ' )
161
+ ->will ($ this ->returnSelf ());
162
+ $ this ->templateMock ->expects ($ this ->any ())
163
+ ->method ('isPlain ' )
164
+ ->will ($ this ->returnValue (true ));
144
165
/** @var Store $store */
145
- $ this ->storeManager ->expects ($ this ->once ())->method ('getDefaultStoreView ' )->will ($ this ->returnValue (null ));
166
+ $ this ->storeManagerMock ->expects ($ this ->once ())
167
+ ->method ('getDefaultStoreView ' )
168
+ ->will ($ this ->returnValue (null ));
146
169
$ store = $ this ->createPartialMock (Store::class, ['getId ' ]);
147
- $ this ->storeManager ->expects ($ this ->once ())->method ('getStores ' )->will ($ this ->returnValue ([0 => $ store ]));
170
+ $ this ->storeManagerMock ->expects ($ this ->once ())
171
+ ->method ('getStores ' )
172
+ ->will ($ this ->returnValue ([0 => $ store ]));
148
173
$ result = $ this ->preview ->toHtml ();
149
174
$ this ->assertEquals ('<pre></pre> ' , $ result );
150
175
}
0 commit comments