public function testTagsField()
 {
     $this->drupalLogin($this->admin_user);
     $this->drupalGet('node/add/page');
     $title_key = 'title[0][value]';
     $body_key = 'body[0][value]';
     // Fill in node creation form and preview node.
     $edit = array();
     $edit[$title_key] = $this->randomMachineName(8);
     $edit[$body_key] = $this->randomMachineName(16);
     $edit['tags'] = 'tag1, tag2, tag3';
     $this->drupalPostForm('node/add/page', $edit, t('Save and publish'));
     $tags = entity_load_multiple('taxonomy_term');
     foreach ($tags as $tag) {
         $this->assertSitemapLinkValues('taxonomy_term', $tag->id(), array('status' => 0, 'priority' => 0.5, 'changefreq' => 0));
         $tag->delete();
     }
     xmlsitemap_link_bundle_settings_save('taxonomy_term', 'tags', array('status' => 1, 'priority' => 0.2, 'changefreq' => XMLSITEMAP_FREQUENCY_HOURLY));
     $this->drupalPostForm('node/add/page', $edit, t('Save and publish'));
     $tags = entity_load_multiple('taxonomy_term');
     foreach ($tags as $tag) {
         $this->assertSitemapLinkValues('taxonomy_term', $tag->id(), array('status' => 1, 'priority' => 0.2, 'changefreq' => XMLSITEMAP_FREQUENCY_HOURLY));
         $tag->delete();
     }
 }
コード例 #2
0
 /**
  * Test if user links are included in sitemap after rebuild.
  */
 public function testUserLinksRebuild()
 {
     xmlsitemap_link_bundle_settings_save('user', 'user', array('status' => 1, 'priority' => 0.4, 'changefreq' => XMLSITEMAP_FREQUENCY_MONTHLY));
     $dummy_user = $this->drupalCreateUser(array());
     $this->drupalLogin($this->admin_user);
     $this->drupalPostForm('admin/config/search/xmlsitemap/rebuild', array(), t('Save configuration'));
     $this->assertText('The sitemap links were rebuilt.');
     $this->assertSitemapLinkValues('user', $dummy_user->id(), array('status' => 1, 'priority' => 0.4, 'changefreq' => XMLSITEMAP_FREQUENCY_MONTHLY, 'access' => 1));
     $this->drupalGet('sitemap.xml');
     $this->assertRaw("user/{$dummy_user->id()}");
 }
 /**
  * Test xmlsitemap settings for menu entity.
  */
 public function testMenuSettings()
 {
     $this->drupalLogin($this->admin_user);
     $edit = array('label' => $this->randomMachineName(), 'id' => Unicode::strtolower($this->randomMachineName()), 'xmlsitemap[status]' => '1', 'xmlsitemap[priority]' => '1.0');
     $this->drupalPostForm('admin/structure/menu/add', $edit, 'Save');
     xmlsitemap_link_bundle_settings_save('menu', $edit['id'], array('status' => 0, 'priority' => 0.5, 'changefreq' => 0));
     $this->drupalGet('admin/structure/menu/manage/' . $edit['id']);
     $menu_id = $edit['id'];
     $this->clickLink('Add link');
     $edit = array('url' => 'node', 'title[0][value]' => $this->randomMachineName(), 'description[0][value]' => '', 'enabled[value]' => 1, 'expanded[value]' => FALSE, 'menu_parent' => $menu_id . ':', 'weight[0][value]' => 0);
     $this->drupalPostForm(NULL, $edit, 'Save');
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $entity = $form['xmlsitemap']['#entity'];
     $bundle = $form['xmlsitemap']['#bundle'];
     // Handle new bundles by fetching the proper bundle key value from the form
     // state values.
     if (empty($bundle)) {
         $entity_info = $form['xmlsitemap']['#entity_info'];
         if (isset($entity_info['bundle keys']['bundle'])) {
             $bundle_key = $entity_info['bundle keys']['bundle'];
             if ($form_state->hasValue($bundle_key)) {
                 $bundle = $form_state->getValue($bundle_key);
                 $form['xmlsitemap']['#bundle'] = $bundle;
             }
         }
     }
     $xmlsitemap = $form_state->getValue('xmlsitemap');
     xmlsitemap_link_bundle_settings_save($this->entity_type, $this->bundle_type, $xmlsitemap, TRUE);
     $entity_info = $form['xmlsitemap']['#entity_info'];
     if (!empty($form['xmlsitemap']['#show_message'])) {
         drupal_set_message($this->t('XML sitemap settings for the %bundle have been saved.', array('%bundle' => $entity_info['bundles'][$bundle]['label'])));
     }
     // Unset the form values since we have already saved the bundle settings and
     // we don't want these values to get saved as configuration, depending on how
     // the form saves the form values.
     $form_state->unsetValue('xmlsitemap');
     parent::submitForm($form, $form_state);
 }