SimplesitemapTest.php 20.1 KB
Newer Older
1 2
<?php

3 4 5
namespace Drupal\Tests\simple_sitemap\Functional;

use Drupal\Core\Url;
6 7

/**
8
 * Tests Simple XML sitemap functional integration.
9
 *
10
 * @group simple_sitemap
11
 */
gbyte.co's avatar
gbyte.co committed
12
class SimplesitemapTest extends SimplesitemapTestBase {
13 14

  /**
15
   * Verify sitemap.xml has the link to the front page after first generation.
16
   */
gbyte.co's avatar
gbyte.co committed
17
  public function testInitialGeneration() {
gbyte.co's avatar
gbyte.co committed
18
    $this->generator->generateSitemap('nobatch');
19
    $this->drupalGet($this->defaultSitemapUrl);
20 21 22 23
    $this->assertSession()->responseContains('urlset');
    $this->assertSession()->responseContains(Url::fromRoute('<front>')->setAbsolute()->toString());
    $this->assertSession()->responseContains('1.0');
    $this->assertSession()->responseContains('daily');
24 25
  }

26 27 28
  /**
   * Test custom link.
   */
29 30 31 32
  public function testAddCustomLink() {
    $this->generator->addCustomLink('/node/' . $this->node->id(), ['priority' => 0.2, 'changefreq' => 'monthly'])
      ->generateSitemap('nobatch');

33
    $this->drupalGet($this->defaultSitemapUrl);
34 35 36
    $this->assertSession()->responseContains('node/' . $this->node->id());
    $this->assertSession()->responseContains('0.2');
    $this->assertSession()->responseContains('monthly');
gbyte.co's avatar
gbyte.co committed
37

38
    $this->drupalLogin($this->privilegedUser);
gbyte.co's avatar
gbyte.co committed
39 40

    $this->drupalGet('admin/config/search/simplesitemap/custom');
41
    $this->assertSession()->pageTextContains('/node/' . $this->node->id() . ' 0.2 monthly');
gbyte.co's avatar
gbyte.co committed
42 43 44 45 46

    $this->generator->addCustomLink('/node/' . $this->node->id(), ['changefreq' => 'yearly'])
      ->generateSitemap('nobatch');

    $this->drupalGet('admin/config/search/simplesitemap/custom');
47
    $this->assertSession()->pageTextContains('/node/' . $this->node->id() . ' yearly');
gbyte.co's avatar
gbyte.co committed
48
  }
49

gbyte.co's avatar
gbyte.co committed
50
  /**
gbyte.co's avatar
gbyte.co committed
51
   * Test default settings of custom links.
gbyte.co's avatar
gbyte.co committed
52
   */
53 54 55 56 57
  public function testAddCustomLinkDefaults() {
    $this->generator->removeCustomLinks()
      ->addCustomLink('/node/' . $this->node->id())
      ->generateSitemap('nobatch');

58
    $this->drupalGet($this->defaultSitemapUrl);
59 60 61
    $this->assertSession()->responseContains('node/' . $this->node->id());
    $this->assertSession()->responseContains('0.5');
    $this->assertSession()->responseNotContains('changefreq');
62 63 64
  }

  /**
65
   * Test removing custom paths from the sitemap settings.
66
   */
67 68 69
  public function testRemoveCustomLinks() {

    // Test removing one custom path from the sitemap.
70
    $this->generator->addCustomLink('/node/' . $this->node->id())
71
      ->removeCustomLinks('/node/' . $this->node->id())
72 73
      ->generateSitemap('nobatch');

74
    $this->drupalGet($this->defaultSitemapUrl);
75
    $this->assertSession()->responseNotContains('node/' . $this->node->id());
76

77
    // Test removing all custom paths from the sitemap.
78 79 80
    $this->generator->removeCustomLinks()
      ->generateSitemap('nobatch');

81
    $this->drupalGet($this->defaultSitemapUrl);
82
    $this->assertSession()->responseNotContains(Url::fromRoute('<front>')->setAbsolute()->toString());
83 84 85
  }

