diff --git a/app/code/Magento/Captcha/Block/Captcha.php b/app/code/Magento/Captcha/Block/Captcha.php index 7daafd0ef14f6db39abe89e1bd370dca6ac37e76..228a530ad6596bdad4188ef7932caac77b42d28b 100644 --- a/app/code/Magento/Captcha/Block/Captcha.php +++ b/app/code/Magento/Captcha/Block/Captcha.php @@ -32,6 +32,7 @@ class Captcha extends \Magento\Framework\View\Element\Template ) { $this->_captchaData = $captchaData; parent::__construct($context, $data); + $this->_isScopePrivate = true; } /** diff --git a/app/code/Magento/Customer/Block/Form/Register.php b/app/code/Magento/Customer/Block/Form/Register.php index e6e77a075a8274e0a0315e12802158e53b64cd43..4c3f28f819261ae96ccfdbca93907ff32c25c5d7 100644 --- a/app/code/Magento/Customer/Block/Form/Register.php +++ b/app/code/Magento/Customer/Block/Form/Register.php @@ -63,7 +63,7 @@ class Register extends \Magento\Directory\Block\Data $countryCollectionFactory, $data ); - $this->_isScopePrivate = true; + $this->_isScopePrivate = false; } /** diff --git a/app/code/Magento/Review/Block/Form.php b/app/code/Magento/Review/Block/Form.php index 2bcc859bdd4f7f557c630d186297a5bdf8a2f185..8efe29b58e719a8c421ccd2e09bd7b9c96565d13 100644 --- a/app/code/Magento/Review/Block/Form.php +++ b/app/code/Magento/Review/Block/Form.php @@ -158,7 +158,13 @@ class Form extends \Magento\Framework\View\Element\Template */ public function getAction() { - return $this->getUrl('review/product/post', ['id' => $this->getProductId()]); + return $this->getUrl( + 'review/product/post', + [ + '_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 02764dc5123f1f59535e6865bb9024a361f9d635..bae4bd8dc5db56001f9e808f34b0fe5533ba7bbc 100644 --- a/app/code/Magento/Review/Block/Product/Review.php +++ b/app/code/Magento/Review/Block/Product/Review.php @@ -66,7 +66,13 @@ class Review extends Template implements IdentityInterface */ public function getProductReviewUrl() { - return $this->getUrl('review/product/listAjax', ['id' => $this->getProductId()]); + return $this->getUrl( + 'review/product/listAjax', + [ + '_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..b237ddc28be2ec8e4316e7bb988d4cce24f1218a 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..2ed841081169cfda04fbeb58a7f2f4e443bb7b26 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], + ]; } }