/**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     if ($this->profile != 'standard') {
         $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page', 'settings' => array('node' => array('options' => array('promote' => FALSE), 'submitted' => FALSE))));
         $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
     }
     $this->admin_user = $this->drupalCreateUser(array('administer nodes', 'bypass node access', 'administer content types', 'administer xmlsitemap', 'administer taxonomy'));
     $this->normal_user = $this->drupalCreateUser(array('create page content', 'edit any page content', 'access content', 'view own unpublished content'));
     // allow anonymous user to view user profiles
     $user_role = entity_load('user_role', DRUPAL_ANONYMOUS_RID);
     $user_role->grantPermission('access content');
     $user_role->save();
     xmlsitemap_link_bundle_enable('node', 'article');
     xmlsitemap_link_bundle_enable('node', 'page');
     $this->config->set('xmlsitemap_entity_taxonomy_vocabulary', 1);
     $this->config->set('xmlsitemap_entity_taxonomy_term', 1);
     $this->config->save();
     xmlsitemap_link_bundle_settings_save('node', 'page', array('status' => 1, 'priority' => 0.6, 'changefreq' => XMLSITEMAP_FREQUENCY_WEEKLY));
     // Add a vocabulary so we can test different view modes.
     $vocabulary = entity_create('taxonomy_vocabulary', array('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';
     entity_create('field_storage_config', array('name' => $field_name, 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', 'settings' => array('allowed_values' => array(array('vocabulary' => $vocabulary->vid, 'parent' => '0'))), 'cardinality' => '-1'))->save();
     entity_create('field_instance_config', array('field_name' => $field_name, 'entity_type' => 'node', 'bundle' => 'page'))->save();
     entity_get_form_display('node', 'page', 'default')->setComponent($field_name, array('type' => 'taxonomy_autocomplete'))->save();
     // Show on default display and teaser.
     entity_get_display('node', 'page', 'default')->setComponent($field_name, array('type' => 'taxonomy_term_reference_link'))->save();
     entity_get_display('node', 'page', 'teaser')->setComponent($field_name, array('type' => 'taxonomy_term_reference_link'))->save();
 }
 /**
  * {@inheritdoc}
  */
 public function setUp($modules = array())
 {
     parent::setUp();
     // allow anonymous user to view user profiles
     $user_role = entity_load('user_role', DRUPAL_ANONYMOUS_RID);
     $user_role->grantPermission('access user profiles');
     $user_role->save();
     xmlsitemap_link_bundle_enable('user', 'user');
     // Create the users
     $this->admin_user = $this->drupalCreateUser(array('administer users', 'administer permissions', 'administer xmlsitemap'));
     $this->normal_user = $this->drupalCreateUser(array('access content'));
     // Update the normal user to make its sitemap link visible.
     $account = clone $this->normal_user;
     $account->save();
 }
 /**
  * Test xmlsitemap settings for taxonomies.
  */
 public function testTaxonomySettings()
 {
     $this->drupalLogin($this->admin_user);
     $this->drupalGet('admin/structure/taxonomy/add');
     $this->assertField('xmlsitemap[status]');
     $this->assertField('xmlsitemap[priority]');
     $edit = array('name' => $this->randomMachineName(), 'vid' => Unicode::strtolower($this->randomMachineName()), 'xmlsitemap[status]' => '1', 'xmlsitemap[priority]' => '1.0');
     $this->drupalPostForm(NULL, $edit, t('Save'));
     $this->assertText("Created new vocabulary {$edit['name']}.");
     $vocabulary = \Drupal\taxonomy\Entity\Vocabulary::load($edit['vid']);
     xmlsitemap_link_bundle_enable('taxonomy_term', $vocabulary->id());
     $this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add');
     $this->assertResponse(200);
     $this->assertField('xmlsitemap[status]');
     $this->assertField('xmlsitemap[priority]');
     $this->assertField('xmlsitemap[changefreq]');
     $edit = array('name[0][value]' => $this->randomMachineName(), 'xmlsitemap[status]' => 'default', 'xmlsitemap[priority]' => 'default');
     $this->drupalPostForm(NULL, $edit, t('Save'));
 }
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     if ($this->profile != 'standard') {
         $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page', 'settings' => array('node' => array('options' => array('promote' => FALSE), 'submitted' => FALSE))));
         $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
     }
     $this->admin_user = $this->drupalCreateUser(array('administer nodes', 'administer languages', 'administer content types', 'access administration pages', 'create page content', 'edit own page content'));
     $this->drupalLogin($this->admin_user);
     xmlsitemap_link_bundle_enable('node', 'article');
     xmlsitemap_link_bundle_enable('node', 'page');
     // allow anonymous user to view user profiles
     $user_role = entity_load('user_role', DRUPAL_ANONYMOUS_RID);
     $user_role->grantPermission('access content');
     $user_role->save();
     // Set "Basic page" content type to use multilingual support.
     $edit = array('language_configuration[language_show]' => TRUE);
     $this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type'));
     $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Basic page')), 'Basic page content type has been updated.');
 }
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     if ($this->profile != 'standard') {
         $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page', 'settings' => array('node' => array('options' => array('promote' => FALSE), 'submitted' => FALSE))));
         $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
     }
     // allow anonymous user to administer menu links
     $user_role = entity_load('user_role', DRUPAL_ANONYMOUS_RID);
     $user_role->grantPermission('administer menu');
     $user_role->grantPermission('access content');
     $user_role->save();
     $bundles = $this->entityManager->getAllBundleInfo();
     foreach ($bundles['menu_link_content'] as $bundle_id => $bundle) {
         xmlsitemap_link_bundle_enable('menu_link_content', $bundle_id);
     }
     foreach ($bundles['menu'] as $bundle_id => $bundle) {
         xmlsitemap_link_bundle_enable('menu', $bundle_id);
     }
     $this->admin_user = $this->drupalCreateUser(array('administer menu', 'administer xmlsitemap', 'access administration pages'));
     $this->normal_user = $this->drupalCreateUser(array('access content'));
 }
 public function testUserCannotViewEntity()
 {
     // allow anonymous user to view entity
     $user_role = entity_load('user_role', DRUPAL_ANONYMOUS_RID);
     $user_role->revokePermission('view test entity');
     $user_role->save();
     xmlsitemap_link_bundle_enable('entity_test', 'entity_test');
     $entity = entity_create('entity_test', array('bundle' => 'entity_test'));
     $entity->save();
     $this->assertSitemapLinkValues('entity_test', $entity->id(), array('status' => 0, 'priority' => 0.5, 'changefreq' => 0, 'access' => 0));
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $bundles = $this->entityManager->getAllBundleInfo();
     $values = $form_state->getValues();
     $entity_values = $values['entity_types'];
     $config = $this->config('xmlsitemap.settings');
     $settings = $form_state->getValue('settings');
     foreach ($entity_values as $key => $value) {
         if ($value) {
             foreach ($bundles[$key] as $bundle_key => $bundle_value) {
                 if (!$values['settings'][$key]['types'][$bundle_key]) {
                     xmlsitemap_link_bundle_delete($key, $bundle_key, TRUE);
                 } else {
                     if (!xmlsitemap_link_bundle_check_enabled($key, $bundle_key)) {
                         xmlsitemap_link_bundle_enable($key, $bundle_key);
                     }
                 }
             }
         } else {
             foreach ($bundles[$key] as $bundle_key => $bundle_value) {
                 xmlsitemap_link_bundle_delete($key, $bundle_key, TRUE);
             }
         }
     }
     parent::submitForm($form, $form_state);
 }