10 class FormTest extends \PHPUnit\Framework\TestCase
41 private $serializerMock;
45 $this->storeManager = $this->createMock(\
Magento\Store\Model\StoreManagerInterface::class);
46 $this->requestMock = $this->createMock(\
Magento\Framework\
App\RequestInterface::class);
47 $this->reviewDataMock = $this->getMockBuilder(\
Magento\Review\Helper\Data::class)
48 ->disableOriginalConstructor()
51 $this->reviewDataMock->expects($this->once())
52 ->method(
'getIsGuestAllowToWrite')
55 $this->urlBuilder = $this->getMockBuilder(\
Magento\Framework\UrlInterface::class)->getMockForAbstractClass();
56 $this->context = $this->createMock(\
Magento\Framework\View\Element\Template\Context::class);
57 $this->context->expects(
62 $this->returnValue($this->storeManager)
64 $this->context->expects($this->any())
65 ->method(
'getRequest')
66 ->willReturn($this->requestMock);
67 $this->context->expects($this->any())->method(
'getUrlBuilder')->willReturn($this->urlBuilder);
68 $this->productRepository = $this->createMock(\
Magento\Catalog\Api\ProductRepositoryInterface::class);
70 $this->serializerMock = $this->getMockBuilder(\
Magento\Framework\Serialize\Serializer\Json::class)->getMock();
72 $this->objectManagerHelper =
new ObjectManagerHelper($this);
73 $this->
object = $this->objectManagerHelper->getObject(
74 \
Magento\Review\Block\Form::class,
76 'context' => $this->context,
77 'reviewData' => $this->reviewDataMock,
78 'productRepository' => $this->productRepository,
81 'some-layout' =>
'layout information' 84 'serializer' => $this->serializerMock
94 $this->storeManager->expects(
99 $this->returnValue(
new \
Magento\Framework\DataObject([
'id' =>
$storeId]))
102 $this->requestMock->expects($this->once())
107 $productMock = $this->createMock(\
Magento\Catalog\Api\Data\ProductInterface::class);
108 $this->productRepository->expects($this->once())
111 ->willReturn($productMock);
113 $this->assertSame($productMock, $this->object->getProductInfo());
124 $this->urlBuilder->expects($this->any())
126 ->with(
'review/product/post', [
'_secure' => $isSecure,
'id' =>
$productId])
127 ->willReturn($actionUrl .
'/id/' .
$productId);
128 $this->requestMock->expects($this->any())
132 $this->requestMock->expects($this->any())
134 ->willReturn($isSecure);
136 $this->assertEquals($actionUrl .
'/id/' .
$productId, $this->object->getAction());
145 [
false,
'http://localhost/review/product/post', 3],
146 [
true,
'https://localhost/review/product/post' ,3],
153 'some-layout' =>
'layout information' 156 $this->serializerMock->expects($this->once())->method(
'serialize')
157 ->will($this->returnValue(json_encode($jsLayout)));
158 $this->assertEquals(
'{"some-layout":"layout information"}', $this->object->getJsLayout());