MDL-65060 core_message: add render buffer to conversations
[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
1e815600
AN
48 foreach (self::$customreplacements as $from => $tos) {
49 $this->registerReplacement($from, implode(' or ', $tos));
50 }
51
8857c715
DW
52 $this->registerReplacement('%iconMatch%', "(contains(concat(' ', @class, ' '), ' icon ') or name() = 'img')");
53 $this->registerReplacement('%imgAltMatch%', './/*[%iconMatch% and (%altMatch% or %titleMatch%)]');
520071f0
AN
54 parent::__construct();
55 }
56
57 /**
1e815600 58 * @var array Allowed types when using text selectors arguments.
520071f0
AN
59 */
60 protected static $allowedtextselectors = array(
61 'activity' => 'activity',
62 'block' => 'block',
63 'css_element' => 'css_element',
64 'dialogue' => 'dialogue',
65 'fieldset' => 'fieldset',
8857c715 66 'icon' => 'icon',
520071f0
AN
67 'list_item' => 'list_item',
68 'question' => 'question',
69 'region' => 'region',
70 'section' => 'section',
71 'table' => 'table',
72 'table_row' => 'table_row',
73 'xpath_element' => 'xpath_element',
74 'form_row' => 'form_row',
e688eab8 75 'group_message_header' => 'group_message_header',
520071f0
AN
76 );
77
78 /**
1e815600 79 * @var array Allowed types when using selector arguments.
520071f0
AN
80 */
81 protected static $allowedselectors = array(
82 'activity' => 'activity',
83 'block' => 'block',
84 'button' => 'button',
85 'checkbox' => 'checkbox',
86 'css_element' => 'css_element',
87 'dialogue' => 'dialogue',
88 'field' => 'field',
89 'fieldset' => 'fieldset',
90 'file' => 'file',
91 'filemanager' => 'filemanager',
65f631c5 92 'group_message' => 'group_message',
d624c135 93 'group_message_conversation' => 'group_message_conversation',
65f631c5
AA
94 'group_message_header' => 'group_message_header',
95 'group_message_member' => 'group_message_member',
96 'group_message_tab' => 'group_message_tab',
e688eab8 97 'group_message_list_area' => 'group_message_list_area',
8857c715 98 'icon' => 'icon',
520071f0
AN
99 'link' => 'link',
100 'link_or_button' => 'link_or_button',
101 'list_item' => 'list_item',
102 'optgroup' => 'optgroup',
103 'option' => 'option',
104 'question' => 'question',
105 'radio' => 'radio',
106 'region' => 'region',
107 'section' => 'section',
108 'select' => 'select',
109 'table' => 'table',
110 'table_row' => 'table_row',
111 'text' => 'text',
112 'xpath_element' => 'xpath_element',
113 'form_row' => 'form_row',
ab2095fb 114 'autocomplete_selection' => 'autocomplete_selection',
1b63ff10 115 'autocomplete_suggestions' => 'autocomplete_suggestions',
520071f0
AN
116 );
117
118 /**
119 * Behat by default comes with XPath, CSS and named selectors,
120 * named selectors are a mapping between names (like button) and
121 * xpaths that represents that names and includes a placeholder that
122 * will be replaced by the locator. These are Moodle's own xpaths.
123 *
1e815600 124 * @var array XPaths for moodle elements.
520071f0
AN
125 */
126 protected static $moodleselectors = array(
127 'activity' => <<<XPATH
128.//li[contains(concat(' ', normalize-space(@class), ' '), ' activity ')][normalize-space(.) = %locator% ]
129XPATH
130 , 'block' => <<<XPATH
131.//*[@data-block][contains(concat(' ', normalize-space(@class), ' '), concat(' ', %locator%, ' ')) or
3ec69c2e 132 descendant::*[self::h2|self::h3|self::h4|self::h5][normalize-space(.) = %locator%] or
520071f0
AN
133 @aria-label = %locator%]
134XPATH
135 , 'dialogue' => <<<XPATH
136.//div[contains(concat(' ', normalize-space(@class), ' '), ' moodle-dialogue ') and
137 normalize-space(descendant::div[
138 contains(concat(' ', normalize-space(@class), ' '), ' moodle-dialogue-hd ')
139 ]) = %locator%] |
140.//div[contains(concat(' ', normalize-space(@class), ' '), ' yui-dialog ') and
141 normalize-space(descendant::div[@class='hd']) = %locator%]
434d7869 142 |
dd4ac3d2
AN
143.//div[@data-region='modal' and descendant::*[@data-region='title'] = %locator%]
144 |
145.//div[
146 contains(concat(' ', normalize-space(@class), ' '), ' modal-content ')
147 and
3ec69c2e 148 normalize-space(descendant::*[self::h4 or self::h5][contains(concat(' ', normalize-space(@class), ' '), ' modal-title ')]) = %locator%
dd4ac3d2
AN
149 ]
150 |
151.//div[
152 contains(concat(' ', normalize-space(@class), ' '), ' modal ')
153 and
154 normalize-space(descendant::*[contains(concat(' ', normalize-space(@class), ' '), ' modal-header ')] = %locator%)
155 ]
65f631c5
AA
156XPATH
157 , 'group_message' => <<<XPATH
158 .//*[@data-conversation-id]//img[contains(@alt, %locator%)]/..
159XPATH
d624c135
AA
160 , 'group_message_conversation' => <<<XPATH
161 .//*[@data-region='message-drawer' and contains(., %locator%)]//div[@data-region='content-message-container']
162XPATH
163 , 'group_message_header' => <<<XPATH
e688eab8 164 .//*[@data-region='message-drawer']//div[@data-region='header-container' and contains(., %locator%)]
65f631c5
AA
165XPATH
166 , 'group_message_member' => <<<XPATH
167 .//*[@data-region='message-drawer']//div[@data-region='group-info-content-container']
168 //div[@class='list-group' and not(contains(@class, 'hidden'))]//*[text()[contains(., %locator%)]] |
169 .//*[@data-region='message-drawer']//div[@data-region='group-info-content-container']
9171b588 170 //div[@data-region='empty-message-container' and not(contains(@class, 'hidden')) and contains(., %locator%)]
65f631c5
AA
171XPATH
172 , 'group_message_tab' => <<<XPATH
a58fbd48 173 .//*[@data-region='message-drawer']//button[@data-toggle='collapse' and contains(string(), %locator%)]
e688eab8
AA
174XPATH
175 , 'group_message_list_area' => <<<XPATH
176 .//*[@data-region='message-drawer']//*[contains(@data-region, concat('view-overview-', %locator%))]
8857c715
DW
177XPATH
178 , 'icon' => <<<XPATH
179.//*[contains(concat(' ', normalize-space(@class), ' '), ' icon ') and ( contains(normalize-space(@title), %locator%))]
520071f0
AN
180XPATH
181 , 'list_item' => <<<XPATH
182.//li[contains(normalize-space(.), %locator%) and not(.//li[contains(normalize-space(.), %locator%)])]
183XPATH
184 , 'question' => <<<XPATH
185.//div[contains(concat(' ', normalize-space(@class), ' '), ' que ')]
186 [contains(div[@class='content']/div[contains(concat(' ', normalize-space(@class), ' '), ' formulation ')], %locator%)]
187XPATH
188 , 'region' => <<<XPATH
189.//*[self::div | self::section | self::aside | self::header | self::footer][./@id = %locator%]
190XPATH
191 , 'section' => <<<XPATH
192.//li[contains(concat(' ', normalize-space(@class), ' '), ' section ')][./descendant::*[self::h3]
193 [normalize-space(.) = %locator%][contains(concat(' ', normalize-space(@class), ' '), ' sectionname ') or
194 contains(concat(' ', normalize-space(@class), ' '), ' section-title ')]] |
195.//div[contains(concat(' ', normalize-space(@class), ' '), ' sitetopic ')]
196 [./descendant::*[self::h2][normalize-space(.) = %locator%] or %locator% = 'frontpage']
197XPATH
198 , 'table' => <<<XPATH
199.//table[(./@id = %locator% or contains(.//caption, %locator%) or contains(.//th, %locator%) or contains(concat(' ', normalize-space(@class), ' '), %locator% ))]
200XPATH
201 , 'table_row' => <<<XPATH
202.//tr[contains(normalize-space(.), %locator%) and not(.//tr[contains(normalize-space(.), %locator%)])]
203XPATH
204 , 'text' => <<<XPATH
205.//*[contains(., %locator%) and not(.//*[contains(., %locator%)])]
206XPATH
207 , 'form_row' => <<<XPATH
208.//*[self::label or self::div[contains(concat(' ', @class, ' '), ' fstaticlabel ')]][contains(., %locator%)]/ancestor::*[contains(concat(' ', @class, ' '), ' fitem ')]
ab2095fb
AG
209XPATH
210 , 'autocomplete_selection' => <<<XPATH
211.//div[contains(concat(' ', normalize-space(@class), ' '), concat(' ', 'form-autocomplete-selection', ' '))]/span[@role='listitem'][contains(normalize-space(.), %locator%)]
1b63ff10
SR
212XPATH
213 , 'autocomplete_suggestions' => <<<XPATH
214.//ul[contains(concat(' ', normalize-space(@class), ' '), concat(' ', 'form-autocomplete-suggestions', ' '))]/li[@role='option'][contains(normalize-space(.), %locator%)]
520071f0
AN
215XPATH
216 );
217
218 protected static $customselectors = [
219 'field' => [
220 'upstream' => <<<XPATH
221.//*
222[%fieldFilterWithPlaceholder%][%notFieldTypeFilter%][%fieldMatchWithPlaceholder%]
223|
224.//label[%tagTextMatch%]//.//*[%fieldFilterWithPlaceholder%][%notFieldTypeFilter%]
225|
226.//*
227[%fieldFilterWithoutPlaceholder%][%notFieldTypeFilter%][%fieldMatchWithoutPlaceholder%]
228|
229.//label[%tagTextMatch%]//.//*[%fieldFilterWithoutPlaceholder%][%notFieldTypeFilter%]
230XPATH
231 ,
232 'filemanager' => <<<XPATH
6ee51d01 233.//*[@data-fieldtype = 'filemanager' or @data-fieldtype = 'filepicker']
d9821755 234 /descendant::input[@id = //label[contains(normalize-space(string(.)), %locator%)]/@for]
ca25005c
AN
235XPATH
236 ,
237 'passwordunmask' => <<<XPATH
238.//*[@data-passwordunmask='wrapper']
737b54fe 239 /descendant::input[@id = %locator% or @id = //label[contains(normalize-space(string(.)), %locator%)]/@for]
520071f0
AN
240XPATH
241 ],
242 ];
243
1e815600
AN
244 /**
245 * Mink comes with a number of named replacements.
246 * Sometimes we want to add our own.
247 *
248 * @var array XPaths for moodle elements.
249 */
250 protected static $customreplacements = [
251 '%buttonMatch%' => [
252 'upstream' => '%idOrNameMatch% or %valueMatch% or %titleMatch%',
253 'aria' => '%ariaLabelMatch%',
254 ],
255 '%ariaLabelMatch%' => [
256 'moodle' => 'contains(./@aria-label, %locator%)',
257 ],
258 ];
259
520071f0
AN
260 /**
261 * Allowed selectors getter.
262 *
263 * @return array
264 */
265 public static function get_allowed_selectors() {
266 return static::$allowedselectors;
267 }
268
269 /**
270 * Allowed text selectors getter.
271 *
272 * @return array
273 */
274 public static function get_allowed_text_selectors() {
275 return static::$allowedtextselectors;
276 }
277}