  /**
gbyte.co's avatar
gbyte.co committed
86
   * Tests setting bundle settings.
gbyte.co's avatar
gbyte.co committed
87 88
   *
   * @todo Add form tests
89
   */
gbyte.co's avatar
gbyte.co committed
90
  public function testSetBundleSettings() {
gbyte.co's avatar
gbyte.co committed
91 92
    $this->assertFalse($this->generator->bundleIsIndexed('node', 'page'));

gbyte.co's avatar
gbyte.co committed
93
    // Index new bundle.
94
    $this->generator->removeCustomLinks()
95 96 97 98 99
      ->setBundleSettings('node', 'page', [
        'index' => TRUE,
        'priority' => 0.5,
        'changefreq' => 'hourly',
      ])
gbyte.co's avatar
gbyte.co committed
100 101
      ->generateSitemap('nobatch');

102
    $this->drupalGet($this->defaultSitemapUrl);
103 104 105
    $this->assertSession()->responseContains('node/' . $this->node->id());
    $this->assertSession()->responseContains('0.5');
    $this->assertSession()->responseContains('hourly');
gbyte.co's avatar
gbyte.co committed
106

gbyte.co's avatar
gbyte.co committed
107 108
    $this->assertTrue($this->generator->bundleIsIndexed('node', 'page'));

gbyte.co's avatar
gbyte.co committed
109 110 111 112
    // Only change bundle priority.
    $this->generator->setBundleSettings('node', 'page', ['priority' => 0.9])
      ->generateSitemap('nobatch');

113
    $this->drupalGet($this->defaultSitemapUrl);
114 115 116
    $this->assertSession()->responseContains('node/' . $this->node->id());
    $this->assertSession()->responseNotContains('0.5');
    $this->assertSession()->responseContains('0.9');
gbyte.co's avatar
gbyte.co committed
117

118 119 120 121
    // Only change bundle changefreq.
    $this->generator->setBundleSettings('node', 'page', ['changefreq' => 'daily'])
      ->generateSitemap('nobatch');

122
    $this->drupalGet($this->defaultSitemapUrl);
123 124 125
    $this->assertSession()->responseContains('node/' . $this->node->id());
    $this->assertSession()->responseNotContains('hourly');
    $this->assertSession()->responseContains('daily');
126 127 128 129 130

    // Remove changefreq setting.
    $this->generator->setBundleSettings('node', 'page', ['changefreq' => ''])
      ->generateSitemap('nobatch');

131
    $this->drupalGet($this->defaultSitemapUrl);
132 133 134
    $this->assertSession()->responseContains('node/' . $this->node->id());
    $this->assertSession()->responseNotContains('changefreq');
    $this->assertSession()->responseNotContains('daily');
135

gbyte.co's avatar
gbyte.co committed
136 137 138 139 140 141 142 143
    // 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');

144
    $this->drupalGet($this->defaultSitemapUrl);
145 146
    $this->assertSession()->responseContains('node/' . $this->node->id());
    $this->assertSession()->responseContains('node/' . $node3->id());
gbyte.co's avatar
gbyte.co committed
147

148 149
    // Set bundle 'index' setting to false.
    $this->generator->setBundleSettings('node', 'page', ['index' => FALSE])
gbyte.co's avatar
gbyte.co committed
150
      ->setBundleSettings('node', 'blog', ['index' => FALSE])
gbyte.co's avatar
gbyte.co committed
151 152
      ->generateSitemap('nobatch');

153
    $this->drupalGet($this->defaultSitemapUrl);
154

155 156
    $this->assertSession()->responseNotContains('node/' . $this->node->id());
    $this->assertSession()->responseNotContains('node/' . $node3->id());
157 158 159
  }

