You are here

public function MetatagNoIndexTest::setUp in XML sitemap 8

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

Overrides KernelTestBase::setUp

File

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

Class

MetatagNoIndexTest
Tests integration with the Metatag module.

Namespace

Drupal\Tests\xmlsitemap\Kernel

Code

public function setUp() {
  parent::setUp();
  $this
    ->installConfig([
    'system',
    'user',
    'field',
    'metatag',
  ]);
  $this
    ->installEntitySchema('user');
  $this
    ->installSchema('system', [
    'sequences',
  ]);

  // Allow anonymous user to view user profiles.
  $role = Role::load(AccountInterface::ANONYMOUS_ROLE);
  $role
    ->grantPermission('access user profiles');
  $role
    ->save();

  // Enable XML Sitemap settings for users.
  xmlsitemap_link_bundle_enable('user', 'user');
  xmlsitemap_link_bundle_settings_save('user', 'user', [
    'status' => 1,
    'priority' => XMLSITEMAP_PRIORITY_DEFAULT,
  ]);

  // Create a generic metatag field.
  FieldStorageConfig::create([
    'entity_type' => 'user',
    'field_name' => 'field_metatags',
    'type' => 'metatag',
  ])
    ->save();
  FieldConfig::create([
    'entity_type' => 'user',
    'field_name' => 'field_metatags',
    'bundle' => 'user',
  ])
    ->save();
  $this->linkStorage = $this->container
    ->get('xmlsitemap.link_storage');
  $this->account = $this
    ->createUser();

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