From 9b41c6a823d1445e8f1975ace00de33cada675f3 Mon Sep 17 00:00:00 2001
From: Dave Long <dave@longwaveconsulting.com>
Date: Mon, 14 Oct 2024 10:34:39 +0100
Subject: [PATCH] Issue #3227335 by mondrake, quietone, smustgrave, longwave:
 Deprecate unused kernel test assertions in AssertContentTrait

---
 .../Drupal/KernelTests/AssertContentTrait.php | 120 +++++++++++++++++-
 1 file changed, 119 insertions(+), 1 deletion(-)

diff --git a/core/tests/Drupal/KernelTests/AssertContentTrait.php b/core/tests/Drupal/KernelTests/AssertContentTrait.php
index 84884e674b24..4a485812acf1 100644
--- a/core/tests/Drupal/KernelTests/AssertContentTrait.php
+++ b/core/tests/Drupal/KernelTests/AssertContentTrait.php
@@ -351,8 +351,14 @@ protected function assertLinkByHref($href, $index = 0, $message = ''): bool {
    *
    * @return bool
    *   TRUE if the assertion succeeded.
+   *
+   * @deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no
+   *   replacement.
+   *
+   * @see https://www.drupal.org/node/3476110
    */
   protected function assertNoLinkByHref($href, $message = ''): bool {
+    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
     $links = $this->xpath('//a[contains(@href, :href)]', [':href' => $href]);
     $message = ($message ? $message : new FormattableMarkup('No link containing href %href found.', ['%href' => $href]));
     $this->assertEmpty($links, $message);
@@ -373,8 +379,14 @@ protected function assertNoLinkByHref($href, $message = ''): bool {
    *
    * @return bool
    *   TRUE if the assertion succeeded.
+   *
+   * @deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no
+   *   replacement.
+   *
+   * @see https://www.drupal.org/node/3476110
    */
   protected function assertNoLinkByHrefInMainRegion($href, $message = ''): bool {
+    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
     $links = $this->xpath('//main//a[contains(@href, :href)]', [':href' => $href]);
     $message = ($message ? $message : new FormattableMarkup('No link containing href %href found.', ['%href' => $href]));
     $this->assertEmpty($links, $message);
@@ -459,6 +471,7 @@ protected function assertEscaped($raw, $message = ''): void {
    *   a string. If left blank, a default message will be displayed.
    */
   protected function assertNoEscaped($raw, $message = ''): void {
+    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
     if (!$message) {
       $message = 'Escaped "' . Html::escape((string) $raw) . '" not found';
     }
@@ -556,8 +569,14 @@ protected function assertTextHelper($text, $message = '', $group = NULL, $not_ex
    *
    * @return bool
    *   TRUE on pass, FALSE on fail.
+   *
+   * @deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no
+   *   replacement.
+   *
+   * @see https://www.drupal.org/node/3476110
    */
-  protected function assertUniqueText($text, $message = ''): bool {
+  protected function assertUniqueText($text, $message = '') {
+    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
     return $this->assertUniqueTextHelper($text, $message, NULL, TRUE);
   }
 
@@ -579,8 +598,14 @@ protected function assertUniqueText($text, $message = ''): bool {
    *
    * @return bool
    *   TRUE on pass, FALSE on fail.
+   *
+   * @deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no
+   *   replacement.
+   *
+   * @see https://www.drupal.org/node/3476110
    */
   protected function assertNoUniqueText($text, $message = ''): bool {
+    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
     return $this->assertUniqueTextHelper($text, $message, NULL, FALSE);
   }
 
@@ -605,8 +630,14 @@ protected function assertNoUniqueText($text, $message = ''): bool {
    *
    * @return bool
    *   TRUE on pass.
+   *
+   * @deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no
+   *   replacement.
+   *
+   * @see https://www.drupal.org/node/3476110
    */
   protected function assertUniqueTextHelper($text, $message = '', $group = NULL, $be_unique = FALSE): bool {
+    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
     // Cast MarkupInterface objects to string.
     $text = (string) $text;
     if (!$message) {
@@ -678,8 +709,14 @@ protected function assertNoPattern($pattern, $message = ''): bool {
    *
    * @return bool
    *   TRUE on pass.
+   *
+   * @deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no
+   *   replacement.
+   *
+   * @see https://www.drupal.org/node/3476110
    */
   protected function assertTextPattern($pattern, $message = NULL): bool {
+    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
     if (!isset($message)) {
       $message = new FormattableMarkup('Pattern "@pattern" found', ['@pattern' => $pattern]);
     }
@@ -730,6 +767,7 @@ protected function assertTitle($title, $message = '') {
    *   a string. If left blank, a default message will be displayed.
    */
   protected function assertNoTitle($title, $message = '') {
+    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
     $actual = (string) current($this->xpath('//title'));
     if (!$message) {
       $message = new FormattableMarkup('Page title @actual is not equal to @unexpected.', [
@@ -893,8 +931,14 @@ protected function getSelectedItem(\SimpleXMLElement $element) {
    *
    * @return bool
    *   TRUE on pass.
+   *
+   * @deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no
+   *   replacement.
+   *
+   * @see https://www.drupal.org/node/3476110
    */
   protected function assertNoFieldByXPath($xpath, $value = NULL, $message = ''): bool {
+    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
     $fields = $this->xpath($xpath);
 
     // If value specified then check array for match.
@@ -969,8 +1013,14 @@ protected function assertFieldByName($name, $value = NULL, $message = NULL): boo
    *
    * @return bool
    *   TRUE on pass, FALSE on fail.
+   *
+   * @deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no
+   *   replacement.
+   *
+   * @see https://www.drupal.org/node/3476110
    */
   protected function assertNoFieldByName($name, $value = '', $message = ''): bool {
+    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
     return $this->assertNoFieldByXPath($this->constructFieldXpath('name', $name), $value, $message ? $message : new FormattableMarkup('Did not find field by name @name', ['@name' => $name]));
   }
 
@@ -993,8 +1043,14 @@ protected function assertNoFieldByName($name, $value = '', $message = ''): bool
    *
    * @return bool
    *   TRUE on pass, FALSE on fail.
+   *
+   * @deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no
+   *   replacement.
+   *
+   * @see https://www.drupal.org/node/3476110
    */
   protected function assertFieldById($id, $value = '', $message = ''): bool {
+    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
     // Cast MarkupInterface objects to string.
     if (isset($value)) {
       $value = (string) $value;
@@ -1022,8 +1078,14 @@ protected function assertFieldById($id, $value = '', $message = ''): bool {
    *
    * @return bool
    *   TRUE on pass, FALSE on fail.
+   *
+   * @deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no
+   *   replacement.
+   *
+   * @see https://www.drupal.org/node/3476110
    */
   protected function assertNoFieldById($id, $value = '', $message = ''): bool {
+    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
     return $this->assertNoFieldByXPath($this->constructFieldXpath('id', $id), $value, $message ? $message : new FormattableMarkup('Did not find field by id @id', ['@id' => $id]));
   }
 
@@ -1041,8 +1103,14 @@ protected function assertNoFieldById($id, $value = '', $message = ''): bool {
    *
    * @return bool
    *   TRUE on pass.
+   *
+   * @deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no
+   *   replacement.
+   *
+   * @see https://www.drupal.org/node/3476110
    */
   protected function assertFieldChecked($id, $message = ''): bool {
+    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
     $message = $message ? $message : new FormattableMarkup('Checkbox field @id is checked.', ['@id' => $id]);
     $elements = $this->xpath('//input[@id=:id]', [':id' => $id]);
     $this->assertNotEmpty($elements, $message);
@@ -1064,8 +1132,14 @@ protected function assertFieldChecked($id, $message = ''): bool {
    *
    * @return bool
    *   TRUE on pass.
+   *
+   * @deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no
+   *   replacement.
+   *
+   * @see https://www.drupal.org/node/3476110
    */
   protected function assertNoFieldChecked($id, $message = ''): bool {
+    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
     $message = $message ? $message : new FormattableMarkup('Checkbox field @id is not checked.', ['@id' => $id]);
     $elements = $this->xpath('//input[@id=:id]', [':id' => $id]);
     $this->assertNotEmpty($elements, $message);
@@ -1088,6 +1162,7 @@ protected function assertNoFieldChecked($id, $message = ''): bool {
    *   a string. If left blank, a default message will be displayed.
    */
   protected function assertOption($id, $option, $message = '') {
+    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
     $options = $this->xpath('//select[@id=:id]//option[@value=:option]', [':id' => $id, ':option' => $option]);
     $this->assertTrue(isset($options[0]), $message ? $message : new FormattableMarkup('Option @option for field @id exists.', ['@option' => $option, '@id' => $id]));
   }
@@ -1101,8 +1176,14 @@ protected function assertOption($id, $option, $message = '') {
    *   The text for the option tag to assert.
    * @param string $message
    *   (optional) A message to display with the assertion.
+   *
+   * @deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no
+   *   replacement.
+   *
+   * @see https://www.drupal.org/node/3476110
    */
   protected function assertOptionByText($id, $text, $message = '') {
+    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
     $options = $this->xpath('//select[@id=:id]//option[normalize-space(text())=:text]', [':id' => $id, ':text' => $text]);
     $this->assertTrue(isset($options[0]), $message ?: 'Option with text label ' . $text . ' for select field ' . $id . ' exits.');
   }
@@ -1122,6 +1203,7 @@ protected function assertOptionByText($id, $text, $message = '') {
    *   a string. If left blank, a default message will be displayed.
    */
   protected function assertOptionWithDrupalSelector($drupal_selector, $option, $message = '') {
+    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
     $options = $this->xpath('//select[@data-drupal-selector=:data_drupal_selector]//option[@value=:option]', [':data_drupal_selector' => $drupal_selector, ':option' => $option]);
     $this->assertTrue(isset($options[0]), $message ? $message : new FormattableMarkup('Option @option for field @data_drupal_selector exists.', ['@option' => $option, '@data_drupal_selector' => $drupal_selector]));
   }
@@ -1142,8 +1224,14 @@ protected function assertOptionWithDrupalSelector($drupal_selector, $option, $me
    *
    * @return bool
    *   TRUE on pass.
+   *
+   * @deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no
+   *   replacement.
+   *
+   * @see https://www.drupal.org/node/3476110
    */
   protected function assertNoOption($id, $option, $message = ''): bool {
+    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
     $message = $message ? $message : new FormattableMarkup('Option @option for field @id does not exist.', ['@option' => $option, '@id' => $id]);
     $selects = $this->xpath('//select[@id=:id]', [':id' => $id]);
     $options = $this->xpath('//select[@id=:id]//option[@value=:option]', [':id' => $id, ':option' => $option]);
@@ -1170,8 +1258,14 @@ protected function assertNoOption($id, $option, $message = ''): bool {
    *   TRUE on pass.
    *
    * @todo $id is unusable. Replace with $name.
+   *
+   * @deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no
+   *   replacement.
+   *
+   * @see https://www.drupal.org/node/3476110
    */
   protected function assertOptionSelected($id, $option, $message = ''): bool {
+    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
     $message = $message ? $message : new FormattableMarkup('Option @option for field @id is selected.', ['@option' => $option, '@id' => $id]);
     $elements = $this->xpath('//select[@id=:id]//option[@value=:option]', [':id' => $id, ':option' => $option]);
     $this->assertNotEmpty($elements, $message);
@@ -1197,8 +1291,14 @@ protected function assertOptionSelected($id, $option, $message = ''): bool {
    *   TRUE on pass, FALSE on fail.
    *
    * @todo $id is unusable. Replace with $name.
+   *
+   * @deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no
+   *   replacement.
+   *
+   * @see https://www.drupal.org/node/3476110
    */
   protected function assertOptionSelectedWithDrupalSelector($drupal_selector, $option, $message = ''): bool {
+    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
     $message = $message ? $message : new FormattableMarkup('Option @option for field @data_drupal_selector is selected.', ['@option' => $option, '@data_drupal_selector' => $drupal_selector]);
     $elements = $this->xpath('//select[@data-drupal-selector=:data_drupal_selector]//option[@value=:option]', [':data_drupal_selector' => $drupal_selector, ':option' => $option]);
     $this->assertNotEmpty($elements, $message);
@@ -1222,8 +1322,14 @@ protected function assertOptionSelectedWithDrupalSelector($drupal_selector, $opt
    *
    * @return bool
    *   TRUE on pass.
+   *
+   * @deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no
+   *   replacement.
+   *
+   * @see https://www.drupal.org/node/3476110
    */
   protected function assertNoOptionSelected($id, $option, $message = ''): bool {
+    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
     $message = $message ? $message : new FormattableMarkup('Option @option for field @id is not selected.', ['@option' => $option, '@id' => $id]);
     $elements = $this->xpath('//select[@id=:id]//option[@value=:option]', [':id' => $id, ':option' => $option]);
     $this->assertNotEmpty($elements, $message);
@@ -1264,8 +1370,14 @@ protected function assertField($field, $message = ''): bool {
    *
    * @return bool
    *   TRUE on pass, FALSE on fail.
+   *
+   * @deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no
+   *   replacement.
+   *
+   * @see https://www.drupal.org/node/3476110
    */
   protected function assertNoField($field, $message = ''): bool {
+    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
     return $this->assertNoFieldByXPath($this->constructFieldXpath('name', $field) . '|' . $this->constructFieldXpath('id', $field), NULL, $message);
   }
 
@@ -1290,8 +1402,14 @@ protected function assertNoField($field, $message = ''): bool {
    *
    * @return bool
    *   TRUE on pass.
+   *
+   * @deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no
+   *   replacement.
+   *
+   * @see https://www.drupal.org/node/3476110
    */
   protected function assertNoDuplicateIds($message = '', $group = NULL, $ids_to_skip = []): bool {
+    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
     $status = TRUE;
     foreach ($this->xpath('//*[@id]') as $element) {
       $id = (string) $element['id'];
-- 
GitLab