Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TopToolbar.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\Block\Block;
10 use Magento\Mtf\Client\Locator;
11 
15 class TopToolbar extends Block
16 {
22  protected $sorter = '#sorter';
23 
29  private $direction = '[data-role="direction-switcher"]';
30 
36  public function getSelectSortType()
37  {
38  $selectedOption = $this->_rootElement->find($this->sorter)->getElements('option[selected]')[0]->getText();
39  preg_match('/\w+\s?\w+/', $selectedOption, $matches);
40  return $matches[0];
41  }
42 
48  public function getSortType()
49  {
50  $content = $this->_rootElement->find($this->sorter)->getText();
51  return explode("\n", $content);
52  }
53 
60  public function applySorting(array $sortBy)
61  {
62  if (!empty($sortBy['field'])) {
63  $this->_rootElement->find($this->sorter, Locator::SELECTOR_CSS, 'select')->setValue($sortBy['field']);
64  }
65 
66  if (!empty($sortBy['direction'])) {
67  $switcher = $this->_rootElement->find($this->direction);
68  if ($switcher->getAttribute('data-value') == $sortBy['direction']) {
69  $switcher->click();
70  }
71  }
72  }
73 }