MDL-40759 icons: Better mapping of some icons
[moodle.git] / lib / behat / classes / partial_named_selector.php
CommitLineData
520071f0
AN
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Moodle-specific selectors.
19 *
20 * @package core
21 * @category test
22 * @copyright 2013 David MonllaĆ³
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26/**
27 * Moodle selectors manager.
28 *
29 * @package core
30 * @category test
31 * @copyright 2013 David MonllaĆ³
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33 */
34class behat_partial_named_selector extends \Behat\Mink\Selector\PartialNamedSelector {
35
36 /**
37 * Creates selector instance.
38 */
39 public function __construct() {
40 foreach (self::$customselectors as $alias => $selectors) {
41 $this->registerNamedXpath($alias, implode(' | ', $selectors));
42 }
43
44 foreach (static::$moodleselectors as $name => $xpath) {
45 $this->registerNamedXpath($name, $xpath);
46 }
47
48 // Call the constructor after adding any new selector or replacement values.
49 parent::__construct();
50 }
51
52 /**
53 * @var Allowed types when using text selectors arguments.
54 */
55 protected static $allowedtextselectors = array(
56 'activity' => 'activity',
57 'block' => 'block',
58 'css_element' => 'css_element',
59 'dialogue' => 'dialogue',
60 'fieldset' => 'fieldset',
61 'list_item' => 'list_item',
f05c1013
RW
62 'message_area_region' => 'message_area_region',
63 'message_area_region_content' => 'message_area_region_content',
520071f0
AN
64 'question' => 'question',
65 'region' => 'region',
66 'section' => 'section',
67 'table' => 'table',
68 'table_row' => 'table_row',
69 'xpath_element' => 'xpath_element',
70 'form_row' => 'form_row',
71 );
72
73 /**
74 * @var Allowed types when using selector arguments.
75 */
76 protected static $allowedselectors = array(
77 'activity' => 'activity',
78 'block' => 'block',
79 'button' => 'button',
80 'checkbox' => 'checkbox',
81 'css_element' => 'css_element',
82 'dialogue' => 'dialogue',
83 'field' => 'field',
84 'fieldset' => 'fieldset',
85 'file' => 'file',
86 'filemanager' => 'filemanager',
87 'link' => 'link',
88 'link_or_button' => 'link_or_button',
89 'list_item' => 'list_item',
f05c1013
RW
90 'message_area_action' => 'message_area_action',
91 'message_area_region' => 'message_area_region',
92 'message_area_region_content' => 'message_area_region_content',
520071f0
AN
93 'optgroup' => 'optgroup',
94 'option' => 'option',
95 'question' => 'question',
96 'radio' => 'radio',
97 'region' => 'region',
98 'section' => 'section',
99 'select' => 'select',
100 'table' => 'table',
101 'table_row' => 'table_row',
102 'text' => 'text',
103 'xpath_element' => 'xpath_element',
104 'form_row' => 'form_row',
105 );
106
107 /**
108 * Behat by default comes with XPath, CSS and named selectors,
109 * named selectors are a mapping between names (like button) and
110 * xpaths that represents that names and includes a placeholder that
111 * will be replaced by the locator. These are Moodle's own xpaths.
112 *
113 * @var XPaths for moodle elements.
114 */
115 protected static $moodleselectors = array(
116 'activity' => <<<XPATH
117.//li[contains(concat(' ', normalize-space(@class), ' '), ' activity ')][normalize-space(.) = %locator% ]
118XPATH
119 , 'block' => <<<XPATH
120.//*[@data-block][contains(concat(' ', normalize-space(@class), ' '), concat(' ', %locator%, ' ')) or
121 descendant::*[self::h2|self::h3][normalize-space(.) = %locator%] or
122 @aria-label = %locator%]
123XPATH
124 , 'dialogue' => <<<XPATH
125.//div[contains(concat(' ', normalize-space(@class), ' '), ' moodle-dialogue ') and
126 normalize-space(descendant::div[
127 contains(concat(' ', normalize-space(@class), ' '), ' moodle-dialogue-hd ')
128 ]) = %locator%] |
129.//div[contains(concat(' ', normalize-space(@class), ' '), ' yui-dialog ') and
130 normalize-space(descendant::div[@class='hd']) = %locator%]
131XPATH
132 , 'list_item' => <<<XPATH
133.//li[contains(normalize-space(.), %locator%) and not(.//li[contains(normalize-space(.), %locator%)])]
134XPATH
135 , 'question' => <<<XPATH
136.//div[contains(concat(' ', normalize-space(@class), ' '), ' que ')]
137 [contains(div[@class='content']/div[contains(concat(' ', normalize-space(@class), ' '), ' formulation ')], %locator%)]
138XPATH
139 , 'region' => <<<XPATH
140.//*[self::div | self::section | self::aside | self::header | self::footer][./@id = %locator%]
141XPATH
142 , 'section' => <<<XPATH
143.//li[contains(concat(' ', normalize-space(@class), ' '), ' section ')][./descendant::*[self::h3]
144 [normalize-space(.) = %locator%][contains(concat(' ', normalize-space(@class), ' '), ' sectionname ') or
145 contains(concat(' ', normalize-space(@class), ' '), ' section-title ')]] |
146.//div[contains(concat(' ', normalize-space(@class), ' '), ' sitetopic ')]
147 [./descendant::*[self::h2][normalize-space(.) = %locator%] or %locator% = 'frontpage']
148XPATH
149 , 'table' => <<<XPATH
150.//table[(./@id = %locator% or contains(.//caption, %locator%) or contains(.//th, %locator%) or contains(concat(' ', normalize-space(@class), ' '), %locator% ))]
151XPATH
152 , 'table_row' => <<<XPATH
153.//tr[contains(normalize-space(.), %locator%) and not(.//tr[contains(normalize-space(.), %locator%)])]
154XPATH
155 , 'text' => <<<XPATH
156.//*[contains(., %locator%) and not(.//*[contains(., %locator%)])]
157XPATH
158 , 'form_row' => <<<XPATH
159.//*[self::label or self::div[contains(concat(' ', @class, ' '), ' fstaticlabel ')]][contains(., %locator%)]/ancestor::*[contains(concat(' ', @class, ' '), ' fitem ')]
f05c1013
RW
160XPATH
161 , 'message_area_region' => <<<XPATH
162.//div[@data-region='messaging-area']/descendant::*[@data-region = %locator%]
163XPATH
164 , 'message_area_region_content' => <<<XPATH
165.//div[@data-region='messaging-area']/descendant::*[@data-region-content = %locator%]
166XPATH
167 , 'message_area_action' => <<<XPATH
168.//div[@data-region='messaging-area']/descendant::*[@data-action = %locator%]
520071f0
AN
169XPATH
170 );
171
172 protected static $customselectors = [
173 'field' => [
174 'upstream' => <<<XPATH
175.//*
176[%fieldFilterWithPlaceholder%][%notFieldTypeFilter%][%fieldMatchWithPlaceholder%]
177|
178.//label[%tagTextMatch%]//.//*[%fieldFilterWithPlaceholder%][%notFieldTypeFilter%]
179|
180.//*
181[%fieldFilterWithoutPlaceholder%][%notFieldTypeFilter%][%fieldMatchWithoutPlaceholder%]
182|
183.//label[%tagTextMatch%]//.//*[%fieldFilterWithoutPlaceholder%][%notFieldTypeFilter%]
184XPATH
185 ,
186 'filemanager' => <<<XPATH
6ee51d01 187.//*[@data-fieldtype = 'filemanager' or @data-fieldtype = 'filepicker']
d9821755 188 /descendant::input[@id = //label[contains(normalize-space(string(.)), %locator%)]/@for]
ca25005c
AN
189XPATH
190 ,
191 'passwordunmask' => <<<XPATH
192.//*[@data-passwordunmask='wrapper']
737b54fe 193 /descendant::input[@id = %locator% or @id = //label[contains(normalize-space(string(.)), %locator%)]/@for]
520071f0
AN
194XPATH
195 ],
196 ];
197
198 /**
199 * Allowed selectors getter.
200 *
201 * @return array
202 */
203 public static function get_allowed_selectors() {
204 return static::$allowedselectors;
205 }
206
207 /**
208 * Allowed text selectors getter.
209 *
210 * @return array
211 */
212 public static function get_allowed_text_selectors() {
213 return static::$allowedtextselectors;
214 }
215}