You are here

public function MetatagNoIndexTest::testEntityNoIndex in XML sitemap 8

Same name and namespace in other branches
  1. 2.x tests/src/Kernel/MetatagNoIndexTest.php \Drupal\Tests\xmlsitemap\Kernel\MetatagNoIndexTest::testEntityNoIndex()

Tests overriding an entity's robots meta tag.

File

tests/src/Kernel/MetatagNoIndexTest.php, line 92

Class

MetatagNoIndexTest
Tests integration with the Metatag module.

Namespace

Drupal\Tests\xmlsitemap\Kernel

Code

public function testEntityNoIndex() {

  // Set the robots metatago on the user entity.
  $this->account
    ->set('field_metatags', serialize([
    'robots' => 'noindex',
  ]));
  $this->account
    ->save();

  // Test that the user is not visible in the sitemap now.
  $link = $this->linkStorage
    ->load('user', $this->account
    ->id());
  $this
    ->assertFalse($link['access'] && $link['status']);

  // Disable the metatag noindex configuration.
  $this
    ->config('xmlsitemap.settings')
    ->set('metatag_exclude_noindex', FALSE)
    ->save(TRUE);
  drupal_static_reset('metatag_xmlsitemap_link_alter');

  // Test that the user is visible in the sitemap again.
  $this->account
    ->save();
  $link = $this->linkStorage
    ->load('user', $this->account
    ->id());
  $this
    ->assertTrue($link['access'] && $link['status']);
}