/** * Create mocks for collection and its factory */ private function initCollectionMocks() { $this->collection = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->setMethods(['addStoreFilter', 'addStatusFilter', 'addEntityFilter', 'getSize', '__wakeup'])->getMock(); $this->collection->expects(static::any())->method('addStoreFilter')->willReturnSelf(); $this->collection->expects(static::any())->method('addStatusFilter')->with(Review::STATUS_APPROVED)->willReturnSelf(); $this->collection->expects(static::any())->method('addEntityFilter')->willReturnSelf(); $this->collectionFactory = $this->getMockBuilder(CollectionFactory::class)->disableOriginalConstructor()->setMethods(['create', '__wakeup'])->getMock(); $this->collectionFactory->expects(static::once())->method('create')->willReturn($this->collection); }
/** * @magentoDataFixture Magento/Review/_files/customer_review_with_rating.php */ public function testAggregate() { $rating = $this->reviewCollection->getFirstItem(); $this->reviewResource->aggregate($rating); $select = $this->connection->select()->from($this->resource->getTableName('review_entity_summary')); $result = $this->connection->fetchRow($select); $this->assertEquals(1, $result['reviews_count']); $this->assertEquals(40, $result['rating_summary']); }
/** * Set order * * @param string $attribute * @param string $dir * @return $this */ public function setOrder($attribute, $dir = self::SORT_ORDER_DESC) { if (in_array($attribute, ['nickname', 'title', 'detail', 'created_at'])) { $this->_select->order($attribute . ' ' . $dir); } else { parent::setOrder($attribute, $dir); } return $this; }
/** * Last review date. * * @return string */ public function getLastReviewDate() { if ($this->reviewCollection->getSize()) { //@codingStandardsIgnoreStart $createdAt = $this->reviewCollection->getSelect()->limit(1)->getFirstItem()->getCreatedAt(); //@codingStandardsIgnoreEnd return $createdAt; } return ''; }
public function testAddReviewsTotalCount() { $this->selectMock->expects($this->once())->method('joinLeft')->with(['r' => 'review'], 'main_table.entity_pk_value = r.entity_pk_value', ['total_reviews' => new \Zend_Db_Expr('COUNT(r.review_id)')])->willReturnSelf(); $this->selectMock->expects($this->once())->method('group'); $this->model->addReviewsTotalCount(); }
/** * @param \Magento\Review\Model\ResourceModel\Review\Collection $reviewsCollection * @return int[] */ protected function getCustomerList($reviewsCollection) { return array_filter($reviewsCollection->getColumnValues('customer_id')); }
/** * Init Select * * @return $this */ protected function _initSelect() { parent::_initSelect(); $this->_joinCustomers(); return $this; }