diff --git a/core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php b/core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php index 9839a8e445..d6a5a80733 100644 --- a/core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php +++ b/core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php @@ -379,7 +379,7 @@ public function testMediaReferenceWidget($cardinality, array $media_type_create_ $fieldset_selector = '#edit-field-media-reference-wrapper fieldset'; $fieldset = $this->session->elementExists('css', $fieldset_selector); - $this->assertEquals($field->getLabel(), $fieldset->find('css', 'legend')->getText()); + $this->assertSame($field->getLabel(), $this->session->elementExists('css', 'legend', $fieldset)->getText()); // Assert text that should be displayed regardless of other access. $this->assertHelpTexts([$use_header, $use_help, $type_list], $fieldset_selector); @@ -424,11 +424,14 @@ public function testMediaReferenceWidget($cardinality, array $media_type_create_ * * @param string[] $texts * A list of the help texts to check. - * @param bool $expected - * Whether or not the text is expected. + * @param string $selector + * (optional) The selector to search. */ public function assertHelpTexts(array $texts, $selector = '') { foreach ($texts as $text) { + // We only want to escape single quotes, so use str_replace() rather than + // addslashes(). + $text = str_replace("'", "\'", $text); if ($selector) { $this->session->elementsCount('css', $selector . ":contains('$text')", 1); } @@ -460,23 +463,14 @@ public function assertNoHelpTexts(array $texts) { * @param string[] attributes * An associative array of any expected attributes, keyed by the * attribute name. - * @param bool $exists - * Whether the link should exist. Defaults to TRUE. */ - protected function assertHelpLink(NodeElement $element, $text, array $attributes = [], $exists = TRUE) { + protected function assertHelpLink(NodeElement $element, $text, array $attributes = []) { // Find all the links inside the element. $link = $element->findLink($text); - if ($exists) { - $this->assertNotEmpty($link); - foreach ($attributes as $attribute => $value) { - $this->assertEquals($link->getAttribute($attribute), $value); - } - } - else { - // Assert that the link is not present anywhere on the page. - $this->assertEmpty($link); - $this->session->pageTextNotContains($text); + $this->assertNotEmpty($link); + foreach ($attributes as $attribute => $value) { + $this->assertEquals($link->getAttribute($attribute), $value); } } @@ -489,7 +483,9 @@ protected function assertHelpLink(NodeElement $element, $text, array $attributes * The link text. */ protected function assertNoHelpLink(NodeElement $element, $text) { - $this->assertHelpLink($element, $text, [], FALSE); + // Assert that the link and its text are not present anywhere on the page. + $this->session->elementNotExists('named', ['link', $text], $element); + $this->session->pageTextNotContains($text); } /**