You are here

public function XmlSitemapEnginesFunctionalTest::testSubmitSitemaps in XML sitemap 8

Same name and namespace in other branches
  1. 2.x xmlsitemap_engines/tests/src/Functional/XmlSitemapEnginesFunctionalTest.php \Drupal\Tests\xmlsitemap_engines\Functional\XmlSitemapEnginesFunctionalTest::testSubmitSitemaps()

Create sitemaps and send them to search engines.

File

xmlsitemap_engines/tests/src/Functional/XmlSitemapEnginesFunctionalTest.php, line 82

Class

XmlSitemapEnginesFunctionalTest
Test xmlsitemap_engines functionality.

Namespace

Drupal\Tests\xmlsitemap_engines\Functional

Code

public function testSubmitSitemaps() {
  $sitemaps = [];
  $context = [
    1,
  ];
  $sitemap = XmlSitemap::create([
    'id' => xmlsitemap_sitemap_get_context_hash($context),
  ]);
  $sitemap
    ->setContext(serialize($context));
  $sitemap
    ->setLabel('http://example.com');
  $sitemap
    ->save();
  $sitemap->uri = [
    'path' => 'http://example.com/sitemap.xml',
    'options' => [],
  ];
  $sitemaps[] = $sitemap;
  $context = [
    2,
  ];
  $sitemap = XmlSitemap::create([
    'id' => xmlsitemap_sitemap_get_context_hash($context),
  ]);
  $sitemap
    ->setContext(serialize($context));
  $sitemap
    ->setLabel('http://example.com');
  $sitemap->uri = [
    'path' => 'http://example.com/sitemap-2.xml',
    'options' => [],
  ];
  $sitemaps[] = $sitemap;
  xmlsitemap_engines_submit_sitemaps($this->submit_url, $sitemaps);
  $this
    ->assertWatchdogMessage([
    'type' => 'xmlsitemap',
    'message' => 'Received ping for @sitemap.',
    'variables' => [
      '@sitemap' => 'http://example.com/sitemap.xml',
    ],
  ]);
  $this
    ->assertWatchdogMessage([
    'type' => 'xmlsitemap',
    'message' => 'Received ping for @sitemap.',
    'variables' => [
      '@sitemap' => 'http://example.com/sitemap-2.xml',
    ],
  ]);
}