|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\LayeredNavigation\Test\Block; |
| 7 | + |
| 8 | +use Magento\Mtf\Block\Block; |
| 9 | +use Magento\Mtf\Client\Locator; |
| 10 | + |
| 11 | +/** |
| 12 | + * Catalog layered navigation view block |
| 13 | + */ |
| 14 | +class Navigation extends Block |
| 15 | +{ |
| 16 | + /** |
| 17 | + * 'Clear All' link. |
| 18 | + * |
| 19 | + * @var string |
| 20 | + */ |
| 21 | + protected $clearAll = '.action.clear'; |
| 22 | + |
| 23 | + /** |
| 24 | + * Price range. |
| 25 | + * |
| 26 | + * @var string |
| 27 | + */ |
| 28 | + protected $priceRange = "[href$='?price=%s']"; |
| 29 | + |
| 30 | + /** |
| 31 | + * Attribute option. |
| 32 | + * |
| 33 | + * @var string |
| 34 | + */ |
| 35 | + protected $attributeOption = "//a[contains(text(), '%s')]"; |
| 36 | + |
| 37 | + /** |
| 38 | + * Attribute option title selector. |
| 39 | + * |
| 40 | + * @var string |
| 41 | + */ |
| 42 | + protected $optionTitle = '.filter-options-title'; |
| 43 | + |
| 44 | + /** |
| 45 | + * Attribute option content selector. |
| 46 | + * |
| 47 | + * @var string |
| 48 | + */ |
| 49 | + protected $optionContent = '.filter-options-content'; |
| 50 | + |
| 51 | + /** |
| 52 | + * Click on 'Clear All' link. |
| 53 | + * |
| 54 | + * @return void |
| 55 | + */ |
| 56 | + public function clearAll() |
| 57 | + { |
| 58 | + $this->_rootElement->find($this->clearAll, locator::SELECTOR_CSS)->click(); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Select product price range. |
| 63 | + * |
| 64 | + * @param string $range |
| 65 | + * @return void |
| 66 | + */ |
| 67 | + public function selectPriceRange($range) |
| 68 | + { |
| 69 | + $this->_rootElement->find(sprintf($this->priceRange, $range))->click(); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Select attribute option. |
| 74 | + * |
| 75 | + * @param string $optionName |
| 76 | + * @return void |
| 77 | + */ |
| 78 | + public function selectAttributeOption($optionName) |
| 79 | + { |
| 80 | + $this->_rootElement->find(sprintf($this->attributeOption, $optionName), Locator::SELECTOR_XPATH)->click(); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * Get array of available filters. |
| 85 | + * |
| 86 | + * @return array |
| 87 | + */ |
| 88 | + public function getFilters() |
| 89 | + { |
| 90 | + $options = $this->_rootElement->getElements($this->optionTitle); |
| 91 | + $data = []; |
| 92 | + foreach ($options as $option) { |
| 93 | + $data[] = $option->getText(); |
| 94 | + } |
| 95 | + return $data; |
| 96 | + } |
| 97 | +} |
0 commit comments