public function testGetData() { $expected = ['totalRecords' => null, 'items' => []]; $this->collectionMock->expects($this->once())->method('addEntityFilter')->willReturnSelf(); $this->collectionMock->expects($this->once())->method('addStoreData')->willReturnSelf(); $this->requestMock->expects($this->once())->method('getParam')->with('current_product_id', 0)->willReturn(1); $this->assertSame($expected, $this->model->getData()); }
/** * Return collection of reviews * * @return array|\Magento\Review\Model\ResourceModel\Review\Product\Collection */ public function getReviews() { if (!($customerId = $this->currentCustomer->getCustomerId())) { return []; } if (!$this->_collection) { $this->_collection = $this->_collectionFactory->create(); $this->_collection->addStoreFilter($this->_storeManager->getStore()->getId())->addCustomerFilter($customerId)->setDateOrder()->setPageSize(5)->load()->addReviewSummary(); } return $this->_collection; }
/** * @dataProvider addAttributeToFilterWithAttributeTypeDataProvider * @param $condition * @param $sqlConditionWith * @param $sqlConditionWithSec * @param $doubleConditionSqlQuery */ public function testAddAttributeToFilterWithAttributeType($condition, $sqlConditionWith, $sqlConditionWithSec, $doubleConditionSqlQuery) { $conditionSqlQuery = 'sqlQuery'; $this->connectionMock->expects($this->at(0))->method('prepareSqlCondition')->with('rdt.customer_id', $sqlConditionWith)->will($this->returnValue($conditionSqlQuery)); if ($sqlConditionWithSec) { $this->connectionMock->expects($this->at(1))->method('prepareSqlCondition')->with('rdt.store_id', $sqlConditionWithSec)->will($this->returnValue($conditionSqlQuery)); } $conditionSqlQuery = $doubleConditionSqlQuery ? $conditionSqlQuery . ' AND ' . $conditionSqlQuery : $conditionSqlQuery; $this->dbSelect->expects($this->once())->method('where')->with($conditionSqlQuery)->will($this->returnSelf()); $this->model->addAttributeToFilter('type', $condition); }
public function testGetCollection() { $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue(new \Magento\Framework\DataObject(['id' => 42]))); $this->currentCustomer->expects($this->any())->method('getCustomerId')->will($this->returnValue(4242)); $this->collection->expects($this->any())->method('addStoreFilter')->with(42)->will($this->returnValue($this->collection)); $this->collection->expects($this->any())->method('addCustomerFilter')->with(4242)->will($this->returnValue($this->collection)); $this->collection->expects($this->any())->method('setDateOrder')->with()->will($this->returnValue($this->collection)); $this->collection->expects($this->any())->method('setPageSize')->with(5)->will($this->returnValue($this->collection)); $this->collection->expects($this->any())->method('load')->with()->will($this->returnValue($this->collection)); $this->collection->expects($this->any())->method('addReviewSummary')->with()->will($this->returnValue($this->collection)); $this->assertSame($this->collection, $this->object->getReviews()); }
/** * Append review summary to product collection * * @param ProductCollection $collection * @return $this */ public function appendSummary($collection) { $entityIds = []; foreach ($collection->getItems() as $item) { $entityIds[] = $item->getEntityId(); } if (sizeof($entityIds) == 0) { return $this; } $summaryData = $this->_summaryFactory->create()->addEntityFilter($entityIds)->addStoreFilter($this->_storeManager->getStore()->getId())->load(); foreach ($collection->getItems() as $item) { foreach ($summaryData as $summary) { if ($summary->getEntityPkValue() == $item->getEntityId()) { $item->setRatingSummary($summary); } } } return $this; }