function MediaUiReferenceWidgetTest::assertHelpTexts

Same name in other branches
  1. 11.x core/modules/media/tests/src/Functional/MediaUiReferenceWidgetTest.php \Drupal\Tests\media\Functional\MediaUiReferenceWidgetTest::assertHelpTexts()

Asserts that the given texts are present exactly once.

@internal

Parameters

string[] $texts: A list of the help texts to check.

string $selector: (optional) The selector to search.

1 call to MediaUiReferenceWidgetTest::assertHelpTexts()
MediaUiReferenceWidgetTest::testMediaReferenceWidget in core/modules/media/tests/src/Functional/MediaUiReferenceWidgetTest.php
Tests the default autocomplete widgets for media reference fields.

File

core/modules/media/tests/src/Functional/MediaUiReferenceWidgetTest.php, line 286

Class

MediaUiReferenceWidgetTest
Ensures that media UI works correctly.

Namespace

Drupal\Tests\media\Functional

Code

protected function assertHelpTexts(array $texts, string $selector = '') : void {
    $assert_session = $this->assertSession();
    foreach ($texts as $text) {
        // We only want to escape single quotes, so use str_replace() rather than
        // addslashes().
        $text = str_replace("'", "\\'", $text);
        if ($selector) {
            $assert_session->elementsCount('css', $selector . ":contains('{$text}')", 1);
        }
        else {
            $assert_session->pageTextContains($text);
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.