Skip to content

Commit 404790a

Browse files
author
Oleksandr Karpenko
committed
Merge remote-tracking branch 'origin/MAGETWO-44723' into BUGS
2 parents 81ba586 + a31accc commit 404790a

File tree

4 files changed

+88
-4
lines changed

4 files changed

+88
-4
lines changed

app/code/Magento/Review/Block/Form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public function getAction()
161161
return $this->getUrl(
162162
'review/product/post',
163163
[
164-
'_secure' => $this->_request->isSecure(),
164+
'_secure' => $this->getRequest()->isSecure(),
165165
'id' => $this->getProductId(),
166166
]
167167
);

app/code/Magento/Review/Block/Product/Review.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function getProductReviewUrl()
6969
return $this->getUrl(
7070
'review/product/listAjax',
7171
[
72-
'_secure' => $this->_request->isSecure(),
72+
'_secure' => $this->getRequest()->isSecure(),
7373
'id' => $this->getProductId(),
7474
]
7575
);

app/code/Magento/Review/Test/Unit/Block/FormTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ class FormTest extends \PHPUnit_Framework_TestCase
3434
/** @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
3535
protected $storeManager;
3636

37+
/** @var \Magento\Framework\UrlInterface|PHPUnit_Framework_MockObject_MockObject */
38+
protected $urlBuilder;
39+
3740
protected function setUp()
3841
{
3942
$this->storeManager = $this->getMock('\Magento\Store\Model\StoreManagerInterface');
@@ -46,6 +49,7 @@ protected function setUp()
4649
->method('getIsGuestAllowToWrite')
4750
->willReturn(true);
4851

52+
$this->urlBuilder = $this->getMockBuilder('Magento\Framework\UrlInterface')->getMockForAbstractClass();
4953
$this->context = $this->getMock('Magento\Framework\View\Element\Template\Context', [], [], '', false);
5054
$this->context->expects(
5155
$this->any()
@@ -57,6 +61,7 @@ protected function setUp()
5761
$this->context->expects($this->any())
5862
->method('getRequest')
5963
->willReturn($this->requestMock);
64+
$this->context->expects($this->any())->method('getUrlBuilder')->willReturn($this->urlBuilder);
6065
$this->productRepository = $this->getMock('\Magento\Catalog\Api\ProductRepositoryInterface');
6166

6267
$this->objectManagerHelper = new ObjectManagerHelper($this);
@@ -96,4 +101,35 @@ public function testGetProductInfo()
96101

97102
$this->assertSame($productMock, $this->object->getProductInfo());
98103
}
104+
105+
/**
106+
* @param bool $isSecure
107+
* @param string $actionUrl
108+
* @param int $productId
109+
* @dataProvider getActionDataProvider
110+
*/
111+
public function testGetAction($isSecure, $actionUrl, $productId)
112+
{
113+
$this->urlBuilder->expects($this->any())
114+
->method('getUrl')
115+
->with('review/product/post', ['_secure' => $isSecure, 'id' => $productId])
116+
->willReturn($actionUrl . '/id/' . $productId);
117+
$this->requestMock->expects($this->any())
118+
->method('getParam')
119+
->with('id', false)
120+
->willReturn($productId);
121+
$this->requestMock->expects($this->any())
122+
->method('isSecure')
123+
->willReturn($isSecure);
124+
125+
$this->assertEquals($actionUrl . '/id/' . $productId , $this->object->getAction());
126+
}
127+
128+
public function getActionDataProvider()
129+
{
130+
return [
131+
[false, 'http://localhost/review/product/post', 3],
132+
[true, 'https://localhost/review/product/post' ,3],
133+
];
134+
}
99135
}

app/code/Magento/Review/Test/Unit/Block/Product/ReviewTest.php

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)