You are here

public function SimplesitemapTest::testLinkCount in Simple XML sitemap 8.3

Same name and namespace in other branches
  1. 4.x tests/src/Functional/SimplesitemapTest.php \Drupal\Tests\simple_sitemap\Functional\SimplesitemapTest::testLinkCount()

Test link count.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\Drupal\Core\Entity\EntityStorageException

File

tests/src/Functional/SimplesitemapTest.php, line 240

Class

SimplesitemapTest
Tests Simple XML Sitemap functional integration.

Namespace

Drupal\Tests\simple_sitemap\Functional

Code

public function testLinkCount() {
  $this->generator
    ->setBundleSettings('node', 'page')
    ->removeCustomLinks()
    ->generateSitemap(QueueWorker::GENERATE_TYPE_BACKEND);
  $this
    ->drupalLogin($this
    ->createUser([
    'administer sitemap settings',
  ]));
  $this
    ->drupalGet('admin/config/search/simplesitemap');
  $link_count_elements = $this
    ->xpath('//*[@id="simple-sitemap-sitemaps-form"]//table/tbody/tr/td[3]');
  $this
    ->assertSame('2', $link_count_elements[0]
    ->getText());
  $this
    ->createNode([
    'title' => 'Another node',
    'type' => 'page',
  ]);
  $this->generator
    ->setBundleSettings('node', 'page')
    ->removeCustomLinks()
    ->generateSitemap(QueueWorker::GENERATE_TYPE_BACKEND);
  $this
    ->drupalLogin($this
    ->createUser([
    'administer sitemap settings',
  ]));
  $this
    ->drupalGet('admin/config/search/simplesitemap');
  $link_count_elements = $this
    ->xpath('//*[@id="simple-sitemap-sitemaps-form"]//table/tbody/tr/td[3]');
  $this
    ->assertSame('3', $link_count_elements[0]
    ->getText());

  // Pretend that we've just run the simple_sitemap_update_8305() update on a
  // site with existing sitemaps.
  \Drupal::database()
    ->update('simple_sitemap')
    ->fields([
    'link_count' => 0,
  ])
    ->execute();
  $this
    ->drupalGet('admin/config/search/simplesitemap');
  $link_count_elements = $this
    ->xpath('//*[@id="simple-sitemap-sitemaps-form"]//table/tbody/tr/td[3]');
  $this
    ->assertSame('unavailable', $link_count_elements[0]
    ->getText());
}