1 | <?php |
||
12 | class MessageContext extends RawDrupalContext implements TranslatableContext { |
||
13 | |||
14 | /** |
||
15 | * {@inheritDoc} |
||
16 | */ |
||
17 | public static function getTranslationResources() { |
||
20 | |||
21 | /** |
||
22 | * Checks if the current page contains the given error message |
||
23 | * |
||
24 | * @param $message |
||
25 | * string The text to be checked |
||
26 | * |
||
27 | * @Then I should see the error message( containing) :message |
||
28 | */ |
||
29 | public function assertErrorVisible($message) { |
||
37 | |||
38 | /** |
||
39 | * Checks if the current page contains the given set of error messages |
||
40 | * |
||
41 | * @param $messages |
||
42 | * array An array of texts to be checked |
||
43 | * |
||
44 | * @Then I should see the following error message(s): |
||
45 | */ |
||
46 | public function assertMultipleErrors(TableNode $messages) { |
||
52 | |||
53 | /** |
||
54 | * Checks if the current page does not contain the given error message |
||
55 | * |
||
56 | * @param $message |
||
57 | * string The text to be checked |
||
58 | * |
||
59 | * @Given I should not see the error message( containing) :message |
||
60 | */ |
||
61 | public function assertNotErrorVisible($message) { |
||
68 | |||
69 | /** |
||
70 | * Checks if the current page does not contain the given set error messages |
||
71 | * |
||
72 | * @param $messages |
||
73 | * array An array of texts to be checked |
||
74 | * |
||
75 | * @Then I should not see the following error messages: |
||
76 | */ |
||
77 | public function assertNotMultipleErrors(TableNode $messages) { |
||
83 | |||
84 | /** |
||
85 | * Checks if the current page contains the given success message |
||
86 | * |
||
87 | * @param $message |
||
88 | * string The text to be checked |
||
89 | * |
||
90 | * @Then I should see the success message( containing) :message |
||
91 | */ |
||
92 | public function assertSuccessMessage($message) { |
||
100 | |||
101 | /** |
||
102 | * Checks if the current page contains the given set of success messages |
||
103 | * |
||
104 | * @param $message |
||
105 | * array An array of texts to be checked |
||
106 | * |
||
107 | * @Then I should see the following success messages: |
||
108 | */ |
||
109 | public function assertMultipleSuccessMessage(TableNode $messages) { |
||
115 | |||
116 | /** |
||
117 | * Checks if the current page does not contain the given set of success message |
||
118 | * |
||
119 | * @param $message |
||
120 | * string The text to be checked |
||
121 | * |
||
122 | * @Given I should not see the success message( containing) :message |
||
123 | */ |
||
124 | public function assertNotSuccessMessage($message) { |
||
131 | |||
132 | /** |
||
133 | * Checks if the current page does not contain the given set of success messages |
||
134 | * |
||
135 | * @param $message |
||
136 | * array An array of texts to be checked |
||
137 | * |
||
138 | * @Then I should not see the following success messages: |
||
139 | */ |
||
140 | public function assertNotMultipleSuccessMessage(TableNode $messages) { |
||
146 | |||
147 | /** |
||
148 | * Checks if the current page contains the given warning message |
||
149 | * |
||
150 | * @param $message |
||
151 | * string The text to be checked |
||
152 | * |
||
153 | * @Then I should see the warning message( containing) :message |
||
154 | */ |
||
155 | public function assertWarningMessage($message) { |
||
163 | |||
164 | /** |
||
165 | * Checks if the current page contains the given set of warning messages |
||
166 | * |
||
167 | * @param $message |
||
168 | * array An array of texts to be checked |
||
169 | * |
||
170 | * @Then I should see the following warning messages: |
||
171 | */ |
||
172 | public function assertMultipleWarningMessage(TableNode $messages) { |
||
178 | |||
179 | /** |
||
180 | * Checks if the current page does not contain the given set of warning message |
||
181 | * |
||
182 | * @param $message |
||
183 | * string The text to be checked |
||
184 | * |
||
185 | * @Given I should not see the warning message( containing) :message |
||
186 | */ |
||
187 | public function assertNotWarningMessage($message) { |
||
194 | |||
195 | /** |
||
196 | * Checks if the current page does not contain the given set of warning messages |
||
197 | * |
||
198 | * @param $message |
||
199 | * array An array of texts to be checked |
||
200 | * |
||
201 | * @Then I should not see the following warning messages: |
||
202 | */ |
||
203 | public function assertNotMultipleWarningMessage(TableNode $messages) { |
||
209 | |||
210 | /** |
||
211 | * Checks if the current page contain the given message |
||
212 | * |
||
213 | * @param $message |
||
214 | * string The message to be checked |
||
215 | * |
||
216 | * @Then I should see the message( containing) :message |
||
217 | */ |
||
218 | public function assertMessage($message) { |
||
226 | |||
227 | /** |
||
228 | * Checks if the current page does not contain the given message |
||
229 | * |
||
230 | * @param $message |
||
231 | * string The message to be checked |
||
232 | * |
||
233 | * @Then I should not see the message( containing) :message |
||
234 | */ |
||
235 | public function assertNotMessage($message) { |
||
242 | |||
243 | /** |
||
244 | * Internal callback to check for a specific message in a given context. |
||
245 | * |
||
246 | * @param $message |
||
247 | * string The message to be checked |
||
248 | * @param $selectorId |
||
249 | * string CSS selector name |
||
250 | * @param $exceptionMsgNone |
||
251 | * string The message being thrown when no message is contained, string |
||
252 | * should contain one '%s' as a placeholder for the current URL |
||
253 | * @param $exceptionMsgMissing |
||
254 | * string The message being thrown when the message is not contained, string |
||
255 | * should contain two '%s' as placeholders for the current URL and the message. |
||
256 | * |
||
257 | * @throws \Behat\Mink\Exception\ExpectationException |
||
258 | * Thrown when the expected message is not present in the page. |
||
259 | */ |
||
260 | private function _assert($message, $selectorId, $exceptionMsgNone, $exceptionMsgMissing) { |
||
261 | $selector = $this->getDrupalSelector($selectorId); |
||
262 | $selectorObjects = $this->getSession()->getPage()->findAll("css", $selector); |
||
263 | if (empty($selectorObjects)) { |
||
264 | throw new ExpectationException(sprintf($exceptionMsgNone, $this->getSession()->getCurrentUrl()), $this->getSession()->getDriver()); |
||
265 | } |
||
266 | foreach ($selectorObjects as $selectorObject) { |
||
267 | if (strpos(trim($selectorObject->getText()), $message) !== FALSE) { |
||
268 | return; |
||
269 | } |
||
270 | } |
||
271 | throw new ExpectationException(sprintf($exceptionMsgMissing, $this->getSession()->getCurrentUrl(), $message), $this->getSession()->getDriver()); |
||
272 | } |
||
273 | |||
274 | /** |
||
275 | * Internal callback to check if the current page does not contain the given message |
||
276 | * |
||
277 | * @param $message |
||
278 | * string The message to be checked |
||
279 | * @param $selectorId |
||
280 | * string CSS selector name |
||
281 | * @param $exceptionMsg |
||
282 | * string The message being thrown when the message is contained, string |
||
283 | * should contain two '%s' as placeholders for the current URL and the message. |
||
284 | * |
||
285 | * @throws \Behat\Mink\Exception\ExpectationException |
||
286 | * Thrown when the expected message is present in the page. |
||
287 | */ |
||
288 | private function _assertNot($message, $selectorId, $exceptionMsg) { |
||
299 | |||
300 | } |
||
301 |