Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RatingElement.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\Client\Locator;
10 use Magento\Mtf\Client\Element\SimpleElement;
11 
16 class RatingElement extends SimpleElement
17 {
23  protected $rating = './/*[@data-widget="ratingControl"]//label[contains(@for, "%s_%s")]';
24 
30  protected $checkedRating = 'input[id$="_%d"]:checked + label';
31 
37  protected $ratingByNumber = './/*[contains(@class,"field-rating")][%d]';
38 
45  public function setValue($value)
46  {
47  foreach ($value as $rating) {
48  $ratingSelector = sprintf($this->rating, $rating['title'], $rating['rating']);
49  $this->find($ratingSelector, Locator::SELECTOR_XPATH)->click();
50  }
51  }
52 
59  protected function getRatingVote(SimpleElement $rating)
60  {
61  $ratingVote = 5;
62  $ratingVoteElement = $rating->find(sprintf($this->checkedRating, $ratingVote));
63  while (!$ratingVoteElement->isVisible() && $ratingVote) {
64  --$ratingVote;
65  $ratingVoteElement = $rating->find(sprintf($this->checkedRating, $ratingVote));
66  }
67 
68  return $ratingVote;
69  }
70 
76  public function getValue()
77  {
78  $ratings = [];
79 
80  $count = 1;
81  $rating = $this->find(sprintf($this->ratingByNumber, $count), Locator::SELECTOR_XPATH);
82  while ($rating->isVisible()) {
83  $ratings[$count] = [
84  'title' => $rating->find('./label/span', Locator::SELECTOR_XPATH)->getText(),
85  'rating' => $this->getRatingVote($rating),
86  ];
87 
88  ++$count;
89  $rating = $this->find(sprintf($this->ratingByNumber, $count), Locator::SELECTOR_XPATH);
90  }
91  return $ratings;
92  }
93 }
$count
Definition: recent.phtml:13
taxRateField find('.mselect-list') .on( 'click.mselect-edit'
Definition: edit.phtml:162
$value
Definition: gender.phtml:16