diff --git a/app/code/Magento/Review/Block/Form.php b/app/code/Magento/Review/Block/Form.php index 61183ec7ceb223bff316bad8e4da73b581a2d979..8efe29b58e719a8c421ccd2e09bd7b9c96565d13 100644 --- a/app/code/Magento/Review/Block/Form.php +++ b/app/code/Magento/Review/Block/Form.php @@ -161,7 +161,7 @@ class Form extends \Magento\Framework\View\Element\Template return $this->getUrl( 'review/product/post', [ - '_secure' => $this->_request->isSecure(), + '_secure' => $this->getRequest()->isSecure(), 'id' => $this->getProductId(), ] ); diff --git a/app/code/Magento/Review/Block/Product/Review.php b/app/code/Magento/Review/Block/Product/Review.php index b6d03c885d6462d2811e68774e2fa402a67f628d..bae4bd8dc5db56001f9e808f34b0fe5533ba7bbc 100644 --- a/app/code/Magento/Review/Block/Product/Review.php +++ b/app/code/Magento/Review/Block/Product/Review.php @@ -69,7 +69,7 @@ class Review extends Template implements IdentityInterface return $this->getUrl( 'review/product/listAjax', [ - '_secure' => $this->_request->isSecure(), + '_secure' => $this->getRequest()->isSecure(), 'id' => $this->getProductId(), ] ); diff --git a/app/code/Magento/Review/Test/Unit/Block/FormTest.php b/app/code/Magento/Review/Test/Unit/Block/FormTest.php index 03f004f470c5727ad38c252c7503bd00dfca163e..c806cc6f2452b2c3f73e5018c0e598a7a44b4f5f 100644 --- a/app/code/Magento/Review/Test/Unit/Block/FormTest.php +++ b/app/code/Magento/Review/Test/Unit/Block/FormTest.php @@ -34,6 +34,9 @@ class FormTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $storeManager; + /** @var \Magento\Framework\UrlInterface|PHPUnit_Framework_MockObject_MockObject */ + protected $urlBuilder; + protected function setUp() { $this->storeManager = $this->getMock('\Magento\Store\Model\StoreManagerInterface'); @@ -46,6 +49,7 @@ class FormTest extends \PHPUnit_Framework_TestCase ->method('getIsGuestAllowToWrite') ->willReturn(true); + $this->urlBuilder = $this->getMockBuilder('Magento\Framework\UrlInterface')->getMockForAbstractClass(); $this->context = $this->getMock('Magento\Framework\View\Element\Template\Context', [], [], '', false); $this->context->expects( $this->any() @@ -57,6 +61,7 @@ class FormTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->any()) ->method('getRequest') ->willReturn($this->requestMock); + $this->context->expects($this->any())->method('getUrlBuilder')->willReturn($this->urlBuilder); $this->productRepository = $this->getMock('\Magento\Catalog\Api\ProductRepositoryInterface'); $this->objectManagerHelper = new ObjectManagerHelper($this); @@ -96,4 +101,35 @@ class FormTest extends \PHPUnit_Framework_TestCase $this->assertSame($productMock, $this->object->getProductInfo()); } + + /** + * @param bool $isSecure + * @param string $actionUrl + * @param int $productId + * @dataProvider getActionDataProvider + */ + public function testGetAction($isSecure, $actionUrl, $productId) + { + $this->urlBuilder->expects($this->any()) + ->method('getUrl') + ->with('review/product/post', ['_secure' => $isSecure, 'id' => $productId]) + ->willReturn($actionUrl . '/id/' . $productId); + $this->requestMock->expects($this->any()) + ->method('getParam') + ->with('id', false) + ->willReturn($productId); + $this->requestMock->expects($this->any()) + ->method('isSecure') + ->willReturn($isSecure); + + $this->assertEquals($actionUrl . '/id/' . $productId , $this->object->getAction()); + } + + public function getActionDataProvider() + { + return [ + [false, 'http://localhost/review/product/post', 3], + [true, 'https://localhost/review/product/post' ,3], + ]; + } } diff --git a/app/code/Magento/Review/Test/Unit/Block/Product/ReviewTest.php b/app/code/Magento/Review/Test/Unit/Block/Product/ReviewTest.php index 0bc6dd49473e2f59ec96f7313e98a4bdc1f32963..d43824ac167a88bd86304c1982822c782042eaae 100644 --- a/app/code/Magento/Review/Test/Unit/Block/Product/ReviewTest.php +++ b/app/code/Magento/Review/Test/Unit/Block/Product/ReviewTest.php @@ -58,6 +58,15 @@ class ReviewTest extends \PHPUnit_Framework_TestCase */ private $store; + /** @var \Magento\Framework\View\Element\Template\Context|\PHPUnit_Framework_MockObject_MockObject */ + protected $context; + + /** @var \Magento\Framework\UrlInterface|PHPUnit_Framework_MockObject_MockObject */ + protected $urlBuilder; + + /** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */ + protected $requestMock; + protected function setUp() { $this->initContextMock(); @@ -66,7 +75,7 @@ class ReviewTest extends \PHPUnit_Framework_TestCase $helper = new ObjectManager($this); $this->block = $helper->getObject(ReviewBlock::class, [ - 'storeManager' => $this->storeManager, + 'context' => $this->context, 'registry' => $this->registry, 'collectionFactory' => $this->collectionFactory, ]); @@ -124,7 +133,7 @@ class ReviewTest extends \PHPUnit_Framework_TestCase ->setMethods(['registry']) ->getMock(); - $this->registry->expects(static::once()) + $this->registry->expects($this->any()) ->method('registry') ->with('product') ->willReturn($this->product); @@ -159,5 +168,44 @@ class ReviewTest extends \PHPUnit_Framework_TestCase $this->storeManager->expects(static::any()) ->method('getStore') ->willReturn($this->store); + $this->urlBuilder = $this->getMockBuilder('Magento\Framework\UrlInterface')->getMockForAbstractClass(); + $this->requestMock = $this->getMockBuilder('Magento\Framework\App\RequestInterface') + ->getMockForAbstractClass(); + $this->context = $this->getMockBuilder('Magento\Framework\View\Element\Template\Context') + ->disableOriginalConstructor() + ->getMock(); + $this->context->expects($this->any())->method('getRequest')->willReturn($this->requestMock); + $this->context->expects($this->any())->method('getUrlBuilder')->willReturn($this->urlBuilder); + $this->context->expects($this->any())->method('getStoreManager')->willReturn($this->storeManager); + } + + /** + * @param bool $isSecure + * @param string $actionUrl + * @param int $productId + * @dataProvider getProductReviewUrlDataProvider + */ + public function testGetProductReviewUrl($isSecure, $actionUrl, $productId) + { + $this->urlBuilder->expects($this->any()) + ->method('getUrl') + ->with('review/product/listAjax', ['_secure' => $isSecure, 'id' => $productId]) + ->willReturn($actionUrl . '/id/' . $productId); + $this->product->expects($this->any()) + ->method('getId') + ->willReturn($productId); + $this->requestMock->expects($this->any()) + ->method('isSecure') + ->willReturn($isSecure); + + $this->assertEquals($actionUrl . '/id/' . $productId , $this->block->getProductReviewUrl()); + } + + public function getProductReviewUrlDataProvider() + { + return [ + [false, 'http://localhost/review/product/listAjax', 3], + [true, 'https://localhost/review/product/listAjax' ,3], + ]; } }