You are here

public function RobotsTxtBasicTestCase::testRobotsTxtConfigureRobotsTxt in RobotsTxt 7

Checks that a configured robots.txt file is delivered as configured.

File

./robotstxt.test, line 78
Tests for robotstxt.module.

Class

RobotsTxtBasicTestCase
Tests basic functionality of configured robots.txt files.

Code

public function testRobotsTxtConfigureRobotsTxt() {

  // Create an admin user, log in and access settings form.
  $admin_user = $this
    ->drupalCreateUser(array(
    'administer robots.txt',
  ));
  $this
    ->drupalLogin($admin_user);

  // Modify and save the robots.txt content.
  $edit = array();
  $test_string = "# SimpleTest {$this->testId}";
  $edit['robotstxt'] = "#\n{$test_string}\n#\n" . variable_get('robotstxt', '');
  $this
    ->drupalPost('admin/config/search/robotstxt', $edit, t('Save configuration'));

  // Confirm that output contains changes.
  $this
    ->drupalLogout();
  $this
    ->drupalGet('robots-test.txt');
  $this
    ->assertResponse(200, 'An anonymous user is delivered content at the /robots.txt path.');
  $this
    ->assertText("# SimpleTest {$this->testId}", sprintf('Test string [%s] is displayed in the configured robots.txt file.', $test_string));
}