You are here

protected function XmlSitemapNodeFunctionalTest::setUp in XML sitemap 2.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/XmlSitemapNodeFunctionalTest.php \Drupal\Tests\xmlsitemap\Functional\XmlSitemapNodeFunctionalTest::setUp()

Overrides XmlSitemapTestBase::setUp

File

tests/src/Functional/XmlSitemapNodeFunctionalTest.php, line 45

Class

XmlSitemapNodeFunctionalTest
Tests the generation of node links.

Namespace

Drupal\Tests\xmlsitemap\Functional

Code

protected function setUp() {
  parent::setUp();
  $this->entityTypeManager = $this->container
    ->get('entity_type.manager');
  $this->admin_user = $this
    ->drupalCreateUser([
    'administer nodes',
    'bypass node access',
    'administer content types',
    'administer xmlsitemap',
    'administer taxonomy',
  ]);
  $this->normal_user = $this
    ->drupalCreateUser([
    'create page content',
    'edit any page content',
    'access content',
    'view own unpublished content',
  ]);

  // Allow anonymous user to view user profiles.
  $user_role = Role::load(AccountInterface::ANONYMOUS_ROLE);
  $user_role
    ->grantPermission('access content');
  $user_role
    ->save();
  xmlsitemap_link_bundle_enable('node', 'article');
  xmlsitemap_link_bundle_enable('node', 'page');
  xmlsitemap_link_bundle_settings_save('node', 'page', [
    'status' => 1,
    'priority' => 0.6,
    'changefreq' => XMLSITEMAP_FREQUENCY_WEEKLY,
  ]);

  // Add a vocabulary so we can test different view modes.
  $vocabulary = Vocabulary::create([
    'name' => 'Tags',
    'description' => $this
      ->randomMachineName(),
    'vid' => 'tags',
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
    'help' => '',
  ]);
  $vocabulary
    ->save();
  xmlsitemap_link_bundle_enable('taxonomy_term', 'tags');

  // Set up a field and instance.
  $field_name = 'tags';
  FieldStorageConfig::create([
    'field_name' => $field_name,
    'entity_type' => 'node',
    'type' => 'entity_reference',
    'settings' => [
      'target_type' => 'taxonomy_term',
    ],
    'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
  ])
    ->save();
  FieldConfig::create([
    'field_name' => $field_name,
    'entity_type' => 'node',
    'bundle' => 'page',
  ])
    ->save();
  EntityFormDisplay::load('node.page.default')
    ->setComponent($field_name, [
    'type' => 'entity_reference_autocomplete_tags',
  ])
    ->save();

  // Show on default display and teaser.
  EntityViewDisplay::load('node.page.default')
    ->setComponent($field_name, [
    'type' => 'entity_reference_label',
  ])
    ->save();
  EntityViewDisplay::load('node.page.teaser')
    ->setComponent($field_name, [
    'type' => 'entity_reference_label',
  ])
    ->save();
}