From a31accc7e248ce1ebb04aaa2cc109aedf2053e27 Mon Sep 17 00:00:00 2001 From: Maxim Medinskiy <mmedinskiy@ebay.com> Date: Thu, 29 Oct 2015 19:02:22 +0200 Subject: [PATCH] MAGETWO-44723: Errors related to mixed content after redirecting from wishlist to product page when secure URLs for storefront used --- app/code/Magento/Review/Block/Form.php | 2 +- .../Magento/Review/Block/Product/Review.php | 2 +- .../Review/Test/Unit/Block/FormTest.php | 36 +++++++++++++ .../Test/Unit/Block/Product/ReviewTest.php | 52 ++++++++++++++++++- 4 files changed, 88 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Review/Block/Form.php b/app/code/Magento/Review/Block/Form.php index 61183ec7ceb..8efe29b58e7 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 b6d03c885d6..bae4bd8dc5d 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 03f004f470c..c806cc6f245 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 0bc6dd49473..d43824ac167 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], + ]; } } -- GitLab