  /**
gbyte.co's avatar
gbyte.co committed
160
   * Test default settings of bundles.
161 162 163 164 165 166
   */
  public function testSetBundleSettingsDefaults() {
    $this->generator->setBundleSettings('node', 'page')
      ->removeCustomLinks()
      ->generateSitemap('nobatch');

167
    $this->drupalGet($this->defaultSitemapUrl);
168 169 170
    $this->assertSession()->responseContains('node/' . $this->node->id());
    $this->assertSession()->responseContains('0.5');
    $this->assertSession()->responseNotContains('changefreq');
gbyte.co's avatar
gbyte.co committed
171
  }
172

173 174 175 176 177 178 179 180 181
  /**
   * Test the lastmod parameter in different scenarios.
   */
  public function testLastmod() {
    // Entity links should have 'lastmod'.
    $this->generator->setBundleSettings('node', 'page')
      ->removeCustomLinks()
      ->generateSitemap('nobatch');

182
    $this->drupalGet($this->defaultSitemapUrl);
183
    $this->assertSession()->responseContains('lastmod');
184 185 186 187 188 189

    // Entity custom links should have 'lastmod'.
    $this->generator->setBundleSettings('node', 'page', ['index' => FALSE])
      ->addCustomLink('/node/' . $this->node->id())
      ->generateSitemap('nobatch');

190
    $this->drupalGet($this->defaultSitemapUrl);
191
    $this->assertSession()->responseContains('lastmod');
192 193 194 195 196 197

    // Non-entity custom links should not have 'lastmod'.
    $this->generator->removeCustomLinks()
      ->addCustomLink('/')
      ->generateSitemap('nobatch');

198
    $this->drupalGet($this->defaultSitemapUrl);
199
//    $this->assertSession()->responseNotContains('lastmod'); // todo: Not passing.
200 201
  }

gbyte.co's avatar
gbyte.co committed
202 203 204 205 206 207
  /**
   * Tests the duplicate setting.
   *
   * @todo On second generation too many links in XML output here?
   */
  public function testRemoveDuplicatesSetting() {
gbyte.co's avatar
gbyte.co committed
208
    $this->generator->setBundleSettings('node', 'page', ['index' => TRUE])
gbyte.co's avatar
gbyte.co committed
209 210 211 212
      ->addCustomLink('/node/1')
      ->saveSetting('remove_duplicates', TRUE)
      ->generateSitemap('nobatch');

213
    $this->drupalGet($this->defaultSitemapUrl);
214
    $this->assertUniqueTextWorkaround('node/' . $this->node->id());
gbyte.co's avatar
gbyte.co committed
215 216 217 218

    $this->generator->saveSetting('remove_duplicates', FALSE)
      ->generateSitemap('nobatch');

219
    $this->drupalGet($this->defaultSitemapUrl);
220
    $this->assertNoUniqueTextWorkaround('node/' . $this->node->id());
gbyte.co's avatar
gbyte.co committed
221 222 223 224 225 226 227 228 229 230 231
  }

