@@ -49,18 +49,18 @@ protected function setUp()
49
49
{
50
50
$ context = $ this ->createMock (\Magento \Backend \Block \Template \Context::class);
51
51
$ 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 );
53
53
$ 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 );
55
55
$ 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 );
57
57
$ this ->storeManager = $ this ->createPartialMock (
58
58
\Magento \Store \Model \StoreManager::class,
59
59
['getStores ' , 'getDefaultStoreView ' ]
60
60
);
61
- $ context ->expects ($ this ->once ())->method ('getStoreManager ' )->will ($ this ->returnValue ( $ this -> storeManager ) );
61
+ $ context ->expects ($ this ->once ())->method ('getStoreManager ' )->willReturn ($ this ->storeManager );
62
62
$ 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 );
64
64
65
65
$ backendSession = $ this ->getMockBuilder (\Magento \Backend \Model \Session::class)
66
66
->disableOriginalConstructor ()
@@ -69,16 +69,34 @@ protected function setUp()
69
69
$ context ->expects ($ this ->once ())->method ('getBackendSession ' )->willReturn ($ backendSession );
70
70
71
71
$ 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 );
74
83
75
84
$ subscriberFactory = $ this ->createPartialMock (\Magento \Newsletter \Model \SubscriberFactory::class, ['create ' ]);
76
85
$ 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 );
78
87
79
88
$ 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 );
82
100
83
101
$ this ->objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
84
102
@@ -100,27 +118,37 @@ public function testToHtmlEmpty()
100
118
{
101
119
/** @var \Magento\Store\Model\Store $store */
102
120
$ 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 );
104
122
$ result = $ this ->preview ->toHtml ();
105
123
$ this ->assertEquals ('' , $ result );
106
124
}
107
125
108
126
public function testToHtmlWithId ()
109
127
{
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
+ ]
117
137
);
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 );
120
148
/** @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 );
122
150
$ 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 ]);
124
152
$ result = $ this ->preview ->toHtml ();
125
153
$ this ->assertEquals ('<pre></pre> ' , $ result );
126
154
}
0 commit comments