/** * Check postAction method and assert that review model storeId equals null. */ public function testPostAction() { $this->requestMock->expects($this->any()) ->method('getParam') ->willReturnMap( [ ['product_id', false, 1], ['ratings', [], ['1' => '1']] ] ); $this->requestMock->expects($this->once()) ->method('getPostValue') ->willReturn(['status_id' => 1]); $this->objectManagerMock->expects($this->any()) ->method('get') ->with('Magento\Store\Model\StoreManagerInterface') ->willReturn($this->storeManagerMock); $this->reviewFactoryMock->expects($this->once()) ->method('create') ->willReturn($this->reviewMock); $this->ratingFactoryMock->expects($this->once()) ->method('create') ->willReturn($this->ratingMock); $this->storeManagerMock->expects($this->once()) ->method('hasSingleStore') ->willReturn(true); $this->storeManagerMock->expects($this->once()) ->method('getStore') ->willReturn($this->storeModelMock); $this->storeModelMock->expects($this->once()) ->method('getId') ->willReturn(1); $this->reviewMock->expects($this->once()) ->method('save') ->willReturn($this->reviewMock); $this->reviewMock->expects($this->once()) ->method('getId') ->willReturn(1); $this->reviewMock->expects($this->once()) ->method('aggregate') ->willReturn($this->reviewMock); $this->ratingMock->expects($this->once()) ->method('setRatingId') ->willReturnSelf(); $this->ratingMock->expects($this->once()) ->method('setReviewId') ->willReturnSelf(); $this->ratingMock->expects($this->once()) ->method('addOptionVote') ->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->postController->executeInternal()); }
public function testToHtmlCoreRegistryRatingData() { $this->registry->expects($this->any())->method('registry')->will($this->returnValue($this->rating)); $this->form->expects($this->at(7))->method('getElement')->will($this->returnValue($this->element)); $this->form->expects($this->at(13))->method('getElement')->will($this->returnValue($this->element)); $this->form->expects($this->at(16))->method('getElement')->will($this->returnValue($this->element)); $this->form->expects($this->at(17))->method('getElement')->will($this->returnValue($this->element)); $this->form->expects($this->any())->method('getElement')->will($this->returnValue(false)); $this->session->expects($this->any())->method('getRatingData')->will($this->returnValue(false)); $ratingCodes = ['rating_codes' => ['0' => 'rating_code']]; $this->rating->expects($this->any())->method('getRatingCodes')->will($this->returnValue($ratingCodes)); $this->block->toHtml(); }
/** * Review summary * * @param \Magento\Review\Model\Rating $object * @param boolean $onlyForCurrentStore * @return array */ public function getReviewSummary($object, $onlyForCurrentStore = true) { $adapter = $this->_getReadAdapter(); $sumColumn = new \Zend_Db_Expr("SUM(rating_vote.{$adapter->quoteIdentifier('percent')})"); $countColumn = new \Zend_Db_Expr('COUNT(*)'); $select = $adapter->select()->from(array('rating_vote' => $this->getTable('rating_option_vote')), array('sum' => $sumColumn, 'count' => $countColumn))->joinLeft(array('review_store' => $this->getTable('review_store')), 'rating_vote.review_id = review_store.review_id', array('review_store.store_id')); if (!$this->_storeManager->isSingleStoreMode()) { $select->join(array('rating_store' => $this->getTable('rating_store')), 'rating_store.rating_id = rating_vote.rating_id AND rating_store.store_id = review_store.store_id', array()); } $select->where('rating_vote.review_id = :review_id')->group('rating_vote.review_id')->group('review_store.store_id'); $data = $adapter->fetchAll($select, array(':review_id' => $object->getReviewId())); if ($onlyForCurrentStore) { foreach ($data as $row) { if ($row['store_id'] == $this->_storeManager->getStore()->getId()) { $object->addData($row); } } return $object; } $result = array(); $stores = $this->_storeManager->getStore()->getResourceCollection()->load(); foreach ($data as $row) { $clone = clone $object; $clone->addData($row); $result[$clone->getStoreId()] = $clone; } $usedStoresId = array_keys($result); foreach ($stores as $store) { if (!in_array($store->getId(), $usedStoresId)) { $clone = clone $object; $clone->setCount(0); $clone->setSum(0); $clone->setStoreId($store->getId()); $result[$store->getId()] = $clone; } } return array_values($result); }
/** * @covers \Magento\Review\Model\Rating::getIdentities() * @return void */ public function testGetIdentities() { static::assertEquals([Review::CACHE_TAG], $this->rating->getIdentities()); }
/** * Aggregate review summary * * @param \Magento\Framework\Model\AbstractModel $object * @param \Magento\Review\Model\Rating $ratingSummaryObject * @return void */ protected function aggregateReviewSummary($object, $ratingSummaryObject) { $readAdapter = $this->_getReadAdapter(); if ($ratingSummaryObject->getCount()) { $ratingSummary = round($ratingSummaryObject->getSum() / $ratingSummaryObject->getCount()); } else { $ratingSummary = $ratingSummaryObject->getSum(); } $reviewsCount = $this->getTotalReviews($object->getEntityPkValue(), true, $ratingSummaryObject->getStoreId()); $select = $readAdapter->select()->from($this->_aggregateTable)->where('entity_pk_value = :pk_value')->where('entity_type = :entity_type')->where('store_id = :store_id'); $bind = [':pk_value' => $object->getEntityPkValue(), ':entity_type' => $object->getEntityId(), ':store_id' => $ratingSummaryObject->getStoreId()]; $oldData = $readAdapter->fetchRow($select, $bind); $data = new \Magento\Framework\Object(); $data->setReviewsCount($reviewsCount)->setEntityPkValue($object->getEntityPkValue())->setEntityType($object->getEntityId())->setRatingSummary($ratingSummary > 0 ? $ratingSummary : 0)->setStoreId($ratingSummaryObject->getStoreId()); $this->writeReviewSummary($oldData, $data); }