function LanguageSwitchingTest::assertLinkMarkup

Same name in other branches
  1. 10 core/modules/language/tests/src/Functional/LanguageSwitchingTest.php \Drupal\Tests\language\Functional\LanguageSwitchingTest::assertLinkMarkup()
  2. 11.x core/modules/language/tests/src/Functional/LanguageSwitchingTest.php \Drupal\Tests\language\Functional\LanguageSwitchingTest::assertLinkMarkup()

Asserts that restricted text is or is not present in the page response.

Parameters

string $path: The path to test.

int $status: The HTTP status code, such as 200 or 403.

string $marker: Text that should always be present.

string $restricted: Text that should be tested.

bool $found: (optional) If TRUE, then the restricted text is present. Defaults to FALSE.

1 call to LanguageSwitchingTest::assertLinkMarkup()
LanguageSwitchingTest::testRestrictedPaths in core/modules/language/tests/src/Functional/LanguageSwitchingTest.php
Test that the language switching block does not expose restricted paths.

File

core/modules/language/tests/src/Functional/LanguageSwitchingTest.php, line 605

Class

LanguageSwitchingTest
Functional tests for the language switching feature.

Namespace

Drupal\Tests\language\Functional

Code

protected function assertLinkMarkup(string $path, int $status, string $marker, string $restricted, bool $found = FALSE) : void {
    $this->drupalGet($path);
    $this->assertSession()
        ->statusCodeEquals($status);
    $this->assertSession()
        ->pageTextContains($marker);
    if ($found) {
        $this->assertSession()
            ->responseContains($restricted);
    }
    else {
        $this->assertSession()
            ->responseNotContains($restricted);
    }
    // Assert that all languages had a link passed to
    // hook_language_switch_links_alter() to allow alternatives to be provided.
    $languages = \Drupal::languageManager()->getNativeLanguages();
    $links_for_alter = \Drupal::state()->get('language_test.language_switch_link_ids');
    $this->assertSame(array_keys($languages), $links_for_alter);
}

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