You are here

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

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

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

File

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

Class

HumansTxtBasicTest
Tests basic functionality of configured humans.txt files.

Namespace

Drupal\Tests\humanstxt\Functional

Code

public function testHumansTxtConfigureHumansTxtWithLink() {
  $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' => TRUE,
  ], 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 in HTML <head> section.
  $this
    ->drupalGet('/admin/config/development/humanstxt');
  $tags = $this
    ->getSession()
    ->getPage()
    ->getHtml();
  $this
    ->assertContains($this->fileLink, $tags, sprintf('Humans.txt link: [%s] is shown in the -head- section.', $this->fileLink));
}