@@ -58,6 +58,15 @@ class ReviewTest extends \PHPUnit_Framework_TestCase
58
58
*/
59
59
private $ store ;
60
60
61
+ /** @var \Magento\Framework\View\Element\Template\Context|\PHPUnit_Framework_MockObject_MockObject */
62
+ protected $ context ;
63
+
64
+ /** @var \Magento\Framework\UrlInterface|PHPUnit_Framework_MockObject_MockObject */
65
+ protected $ urlBuilder ;
66
+
67
+ /** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */
68
+ protected $ requestMock ;
69
+
61
70
protected function setUp ()
62
71
{
63
72
$ this ->initContextMock ();
@@ -66,7 +75,7 @@ protected function setUp()
66
75
67
76
$ helper = new ObjectManager ($ this );
68
77
$ this ->block = $ helper ->getObject (ReviewBlock::class, [
69
- 'storeManager ' => $ this ->storeManager ,
78
+ 'context ' => $ this ->context ,
70
79
'registry ' => $ this ->registry ,
71
80
'collectionFactory ' => $ this ->collectionFactory ,
72
81
]);
@@ -124,7 +133,7 @@ private function initRegistryMock()
124
133
->setMethods (['registry ' ])
125
134
->getMock ();
126
135
127
- $ this ->registry ->expects (static :: once ())
136
+ $ this ->registry ->expects ($ this -> any ())
128
137
->method ('registry ' )
129
138
->with ('product ' )
130
139
->willReturn ($ this ->product );
@@ -159,5 +168,44 @@ private function initContextMock()
159
168
$ this ->storeManager ->expects (static ::any ())
160
169
->method ('getStore ' )
161
170
->willReturn ($ this ->store );
171
+ $ this ->urlBuilder = $ this ->getMockBuilder ('Magento\Framework\UrlInterface ' )->getMockForAbstractClass ();
172
+ $ this ->requestMock = $ this ->getMockBuilder ('Magento\Framework\App\RequestInterface ' )
173
+ ->getMockForAbstractClass ();
174
+ $ this ->context = $ this ->getMockBuilder ('Magento\Framework\View\Element\Template\Context ' )
175
+ ->disableOriginalConstructor ()
176
+ ->getMock ();
177
+ $ this ->context ->expects ($ this ->any ())->method ('getRequest ' )->willReturn ($ this ->requestMock );
178
+ $ this ->context ->expects ($ this ->any ())->method ('getUrlBuilder ' )->willReturn ($ this ->urlBuilder );
179
+ $ this ->context ->expects ($ this ->any ())->method ('getStoreManager ' )->willReturn ($ this ->storeManager );
180
+ }
181
+
182
+ /**
183
+ * @param bool $isSecure
184
+ * @param string $actionUrl
185
+ * @param int $productId
186
+ * @dataProvider getProductReviewUrlDataProvider
187
+ */
188
+ public function testGetProductReviewUrl ($ isSecure , $ actionUrl , $ productId )
189
+ {
190
+ $ this ->urlBuilder ->expects ($ this ->any ())
191
+ ->method ('getUrl ' )
192
+ ->with ('review/product/listAjax ' , ['_secure ' => $ isSecure , 'id ' => $ productId ])
193
+ ->willReturn ($ actionUrl . '/id/ ' . $ productId );
194
+ $ this ->product ->expects ($ this ->any ())
195
+ ->method ('getId ' )
196
+ ->willReturn ($ productId );
197
+ $ this ->requestMock ->expects ($ this ->any ())
198
+ ->method ('isSecure ' )
199
+ ->willReturn ($ isSecure );
200
+
201
+ $ this ->assertEquals ($ actionUrl . '/id/ ' . $ productId , $ this ->block ->getProductReviewUrl ());
202
+ }
203
+
204
+ public function getProductReviewUrlDataProvider ()
205
+ {
206
+ return [
207
+ [false , 'http://localhost/review/product/listAjax ' , 3 ],
208
+ [true , 'https://localhost/review/product/listAjax ' ,3 ],
209
+ ];
162
210
}
163
211
}
0 commit comments