public function testGetEntityIdByCode() { $entityCode = 'test'; $result = 22; $this->resource->expects($this->once())->method('getEntityIdByCode')->with($this->equalTo($entityCode))->will($this->returnValue($result)); $this->assertSame($result, $this->review->getEntityIdByCode($entityCode)); }
/** * Validate review summary fields * * @return bool|string[] */ public function validate() { if (preg_match('/-/', $this->getNickname())) { $errors[] = __('Nickname is not correct.'); return $errors; } return parent::validate(); }
public function testGetIdentities() { $this->review->setStatusId(Review::STATUS_PENDING); $this->assertEmpty($this->review->getIdentities()); $productId = 1; $this->review->setEntityPkValue($productId); $this->review->setStatusId(Review::STATUS_APPROVED); $this->assertEquals([Product::CACHE_TAG . '_' . $productId], $this->review->getIdentities()); }
/** * Validate review summary fields * * @return array|bool|\string[] */ public function validate() { $errors = []; if (\Zend_Validate::is($this->getNickname(), 'Regex', array('pattern' => '/-/'))) { $errors[] = __('Nickname should not contain dashes'); } if (!empty($errors)) { return $errors; } return parent::validate(); }
/** * Validate nickname of customer * @return array|bool|\string[] */ public function validate() { $errors = []; $validator = new Regex(array('pattern' => '/^[a-zA-Z0-9]*[^_]*$/')); if ($validator->isValid($this->getNickname())) { $errors[] = __('Your nickname should not contain dashes. Please try again'); } if (!empty($errors)) { return $errors; } return parent::validate(); }
/** * 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()); }
/** * Validate nick should not contain dashes * * @return array|bool|\string[] */ public function validate() { $errors = []; $validator = new \Zend\Validator\Regex(array('pattern' => '/^[a-zA-Z0-9]*-[-a-zA-Z0-9]*$/')); if ($validator->isValid($this->getNickname())) { $errors[] = __('Nickname should not contain dashes'); } if (!empty($errors)) { return $errors; } return parent::validate(); }
/** * @param \Magento\Review\Model\Review $review * @param array $row * @return void */ protected function setReviewRating(\Magento\Review\Model\Review $review, $row) { $rating = $this->getRating($row['rating_code']); foreach ($rating->getOptions() as $option) { $optionId = $option->getOptionId(); if ($option->getValue() == $row['rating_value'] && !empty($optionId)) { $rating->setReviewId($review->getId())->addOptionVote($optionId, $this->getProductIdBySku($row['sku'])); } } $review->aggregate(); }
/** * set review data * * @return $this */ public function setReviewData(\Magento\Review\Model\Review $review) { $store = $this->_storeManager->getStore($review->getStoreId()); $websiteName = $store->getWebsite()->getName(); $storeName = $store->getName(); $this->setId($review->getReviewId())->setWebsiteName($websiteName)->setStoreName($storeName)->setReviewDate($review->getCreatedAt()); return $this; }
/** * Get row url * * @param \Magento\Review\Model\Review|\Magento\Framework\Object $row * @return string */ public function getRowUrl($row) { return $this->getUrl('review/product/edit', ['id' => $row->getReviewId(), 'productId' => $this->getProductId(), 'customerId' => $this->getCustomerId(), 'ret' => $this->_coreRegistry->registry('usePendingFilter') ? 'pending' : null]); }