From 92c253bec8c956283cea4c1b3c0fbef7592c1598 Mon Sep 17 00:00:00 2001
From: florenttorregrosa <florenttorregrosa@2388214.no-reply.drupal.org>
Date: Sat, 20 Jan 2018 15:22:43 +0100
Subject: [PATCH] Issue #2938243 by Grimreaper: Convert tests to PHPUnit

---
 src/Tests/SimplesitemapTest.php                | 468 ------------------------
 src/Tests/SimplesitemapTestBase.php            |  55 ---
 tests/src/Functional/SimplesitemapTest.php     | 477 +++++++++++++++++++++++++
 tests/src/Functional/SimplesitemapTestBase.php | 113 ++++++
 4 files changed, 590 insertions(+), 523 deletions(-)
 delete mode 100644 src/Tests/SimplesitemapTest.php
 delete mode 100644 src/Tests/SimplesitemapTestBase.php
 create mode 100644 tests/src/Functional/SimplesitemapTest.php
 create mode 100644 tests/src/Functional/SimplesitemapTestBase.php

diff --git a/src/Tests/SimplesitemapTest.php b/src/Tests/SimplesitemapTest.php
deleted file mode 100644
index 34f7f79..0000000
--- a/src/Tests/SimplesitemapTest.php
+++ /dev/null
@@ -1,468 +0,0 @@
-<?php
-
-namespace Drupal\simple_sitemap\Tests;
-
-/**
- * Tests Simple XML sitemap functional integration.
- *
- * @package Drupal\simple_sitemap\Tests
- * @group simple_sitemap
- */
-class SimplesitemapTest extends SimplesitemapTestBase {
-
-  /**
-   * Verify sitemap.xml has the link to the front page after first generation.
-   */
-  public function testInitialGeneration() {
-    $this->generator->generateSitemap('nobatch');
-    $this->drupalGet('sitemap.xml');
-    $this->assertRaw('urlset');
-    $this->assertText($GLOBALS['base_url']);
-    $this->assertText('1.0');
-    $this->assertText('daily');
-  }
-
-  public function testAddCustomLink() {
-    $this->generator->addCustomLink('/node/' . $this->node->id(), ['priority' => 0.2, 'changefreq' => 'monthly'])
-      ->generateSitemap('nobatch');
-
-    $this->drupalGet('sitemap.xml');
-    $this->assertText('node/' . $this->node->id());
-    $this->assertText('0.2');
-    $this->assertText('monthly');
-
-    $this->drupalLogin($this->createPrivilegedUser());
-
-    $this->drupalGet('admin/config/search/simplesitemap/custom');
-    $this->assertText('/node/' . $this->node->id() . ' 0.2 monthly');
-
-    $this->generator->addCustomLink('/node/' . $this->node->id(), ['changefreq' => 'yearly'])
-      ->generateSitemap('nobatch');
-
-    $this->drupalGet('admin/config/search/simplesitemap/custom');
-    $this->assertText('/node/' . $this->node->id() . ' yearly');
-  }
-
-  /**
-   * Test default settings of custom links.
-   */
-  public function testAddCustomLinkDefaults() {
-    $this->generator->removeCustomLinks()
-      ->addCustomLink('/node/' . $this->node->id())
-      ->generateSitemap('nobatch');
-
-    $this->drupalGet('sitemap.xml');
-    $this->assertText('node/' . $this->node->id());
-    $this->assertText('0.5');
-    $this->assertNoRaw('changefreq');
-  }
-
-  /**
-   * Test removing custom links from the sitemap.
-   */
-  public function testRemoveCustomLink() {
-    $this->generator->addCustomLink('/node/' . $this->node->id())
-      ->removeCustomLink('/node/' . $this->node->id())
-      ->generateSitemap('nobatch');
-
-    $this->drupalGet('sitemap.xml');
-    $this->assertNoText('node/' . $this->node->id());
-  }
-
-  /**
-   * Test removing all custom paths from the sitemap settings.
-   */
-  public function testRemoveCustomLinks() {
-    $this->generator->removeCustomLinks()
-      ->generateSitemap('nobatch');
-
-    $this->drupalGet('sitemap.xml');
-    $this->assertNoText($GLOBALS['base_url']);
-  }
-
-  /**
-   * Tests setting bundle settings.
-   *
-   * @todo Add form tests
-   */
-  public function testSetBundleSettings() {
-
-    $this->assertFalse($this->generator->bundleIsIndexed('node', 'page'));
-
-    // Index new bundle.
-    $this->generator->removeCustomLinks()
-      ->setBundleSettings('node', 'page', ['index' => TRUE, 'priority' => 0.5, 'changefreq' => 'hourly'])
-      ->generateSitemap('nobatch');
-
-    $this->drupalGet('sitemap.xml');
-    $this->assertText('node/' . $this->node->id());
-    $this->assertText('0.5');
-    $this->assertText('hourly');
-
-    $this->assertTrue($this->generator->bundleIsIndexed('node', 'page'));
-
-    // Only change bundle priority.
-    $this->generator->setBundleSettings('node', 'page', ['priority' => 0.9])
-      ->generateSitemap('nobatch');
-
-    $this->drupalGet('sitemap.xml');
-    $this->assertText('node/' . $this->node->id());
-    $this->assertNoText('0.5');
-    $this->assertText('0.9');
-
-    // Only change bundle changefreq.
-    $this->generator->setBundleSettings('node', 'page', ['changefreq' => 'daily'])
-      ->generateSitemap('nobatch');
-
-    $this->drupalGet('sitemap.xml');
-    $this->assertText('node/' . $this->node->id());
-    $this->assertNoText('hourly');
-    $this->assertText('daily');
-
-    // Remove changefreq setting.
-    $this->generator->setBundleSettings('node', 'page', ['changefreq' => ''])
-      ->generateSitemap('nobatch');
-
-    $this->drupalGet('sitemap.xml');
-    $this->assertText('node/' . $this->node->id());
-    $this->assertNoRaw('changefreq');
-    $this->assertNoText('daily');
-
-    // Index two bundles.
-    $this->drupalCreateContentType(['type' => 'blog']);
-
-    $node3 = $this->createNode(['title' => 'Node3', 'type' => 'blog']);
-    $this->generator->setBundleSettings('node', 'page', ['index' => TRUE])
-      ->setBundleSettings('node', 'blog', ['index' => TRUE])
-      ->generateSitemap('nobatch');
-
-    $this->drupalGet('sitemap.xml');
-    $this->assertText('node/' . $this->node->id());
-    $this->assertText('node/' . $node3->id());
-
-    // Set bundle 'index' setting to false.
-    $this->generator->setBundleSettings('node', 'page', ['index' => FALSE])
-      ->setBundleSettings('node', 'blog', ['index' => FALSE])
-      ->generateSitemap('nobatch');
-
-    $this->drupalGet('sitemap.xml');
-    $this->assertNoText('node/' . $this->node->id());
-    $this->assertNoText('node/' . $node3->id());
-  }
-
-  /**
-   * Test default settings of bundles.
-   */
-  public function testSetBundleSettingsDefaults() {
-
-    $this->generator->setBundleSettings('node', 'page')
-      ->removeCustomLinks()
-      ->generateSitemap('nobatch');
-
-    $this->drupalGet('sitemap.xml');
-    $this->assertText('node/' . $this->node->id());
-    $this->assertText('0.5');
-    $this->assertNoRaw('changefreq');
-  }
-
-  /**
-   * Test the lastmod parameter in different scenarios.
-   */
-  public function testLastmod() {
-
-    // Entity links should have 'lastmod'.
-    $this->generator->setBundleSettings('node', 'page')
-      ->removeCustomLinks()
-      ->generateSitemap('nobatch');
-
-    $this->drupalGet('sitemap.xml');
-    $this->assertRaw('lastmod');
-
-    // Entity custom links should have 'lastmod'.
-    $this->generator->setBundleSettings('node', 'page', ['index' => FALSE])
-      ->addCustomLink('/node/' . $this->node->id())
-      ->generateSitemap('nobatch');
-
-    $this->drupalGet('sitemap.xml');
-    $this->assertRaw('lastmod');
-
-    // Non-entity custom links should not have 'lastmod'.
-    $this->generator->removeCustomLinks()
-      ->addCustomLink('/')
-      ->generateSitemap('nobatch');
-
-    $this->drupalGet('sitemap.xml');
-    $this->assertNoRaw('lastmod');
-  }
-
-  /**
-   * Tests the duplicate setting.
-   *
-   * @todo On second generation too many links in XML output here?
-   */
-  public function testRemoveDuplicatesSetting() {
-    $this->generator->setBundleSettings('node', 'page', ['index' => TRUE])
-      ->addCustomLink('/node/1')
-      ->saveSetting('remove_duplicates', TRUE)
-      ->generateSitemap('nobatch');
-
-    $this->drupalGet('sitemap.xml');
-    $this->assertUniqueText('node/' . $this->node->id());
-
-    $this->generator->saveSetting('remove_duplicates', FALSE)
-      ->generateSitemap('nobatch');
-
-    $this->drupalGet('sitemap.xml');
-    $this->assertNoUniqueText('node/' . $this->node->id());
-  }
-
-  /**
-   * Test max links setting and the sitemap index.
-   */
-  public function testMaxLinksSetting() {
-    $this->generator->setBundleSettings('node', 'page')
-      ->saveSetting('max_links', 1)
-      ->removeCustomLinks()
-      ->generateSitemap('nobatch');
-
-    $this->drupalGet('sitemap.xml');
-    $this->assertText('sitemaps/1/sitemap.xml');
-    $this->assertText('sitemaps/2/sitemap.xml');
-
-    $this->drupalGet('sitemaps/1/sitemap.xml');
-    $this->assertText('node/' . $this->node->id());
-    $this->assertText('0.5');
-    $this->assertNoText('node/' . $this->node2->id());
-
-    $this->drupalGet('sitemaps/2/sitemap.xml');
-    $this->assertText('node/' . $this->node2->id());
-    $this->assertText('0.5');
-    $this->assertNoText('node/' . $this->node->id());
-  }
-
-  public function testBatchProcessLimitSetting() {
-
-    // Create some nodes.
-    for ($i = 3; $i <= 50; $i++) {
-      $this->createNode(['title' => "Node{$i}", 'type' => 'page']);
-    }
-
-    // Test batch_process_limit setting.
-    $sitemap = $this->generator->setBundleSettings('node', 'page')
-      ->generateSitemap('nobatch')
-      ->getSitemap();
-
-    $sitemap2 = $this->generator->saveSetting('batch_process_limit', 1)
-      ->generateSitemap('nobatch')
-      ->getSitemap();
-
-    $sitemap3 = $this->generator->saveSetting('batch_process_limit', 10)
-      ->generateSitemap('nobatch')
-      ->getSitemap();
-
-    $this->assertEqual($sitemap, $sitemap2);
-    $this->assertEqual($sitemap, $sitemap3);
-
-    // Test batch_process_limit setting in combination with max_links setting.
-    $sitemap_index = $this->generator->setBundleSettings('node', 'page')
-      ->saveSetting('batch_process_limit', 1500)
-      ->saveSetting('max_links', 30)
-      ->generateSitemap('nobatch')
-      ->getSitemap();
-
-    $sitemap_chunk = $this->generator->getSitemap(1);
-
-    $sitemap_index2 = $this->generator->saveSetting('batch_process_limit', 1)
-      ->generateSitemap('nobatch')
-      ->getSitemap();
-
-    $sitemap_chunk2 = $this->generator->getSitemap(1);
-
-    $sitemap_index3 = $this->generator->saveSetting('batch_process_limit', 10)
-      ->generateSitemap('nobatch')
-      ->getSitemap();
-
-    $sitemap_chunk3 = $this->generator->getSitemap(1);
-
-    $this->assertIdentical($sitemap_index, $sitemap_index2);
-    $this->assertIdentical($sitemap_chunk, $sitemap_chunk2);
-    $this->assertIdentical($sitemap_index, $sitemap_index3);
-    $this->assertIdentical($sitemap_chunk, $sitemap_chunk3);
-
-  }
-
-  /**
-   * Test setting the base URL.
-   */
-  public function testBaseUrlSetting() {
-    $this->generator->setBundleSettings('node', 'page')
-      ->saveSetting('base_url', 'http://base_url_test')
-      ->generateSitemap('nobatch');
-
-    $this->drupalGet('sitemap.xml');
-    $this->assertText('http://base_url_test');
-
-    // Set base URL in the sitemap index.
-    $this->generator->saveSetting('max_links', 1)
-      ->generateSitemap('nobatch');
-
-    $this->drupalGet('sitemap.xml');
-    $this->assertText('http://base_url_test/sitemaps/1/sitemap.xml');
-  }
-
-  /**
-   * @todo testSkipUntranslatedSetting
-   */
-
-  /**
-   * @todo testSkipNonExistentTranslations
-   */
-
-  /**
-   * Test cacheability of the response.
-   */
-  public function testCacheability() {
-    $this->generator->setBundleSettings('node', 'page')
-      ->generateSitemap('nobatch');
-
-    // Verify the cache was flushed and node is in the sitemap.
-    $this->drupalGet('sitemap.xml');
-    $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS');
-    $this->assertText('node/' . $this->node->id());
-
-    // Verify the sitemap is taken from cache on second call and node is in the sitemap.
-    $this->drupalGet('sitemap.xml');
-    $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT');
-    $this->assertText('node/' . $this->node->id());
-  }
-
-  /**
-   * Test overriding of bundle settings for a single entity.
-   *
-   * @todo: Use form testing instead of assertRaw().
-   */
-  public function testSetEntityInstanceSettings() {
-    $this->generator->setBundleSettings('node', 'page')
-      ->removeCustomLinks()
-      ->setEntityInstanceSettings('node', $this->node->id(), ['priority' => 0.1, 'changefreq' => 'never'])
-      ->setEntityInstanceSettings('node', $this->node2->id(), ['index' => FALSE])
-      ->generateSitemap('nobatch');
-
-    // Test sitemap result.
-    $this->drupalGet('sitemap.xml');
-    $this->assertText('node/' . $this->node->id());
-    $this->assertText('0.1');
-    $this->assertText('never');
-    $this->assertNoText('node/' . $this->node2->id());
-    $this->assertNoText('0.5');
-
-    $this->drupalLogin($this->createPrivilegedUser());
-
-    // Test UI changes.
-    $this->drupalGet('node/' . $this->node->id() . '/edit');
-    $this->assertRaw('<option value="0.1" selected="selected">0.1</option>');
-    $this->assertRaw('<option value="never" selected="selected">never</option>');
-
-    // Test database changes.
-    $result = \Drupal::database()->select('simple_sitemap_entity_overrides', 'o')
-      ->fields('o', ['inclusion_settings'])
-      ->condition('o.entity_type', 'node')
-      ->condition('o.entity_id', $this->node->id())
-      ->execute()
-      ->fetchField();
-    $this->assertFalse(empty($result));
-
-    $this->generator->setBundleSettings('node', 'page', ['priority' => 0.1, 'changefreq' => 'never'])
-      ->generateSitemap('nobatch');
-
-    // Test sitemap result.
-    $this->drupalGet('sitemap.xml');
-    $this->assertText('node/' . $this->node->id());
-    $this->assertText('0.1');
-    $this->assertText('never');
-    $this->assertNoText('node/' . $this->node2->id());
-    $this->assertNoText('0.5');
-
-    // Test UI changes.
-    $this->drupalGet('node/' . $this->node->id() . '/edit');
-    $this->assertRaw('<option value="0.1" selected="selected">0.1 (default)</option>');
-    $this->assertRaw('<option value="never" selected="selected">never (default)</option>');
-
-    // Test if entity override has been removed from database after its equal to its bundle settings.
-    $result = \Drupal::database()->select('simple_sitemap_entity_overrides', 'o')
-      ->fields('o', ['inclusion_settings'])
-      ->condition('o.entity_type', 'node')
-      ->condition('o.entity_id', $this->node->id())
-      ->execute()
-      ->fetchField();
-    $this->assertTrue(empty($result));
-  }
-
-  /**
-   * Test indexing an atomic entity (here: a user)
-   * @todo Not working
-   */
-/*  public function testAtomicEntityIndexation() {
-    $user = $this->createPrivilegedUser();
-    $this->generator->setBundleSettings('user')
-      ->generateSitemap('nobatch');
-
-    $this->drupalGet('sitemap.xml');
-    $this->assertNoText('user/' . $user->id());
-
-    user_role_grant_permissions(0, ['access user profiles']);
-    $this->generator->generateSitemap('nobatch');
-
-    $this->drupalGet('sitemap.xml');
-    $this->assertText('user/' . $user->id());
-  }*/
-
-  /**
-   * @todo Test indexing menu.
-   */
-
-  /**
-   * @todo Test deleting a bundle.
-   */
-
-  /**
-   * Test disabling sitemap support for an entity type.
-   */
-  public function testDisableEntityType() {
-    $this->generator->setBundleSettings('node', 'page')
-      ->disableEntityType('node');
-
-    $this->drupalLogin($this->createPrivilegedUser());
-    $this->drupalGet('admin/structure/types/manage/page');
-    $this->assertNoText('Simple XML sitemap');
-
-    $this->generator->generateSitemap('nobatch');
-
-    $this->drupalGet('sitemap.xml');
-    $this->assertNoText('node/' . $this->node->id());
-
-    $this->assertFalse($this->generator->entityTypeIsEnabled('node'));
-  }
-
-  /**
-   * Test enabling sitemap support for an entity type.
-   *
-   * @todo Test admin/config/search/simplesitemap/entities form.
-   */
-  public function testEnableEntityType() {
-    $this->generator->disableEntityType('node')
-      ->enableEntityType('node')
-      ->setBundleSettings('node', 'page');
-
-    $this->drupalLogin($this->createPrivilegedUser());
-    $this->drupalGet('admin/structure/types/manage/page');
-    $this->assertText('Simple XML sitemap');
-
-    $this->generator->generateSitemap('nobatch');
-
-    $this->drupalGet('sitemap.xml');
-    $this->assertText('node/' . $this->node->id());
-
-    $this->assertTrue($this->generator->entityTypeIsEnabled('node'));
-  }
-}
diff --git a/src/Tests/SimplesitemapTestBase.php b/src/Tests/SimplesitemapTestBase.php
deleted file mode 100644
index f372d78..0000000
--- a/src/Tests/SimplesitemapTestBase.php
+++ /dev/null
@@ -1,55 +0,0 @@
-<?php
-
-namespace Drupal\simple_sitemap\Tests;
-
-use Drupal\simpletest\WebTestBase;
-
-/**
- * Class SimplesitemapTestBase
- * @package Drupal\simple_sitemap\Tests
- */
-abstract class SimplesitemapTestBase extends WebTestBase {
-
-  /**
-   * Modules to enable.
-   *
-   * @var array
-   */
-  public static $modules = ['simple_sitemap', 'node', 'content_translation'];
-
-  /**
-   * @var \Drupal\simple_sitemap\Simplesitemap
-   */
-  protected $generator;
-
-  /**
-   * @var \Drupal\node\Entity\Node
-   */
-  protected $node;
-
-  /**
-   * @var \Drupal\node\Entity\Node
-   */
-  protected $node2;
-
-  // Uncomment to disable strict schema checks.
-//  protected $strictConfigSchema = FALSE;
-
-  /**
-   * @inheritdoc
-   */
-  protected function setUp() {
-    parent::setUp();
-
-    $this->drupalCreateContentType(['type' => 'page']);
-    $this->node = $this->createNode(['title' => 'Node', 'type' => 'page']);
-    $this->node2 = $this->createNode(['title' => 'Node2', 'type' => 'page']);
-
-    $this->generator = \Drupal::service('simple_sitemap.generator');
-  }
-
-  protected function createPrivilegedUser() {
-    $permissions = array_keys(\Drupal::service('user.permissions')->getPermissions());
-    return $this->drupalCreateUser($permissions);
-  }
-}
diff --git a/tests/src/Functional/SimplesitemapTest.php b/tests/src/Functional/SimplesitemapTest.php
new file mode 100644
index 0000000..72d5820
--- /dev/null
+++ b/tests/src/Functional/SimplesitemapTest.php
@@ -0,0 +1,477 @@
+<?php
+
+namespace Drupal\Tests\simple_sitemap\Functional;
+
+use Drupal\Core\Url;
+
+/**
+ * Tests Simple XML sitemap functional integration.
+ *
+ * @group simple_sitemap
+ */
+class SimplesitemapTest extends SimplesitemapTestBase {
+
+  /**
+   * Verify sitemap.xml has the link to the front page after first generation.
+   */
+  public function testInitialGeneration() {
+    $this->generator->generateSitemap('nobatch');
+    $this->drupalGet('sitemap.xml');
+    $this->assertSession()->responseContains('urlset');
+    $this->assertSession()->responseContains(Url::fromRoute('<front>')->setAbsolute()->toString());
+    $this->assertSession()->responseContains('1.0');
+    $this->assertSession()->responseContains('daily');
+  }
+
+  /**
+   * Test custom link.
+   */
+  public function testAddCustomLink() {
+    $this->generator->addCustomLink('/node/' . $this->node->id(), ['priority' => 0.2, 'changefreq' => 'monthly'])
+      ->generateSitemap('nobatch');
+
+    $this->drupalGet('sitemap.xml');
+    $this->assertSession()->responseContains('node/' . $this->node->id());
+    $this->assertSession()->responseContains('0.2');
+    $this->assertSession()->responseContains('monthly');
+
+    $this->drupalLogin($this->privilegedUser);
+
+    $this->drupalGet('admin/config/search/simplesitemap/custom');
+    $this->assertSession()->pageTextContains('/node/' . $this->node->id() . ' 0.2 monthly');
+
+    $this->generator->addCustomLink('/node/' . $this->node->id(), ['changefreq' => 'yearly'])
+      ->generateSitemap('nobatch');
+
+    $this->drupalGet('admin/config/search/simplesitemap/custom');
+    $this->assertSession()->pageTextContains('/node/' . $this->node->id() . ' yearly');
+  }
+
+  /**
+   * Test default settings of custom links.
+   */
+  public function testAddCustomLinkDefaults() {
+    $this->generator->removeCustomLinks()
+      ->addCustomLink('/node/' . $this->node->id())
+      ->generateSitemap('nobatch');
+
+    $this->drupalGet('sitemap.xml');
+    $this->assertSession()->responseContains('node/' . $this->node->id());
+    $this->assertSession()->responseContains('0.5');
+    $this->assertSession()->responseNotContains('changefreq');
+  }
+
+  /**
+   * Test removing custom links from the sitemap.
+   */
+  public function testRemoveCustomLink() {
+    $this->generator->addCustomLink('/node/' . $this->node->id())
+      ->removeCustomLink('/node/' . $this->node->id())
+      ->generateSitemap('nobatch');
+
+    $this->drupalGet('sitemap.xml');
+    $this->assertSession()->responseNotContains('node/' . $this->node->id());
+  }
+
+  /**
+   * Test removing all custom paths from the sitemap settings.
+   */
+  public function testRemoveCustomLinks() {
+    $this->generator->removeCustomLinks()
+      ->generateSitemap('nobatch');
+
+    $this->drupalGet('sitemap.xml');
+    $this->assertSession()->responseNotContains(Url::fromRoute('<front>')->setAbsolute()->toString());
+  }
+
+  /**
+   * Tests setting bundle settings.
+   *
+   * @todo Add form tests
+   */
+  public function testSetBundleSettings() {
+    $this->assertFalse($this->generator->bundleIsIndexed('node', 'page'));
+
+    // Index new bundle.
+    $this->generator->removeCustomLinks()
+      ->setBundleSettings('node', 'page', [
+        'index' => TRUE,
+        'priority' => 0.5,
+        'changefreq' => 'hourly',
+      ])
+      ->generateSitemap('nobatch');
+
+    $this->drupalGet('sitemap.xml');
+    $this->assertSession()->responseContains('node/' . $this->node->id());
+    $this->assertSession()->responseContains('0.5');
+    $this->assertSession()->responseContains('hourly');
+
+    $this->assertTrue($this->generator->bundleIsIndexed('node', 'page'));
+
+    // Only change bundle priority.
+    $this->generator->setBundleSettings('node', 'page', ['priority' => 0.9])
+      ->generateSitemap('nobatch');
+
+    $this->drupalGet('sitemap.xml');
+    $this->assertSession()->responseContains('node/' . $this->node->id());
+    $this->assertSession()->responseNotContains('0.5');
+    $this->assertSession()->responseContains('0.9');
+
+    // Only change bundle changefreq.
+    $this->generator->setBundleSettings('node', 'page', ['changefreq' => 'daily'])
+      ->generateSitemap('nobatch');
+
+    $this->drupalGet('sitemap.xml');
+    $this->assertSession()->responseContains('node/' . $this->node->id());
+    $this->assertSession()->responseNotContains('hourly');
+    $this->assertSession()->responseContains('daily');
+
+    // Remove changefreq setting.
+    $this->generator->setBundleSettings('node', 'page', ['changefreq' => ''])
+      ->generateSitemap('nobatch');
+
+    $this->drupalGet('sitemap.xml');
+    $this->assertSession()->responseContains('node/' . $this->node->id());
+    $this->assertSession()->responseNotContains('changefreq');
+    $this->assertSession()->responseNotContains('daily');
+
+    // Index two bundles.
+    $this->drupalCreateContentType(['type' => 'blog']);
+
+    $node3 = $this->createNode(['title' => 'Node3', 'type' => 'blog']);
+    $this->generator->setBundleSettings('node', 'page', ['index' => TRUE])
+      ->setBundleSettings('node', 'blog', ['index' => TRUE])
+      ->generateSitemap('nobatch');
+
+    $this->drupalGet('sitemap.xml');
+    $this->assertSession()->responseContains('node/' . $this->node->id());
+    $this->assertSession()->responseContains('node/' . $node3->id());
+
+    // Set bundle 'index' setting to false.
+    $this->generator->setBundleSettings('node', 'page', ['index' => FALSE])
+      ->setBundleSettings('node', 'blog', ['index' => FALSE])
+      ->generateSitemap('nobatch');
+
+    $this->drupalGet('sitemap.xml');
+    $this->assertSession()->responseNotContains('node/' . $this->node->id());
+    $this->assertSession()->responseNotContains('node/' . $node3->id());
+  }
+
+  /**
+   * Test default settings of bundles.
+   */
+  public function testSetBundleSettingsDefaults() {
+    $this->generator->setBundleSettings('node', 'page')
+      ->removeCustomLinks()
+      ->generateSitemap('nobatch');
+
+    $this->drupalGet('sitemap.xml');
+    $this->assertSession()->responseContains('node/' . $this->node->id());
+    $this->assertSession()->responseContains('0.5');
+    $this->assertSession()->responseNotContains('changefreq');
+  }
+
+  /**
+   * Test the lastmod parameter in different scenarios.
+   */
+  public function testLastmod() {
+    // Entity links should have 'lastmod'.
+    $this->generator->setBundleSettings('node', 'page')
+      ->removeCustomLinks()
+      ->generateSitemap('nobatch');
+
+    $this->drupalGet('sitemap.xml');
+    $this->assertSession()->responseContains('lastmod');
+
+    // Entity custom links should have 'lastmod'.
+    $this->generator->setBundleSettings('node', 'page', ['index' => FALSE])
+      ->addCustomLink('/node/' . $this->node->id())
+      ->generateSitemap('nobatch');
+
+    $this->drupalGet('sitemap.xml');
+    $this->assertSession()->responseContains('lastmod');
+
+    // Non-entity custom links should not have 'lastmod'.
+    $this->generator->removeCustomLinks()
+      ->addCustomLink('/')
+      ->generateSitemap('nobatch');
+
+    $this->drupalGet('sitemap.xml');
+    $this->assertSession()->responseNotContains('lastmod');
+  }
+
+  /**
+   * Tests the duplicate setting.
+   *
+   * @todo On second generation too many links in XML output here?
+   */
+  public function testRemoveDuplicatesSetting() {
+    $this->generator->setBundleSettings('node', 'page', ['index' => TRUE])
+      ->addCustomLink('/node/1')
+      ->saveSetting('remove_duplicates', TRUE)
+      ->generateSitemap('nobatch');
+
+    $this->drupalGet('sitemap.xml');
+    $this->assertUniqueTextWorkaround('node/' . $this->node->id());
+
+    $this->generator->saveSetting('remove_duplicates', FALSE)
+      ->generateSitemap('nobatch');
+
+    $this->drupalGet('sitemap.xml');
+    $this->assertNoUniqueTextWorkaround('node/' . $this->node->id());
+  }
+
+  /**
+   * Test max links setting and the sitemap index.
+   */
+  public function testMaxLinksSetting() {
+    $this->generator->setBundleSettings('node', 'page')
+      ->saveSetting('max_links', 1)
+      ->removeCustomLinks()
+      ->generateSitemap('nobatch');
+
+    $this->drupalGet('sitemap.xml');
+    $this->assertSession()->responseContains('sitemaps/1/sitemap.xml');
+    $this->assertSession()->responseContains('sitemaps/2/sitemap.xml');
+
+    $this->drupalGet('sitemaps/1/sitemap.xml');
+    $this->assertSession()->responseContains('node/' . $this->node->id());
+    $this->assertSession()->responseContains('0.5');
+    $this->assertSession()->responseNotContains('node/' . $this->node2->id());
+
+    $this->drupalGet('sitemaps/2/sitemap.xml');
+    $this->assertSession()->responseContains('node/' . $this->node2->id());
+    $this->assertSession()->responseContains('0.5');
+    $this->assertSession()->responseNotContains('node/' . $this->node->id());
+  }
+
+  /**
+   * Test batch process limit setting.
+   */
+  public function testBatchProcessLimitSetting() {
+    // Create some nodes.
+    for ($i = 3; $i <= 50; $i++) {
+      $this->createNode(['title' => "Node{$i}", 'type' => 'page']);
+    }
+
+    // Test batch_process_limit setting.
+    $sitemap = $this->generator->setBundleSettings('node', 'page')
+      ->generateSitemap('nobatch')
+      ->getSitemap();
+
+    $sitemap2 = $this->generator->saveSetting('batch_process_limit', 1)
+      ->generateSitemap('nobatch')
+      ->getSitemap();
+
+    $sitemap3 = $this->generator->saveSetting('batch_process_limit', 10)
+      ->generateSitemap('nobatch')
+      ->getSitemap();
+
+    $this->assertEquals($sitemap2, $sitemap);
+    $this->assertEquals($sitemap3, $sitemap);
+
+    // Test batch_process_limit setting in combination with max_links setting.
+    $sitemap_index = $this->generator->setBundleSettings('node', 'page')
+      ->saveSetting('batch_process_limit', 1500)
+      ->saveSetting('max_links', 30)
+      ->generateSitemap('nobatch')
+      ->getSitemap();
+
+    $sitemap_chunk = $this->generator->getSitemap(1);
+
+    $sitemap_index2 = $this->generator->saveSetting('batch_process_limit', 1)
+      ->generateSitemap('nobatch')
+      ->getSitemap();
+
+    $sitemap_chunk2 = $this->generator->getSitemap(1);
+
+    $sitemap_index3 = $this->generator->saveSetting('batch_process_limit', 10)
+      ->generateSitemap('nobatch')
+      ->getSitemap();
+
+    $sitemap_chunk3 = $this->generator->getSitemap(1);
+
+    $this->assertSame($sitemap_index2, $sitemap_index);
+    $this->assertSame($sitemap_chunk2, $sitemap_chunk);
+    $this->assertSame($sitemap_index3, $sitemap_index);
+    $this->assertSame($sitemap_chunk3, $sitemap_chunk);
+  }
+
+  /**
+   * Test setting the base URL.
+   */
+  public function testBaseUrlSetting() {
+    $this->generator->setBundleSettings('node', 'page')
+      ->saveSetting('base_url', 'http://base_url_test')
+      ->generateSitemap('nobatch');
+
+    $this->drupalGet('sitemap.xml');
+    $this->assertSession()->responseContains('http://base_url_test');
+
+    // Set base URL in the sitemap index.
+    $this->generator->saveSetting('max_links', 1)
+      ->generateSitemap('nobatch');
+
+    $this->drupalGet('sitemap.xml');
+    $this->assertSession()->responseContains('http://base_url_test/sitemaps/1/sitemap.xml');
+  }
+
+  /**
+   * @todo testSkipUntranslatedSetting
+   */
+
+  /**
+   * @todo testSkipNonExistentTranslations
+   */
+
+  /**
+   * Test cacheability of the response.
+   */
+  public function testCacheability() {
+    $this->generator->setBundleSettings('node', 'page')
+      ->generateSitemap('nobatch');
+
+    // Verify the cache was flushed and node is in the sitemap.
+    $this->drupalGet('sitemap.xml');
+    $this->assertEquals('MISS', $this->drupalGetHeader('X-Drupal-Cache'));
+    $this->assertSession()->responseContains('node/' . $this->node->id());
+
+    // Verify the sitemap is taken from cache on second call and node is in the
+    // sitemap.
+    $this->drupalGet('sitemap.xml');
+    $this->assertEquals('HIT', $this->drupalGetHeader('X-Drupal-Cache'));
+    $this->assertSession()->responseContains('node/' . $this->node->id());
+  }
+
+  /**
+   * Test overriding of bundle settings for a single entity.
+   *
+   * @todo: Use form testing instead of assertRaw().
+   */
+  public function testSetEntityInstanceSettings() {
+    $this->generator->setBundleSettings('node', 'page')
+      ->removeCustomLinks()
+      ->setEntityInstanceSettings('node', $this->node->id(), ['priority' => 0.1, 'changefreq' => 'never'])
+      ->setEntityInstanceSettings('node', $this->node2->id(), ['index' => FALSE])
+      ->generateSitemap('nobatch');
+
+    // Test sitemap result.
+    $this->drupalGet('sitemap.xml');
+    $this->assertSession()->responseContains('node/' . $this->node->id());
+    $this->assertSession()->responseContains('0.1');
+    $this->assertSession()->responseContains('never');
+    $this->assertSession()->responseNotContains('node/' . $this->node2->id());
+    $this->assertSession()->responseNotContains('0.5');
+
+    $this->drupalLogin($this->privilegedUser);
+
+    // Test UI changes.
+    $this->drupalGet('node/' . $this->node->id() . '/edit');
+    $this->assertSession()->responseContains('<option value="0.1" selected="selected">0.1</option>');
+    $this->assertSession()->responseContains('<option value="never" selected="selected">never</option>');
+
+    // Test database changes.
+    $result = $this->database->select('simple_sitemap_entity_overrides', 'o')
+      ->fields('o', ['inclusion_settings'])
+      ->condition('o.entity_type', 'node')
+      ->condition('o.entity_id', $this->node->id())
+      ->execute()
+      ->fetchField();
+    $this->assertFalse(empty($result));
+
+    $this->generator->setBundleSettings('node', 'page', ['priority' => 0.1, 'changefreq' => 'never'])
+      ->generateSitemap('nobatch');
+
+    // Test sitemap result.
+    $this->drupalGet('sitemap.xml');
+    $this->assertSession()->responseContains('node/' . $this->node->id());
+    $this->assertSession()->responseContains('0.1');
+    $this->assertSession()->responseContains('never');
+    $this->assertSession()->responseNotContains('node/' . $this->node2->id());
+    $this->assertSession()->responseNotContains('0.5');
+
+    // Test UI changes.
+    $this->drupalGet('node/' . $this->node->id() . '/edit');
+    $this->assertSession()->responseContains('<option value="0.1" selected="selected">0.1 (default)</option>');
+    $this->assertSession()->responseContains('<option value="never" selected="selected">never (default)</option>');
+
+    // Test if entity override has been removed from database after its equal to
+    // its bundle settings.
+    $result = $this->database->select('simple_sitemap_entity_overrides', 'o')
+      ->fields('o', ['inclusion_settings'])
+      ->condition('o.entity_type', 'node')
+      ->condition('o.entity_id', $this->node->id())
+      ->execute()
+      ->fetchField();
+    $this->assertTrue(empty($result));
+  }
+
+  /**
+   * Test indexing an atomic entity (here: a user)
+   * @todo Not working
+   */
+  /*public function testAtomicEntityIndexation() {
+    $user_id = $this->privilegedUser->id();
+    $this->generator->setBundleSettings('user')
+      ->generateSitemap('nobatch');
+
+    $this->drupalGet('sitemap.xml');
+    $this->assertSession()->responseNotContains('user/' . $user_id);
+
+    user_role_grant_permissions(0, ['access user profiles']);
+    $this->generator->generateSitemap('nobatch');
+
+    $this->drupalGet('sitemap.xml');
+    $this->assertSession()->responseContains('user/' . $user_id);
+  }*/
+
+  /**
+   * @todo Test indexing menu.
+   */
+
+  /**
+   * @todo Test deleting a bundle.
+   */
+
+  /**
+   * Test disabling sitemap support for an entity type.
+   */
+  public function testDisableEntityType() {
+    $this->generator->setBundleSettings('node', 'page')
+      ->disableEntityType('node');
+
+    $this->drupalLogin($this->privilegedUser);
+    $this->drupalGet('admin/structure/types/manage/page');
+    $this->assertSession()->pageTextNotContains('Simple XML sitemap');
+
+    $this->generator->generateSitemap('nobatch');
+
+    $this->drupalGet('sitemap.xml');
+    $this->assertSession()->responseNotContains('node/' . $this->node->id());
+
+    $this->assertFalse($this->generator->entityTypeIsEnabled('node'));
+  }
+
+  /**
+   * Test enabling sitemap support for an entity type.
+   *
+   * @todo Test admin/config/search/simplesitemap/entities form.
+   */
+  public function testEnableEntityType() {
+    $this->generator->disableEntityType('node')
+      ->enableEntityType('node')
+      ->setBundleSettings('node', 'page');
+
+    $this->drupalLogin($this->privilegedUser);
+    $this->drupalGet('admin/structure/types/manage/page');
+    $this->assertSession()->pageTextContains('Simple XML sitemap');
+
+    $this->generator->generateSitemap('nobatch');
+
+    $this->drupalGet('sitemap.xml');
+    $this->assertSession()->responseContains('node/' . $this->node->id());
+
+    $this->assertTrue($this->generator->entityTypeIsEnabled('node'));
+  }
+
+}
diff --git a/tests/src/Functional/SimplesitemapTestBase.php b/tests/src/Functional/SimplesitemapTestBase.php
new file mode 100644
index 0000000..9317a4a
--- /dev/null
+++ b/tests/src/Functional/SimplesitemapTestBase.php
@@ -0,0 +1,113 @@
+<?php
+
+namespace Drupal\Tests\simple_sitemap\Functional;
+
+use Drupal\Core\StringTranslation\StringTranslationTrait;
+use Drupal\Tests\BrowserTestBase;
+
+/**
+ * Provides the base class for web tests for Simple sitemap.
+ */
+abstract class SimplesitemapTestBase extends BrowserTestBase {
+
+  use StringTranslationTrait;
+
+  /**
+   * Modules to enable for this test.
+   *
+   * @var string[]
+   */
+  public static $modules = [
+    'simple_sitemap',
+    'node',
+    'content_translation',
+  ];
+
+  /**
+   * Simple sitemap generator.
+   *
+   * @var \Drupal\simple_sitemap\Simplesitemap
+   */
+  protected $generator;
+
+  /**
+   * Database service.
+   *
+   * @var \Drupal\Core\Database\Connection
+   */
+  protected $database;
+
+  /**
+   * An user with all the permissions.
+   *
+   * @var \Drupal\user\Entity\User
+   */
+  protected $privilegedUser;
+
+  /**
+   * A node.
+   *
+   * @var \Drupal\node\Entity\Node
+   */
+  protected $node;
+
+  /**
+   * A node.
+   *
+   * @var \Drupal\node\Entity\Node
+   */
+  protected $node2;
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+
+    $this->generator = $this->container->get('simple_sitemap.generator');
+    $this->database = $this->container->get('database');
+
+    $this->drupalCreateContentType(['type' => 'page']);
+    $this->node = $this->createNode(['title' => 'Node', 'type' => 'page']);
+    $this->node2 = $this->createNode(['title' => 'Node2', 'type' => 'page']);
+
+    // Create an user with all the permissions.
+    $permissions = array_keys($this->container->get('user.permissions')->getPermissions());
+    $this->privilegedUser = $this->drupalCreateUser($permissions);
+  }
+
+  /**
+   * Helper function to replace assertUniqueText.
+   *
+   * Also adapt the legacy trait method because it can't be applied to Non-HTML
+   * pages.
+   *
+   * @param string $text
+   *   The text to look for.
+   *
+   * @See \Drupal\FunctionalTests\AssertLegacyTrait::assertUniqueText().
+   */
+  protected function assertUniqueTextWorkaround($text) {
+    $page_content = $this->getSession()->getPage()->getContent();
+    $nr_found = substr_count($page_content, $text);
+    $this->assertSame(1, $nr_found);
+  }
+
+  /**
+   * Helper function to replace assertNoUniqueText.
+   *
+   * Also adapt the legacy trait method because it can't be applied to Non-HTML
+   * pages.
+   *
+   * @param string $text
+   *   The text to look for.
+   *
+   * @See \Drupal\FunctionalTests\AssertLegacyTrait::assertNoUniqueText().
+   */
+  protected function assertNoUniqueTextWorkaround($text) {
+    $page_text = $this->getSession()->getPage()->getContent();
+    $nr_found = substr_count($page_text, $text);
+    $this->assertGreaterThan(1, $nr_found);
+  }
+
+}
-- 
2.1.4

