Security update for Core, with self-updated composer
[yaffs-website] / web / core / tests / Drupal / FunctionalTests / AssertLegacyTrait.php
1 <?php
2
3 namespace Drupal\FunctionalTests;
4
5 use Behat\Mink\Element\NodeElement;
6 use Behat\Mink\Exception\ExpectationException;
7 use Behat\Mink\Selector\Xpath\Escaper;
8 use Drupal\Component\Render\FormattableMarkup;
9 use Drupal\Component\Utility\Xss;
10 use Drupal\KernelTests\AssertLegacyTrait as BaseAssertLegacyTrait;
11
12 /**
13  * Provides convenience methods for assertions in browser tests.
14  *
15  * @deprecated Scheduled for removal in Drupal 9.0.0. Use the methods on
16  *   \Drupal\Tests\WebAssert instead, for example
17  * @code
18  *    $this->assertSession()->statusCodeEquals(200);
19  * @endcode
20  */
21 trait AssertLegacyTrait {
22
23   use BaseAssertLegacyTrait;
24
25   /**
26    * Asserts that the element with the given CSS selector is present.
27    *
28    * @param string $css_selector
29    *   The CSS selector identifying the element to check.
30    *
31    * @deprecated Scheduled for removal in Drupal 9.0.0.
32    *   Use $this->assertSession()->elementExists() instead.
33    */
34   protected function assertElementPresent($css_selector) {
35     $this->assertSession()->elementExists('css', $css_selector);
36   }
37
38   /**
39    * Asserts that the element with the given CSS selector is not present.
40    *
41    * @param string $css_selector
42    *   The CSS selector identifying the element to check.
43    *
44    * @deprecated Scheduled for removal in Drupal 9.0.0.
45    *   Use $this->assertSession()->elementNotExists() instead.
46    */
47   protected function assertElementNotPresent($css_selector) {
48     $this->assertSession()->elementNotExists('css', $css_selector);
49   }
50
51   /**
52    * Passes if the page (with HTML stripped) contains the text.
53    *
54    * Note that stripping HTML tags also removes their attributes, such as
55    * the values of text fields.
56    *
57    * @param string $text
58    *   Plain text to look for.
59    *
60    * @deprecated Scheduled for removal in Drupal 9.0.0.
61    *   Use instead:
62    *     - $this->assertSession()->responseContains() for non-HTML responses,
63    *       like XML or Json.
64    *     - $this->assertSession()->pageTextContains() for HTML responses. Unlike
65    *       the deprecated assertText(), the passed text should be HTML decoded,
66    *       exactly as a human sees it in the browser.
67    */
68   protected function assertText($text) {
69     // Cast MarkupInterface to string.
70     $text = (string) $text;
71
72     $content_type = $this->getSession()->getResponseHeader('Content-type');
73     // In case of a Non-HTML response (example: XML) check the original
74     // response.
75     if (strpos($content_type, 'html') === FALSE) {
76       $this->assertSession()->responseContains($text);
77     }
78     else {
79       $this->assertTextHelper($text, FALSE);
80     }
81   }
82
83   /**
84    * Passes if the page (with HTML stripped) does not contains the text.
85    *
86    * Note that stripping HTML tags also removes their attributes, such as
87    * the values of text fields.
88    *
89    * @param string $text
90    *   Plain text to look for.
91    *
92    * @deprecated Scheduled for removal in Drupal 9.0.0.
93    *   Use instead:
94    *     - $this->assertSession()->responseNotContains() for non-HTML responses,
95    *       like XML or Json.
96    *     - $this->assertSession()->pageTextNotContains() for HTML responses.
97    *       Unlike the deprecated assertNoText(), the passed text should be HTML
98    *       decoded, exactly as a human sees it in the browser.
99    */
100   protected function assertNoText($text) {
101     // Cast MarkupInterface to string.
102     $text = (string) $text;
103
104     $content_type = $this->getSession()->getResponseHeader('Content-type');
105     // In case of a Non-HTML response (example: XML) check the original
106     // response.
107     if (strpos($content_type, 'html') === FALSE) {
108       $this->assertSession()->responseNotContains($text);
109     }
110     else {
111       $this->assertTextHelper($text);
112     }
113   }
114
115   /**
116    * Helper for assertText and assertNoText.
117    *
118    * @param string $text
119    *   Plain text to look for.
120    * @param bool $not_exists
121    *   (optional) TRUE if this text should not exist, FALSE if it should.
122    *   Defaults to TRUE.
123    *
124    * @return bool
125    *   TRUE on pass, FALSE on fail.
126    */
127   protected function assertTextHelper($text, $not_exists = TRUE) {
128     $args = ['@text' => $text];
129     $message = $not_exists ? new FormattableMarkup('"@text" not found', $args) : new FormattableMarkup('"@text" found', $args);
130
131     $raw_content = $this->getSession()->getPage()->getContent();
132     // Trying to simulate what the user sees, given that it removes all text
133     // inside the head tags, removes inline Javascript, fix all HTML entities,
134     // removes dangerous protocols and filtering out all HTML tags, as they are
135     // not visible in a normal browser.
136     $raw_content = preg_replace('@<head>(.+?)</head>@si', '', $raw_content);
137     $page_text = Xss::filter($raw_content, []);
138
139     $actual = $not_exists == (strpos($page_text, (string) $text) === FALSE);
140     $this->assertTrue($actual, $message);
141
142     return $actual;
143   }
144
145   /**
146    * Passes if the text is found ONLY ONCE on the text version of the page.
147    *
148    * The text version is the equivalent of what a user would see when viewing
149    * through a web browser. In other words the HTML has been filtered out of
150    * the contents.
151    *
152    * @param string|\Drupal\Component\Render\MarkupInterface $text
153    *   Plain text to look for.
154    * @param string $message
155    *   (optional) A message to display with the assertion. Do not translate
156    *   messages with t(). If left blank, a default message will be displayed.
157    *
158    * @deprecated Scheduled for removal in Drupal 9.0.0.
159    *   Use $this->getSession()->getPage()->getText() and substr_count() instead.
160    */
161   protected function assertUniqueText($text, $message = NULL) {
162     // Cast MarkupInterface objects to string.
163     $text = (string) $text;
164
165     $message = $message ?: "'$text' found only once on the page";
166     $page_text = $this->getSession()->getPage()->getText();
167     $nr_found = substr_count($page_text, $text);
168     $this->assertSame(1, $nr_found, $message);
169   }
170
171   /**
172    * Passes if the text is found MORE THAN ONCE on the text version of the page.
173    *
174    * The text version is the equivalent of what a user would see when viewing
175    * through a web browser. In other words the HTML has been filtered out of
176    * the contents.
177    *
178    * @param string|\Drupal\Component\Render\MarkupInterface $text
179    *   Plain text to look for.
180    * @param string $message
181    *   (optional) A message to display with the assertion. Do not translate
182    *   messages with t(). If left blank, a default message will be displayed.
183    *
184    * @deprecated Scheduled for removal in Drupal 9.0.0.
185    *   Use $this->getSession()->getPage()->getText() and substr_count() instead.
186    */
187   protected function assertNoUniqueText($text, $message = '') {
188     // Cast MarkupInterface objects to string.
189     $text = (string) $text;
190
191     $message = $message ?: "'$text' found more than once on the page";
192     $page_text = $this->getSession()->getPage()->getText();
193     $nr_found = substr_count($page_text, $text);
194     $this->assertGreaterThan(1, $nr_found, $message);
195   }
196
197   /**
198    * Asserts the page responds with the specified response code.
199    *
200    * @param int $code
201    *   Response code. For example 200 is a successful page request. For a list
202    *   of all codes see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html.
203    *
204    * @deprecated Scheduled for removal in Drupal 9.0.0.
205    *   Use $this->assertSession()->statusCodeEquals() instead.
206    */
207   protected function assertResponse($code) {
208     $this->assertSession()->statusCodeEquals($code);
209   }
210
211   /**
212    * Asserts that a field exists with the given name and value.
213    *
214    * @param string $name
215    *   Name of field to assert.
216    * @param string $value
217    *   (optional) Value of the field to assert. You may pass in NULL (default)
218    *   to skip checking the actual value, while still checking that the field
219    *   exists.
220    *
221    * @deprecated Scheduled for removal in Drupal 9.0.0.
222    *   Use $this->assertSession()->fieldExists() or
223    *   $this->assertSession()->buttonExists() or
224    *   $this->assertSession()->fieldValueEquals() instead.
225    */
226   protected function assertFieldByName($name, $value = NULL) {
227     $this->assertFieldByXPath($this->constructFieldXpath('name', $name), $value);
228   }
229
230   /**
231    * Asserts that a field does not exist with the given name and value.
232    *
233    * @param string $name
234    *   Name of field to assert.
235    * @param string $value
236    *   (optional) Value for the field, to assert that the field's value on the
237    *   page does not match it. You may pass in NULL to skip checking the
238    *   value, while still checking that the field does not exist. However, the
239    *   default value ('') asserts that the field value is not an empty string.
240    *
241    * @deprecated Scheduled for removal in Drupal 9.0.0.
242    *   Use $this->assertSession()->fieldNotExists() or
243    *   $this->assertSession()->buttonNotExists() or
244    *   $this->assertSession()->fieldValueNotEquals() instead.
245    */
246   protected function assertNoFieldByName($name, $value = '') {
247     $this->assertNoFieldByXPath($this->constructFieldXpath('name', $name), $value);
248   }
249
250   /**
251    * Asserts that a field exists with the given ID and value.
252    *
253    * @param string $id
254    *   ID of field to assert.
255    * @param string|\Drupal\Component\Render\MarkupInterface $value
256    *   (optional) Value for the field to assert. You may pass in NULL to skip
257    *   checking the value, while still checking that the field exists.
258    *   However, the default value ('') asserts that the field value is an empty
259    *   string.
260    *
261    * @throws \Behat\Mink\Exception\ElementNotFoundException
262    *
263    * @deprecated Scheduled for removal in Drupal 9.0.0.
264    *   Use $this->assertSession()->fieldExists() or
265    *   $this->assertSession()->buttonExists() or
266    *   $this->assertSession()->fieldValueEquals() instead.
267    */
268   protected function assertFieldById($id, $value = '') {
269     $this->assertFieldByXPath($this->constructFieldXpath('id', $id), $value);
270   }
271
272   /**
273    * Asserts that a field exists with the given name or ID.
274    *
275    * @param string $field
276    *   Name or ID of field to assert.
277    *
278    * @deprecated Scheduled for removal in Drupal 9.0.0.
279    *   Use $this->assertSession()->fieldExists() or
280    *   $this->assertSession()->buttonExists() instead.
281    */
282   protected function assertField($field) {
283     $this->assertFieldByXPath($this->constructFieldXpath('name', $field) . '|' . $this->constructFieldXpath('id', $field));
284   }
285
286   /**
287    * Asserts that a field does NOT exist with the given name or ID.
288    *
289    * @param string $field
290    *   Name or ID of field to assert.
291    *
292    * @deprecated Scheduled for removal in Drupal 9.0.0.
293    *   Use $this->assertSession()->fieldNotExists() or
294    *   $this->assertSession()->buttonNotExists() instead.
295    */
296   protected function assertNoField($field) {
297     $this->assertNoFieldByXPath($this->constructFieldXpath('name', $field) . '|' . $this->constructFieldXpath('id', $field));
298   }
299
300   /**
301    * Passes if the raw text IS found on the loaded page, fail otherwise.
302    *
303    * Raw text refers to the raw HTML that the page generated.
304    *
305    * @param string $raw
306    *   Raw (HTML) string to look for.
307    *
308    * @deprecated Scheduled for removal in Drupal 9.0.0.
309    *   Use $this->assertSession()->responseContains() instead.
310    */
311   protected function assertRaw($raw) {
312     $this->assertSession()->responseContains($raw);
313   }
314
315   /**
316    * Passes if the raw text IS not found on the loaded page, fail otherwise.
317    *
318    * Raw text refers to the raw HTML that the page generated.
319    *
320    * @param string $raw
321    *   Raw (HTML) string to look for.
322    *
323    * @deprecated Scheduled for removal in Drupal 9.0.0.
324    *   Use $this->assertSession()->responseNotContains() instead.
325    */
326   protected function assertNoRaw($raw) {
327     $this->assertSession()->responseNotContains($raw);
328   }
329
330   /**
331    * Pass if the page title is the given string.
332    *
333    * @param string $expected_title
334    *   The string the page title should be.
335    *
336    * @deprecated Scheduled for removal in Drupal 9.0.0.
337    *   Use $this->assertSession()->titleEquals() instead.
338    */
339   protected function assertTitle($expected_title) {
340     // Cast MarkupInterface to string.
341     $expected_title = (string) $expected_title;
342     return $this->assertSession()->titleEquals($expected_title);
343   }
344
345   /**
346    * Passes if a link with the specified label is found.
347    *
348    * An optional link index may be passed.
349    *
350    * @param string|\Drupal\Component\Render\MarkupInterface $label
351    *   Text between the anchor tags.
352    * @param int $index
353    *   Link position counting from zero.
354    *
355    * @deprecated Scheduled for removal in Drupal 9.0.0.
356    *   Use $this->assertSession()->linkExists() instead.
357    */
358   protected function assertLink($label, $index = 0) {
359     return $this->assertSession()->linkExists($label, $index);
360   }
361
362   /**
363    * Passes if a link with the specified label is not found.
364    *
365    * @param string|\Drupal\Component\Render\MarkupInterface $label
366    *   Text between the anchor tags.
367    *
368    * @deprecated Scheduled for removal in Drupal 9.0.0.
369    *   Use $this->assertSession()->linkNotExists() instead.
370    */
371   protected function assertNoLink($label) {
372     return $this->assertSession()->linkNotExists($label);
373   }
374
375   /**
376    * Passes if a link containing a given href (part) is found.
377    *
378    * @param string $href
379    *   The full or partial value of the 'href' attribute of the anchor tag.
380    * @param int $index
381    *   Link position counting from zero.
382    *
383    * @deprecated Scheduled for removal in Drupal 9.0.0.
384    *   Use $this->assertSession()->linkByHrefExists() instead.
385    */
386   protected function assertLinkByHref($href, $index = 0) {
387     $this->assertSession()->linkByHrefExists($href, $index);
388   }
389
390   /**
391    * Passes if a link containing a given href (part) is not found.
392    *
393    * @param string $href
394    *   The full or partial value of the 'href' attribute of the anchor tag.
395    *
396    * @deprecated Scheduled for removal in Drupal 9.0.0.
397    *   Use $this->assertSession()->linkByHrefNotExists() instead.
398    */
399   protected function assertNoLinkByHref($href) {
400     $this->assertSession()->linkByHrefNotExists($href);
401   }
402
403   /**
404    * Asserts that a field does not exist with the given ID and value.
405    *
406    * @param string $id
407    *   ID of field to assert.
408    * @param string $value
409    *   (optional) Value for the field, to assert that the field's value on the
410    *   page doesn't match it. You may pass in NULL to skip checking the value,
411    *   while still checking that the field doesn't exist. However, the default
412    *   value ('') asserts that the field value is not an empty string.
413    *
414    * @throws \Behat\Mink\Exception\ExpectationException
415    *
416    * @deprecated Scheduled for removal in Drupal 9.0.0.
417    *   Use $this->assertSession()->fieldNotExists() or
418    *   $this->assertSession()->buttonNotExists() or
419    *   $this->assertSession()->fieldValueNotEquals() instead.
420    */
421   protected function assertNoFieldById($id, $value = '') {
422     $this->assertNoFieldByXPath($this->constructFieldXpath('id', $id), $value);
423   }
424
425   /**
426    * Passes if the internal browser's URL matches the given path.
427    *
428    * @param \Drupal\Core\Url|string $path
429    *   The expected system path or URL.
430    *
431    * @deprecated Scheduled for removal in Drupal 9.0.0.
432    *   Use $this->assertSession()->addressEquals() instead.
433    */
434   protected function assertUrl($path) {
435     $this->assertSession()->addressEquals($path);
436   }
437
438   /**
439    * Asserts that a select option in the current page exists.
440    *
441    * @param string $id
442    *   ID of select field to assert.
443    * @param string $option
444    *   Option to assert.
445    *
446    * @deprecated Scheduled for removal in Drupal 9.0.0.
447    *   Use $this->assertSession()->optionExists() instead.
448    */
449   protected function assertOption($id, $option) {
450     return $this->assertSession()->optionExists($id, $option);
451   }
452
453   /**
454    * Asserts that a select option with the visible text exists.
455    *
456    * @param string $id
457    *   The ID of the select field to assert.
458    * @param string $text
459    *   The text for the option tag to assert.
460    *
461    * @deprecated Scheduled for removal in Drupal 9.0.0.
462    *   Use $this->assertSession()->optionExists() instead.
463    */
464   protected function assertOptionByText($id, $text) {
465     return $this->assertSession()->optionExists($id, $text);
466   }
467
468   /**
469    * Asserts that a select option does NOT exist in the current page.
470    *
471    * @param string $id
472    *   ID of select field to assert.
473    * @param string $option
474    *   Option to assert.
475    *
476    * @deprecated Scheduled for removal in Drupal 9.0.0.
477    *   Use $this->assertSession()->optionNotExists() instead.
478    */
479   protected function assertNoOption($id, $option) {
480     return $this->assertSession()->optionNotExists($id, $option);
481   }
482
483   /**
484    * Asserts that a select option in the current page is checked.
485    *
486    * @param string $id
487    *   ID of select field to assert.
488    * @param string $option
489    *   Option to assert.
490    * @param string $message
491    *   (optional) A message to display with the assertion. Do not translate
492    *   messages with t(). If left blank, a default message will be displayed.
493    *
494    * @deprecated Scheduled for removal in Drupal 9.0.0.
495    *   Use $this->assertSession()->optionExists() instead and check the
496    *   "selected" attribute yourself.
497    */
498   protected function assertOptionSelected($id, $option, $message = NULL) {
499     $option_field = $this->assertSession()->optionExists($id, $option);
500     $message = $message ?: "Option $option for field $id is selected.";
501     $this->assertTrue($option_field->hasAttribute('selected'), $message);
502   }
503
504   /**
505    * Asserts that a checkbox field in the current page is checked.
506    *
507    * @param string $id
508    *   ID of field to assert.
509    *
510    * @deprecated Scheduled for removal in Drupal 9.0.0.
511    *   Use $this->assertSession()->checkboxChecked() instead.
512    */
513   protected function assertFieldChecked($id) {
514     $this->assertSession()->checkboxChecked($id);
515   }
516
517   /**
518    * Asserts that a checkbox field in the current page is not checked.
519    *
520    * @param string $id
521    *   ID of field to assert.
522    *
523    * @deprecated Scheduled for removal in Drupal 9.0.0.
524    *   Use $this->assertSession()->checkboxNotChecked() instead.
525    */
526   protected function assertNoFieldChecked($id) {
527     $this->assertSession()->checkboxNotChecked($id);
528   }
529
530   /**
531    * Asserts that a field exists in the current page by the given XPath.
532    *
533    * @param string $xpath
534    *   XPath used to find the field.
535    * @param string $value
536    *   (optional) Value of the field to assert. You may pass in NULL (default)
537    *   to skip checking the actual value, while still checking that the field
538    *   exists.
539    * @param string $message
540    *   (optional) A message to display with the assertion. Do not translate
541    *   messages with t().
542    *
543    * @deprecated Scheduled for removal in Drupal 9.0.0.
544    *   Use $this->xpath() instead and check the values directly in the test.
545    */
546   protected function assertFieldByXPath($xpath, $value = NULL, $message = '') {
547     $fields = $this->xpath($xpath);
548
549     $this->assertFieldsByValue($fields, $value, $message);
550   }
551
552   /**
553    * Asserts that a field does not exist or its value does not match, by XPath.
554    *
555    * @param string $xpath
556    *   XPath used to find the field.
557    * @param string $value
558    *   (optional) Value of the field, to assert that the field's value on the
559    *   page does not match it.
560    * @param string $message
561    *   (optional) A message to display with the assertion. Do not translate
562    *   messages with t().
563    *
564    * @throws \Behat\Mink\Exception\ExpectationException
565    *
566    * @deprecated Scheduled for removal in Drupal 9.0.0.
567    *   Use $this->xpath() instead and assert that the result is empty.
568    */
569   protected function assertNoFieldByXPath($xpath, $value = NULL, $message = '') {
570     $fields = $this->xpath($xpath);
571
572     if (!empty($fields)) {
573       if (isset($value)) {
574         $found = FALSE;
575         try {
576           $this->assertFieldsByValue($fields, $value);
577           $found = TRUE;
578         }
579         catch (\Exception $e) {
580         }
581
582         if ($found) {
583           throw new ExpectationException(sprintf('The field resulting from %s was found with the provided value %s.', $xpath, $value), $this->getSession()->getDriver());
584         }
585       }
586       else {
587         throw new ExpectationException(sprintf('The field resulting from %s was found.', $xpath), $this->getSession()->getDriver());
588       }
589     }
590   }
591
592   /**
593    * Asserts that a field exists in the current page with a given Xpath result.
594    *
595    * @param \Behat\Mink\Element\NodeElement[] $fields
596    *   Xml elements.
597    * @param string $value
598    *   (optional) Value of the field to assert. You may pass in NULL (default) to skip
599    *   checking the actual value, while still checking that the field exists.
600    * @param string $message
601    *   (optional) A message to display with the assertion. Do not translate
602    *   messages with t().
603    *
604    * @deprecated Scheduled for removal in Drupal 9.0.0.
605    *   Iterate over the fields yourself instead and directly check the values in
606    *   the test.
607    */
608   protected function assertFieldsByValue($fields, $value = NULL, $message = '') {
609     // If value specified then check array for match.
610     $found = TRUE;
611     if (isset($value)) {
612       $found = FALSE;
613       if ($fields) {
614         foreach ($fields as $field) {
615           if ($field->getAttribute('type') == 'checkbox') {
616             if (is_bool($value)) {
617               $found = $field->isChecked() == $value;
618             }
619             else {
620               $found = TRUE;
621             }
622           }
623           elseif ($field->getAttribute('value') == $value) {
624             // Input element with correct value.
625             $found = TRUE;
626           }
627           elseif ($field->find('xpath', '//option[@value = ' . (new Escaper())->escapeLiteral($value) . ' and @selected = "selected"]')) {
628             // Select element with an option.
629             $found = TRUE;
630           }
631           elseif ($field->getTagName() === 'textarea' && $field->getValue() == $value) {
632             // Text area with correct text. Use getValue() here because
633             // getText() would remove any newlines in the value.
634             $found = TRUE;
635           }
636           elseif ($field->getTagName() !== 'input' && $field->getText() == $value) {
637             $found = TRUE;
638           }
639         }
640       }
641     }
642     $this->assertTrue($fields && $found, $message);
643   }
644
645   /**
646    * Passes if the raw text IS found escaped on the loaded page, fail otherwise.
647    *
648    * Raw text refers to the raw HTML that the page generated.
649    *
650    * @param string $raw
651    *   Raw (HTML) string to look for.
652    *
653    * @deprecated Scheduled for removal in Drupal 9.0.0.
654    *   Use $this->assertSession()->assertEscaped() instead.
655    */
656   protected function assertEscaped($raw) {
657     $this->assertSession()->assertEscaped($raw);
658   }
659
660   /**
661    * Passes if the raw text is not found escaped on the loaded page.
662    *
663    * Raw text refers to the raw HTML that the page generated.
664    *
665    * @param string $raw
666    *   Raw (HTML) string to look for.
667    *
668    * @deprecated Scheduled for removal in Drupal 9.0.0.
669    *   Use $this->assertSession()->assertNoEscaped() instead.
670    */
671   protected function assertNoEscaped($raw) {
672     $this->assertSession()->assertNoEscaped($raw);
673   }
674
675   /**
676    * Triggers a pass if the Perl regex pattern is found in the raw content.
677    *
678    * @param string $pattern
679    *   Perl regex to look for including the regex delimiters.
680    *
681    * @deprecated Scheduled for removal in Drupal 9.0.0.
682    *   Use $this->assertSession()->responseMatches() instead.
683    */
684   protected function assertPattern($pattern) {
685     $this->assertSession()->responseMatches($pattern);
686   }
687
688   /**
689    * Triggers a pass if the Perl regex pattern is not found in the raw content.
690    *
691    * @param string $pattern
692    *   Perl regex to look for including the regex delimiters.
693    *
694    * @deprecated Scheduled for removal in Drupal 9.0.0.
695    *   Use $this->assertSession()->responseNotMatches() instead.
696    *
697    * @see https://www.drupal.org/node/2864262
698    */
699   protected function assertNoPattern($pattern) {
700     @trigger_error('assertNoPattern() is deprecated and scheduled for removal in Drupal 9.0.0. Use $this->assertSession()->responseNotMatches($pattern) instead. See https://www.drupal.org/node/2864262.', E_USER_DEPRECATED);
701     $this->assertSession()->responseNotMatches($pattern);
702   }
703
704   /**
705    * Asserts whether an expected cache tag was present in the last response.
706    *
707    * @param string $expected_cache_tag
708    *   The expected cache tag.
709    *
710    * @deprecated Scheduled for removal in Drupal 9.0.0.
711    *   Use $this->assertSession()->responseHeaderContains() instead.
712    */
713   protected function assertCacheTag($expected_cache_tag) {
714     $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', $expected_cache_tag);
715   }
716
717   /**
718    * Asserts whether an expected cache tag was absent in the last response.
719    *
720    * @param string $cache_tag
721    *   The cache tag to check.
722    *
723    * @deprecated Scheduled for removal in Drupal 9.0.0.
724    *   Use $this->assertSession()->responseHeaderNotContains() instead.
725    *
726    * @see https://www.drupal.org/node/2864029
727    */
728   protected function assertNoCacheTag($cache_tag) {
729     @trigger_error('assertNoCacheTag() is deprecated and scheduled for removal in Drupal 9.0.0. Use $this->assertSession()->responseHeaderNotContains() instead. See https://www.drupal.org/node/2864029.', E_USER_DEPRECATED);
730     $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', $cache_tag);
731   }
732
733   /**
734    * Checks that current response header equals value.
735    *
736    * @param string $name
737    *   Name of header to assert.
738    * @param string $value
739    *   Value of the header to assert
740    *
741    * @deprecated Scheduled for removal in Drupal 9.0.0.
742    *   Use $this->assertSession()->responseHeaderEquals() instead.
743    */
744   protected function assertHeader($name, $value) {
745     $this->assertSession()->responseHeaderEquals($name, $value);
746   }
747
748   /**
749    * Returns WebAssert object.
750    *
751    * @param string $name
752    *   (optional) Name of the session. Defaults to the active session.
753    *
754    * @return \Drupal\Tests\WebAssert
755    *   A new web-assert option for asserting the presence of elements with.
756    */
757   abstract public function assertSession($name = NULL);
758
759   /**
760    * Builds an XPath query.
761    *
762    * Builds an XPath query by replacing placeholders in the query by the value
763    * of the arguments.
764    *
765    * XPath 1.0 (the version supported by libxml2, the underlying XML library
766    * used by PHP) doesn't support any form of quotation. This function
767    * simplifies the building of XPath expression.
768    *
769    * @param string $xpath
770    *   An XPath query, possibly with placeholders in the form ':name'.
771    * @param array $args
772    *   An array of arguments with keys in the form ':name' matching the
773    *   placeholders in the query. The values may be either strings or numeric
774    *   values.
775    *
776    * @return string
777    *   An XPath query with arguments replaced.
778    *
779    * @deprecated Scheduled for removal in Drupal 9.0.0.
780    *   Use $this->assertSession()->buildXPathQuery() instead.
781    */
782   protected function buildXPathQuery($xpath, array $args = []) {
783     return $this->assertSession()->buildXPathQuery($xpath, $args);
784   }
785
786   /**
787    * Helper: Constructs an XPath for the given set of attributes and value.
788    *
789    * @param string $attribute
790    *   Field attributes.
791    * @param string $value
792    *   Value of field.
793    *
794    * @return string
795    *   XPath for specified values.
796    *
797    * @deprecated Scheduled for removal in Drupal 9.0.0.
798    *   Use $this->getSession()->getPage()->findField() instead.
799    */
800   protected function constructFieldXpath($attribute, $value) {
801     $xpath = '//textarea[@' . $attribute . '=:value]|//input[@' . $attribute . '=:value]|//select[@' . $attribute . '=:value]';
802     return $this->buildXPathQuery($xpath, [':value' => $value]);
803   }
804
805   /**
806    * Gets the current raw content.
807    *
808    * @deprecated Scheduled for removal in Drupal 9.0.0.
809    *   Use $this->getSession()->getPage()->getContent() instead.
810    */
811   protected function getRawContent() {
812     @trigger_error('AssertLegacyTrait::getRawContent() is scheduled for removal in Drupal 9.0.0. Use $this->getSession()->getPage()->getContent() instead.', E_USER_DEPRECATED);
813     return $this->getSession()->getPage()->getContent();
814   }
815
816   /**
817    * Get all option elements, including nested options, in a select.
818    *
819    * @param \Behat\Mink\Element\NodeElement $element
820    *   The element for which to get the options.
821    *
822    * @return \Behat\Mink\Element\NodeElement[]
823    *   Option elements in select.
824    *
825    * @deprecated Scheduled for removal in Drupal 9.0.0.
826    *   Use $element->findAll('xpath', 'option') instead.
827    */
828   protected function getAllOptions(NodeElement $element) {
829     @trigger_error('AssertLegacyTrait::getAllOptions() is scheduled for removal in Drupal 9.0.0. Use $element->findAll(\'xpath\', \'option\') instead.', E_USER_DEPRECATED);
830     return $element->findAll('xpath', '//option');
831   }
832
833 }