59 $this->contextMock = $this->createMock(\
Magento\Framework\Model\Context::class);
60 $this->registryMock = $this->createMock(\
Magento\Framework\Registry::class);
61 $this->productFactoryMock = $this->createPartialMock(
65 $this->statusFactoryMock = $this->createPartialMock(
69 $this->reviewSummaryMock = $this->createMock(
72 $this->summaryModMock = $this->createPartialMock(
77 $this->storeManagerMock = $this->createMock(\
Magento\
Store\Model\StoreManagerInterface::class);
78 $this->urlInterfaceMock = $this->createMock(\
Magento\Framework\UrlInterface::class);
81 $this->objectManagerHelper =
new ObjectManagerHelper($this);
82 $this->review = $this->objectManagerHelper->getObject(
85 'context' => $this->contextMock,
86 'registry' => $this->registryMock,
87 'productFactory' => $this->productFactoryMock,
88 'statusFactory' => $this->statusFactoryMock,
89 'summaryFactory' => $this->reviewSummaryMock,
90 'summaryModFactory' => $this->summaryModMock,
91 'reviewSummary' => $this->summaryMock,
92 'storeManager' => $this->storeManagerMock,
93 'urlModel' => $this->urlInterfaceMock,
94 'resource' => $this->resource,
95 'data' => [
'review_id' => $this->reviewId,
'status_id' => 1,
'stores' => [2, 3, 4]]
103 $this->productFactoryMock->expects($this->once())
106 $this->assertSame(
$collection, $this->review->getProductCollection());
112 $this->statusFactoryMock->expects($this->once())
115 $this->assertSame(
$collection, $this->review->getStatusCollection());
120 $primaryKey =
'review_id';
121 $approvedOnly =
false;
124 $this->resource->expects($this->once())->method(
'getTotalReviews')
125 ->with($this->equalTo($primaryKey), $this->equalTo($approvedOnly), $this->equalTo(
$storeId))
126 ->will($this->returnValue(
$result));
127 $this->assertSame(
$result, $this->review->getTotalReviews($primaryKey, $approvedOnly,
$storeId));
132 $this->resource->expects($this->once())->method(
'aggregate')
133 ->with($this->equalTo($this->review))
134 ->will($this->returnValue($this->review));
135 $this->assertSame($this->review, $this->review->aggregate());
142 $testSummaryData = [
'test' =>
'value'];
143 $summary = new \Magento\Framework\DataObject();
144 $summary->setData($testSummaryData);
146 $product = $this->createPartialMock(
147 \
Magento\Catalog\Model\Product::class,
148 [
'getId',
'setRatingSummary',
'__wakeup']
150 $product->expects($this->once())->method(
'getId')->will($this->returnValue(
$productId));
151 $product->expects($this->once())->method(
'setRatingSummary')->with($summary)->will($this->returnSelf());
153 $summaryData = $this->createPartialMock(
155 [
'load',
'getData',
'setStoreId',
'__wakeup']
157 $summaryData->expects($this->once())->method(
'setStoreId')
159 ->will($this->returnSelf());
160 $summaryData->expects($this->once())->method(
'load')
162 ->will($this->returnSelf());
163 $summaryData->expects($this->once())->method(
'getData')->will($this->returnValue($testSummaryData));
164 $this->summaryModMock->expects($this->once())->method(
'create')->will($this->returnValue($summaryData));
176 $this->urlInterfaceMock->expects($this->once())->method(
'getUrl')
177 ->with($this->equalTo(
'review/product/view'), $this->equalTo([
'id' => $this->reviewId]))
178 ->will($this->returnValue(
$result));
179 $this->assertSame(
$result, $this->review->getReviewUrl());
191 $this->urlInterfaceMock->expects($this->once())->method(
'setScope')
193 ->will($this->returnSelf());
196 $this->urlInterfaceMock->expects($this->once())->method(
'getUrl')
197 ->with($this->equalTo(
'catalog/product/view'), $this->equalTo([
'id' =>
$productId]))
198 ->will($this->returnValue(
$result));
208 'store id specified' => [3, 5,
'http://some.url'],
209 'store id is not specified' => [3,
null,
'http://some.url/2/'],
215 $this->assertTrue($this->review->isApproved());
227 $store->expects($this->once())->method(
'getId')->will($this->returnValue(
$storeId));
228 $this->storeManagerMock->expects($this->once())
230 ->with($this->equalTo(
$store))
231 ->will($this->returnValue(
$store));
233 $this->assertSame(
$result, $this->review->isAvailableOnStore(
$store));
242 'store id is set and not in list' => [1,
false],
243 'store id is set' => [3,
true],
244 'store id is not set' => [
null,
false],
250 $entityCode =
'test';
252 $this->resource->expects($this->once())->method(
'getEntityIdByCode')
253 ->with($this->equalTo($entityCode))
254 ->will($this->returnValue(
$result));
255 $this->assertSame(
$result, $this->review->getEntityIdByCode($entityCode));
261 $this->assertEmpty($this->review->getIdentities());
testIsAvailableOnStore($storeId, $result)
isAvailableOnStoreDataProvider()
const STATUS_NOT_APPROVED
testGetProductUrl($productId, $storeId, $result)
testGetProductCollection()
testGetStatusCollection()
getProductUrlDataProvider()