/**
  * Test if multiple sitemaps exist and have consistent information.
  */
 public function testMoreSitemaps()
 {
     $this->drupalLogin($this->admin_user);
     $edit = array('label' => 'English', 'context[language]' => 'en');
     $this->drupalPostForm('admin/config/search/xmlsitemap/add', $edit, t('Save'));
     $context = array('language' => 'en');
     $id = xmlsitemap_sitemap_get_context_hash($context);
     $this->assertText(t('Saved the English sitemap.'));
     $this->assertText($id);
     $edit = array('label' => 'French', 'context[language]' => 'fr');
     $this->drupalPostForm('admin/config/search/xmlsitemap/add', $edit, t('Save'));
     $context = array('language' => 'fr');
     $id = xmlsitemap_sitemap_get_context_hash($context);
     $this->assertText(t('Saved the French sitemap.'));
     $this->assertText($id);
     $this->drupalPostForm('admin/config/search/xmlsitemap/add', $edit, t('Save'));
     $this->assertText(t('There is another sitemap saved with the same context.'));
     $edit = array('label' => 'Undefined', 'context[language]' => 'und');
     $this->drupalPostForm('admin/config/search/xmlsitemap/add', $edit, t('Save'));
     $this->assertText(t('There is another sitemap saved with the same context.'));
     $sitemaps = entity_load_multiple('xmlsitemap');
     foreach ($sitemaps as $sitemap) {
         $label = $sitemap->label();
         $this->drupalPostForm("admin/config/search/xmlsitemap/{$sitemap->id()}/delete", array(), t('Delete'));
         $this->assertRaw(t("Sitemap :label has been deleted.", array(':label' => $label)));
     }
     $sitemaps = entity_load_multiple('xmlsitemap');
     $this->assertEqual(count($sitemaps), 0, t('No more sitemaps.'));
 }
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     if (!$form_state->hasValue('context')) {
         $form_state->setValue('context', xmlsitemap_get_current_context());
     }
     if ($form_state->hasValue(['context', 'language'])) {
         $language = $form_state->getValue(['context', 'language']);
         if ($language == LanguageInterface::LANGCODE_NOT_SPECIFIED) {
             $form_state->unsetValue(['context', 'language']);
         }
     }
     $context = $form_state->getValue('context');
     $this->entity->context = $context;
     $this->entity->label = $form_state->getValue('label');
     $this->entity->id = xmlsitemap_sitemap_get_context_hash($context);
     try {
         $status = $this->entity->save();
         if ($status == SAVED_NEW) {
             drupal_set_message($this->t('Saved the %label sitemap.', array('%label' => $this->entity->label())));
         } else {
             if ($status == SAVED_UPDATED) {
                 drupal_set_message($this->t('Updated the %label sitemap.', array('%label' => $this->entity->label())));
             }
         }
     } catch (EntityStorageException $ex) {
         drupal_set_message($this->t('There is another sitemap saved with the same context.'), 'error');
     }
     $form_state->setRedirect('xmlsitemap.admin_search');
 }
 /**
  * Create sitemaps and send them to search engines.
  */
 public function testSubmitSitemaps()
 {
     $sitemaps = array();
     $context = array(1);
     $sitemap = $this->entityManager->getStorage('xmlsitemap')->create(array('id' => xmlsitemap_sitemap_get_context_hash($context)));
     $sitemap->setContext(serialize($context));
     $sitemap->setLabel('http://example.com');
     $sitemap->save();
     $sitemap->uri = array('path' => 'http://example.com/sitemap.xml', 'options' => array());
     $sitemaps[] = $sitemap;
     $context = array(2);
     $sitemap = $this->entityManager->getStorage('xmlsitemap')->create(array('id' => xmlsitemap_sitemap_get_context_hash($context)));
     $sitemap->setContext(serialize($context));
     $sitemap->setLabel('http://example.com');
     $sitemap->uri = array('path' => 'http://example.com/sitemap-2.xml', 'options' => array());
     $sitemaps[] = $sitemap;
     xmlsitemap_engines_submit_sitemaps($this->submit_url, $sitemaps);
     $this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Recieved ping for @sitemap.', 'variables' => array('@sitemap' => 'http://example.com/sitemap.xml')));
     $this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Recieved ping for @sitemap.', 'variables' => array('@sitemap' => 'http://example.com/sitemap-2.xml')));
 }