  /**
   * Test max links setting and the sitemap index.
   */
  public function testMaxLinksSetting() {
    $this->generator->setBundleSettings('node', 'page')
      ->saveSetting('max_links', 1)
      ->removeCustomLinks()
      ->generateSitemap('nobatch');

232
    $this->drupalGet($this->defaultSitemapUrl);
233 234
    $this->assertSession()->responseContains('sitemap.xml?page=1');
    $this->assertSession()->responseContains('sitemap.xml?page=2');
gbyte.co's avatar
gbyte.co committed
235

236
    $this->drupalGet('sitemap.xml?page=1');
237 238 239
    $this->assertSession()->responseContains('node/' . $this->node->id());
    $this->assertSession()->responseContains('0.5');
    $this->assertSession()->responseNotContains('node/' . $this->node2->id());
gbyte.co's avatar
gbyte.co committed
240

241
    $this->drupalGet('sitemap.xml?page=2');
242 243 244
    $this->assertSession()->responseContains('node/' . $this->node2->id());
    $this->assertSession()->responseContains('0.5');
    $this->assertSession()->responseNotContains('node/' . $this->node->id());
gbyte.co's avatar
gbyte.co committed
245 246
  }

247 248 249
  /**
   * Test batch process limit setting.
   */
gbyte.co's avatar
gbyte.co committed
250 251
  public function testBatchProcessLimitSetting() {
    // Create some nodes.
gbyte.co's avatar
gbyte.co committed
252
    for ($i = 3; $i <= 50; $i++) {
gbyte.co's avatar
gbyte.co committed
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
      $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();

269 270
    $this->assertEquals($sitemap2, $sitemap);
    $this->assertEquals($sitemap3, $sitemap);
gbyte.co's avatar
gbyte.co committed
271 272 273 274 275 276 277 278

    // 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();

279
    $sitemap_chunk = $this->generator->getSitemap('default', 1);
gbyte.co's avatar
gbyte.co committed
280 281 282 283 284

    $sitemap_index2 = $this->generator->saveSetting('batch_process_limit', 1)
      ->generateSitemap('nobatch')
      ->getSitemap();

285
    $sitemap_chunk2 = $this->generator->getSitemap('default', 1);
gbyte.co's avatar
gbyte.co committed
286 287 288 289 290

    $sitemap_index3 = $this->generator->saveSetting('batch_process_limit', 10)
      ->generateSitemap('nobatch')
      ->getSitemap();

291
    $sitemap_chunk3 = $this->generator->getSitemap('default', 1);
gbyte.co's avatar
gbyte.co committed
292

293 294 295 296
    $this->assertSame($sitemap_index2, $sitemap_index);
    $this->assertSame($sitemap_chunk2, $sitemap_chunk);
    $this->assertSame($sitemap_index3, $sitemap_index);
    $this->assertSame($sitemap_chunk3, $sitemap_chunk);
gbyte.co's avatar
gbyte.co committed
297 298
  }

gbyte.co's avatar
gbyte.co committed
299 300 301 302 303 304 305 306
  /**
   * Test setting the base URL.
   */
  public function testBaseUrlSetting() {
    $this->generator->setBundleSettings('node', 'page')
      ->saveSetting('base_url', 'http://base_url_test')
      ->generateSitemap('nobatch');

307
    $this->drupalGet($this->defaultSitemapUrl);
308
    $this->assertSession()->responseContains('http://base_url_test');
gbyte.co's avatar
gbyte.co committed
309 310 311 312 313

    // Set base URL in the sitemap index.
    $this->generator->saveSetting('max_links', 1)
      ->generateSitemap('nobatch');

314
    $this->drupalGet($this->defaultSitemapUrl);
315
    $this->assertSession()->responseContains('http://base_url_test/sitemap.xml?page=1');
gbyte.co's avatar
gbyte.co committed
316 317
  }

gbyte.co's avatar
gbyte.co committed
318 319 320
  /**
   * @todo testSkipUntranslatedSetting
   */
321 322 323 324 325

  /**
   * @todo testSkipNonExistentTranslations
   */

gbyte.co's avatar
gbyte.co committed
326
  /**
gbyte.co's avatar
gbyte.co committed
327
   * Test overriding of bundle settings for a single entity.
328
   *
gbyte.co's avatar
gbyte.co committed
329
   * @todo: Use form testing instead of responseContains().
gbyte.co's avatar
gbyte.co committed
330
   */
331
  public function testSetEntityInstanceSettings() {
332 333 334
    $this->generator->setBundleSettings('node', 'page')
      ->removeCustomLinks()
      ->setEntityInstanceSettings('node', $this->node->id(), ['priority' => 0.1, 'changefreq' => 'never'])
gbyte.co's avatar
gbyte.co committed
335 336 337 338
      ->setEntityInstanceSettings('node', $this->node2->id(), ['index' => FALSE])
      ->generateSitemap('nobatch');

    // Test sitemap result.
339
    $this->drupalGet($this->defaultSitemapUrl);
340 341 342 343 344
    $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');
gbyte.co's avatar
gbyte.co committed
345

346
    $this->drupalLogin($this->privilegedUser);
gbyte.co's avatar
gbyte.co committed
347 348 349

    // Test UI changes.
    $this->drupalGet('node/' . $this->node->id() . '/edit');
350 351
    $this->assertSession()->responseContains('<option value="0.1" selected="selected">0.1</option>');
    $this->assertSession()->responseContains('<option value="never" selected="selected">never</option>');
gbyte.co's avatar
gbyte.co committed
352 353

    // Test database changes.
354
    $result = $this->database->select('simple_sitemap_entity_overrides', 'o')
gbyte.co's avatar
gbyte.co committed
355 356 357 358 359 360 361 362
      ->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'])
gbyte.co's avatar
gbyte.co committed
363
      ->generateSitemap('nobatch');
364

gbyte.co's avatar
gbyte.co committed
365
    // Test sitemap result.
366
    $this->drupalGet($this->defaultSitemapUrl);
367 368 369 370 371
    $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');
gbyte.co's avatar
gbyte.co committed
372 373 374

    // Test UI changes.
    $this->drupalGet('node/' . $this->node->id() . '/edit');
375 376
    $this->assertSession()->responseContains('<option value="0.1" selected="selected">0.1 (default)</option>');
    $this->assertSession()->responseContains('<option value="never" selected="selected">never (default)</option>');
gbyte.co's avatar
gbyte.co committed
377

378 379 380
    // 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')
gbyte.co's avatar
gbyte.co committed
381 382 383 384 385 386
      ->fields('o', ['inclusion_settings'])
      ->condition('o.entity_type', 'node')
      ->condition('o.entity_id', $this->node->id())
      ->execute()
      ->fetchField();
    $this->assertTrue(empty($result));
gbyte.co's avatar
gbyte.co committed
387 388
  }

gbyte.co's avatar
gbyte.co committed
389
  /**
390 391
   * Test indexing an atomic entity (here: a user)
   * @todo Not working
gbyte.co's avatar
gbyte.co committed
392
   */
393 394
  /*public function testAtomicEntityIndexation() {
    $user_id = $this->privilegedUser->id();
395 396 397
    $this->generator->setBundleSettings('user')
      ->generateSitemap('nobatch');

398
    $this->drupalGet($this->defaultSitemapUrl);
399
    $this->assertSession()->responseNotContains('user/' . $user_id);
400 401 402 403

    user_role_grant_permissions(0, ['access user profiles']);
    $this->generator->generateSitemap('nobatch');

404
    $this->drupalGet($this->defaultSitemapUrl);
405
    $this->assertSession()->responseContains('user/' . $user_id);
406
  }*/
gbyte.co's avatar
gbyte.co committed
407 408 409 410 411 412 413 414 415

  /**
   * @todo Test indexing menu.
   */

  /**
   * @todo Test deleting a bundle.
   */

gbyte.co's avatar
gbyte.co committed
416 417 418 419
  /**
   * Test disabling sitemap support for an entity type.
   */
  public function testDisableEntityType() {
420
    $this->generator->setBundleSettings('node', 'page')
gbyte.co's avatar
gbyte.co committed
421 422
      ->disableEntityType('node');

423
    $this->drupalLogin($this->privilegedUser);
gbyte.co's avatar
gbyte.co committed
424
    $this->drupalGet('admin/structure/types/manage/page');
425
    $this->assertSession()->pageTextNotContains('Simple XML sitemap');
gbyte.co's avatar
gbyte.co committed
426 427

    $this->generator->generateSitemap('nobatch');
428

429
    $this->drupalGet($this->defaultSitemapUrl);
430
    $this->assertSession()->responseNotContains('node/' . $this->node->id());
gbyte.co's avatar
gbyte.co committed
431 432

    $this->assertFalse($this->generator->entityTypeIsEnabled('node'));
gbyte.co's avatar
gbyte.co committed
433 434 435 436
  }

  /**
   * Test enabling sitemap support for an entity type.
gbyte.co's avatar
gbyte.co committed
437 438
   *
   * @todo Test admin/config/search/simplesitemap/entities form.
gbyte.co's avatar
gbyte.co committed
439 440 441
   */
  public function testEnableEntityType() {
    $this->generator->disableEntityType('node')
gbyte.co's avatar
gbyte.co committed
442
      ->enableEntityType('node')
443
      ->setBundleSettings('node', 'page');
gbyte.co's avatar
gbyte.co committed
444

445
    $this->drupalLogin($this->privilegedUser);
gbyte.co's avatar
gbyte.co committed
446
    $this->drupalGet('admin/structure/types/manage/page');
447
    $this->assertSession()->pageTextContains('Simple XML sitemap');
gbyte.co's avatar
gbyte.co committed
448 449 450

    $this->generator->generateSitemap('nobatch');

451
    $this->drupalGet($this->defaultSitemapUrl);
452
    $this->assertSession()->responseContains('node/' . $this->node->id());
453

gbyte.co's avatar
gbyte.co committed
454
    $this->assertTrue($this->generator->entityTypeIsEnabled('node'));
455
  }
456

457 458 459 460 461 462 463 464 465 466 467 468 469 470
  public function testSitemapVariants() {

    // Test adding a default variant.
    $this->generator
      ->addSitemapVariant('test')
      ->setBundleSettings('node', 'page')
      ->generateSitemap('nobatch');

    $variants = $this->generator->getSitemapVariants();
    $this->assertTrue(isset($variants['test']));

    $this->drupalGet($this->defaultSitemapUrl);
    $this->assertSession()->responseContains('node/' . $this->node->id());

471
    $this->drupalGet('test/sitemap.xml');
472 473
    $this->assertSession()->responseContains('node/' . $this->node->id());

gbyte.co's avatar
gbyte.co committed
474
    $this->generator->removeSitemapVariant('test');
475 476 477 478 479 480 481

    $variants = $this->generator->getSitemapVariants();
    $this->assertFalse(isset($variants['test']));

    $this->generator->generateSitemap('nobatch');

    // Test if sitemap has been removed along with the variant.
482
    $this->drupalGet('test/sitemap.xml');
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
//    $this->assertSession()->responseNotContains('urlset'); //todo

    // Test adding a variant of new sitemap type.
    $this->generator->removeSitemap()
      ->setSitemapTypeDefinition('test_type', [
      'label' => 'Test type',
      'description' => 'Test description.',
      'sitemap_generator' => 'default',
      'url_generators' => ['custom'],
    ])
      ->addSitemapVariant('test2', ['type' => 'test_type']);

    $types = $this->generator->getSitemapTypeDefinitions();
    $this->assertTrue(isset($types['test_type']));

    $this->generator->generateSitemap('nobatch', 'test2');

    // Test if default variant has been successfully excluded.
    $this->drupalGet($this->defaultSitemapUrl);
//    $this->assertSession()->responseNotContains('urlset'); //todo

    // Test if custom generator has been successfully included.
505
    $this->drupalGet('test2/sitemap.xml');
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
    $this->assertSession()->responseContains(Url::fromRoute('<front>')->setAbsolute()->toString());

    // Test if entity generator has been successfully excluded.
    $this->assertSession()->responseNotContains('node/' . $this->node->id());

    // Test removing sitemap type.
    $this->generator->removeSitemapTypeDefinition('test_type');
    $types = $this->generator->getSitemapTypeDefinitions();
    $this->assertFalse(isset($types['test_type']));

    // Test if variants have been removed along with the sitemap type.
    $variants = $this->generator->getSitemapVariants();
    $this->assertFalse(isset($variants['test2']));

    $this->generator->generateSitemap('nobatch');

    // Test if sitemap has been removed along with the sitemap type.
//    $this->assertFalse($this->generator->getSitemap('test2')); //todo
  }

  /**
   * Test cacheability of the response.
   */
  public function testCacheability() {
    $this->generator
      ->addSitemapVariant('test')
      ->setBundleSettings('node', 'page')
      ->generateSitemap('nobatch');

    // Verify the cache is not set.
    $this->drupalGet('sitemap.xml');
    $this->assertEquals('MISS', $this->drupalGetHeader('X-Drupal-Cache'));
    $this->assertSession()->responseContains('node/' . $this->node->id());

540
    $this->drupalGet('test/sitemap.xml');
541 542 543 544 545 546 547
    $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
    $this->drupalGet('sitemap.xml');
    $this->assertEquals('HIT', $this->drupalGetHeader('X-Drupal-Cache'));

548
    $this->drupalGet('test/sitemap.xml');
549 550 551 552 553 554 555 556 557
    $this->assertEquals('HIT', $this->drupalGetHeader('X-Drupal-Cache'));

    $this->generator->generateSitemap('nobatch', 'default');

    // Verify the cache is not set for default variant as it as just regenerated.
    $this->drupalGet('sitemap.xml');
    $this->assertEquals('MISS', $this->drupalGetHeader('X-Drupal-Cache'));

    // Verify the cache is still set for test variant.
558
    $this->drupalGet('test/sitemap.xml');
559 560 561 562 563
//    $this->assertEquals('HIT', $this->drupalGetHeader('X-Drupal-Cache')); //todo

    $this->generator->removeSitemap('test');

    // Verify the cache is unset for test variant after removing it explicitly.
564
    $this->drupalGet('test/sitemap.xml');
565 566 567 568 569 570
//    $this->assertEquals('MISS', $this->drupalGetHeader('X-Drupal-Cache')); //todo
  }

  /**
   * @todo Test removeSitemap().
   */
571
}