Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ReviewForm.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\Client\Locator;
10 use Magento\Mtf\Fixture\FixtureInterface;
11 use Magento\Mtf\Client\Element\SimpleElement;
12 use Magento\Review\Test\Fixture\Rating;
14 use Magento\Mtf\Block\Form as AbstractForm;
15 
19 class ReviewForm extends AbstractForm
20 {
26  protected $legendSelector = 'legend';
27 
33  protected $submitButton = '.action.submit';
34 
40  protected $rating = './/*[@id="%s_rating_label"]';
41 
47  protected $ratingVoteLabel = './following-sibling::div[contains(@class,"vote")]/label[contains(@id,"_%d_label")]';
48 
54  public function submit()
55  {
56  $this->_rootElement->find($this->submitButton, Locator::SELECTOR_CSS)->click();
57  }
58 
64  public function getLegend()
65  {
66  return $this->_rootElement->find($this->legendSelector);
67  }
68 
75  public function isVisibleRating(Rating $rating)
76  {
77  return $this->getRating($rating)->isVisible();
78  }
79 
86  protected function getRating(Rating $rating)
87  {
88  return $this->_rootElement->find(sprintf($this->rating, $rating->getRatingCode()), Locator::SELECTOR_XPATH);
89  }
90 
98  public function fill(FixtureInterface $review, SimpleElement $element = null)
99  {
100  if ($review->hasData('ratings')) {
101  $this->fillRatings($review->getRatings());
102  }
103  parent::fill($review, $element);
104  }
105 
112  protected function fillRatings(array $ratings)
113  {
114  foreach ($ratings as $rating) {
115  $this->setRating($rating['title'], $rating['rating']);
116  }
117  }
118 
126  protected function setRating($ratingCode, $ratingVote)
127  {
128  $rating = $this->_rootElement->find(sprintf($this->rating, $ratingCode), Locator::SELECTOR_XPATH);
129  $rating->find(sprintf($this->ratingVoteLabel, $ratingVote), Locator::SELECTOR_XPATH)->click();
130  }
131 }
setRating($ratingCode, $ratingVote)
Definition: ReviewForm.php:126
fill(FixtureInterface $review, SimpleElement $element=null)
Definition: ReviewForm.php:98
$element
Definition: element.phtml:12