public function testGetReviewsWithPurchaseDate() { $productId = 15; $customerIds = [2, 4, null, 5, 9]; $customersWithPurchaseDate = [4 => 'date 4', 9 => 'date 9']; $reviews = [$this->createReviewModel(2, null), $this->createReviewModel(4, 'date 4'), $this->createReviewModel(null, null), $this->createReviewModel(5, null), $this->createReviewModel(9, 'date 9')]; $reviewCollection = $this->getMockBuilder('Magento\\Review\\Model\\ResourceModel\\Review\\Collection')->disableOriginalConstructor()->getMock(); $reviewCollection->expects($this->once())->method('getColumnValues')->with('customer_id')->willReturn($customerIds); $reviewCollection->expects($this->any())->method('getIterator')->willReturn(new \ArrayIterator($reviews)); $this->resource->expects($this->once())->method('getCustomersWithWithPurchaseDate')->with($productId, array_filter($customerIds))->willReturn($customersWithPurchaseDate); $this->assertSame($reviewCollection, $this->buyer->getReviewsWithPurchaseDate($productId, $reviewCollection)); }
/** * @param bool $isActive * @param int|null $productId * @dataProvider getReviewItemsDataProvider */ public function testGetReviewItems($isActive, $productId) { $this->generalConfig->expects($this->once())->method('isActive')->willReturn($isActive); $reviewCollection = $this->getMockBuilder('Magento\\Review\\Model\\ResourceModel\\Review\\Collection')->disableOriginalConstructor()->getMock(); $this->listView->expects($this->once())->method('getReviewsCollection')->willReturn($reviewCollection); if ($isActive) { $this->listView->expects($this->once())->method('getProductId')->willReturn($productId); $this->buyer->expects($this->once())->method('getReviewsWithPurchaseDate')->with($productId, $reviewCollection)->willReturn($reviewCollection); } else { $this->listView->expects($this->never())->method('getProductId'); $this->buyer->expects($this->never())->method('getReviewsWithPurchaseDate'); } $this->assertEquals($reviewCollection, $this->listView->getReviewItems()); }
/** * @return \Magento\Review\Model\Review[] */ public function getReviewItems() { return $this->generalConfig->isActive() ? $this->buyer->getReviewsWithPurchaseDate($this->getProductId(), $this->getReviewsCollection()) : $this->getReviewsCollection(); }