You are here

public function XmlSitemapRobotsTxtIntegrationTest::testRobotsTxt in XML sitemap 2.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/XmlSitemapRobotsTxtIntegrationTest.php \Drupal\Tests\xmlsitemap\Functional\XmlSitemapRobotsTxtIntegrationTest::testRobotsTxt()

Test if sitemap link is included in robots.txt file.

File

tests/src/Functional/XmlSitemapRobotsTxtIntegrationTest.php, line 24

Class

XmlSitemapRobotsTxtIntegrationTest
Tests the robots.txt file existence.

Namespace

Drupal\Tests\xmlsitemap\Functional

Code

public function testRobotsTxt() {

  // Request the un-clean robots.txt path so this will work in case there is
  // still the robots.txt file in the root directory. In order to bypass the
  // local robots.txt file we need to rebuild the container and use a Request
  // with clean URLs disabled.
  $this->container = $this->kernel
    ->rebuildContainer();
  $this
    ->prepareRequestForGenerator(FALSE);
  $this
    ->assertNotEmpty(XmlSitemap::loadByContext());
  $this
    ->drupalGet(Url::fromRoute('robotstxt.content'));
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->responseContains('Sitemap: ' . Url::fromRoute('xmlsitemap.sitemap_xml', [], [
    'absolute' => TRUE,
  ])
    ->toString());
}