@@ -58,6 +58,15 @@ class ReviewTest extends \PHPUnit_Framework_TestCase
5858 */
5959 private $ store ;
6060
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+
6170 protected function setUp ()
6271 {
6372 $ this ->initContextMock ();
@@ -66,7 +75,7 @@ protected function setUp()
6675
6776 $ helper = new ObjectManager ($ this );
6877 $ this ->block = $ helper ->getObject (ReviewBlock::class, [
69- 'storeManager ' => $ this ->storeManager ,
78+ 'context ' => $ this ->context ,
7079 'registry ' => $ this ->registry ,
7180 'collectionFactory ' => $ this ->collectionFactory ,
7281 ]);
@@ -124,7 +133,7 @@ private function initRegistryMock()
124133 ->setMethods (['registry ' ])
125134 ->getMock ();
126135
127- $ this ->registry ->expects (static :: once ())
136+ $ this ->registry ->expects ($ this -> any ())
128137 ->method ('registry ' )
129138 ->with ('product ' )
130139 ->willReturn ($ this ->product );
@@ -159,5 +168,44 @@ private function initContextMock()
159168 $ this ->storeManager ->expects (static ::any ())
160169 ->method ('getStore ' )
161170 ->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+ ];
162210 }
163211}
0 commit comments