You are here

public function SimpleSitemapViewsTest::testViewsUrlGenerator in Simple XML sitemap 4.x

Same name and namespace in other branches
  1. 8.3 modules/simple_sitemap_views/tests/src/Functional/SimpleSitemapViewsTest.php \Drupal\Tests\simple_sitemap_views\Functional\SimpleSitemapViewsTest::testViewsUrlGenerator()

Tests the process of generating view display URLs.

File

modules/simple_sitemap_views/tests/src/Functional/SimpleSitemapViewsTest.php, line 96

Class

SimpleSitemapViewsTest
Tests Simple XML Sitemap (Views) functional integration.

Namespace

Drupal\Tests\simple_sitemap_views\Functional

Code

public function testViewsUrlGenerator() {
  $this
    ->assertArrayHasKey('views', SimpleSitemapType::load('default_hreflang')
    ->getUrlGenerators());
  $title = $this->node
    ->getTitle();
  $this->sitemapViews
    ->addArgumentsToIndex($this->testView, [
    'page',
  ]);
  $this->sitemapViews
    ->addArgumentsToIndex($this->testView, [
    'page',
    $title,
  ]);
  $this->sitemapViews
    ->addArgumentsToIndex($this->testView2, [
    'page',
    1,
  ]);
  $this->generator
    ->generateSitemap('backend');
  $url1 = $this->testView
    ->getUrl()
    ->toString();
  $url2 = $this->testView
    ->getUrl([
    'page',
    NULL,
    NULL,
  ])
    ->toString();
  $url3 = $this->testView
    ->getUrl([
    'page',
    $title,
    NULL,
  ])
    ->toString();
  $url4 = $this->testView2
    ->getUrl()
    ->toString();
  $url5 = $this->testView2
    ->getUrl([
    'page',
    1,
  ])
    ->toString();

  // Check that the sitemap contains view display URLs.
  $this
    ->drupalGet($this->defaultSitemapUrl);
  $this
    ->assertSession()
    ->responseContains($url1);
  $this
    ->assertSession()
    ->responseContains($url2);
  $this
    ->assertSession()
    ->responseContains($url3);
  $this
    ->assertSession()
    ->responseNotContains($url4);
  $this
    ->assertSession()
    ->responseContains($url5);
}