Skip to content
Snippets Groups Projects
Commit a31accc7 authored by Maxim Medinskiy's avatar Maxim Medinskiy
Browse files

MAGETWO-44723: Errors related to mixed content after redirecting from wishlist...

MAGETWO-44723: Errors related to mixed content after redirecting from wishlist to product page when secure URLs for storefront used
parent c6f2fb05
Branches
No related merge requests found
......@@ -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(),
]
);
......
......@@ -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(),
]
);
......
......@@ -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],
];
}
}
......@@ -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],
];
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment