c88949df74403232dec1fba4a9cb6825e702c9ef
[yaffs-website] / web / core / tests / Drupal / FunctionalTests / AssertLegacyTrait.php
1 <?php
2
3 namespace Drupal\FunctionalTests;
4
5 use Behat\Mink\Exception\ElementNotFoundException;
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()->fieldValueEquals() instead.
224    */
225   protected function assertFieldByName($name, $value = NULL) {
226     $this->assertSession()->fieldExists($name);
227     if ($value !== NULL) {
228       $this->assertSession()->fieldValueEquals($name, (string) $value);
229     }
230   }
231
232   /**
233    * Asserts that a field does not exist with the given name and value.
234    *
235    * @param string $name
236    *   Name of field to assert.
237    * @param string $value
238    *   (optional) Value for the field, to assert that the field's value on the
239    *   page does not match it. You may pass in NULL to skip checking the
240    *   value, while still checking that the field does not exist. However, the
241    *   default value ('') asserts that the field value is not an empty string.
242    *
243    * @deprecated Scheduled for removal in Drupal 9.0.0.
244    *   Use $this->assertSession()->fieldNotExists() or
245    *   $this->assertSession()->fieldValueNotEquals() instead.
246    */
247   protected function assertNoFieldByName($name, $value = '') {
248     if ($this->getSession()->getPage()->findField($name) && isset($value)) {
249       $this->assertSession()->fieldValueNotEquals($name, (string) $value);
250     }
251     else {
252       $this->assertSession()->fieldNotExists($name);
253     }
254   }
255
256   /**
257    * Asserts that a field exists with the given ID and value.
258    *
259    * @param string $id
260    *   ID of field to assert.
261    * @param string|\Drupal\Component\Render\MarkupInterface $value
262    *   (optional) Value for the field to assert. You may pass in NULL to skip
263    *   checking the value, while still checking that the field exists.
264    *   However, the default value ('') asserts that the field value is an empty
265    *   string.
266    *
267    * @throws \Behat\Mink\Exception\ElementNotFoundException
268    *
269    * @deprecated Scheduled for removal in Drupal 9.0.0.
270    *   Use $this->assertSession()->fieldExists() or
271    *   $this->assertSession()->fieldValueEquals() instead.
272    */
273   protected function assertFieldById($id, $value = '') {
274     $xpath = $this->assertSession()->buildXPathQuery('//textarea[@id=:value]|//input[@id=:value]|//select[@id=:value]', [':value' => $id]);
275     $field = $this->getSession()->getPage()->find('xpath', $xpath);
276
277     if (empty($field)) {
278       throw new ElementNotFoundException($this->getSession()->getDriver(), 'form field', 'id', $field);
279     }
280
281     if ($value !== NULL) {
282       $this->assertEquals($value, $field->getValue());
283     }
284   }
285
286   /**
287    * Asserts that a field exists 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()->fieldExists() instead.
294    */
295   protected function assertField($field) {
296     $this->assertSession()->fieldExists($field);
297   }
298
299   /**
300    * Asserts that a field exists with the given name or ID does NOT exist.
301    *
302    * @param string $field
303    *   Name or ID of field to assert.
304    *
305    * @deprecated Scheduled for removal in Drupal 9.0.0.
306    *   Use $this->assertSession()->fieldNotExists() instead.
307    */
308   protected function assertNoField($field) {
309     $this->assertSession()->fieldNotExists($field);
310   }
311
312   /**
313    * Passes if the raw text IS found on the loaded page, fail otherwise.
314    *
315    * Raw text refers to the raw HTML that the page generated.
316    *
317    * @param string $raw
318    *   Raw (HTML) string to look for.
319    *
320    * @deprecated Scheduled for removal in Drupal 9.0.0.
321    *   Use $this->assertSession()->responseContains() instead.
322    */
323   protected function assertRaw($raw) {
324     $this->assertSession()->responseContains($raw);
325   }
326
327   /**
328    * Passes if the raw text IS not found on the loaded page, fail otherwise.
329    *
330    * Raw text refers to the raw HTML that the page generated.
331    *
332    * @param string $raw
333    *   Raw (HTML) string to look for.
334    *
335    * @deprecated Scheduled for removal in Drupal 9.0.0.
336    *   Use $this->assertSession()->responseNotContains() instead.
337    */
338   protected function assertNoRaw($raw) {
339     $this->assertSession()->responseNotContains($raw);
340   }
341
342   /**
343    * Pass if the page title is the given string.
344    *
345    * @param string $expected_title
346    *   The string the page title should be.
347    *
348    * @deprecated Scheduled for removal in Drupal 9.0.0.
349    *   Use $this->assertSession()->titleEquals() instead.
350    */
351   protected function assertTitle($expected_title) {
352     // Cast MarkupInterface to string.
353     $expected_title = (string) $expected_title;
354     return $this->assertSession()->titleEquals($expected_title);
355   }
356
357   /**
358    * Passes if a link with the specified label is found.
359    *
360    * An optional link index may be passed.
361    *
362    * @param string|\Drupal\Component\Render\MarkupInterface $label
363    *   Text between the anchor tags.
364    * @param int $index
365    *   Link position counting from zero.
366    *
367    * @deprecated Scheduled for removal in Drupal 9.0.0.
368    *   Use $this->assertSession()->linkExists() instead.
369    */
370   protected function assertLink($label, $index = 0) {
371     return $this->assertSession()->linkExists($label, $index);
372   }
373
374   /**
375    * Passes if a link with the specified label is not found.
376    *
377    * @param string|\Drupal\Component\Render\MarkupInterface $label
378    *   Text between the anchor tags.
379    *
380    * @deprecated Scheduled for removal in Drupal 9.0.0.
381    *   Use $this->assertSession()->linkNotExists() instead.
382    */
383   protected function assertNoLink($label) {
384     return $this->assertSession()->linkNotExists($label);
385   }
386
387   /**
388    * Passes if a link containing a given href (part) is found.
389    *
390    * @param string $href
391    *   The full or partial value of the 'href' attribute of the anchor tag.
392    * @param int $index
393    *   Link position counting from zero.
394    *
395    * @deprecated Scheduled for removal in Drupal 9.0.0.
396    *   Use $this->assertSession()->linkByHrefExists() instead.
397    */
398   protected function assertLinkByHref($href, $index = 0) {
399     $this->assertSession()->linkByHrefExists($href, $index);
400   }
401
402   /**
403    * Passes if a link containing a given href (part) is not found.
404    *
405    * @param string $href
406    *   The full or partial value of the 'href' attribute of the anchor tag.
407    *
408    * @deprecated Scheduled for removal in Drupal 9.0.0.
409    *   Use $this->assertSession()->linkByHrefNotExists() instead.
410    */
411   protected function assertNoLinkByHref($href) {
412     $this->assertSession()->linkByHrefNotExists($href);
413   }
414
415   /**
416    * Asserts that a field does not exist with the given ID and value.
417    *
418    * @param string $id
419    *   ID of field to assert.
420    * @param string $value
421    *   (optional) Value for the field, to assert that the field's value on the
422    *   page doesn't match it. You may pass in NULL to skip checking the value,
423    *   while still checking that the field doesn't exist. However, the default
424    *   value ('') asserts that the field value is not an empty string.
425    *
426    * @throws \Behat\Mink\Exception\ExpectationException
427    *
428    * @deprecated Scheduled for removal in Drupal 9.0.0.
429    *   Use $this->assertSession()->fieldNotExists() or
430    *   $this->assertSession()->fieldValueNotEquals() instead.
431    */
432   protected function assertNoFieldById($id, $value = '') {
433     $xpath = $this->assertSession()->buildXPathQuery('//textarea[@id=:value]|//input[@id=:value]|//select[@id=:value]', [':value' => $id]);
434     $field = $this->getSession()->getPage()->find('xpath', $xpath);
435
436     // Return early if the field could not be found as expected.
437     if ($field === NULL) {
438       return;
439     }
440
441     if (!isset($value)) {
442       throw new ExpectationException(sprintf('Id "%s" appears on this page, but it should not.', $id), $this->getSession()->getDriver());
443     }
444     elseif ($value === $field->getValue()) {
445       throw new ExpectationException(sprintf('Failed asserting that %s is not equal to %s', $field->getValue(), $value), $this->getSession()->getDriver());
446     }
447   }
448
449   /**
450    * Passes if the internal browser's URL matches the given path.
451    *
452    * @param \Drupal\Core\Url|string $path
453    *   The expected system path or URL.
454    *
455    * @deprecated Scheduled for removal in Drupal 9.0.0.
456    *   Use $this->assertSession()->addressEquals() instead.
457    */
458   protected function assertUrl($path) {
459     $this->assertSession()->addressEquals($path);
460   }
461
462   /**
463    * Asserts that a select option in the current page exists.
464    *
465    * @param string $id
466    *   ID of select field to assert.
467    * @param string $option
468    *   Option to assert.
469    *
470    * @deprecated Scheduled for removal in Drupal 9.0.0.
471    *   Use $this->assertSession()->optionExists() instead.
472    */
473   protected function assertOption($id, $option) {
474     return $this->assertSession()->optionExists($id, $option);
475   }
476
477   /**
478    * Asserts that a select option with the visible text exists.
479    *
480    * @param string $id
481    *   The ID of the select field to assert.
482    * @param string $text
483    *   The text for the option tag to assert.
484    *
485    * @deprecated Scheduled for removal in Drupal 9.0.0.
486    *   Use $this->assertSession()->optionExists() instead.
487    */
488   protected function assertOptionByText($id, $text) {
489     return $this->assertSession()->optionExists($id, $text);
490   }
491
492   /**
493    * Asserts that a select option does NOT exist in the current page.
494    *
495    * @param string $id
496    *   ID of select field to assert.
497    * @param string $option
498    *   Option to assert.
499    *
500    * @deprecated Scheduled for removal in Drupal 9.0.0.
501    *   Use $this->assertSession()->optionNotExists() instead.
502    */
503   protected function assertNoOption($id, $option) {
504     return $this->assertSession()->optionNotExists($id, $option);
505   }
506
507   /**
508    * Asserts that a select option in the current page is checked.
509    *
510    * @param string $id
511    *   ID of select field to assert.
512    * @param string $option
513    *   Option to assert.
514    * @param string $message
515    *   (optional) A message to display with the assertion. Do not translate
516    *   messages with t(). If left blank, a default message will be displayed.
517    *
518    * @deprecated Scheduled for removal in Drupal 9.0.0.
519    *   Use $this->assertSession()->optionExists() instead and check the
520    *   "selected" attribute yourself.
521    */
522   protected function assertOptionSelected($id, $option, $message = NULL) {
523     $option_field = $this->assertSession()->optionExists($id, $option);
524     $message = $message ?: "Option $option for field $id is selected.";
525     $this->assertTrue($option_field->hasAttribute('selected'), $message);
526   }
527
528   /**
529    * Asserts that a checkbox field in the current page is checked.
530    *
531    * @param string $id
532    *   ID of field to assert.
533    *
534    * @deprecated Scheduled for removal in Drupal 9.0.0.
535    *   Use $this->assertSession()->checkboxChecked() instead.
536    */
537   protected function assertFieldChecked($id) {
538     $this->assertSession()->checkboxChecked($id);
539   }
540
541   /**
542    * Asserts that a checkbox field in the current page is not checked.
543    *
544    * @param string $id
545    *   ID of field to assert.
546    *
547    * @deprecated Scheduled for removal in Drupal 9.0.0.
548    *   Use $this->assertSession()->checkboxNotChecked() instead.
549    */
550   protected function assertNoFieldChecked($id) {
551     $this->assertSession()->checkboxNotChecked($id);
552   }
553
554   /**
555    * Asserts that a field exists in the current page by the given XPath.
556    *
557    * @param string $xpath
558    *   XPath used to find the field.
559    * @param string $value
560    *   (optional) Value of the field to assert. You may pass in NULL (default)
561    *   to skip checking the actual value, while still checking that the field
562    *   exists.
563    * @param string $message
564    *   (optional) A message to display with the assertion. Do not translate
565    *   messages with t().
566    *
567    * @deprecated Scheduled for removal in Drupal 9.0.0.
568    *   Use $this->xpath() instead and check the values directly in the test.
569    */
570   protected function assertFieldByXPath($xpath, $value = NULL, $message = '') {
571     $fields = $this->xpath($xpath);
572
573     $this->assertFieldsByValue($fields, $value, $message);
574   }
575
576   /**
577    * Asserts that a field does not exist or its value does not match, by XPath.
578    *
579    * @param string $xpath
580    *   XPath used to find the field.
581    * @param string $value
582    *   (optional) Value of the field, to assert that the field's value on the
583    *   page does not match it.
584    * @param string $message
585    *   (optional) A message to display with the assertion. Do not translate
586    *   messages with t().
587    *
588    * @deprecated Scheduled for removal in Drupal 9.0.0.
589    *   Use $this->xpath() instead and assert that the result is empty.
590    */
591   protected function assertNoFieldByXPath($xpath, $value = NULL, $message = '') {
592     $fields = $this->xpath($xpath);
593
594     // If value specified then check array for match.
595     $found = TRUE;
596     if (isset($value)) {
597       $found = FALSE;
598       if ($fields) {
599         foreach ($fields as $field) {
600           if ($field->getAttribute('value') == $value) {
601             $found = TRUE;
602           }
603         }
604       }
605     }
606     return $this->assertFalse($fields && $found, $message);
607   }
608
609   /**
610    * Asserts that a field exists in the current page with a given Xpath result.
611    *
612    * @param \Behat\Mink\Element\NodeElement[] $fields
613    *   Xml elements.
614    * @param string $value
615    *   (optional) Value of the field to assert. You may pass in NULL (default) to skip
616    *   checking the actual value, while still checking that the field exists.
617    * @param string $message
618    *   (optional) A message to display with the assertion. Do not translate
619    *   messages with t().
620    *
621    * @deprecated Scheduled for removal in Drupal 9.0.0.
622    *   Iterate over the fields yourself instead and directly check the values in
623    *   the test.
624    */
625   protected function assertFieldsByValue($fields, $value = NULL, $message = '') {
626     // If value specified then check array for match.
627     $found = TRUE;
628     if (isset($value)) {
629       $found = FALSE;
630       if ($fields) {
631         foreach ($fields as $field) {
632           if ($field->getAttribute('value') == $value) {
633             // Input element with correct value.
634             $found = TRUE;
635           }
636           elseif ($field->find('xpath', '//option[@value = ' . (new Escaper())->escapeLiteral($value) . ' and @selected = "selected"]')) {
637             // Select element with an option.
638             $found = TRUE;
639           }
640           elseif ($field->getText() == $value) {
641             // Text area with correct text.
642             $found = TRUE;
643           }
644         }
645       }
646     }
647     $this->assertTrue($fields && $found, $message);
648   }
649
650   /**
651    * Passes if the raw text IS found escaped on the loaded page, fail otherwise.
652    *
653    * Raw text refers to the raw HTML that the page generated.
654    *
655    * @param string $raw
656    *   Raw (HTML) string to look for.
657    *
658    * @deprecated Scheduled for removal in Drupal 9.0.0.
659    *   Use $this->assertSession()->assertEscaped() instead.
660    */
661   protected function assertEscaped($raw) {
662     $this->assertSession()->assertEscaped($raw);
663   }
664
665   /**
666    * Passes if the raw text is not found escaped on the loaded page.
667    *
668    * Raw text refers to the raw HTML that the page generated.
669    *
670    * @param string $raw
671    *   Raw (HTML) string to look for.
672    *
673    * @deprecated Scheduled for removal in Drupal 9.0.0.
674    *   Use $this->assertSession()->assertNoEscaped() instead.
675    */
676   protected function assertNoEscaped($raw) {
677     $this->assertSession()->assertNoEscaped($raw);
678   }
679
680   /**
681    * Triggers a pass if the Perl regex pattern is found in the raw content.
682    *
683    * @param string $pattern
684    *   Perl regex to look for including the regex delimiters.
685    *
686    * @deprecated Scheduled for removal in Drupal 9.0.0.
687    *   Use $this->assertSession()->responseMatches() instead.
688    */
689   protected function assertPattern($pattern) {
690     $this->assertSession()->responseMatches($pattern);
691   }
692
693   /**
694    * Triggers a pass if the Perl regex pattern is not found in the raw content.
695    *
696    * @param string $pattern
697    *   Perl regex to look for including the regex delimiters.
698    *
699    * @deprecated Scheduled for removal in Drupal 9.0.0.
700    *   Use $this->assertSession()->responseNotMatches() instead.
701    *
702    * @see https://www.drupal.org/node/2864262
703    */
704   protected function assertNoPattern($pattern) {
705     @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);
706     $this->assertSession()->responseNotMatches($pattern);
707   }
708
709   /**
710    * Asserts whether an expected cache tag was present in the last response.
711    *
712    * @param string $expected_cache_tag
713    *   The expected cache tag.
714    *
715    * @deprecated Scheduled for removal in Drupal 9.0.0.
716    *   Use $this->assertSession()->responseHeaderContains() instead.
717    */
718   protected function assertCacheTag($expected_cache_tag) {
719     $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', $expected_cache_tag);
720   }
721
722   /**
723    * Checks that current response header equals value.
724    *
725    * @param string $name
726    *   Name of header to assert.
727    * @param string $value
728    *   Value of the header to assert
729    *
730    * @deprecated Scheduled for removal in Drupal 9.0.0.
731    *   Use $this->assertSession()->responseHeaderEquals() instead.
732    */
733   protected function assertHeader($name, $value) {
734     $this->assertSession()->responseHeaderEquals($name, $value);
735   }
736
737   /**
738    * Returns WebAssert object.
739    *
740    * @param string $name
741    *   (optional) Name of the session. Defaults to the active session.
742    *
743    * @return \Drupal\Tests\WebAssert
744    *   A new web-assert option for asserting the presence of elements with.
745    */
746   abstract public function assertSession($name = NULL);
747
748   /**
749    * Builds an XPath query.
750    *
751    * Builds an XPath query by replacing placeholders in the query by the value
752    * of the arguments.
753    *
754    * XPath 1.0 (the version supported by libxml2, the underlying XML library
755    * used by PHP) doesn't support any form of quotation. This function
756    * simplifies the building of XPath expression.
757    *
758    * @param string $xpath
759    *   An XPath query, possibly with placeholders in the form ':name'.
760    * @param array $args
761    *   An array of arguments with keys in the form ':name' matching the
762    *   placeholders in the query. The values may be either strings or numeric
763    *   values.
764    *
765    * @return string
766    *   An XPath query with arguments replaced.
767    *
768    * @deprecated Scheduled for removal in Drupal 9.0.0.
769    *   Use $this->assertSession()->buildXPathQuery() instead.
770    */
771   protected function buildXPathQuery($xpath, array $args = []) {
772     return $this->assertSession()->buildXPathQuery($xpath, $args);
773   }
774
775   /**
776    * Gets the current raw content.
777    *
778    * @deprecated Scheduled for removal in Drupal 9.0.0.
779    *   Use $this->getSession()->getPage()->getContent() instead.
780    */
781   protected function getRawContent() {
782     @trigger_error('AssertLegacyTrait::getRawContent() is scheduled for removal in Drupal 9.0.0. Use $this->getSession()->getPage()->getContent() instead.', E_USER_DEPRECATED);
783     return $this->getSession()->getPage()->getContent();
784   }
785
786 }