You are here

public function MetatagAdminTest::testSpecialPages in Metatag 8

Tests special pages.

File

tests/src/Functional/MetatagAdminTest.php, line 204

Class

MetatagAdminTest
Tests the Metatag administration.

Namespace

Drupal\Tests\metatag\Functional

Code

public function testSpecialPages() {

  // Initiate session with a user who can manage metatags.
  $permissions = [
    'administer site configuration',
    'administer meta tags',
  ];
  $account = $this
    ->drupalCreateUser($permissions);
  $this
    ->drupalLogin($account);

  // Adjust the front page and test it.
  $this
    ->drupalGet('admin/config/search/metatag/front');
  $session = $this
    ->assertSession();
  $session
    ->statusCodeEquals(200);
  $values = [
    'description' => 'Front page description',
  ];
  $this
    ->drupalPostForm(NULL, $values, 'Save');
  $session
    ->pageTextContains('Saved the Front page Metatag defaults.');
  $this
    ->drupalGet('<front>');
  $session
    ->statusCodeEquals(200);
  $session
    ->responseContains($values['description'], $this
    ->t('Front page defaults are used at the front page.'));

  // Adjust the 403 page and test it.
  $this
    ->drupalGet('admin/config/search/metatag/403');
  $session
    ->statusCodeEquals(200);
  $values = [
    'description' => '403 page description.',
  ];
  $this
    ->drupalPostForm(NULL, $values, 'Save');
  $session
    ->pageTextContains('Saved the 403 access denied Metatag defaults.');
  $this
    ->drupalLogout();
  $this
    ->drupalGet('admin/config/search/metatag');
  $session
    ->statusCodeEquals(403);
  $session
    ->responseContains($values['description'], $this
    ->t('403 page defaults are used at 403 pages.'));

  // Adjust the 404 page and test it.
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet('admin/config/search/metatag/404');
  $session
    ->statusCodeEquals(200);
  $values = [
    'description' => '404 page description.',
  ];
  $this
    ->drupalPostForm(NULL, $values, 'Save');
  $session
    ->pageTextContains('Saved the 404 page not found Metatag defaults.');
  $this
    ->drupalGet('foo');
  $session
    ->statusCodeEquals(404);
  $session
    ->responseContains($values['description'], $this
    ->t('404 page defaults are used at 404 pages.'));
  $this
    ->drupalLogout();
}