public function NoReferrerTest::testNoReferrer in No Referrer 8
Functional tests for the rel="noreferrer" attribute.
File
- tests/
src/ Functional/ NoReferrerTest.php, line 34
Class
- NoReferrerTest
- Tests the No Referrer module.
Namespace
Drupal\Tests\noreferrer\FunctionalCode
public function testNoReferrer() {
$admin_user = $this
->drupalCreateUser([
'administer site configuration',
'access administration pages',
]);
$this
->drupalLogin($admin_user);
$edit = [
'whitelisted_domains' => 'drupal.org example.org',
'publish' => 1,
];
$this
->drupalGet('admin/config/content/noreferrer');
$this
->submitForm($edit, $this
->t('Save configuration'));
$this
->assertSame('<a href="https://example.com/" rel="noreferrer">test</a>', (string) Link::fromTextAndUrl('test', Url::fromUri('https://example.com/'))
->toString());
$this
->assertSame('<a href="https://drupal.org/">test</a>', (string) Link::fromTextAndUrl('test', Url::fromUri('https://drupal.org/'))
->toString());
$this
->assertSame('<a href="https://drupal.org/" target="_blank" rel="noopener">test</a>', (string) Link::fromTextAndUrl('test', Url::fromUri('https://drupal.org/', [
'attributes' => [
'target' => '_blank',
],
]))
->toString());
$this
->assertSame('<a href="https://DRUPAL.ORG/">test</a>', (string) Link::fromTextAndUrl('test', Url::fromUri('https://DRUPAL.ORG/'))
->toString());
$this
->assertSame('<a href="https://api.drupal.org/">test</a>', (string) Link::fromTextAndUrl('test', Url::fromUri('https://api.drupal.org/'))
->toString());
$this
->assertSame('<a href="https://example.com/" target="_new_tab" rel="noopener noreferrer">test</a>', (string) Link::fromTextAndUrl('test', Url::fromUri('https://example.com/', [
'attributes' => [
'target' => '_new_tab',
],
]))
->toString());
$this
->assertSame('<a href="https://example.org/" target="0" rel="noopener">test</a>', (string) Link::fromTextAndUrl('test', Url::fromUri('https://example.org/', [
'attributes' => [
'target' => '0',
],
]))
->toString());
// Test help page.
$this
->drupalGet('admin/help/noreferrer');
}