You are here

XmlSitemapRobotsTxtIntegrationTest.php in XML sitemap 8

Same filename and directory in other branches
  1. 2.x tests/src/Functional/XmlSitemapRobotsTxtIntegrationTest.php

File

tests/src/Functional/XmlSitemapRobotsTxtIntegrationTest.php
View source
<?php

namespace Drupal\Tests\xmlsitemap\Functional;

use Drupal\Core\Url;
use Drupal\xmlsitemap\Entity\XmlSitemap;

/**
 * Tests the robots.txt file existence.
 *
 * @group xmlsitemap
 * @dependencies robotstxt
 */
class XmlSitemapRobotsTxtIntegrationTest extends XmlSitemapTestBase {

  /**
   * {@inheritdoc}
   */
  public static $modules = [
    'robotstxt',
  ];

  /**
   * Test if sitemap link is included in robots.txt file.
   */
  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());
  }

}

Classes

Namesort descending Description
XmlSitemapRobotsTxtIntegrationTest Tests the robots.txt file existence.