You are here

public function HumansTxtBasicTest::testHumansTxtConfigureHumansTxtNoLink in Humans.txt 2.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/HumansTxtBasicTest.php \Drupal\Tests\humanstxt\Functional\HumansTxtBasicTest::testHumansTxtConfigureHumansTxtNoLink()

Checks if humans.txt file is delivered with no link in <head>.

File

tests/src/Functional/HumansTxtBasicTest.php, line 96

Class

HumansTxtBasicTest
Tests basic functionality of configured humans.txt files.

Namespace

Drupal\Tests\humanstxt\Functional

Code

public function testHumansTxtConfigureHumansTxtNoLink() {
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet('/admin/config/development/humanstxt');
  $this
    ->assertResponse(200);
  $test_string = "# Testing Humans.txt {$this->randomMachineName()}";
  $this
    ->submitForm([
    'humanstxt_content' => $test_string,
    'humanstxt_display_link' => FALSE,
  ], t('Save configuration'));
  $this
    ->drupalLogout();

  // Test the newly created humans.txt file.
  $this
    ->drupalGet('humans.txt');
  $this
    ->assertResponse(200);
  $content = $this
    ->getSession()
    ->getPage()
    ->getContent();
  $this
    ->assertTrue($content == $test_string, sprintf('Test string: [%s] is displayed in the configured humans.txt file.', $test_string));

  // Test if the link to the object/file is not in HTML <head> section.
  $this
    ->drupalGet('/admin/config/development/humanstxt');
  $tags = $this
    ->getSession()
    ->getPage()
    ->getHtml();
  $this
    ->assertNotContains($this->fileLink, $tags, sprintf('Humans.txt link: [%s] is not shown in the -head- section.', $this->fileLink));
}