You are here

public function XmlSitemapUnitTest::testSaveLink in XML sitemap 8

Same name and namespace in other branches
  1. 2.x tests/src/Functional/XmlSitemapUnitTest.php \Drupal\Tests\xmlsitemap\Functional\XmlSitemapUnitTest::testSaveLink()

Tests for XmlSitemapLinkStorage::save().

File

tests/src/Functional/XmlSitemapUnitTest.php, line 158

Class

XmlSitemapUnitTest
Unit tests for the XML sitemap module.

Namespace

Drupal\Tests\xmlsitemap\Functional

Code

public function testSaveLink() {
  $link = [
    'type' => 'testing',
    'subtype' => '',
    'id' => 1,
    'loc' => '/testing',
    'status' => 1,
  ];
  $this->linkStorage
    ->save($link);
  $this
    ->assertFlag('xmlsitemap_regenerate_needed', TRUE);
  $link['status'] = 0;
  $this->linkStorage
    ->save($link);
  $this
    ->assertFlag('xmlsitemap_regenerate_needed', TRUE);
  $link['priority'] = 0.5;
  $link['loc'] = '/new_location';
  $link['status'] = 1;
  $this->linkStorage
    ->save($link);
  $this
    ->assertFlag('xmlsitemap_regenerate_needed', TRUE);
  $link['priority'] = 0.0;
  $this->linkStorage
    ->save($link);
  $this
    ->assertFlag('xmlsitemap_regenerate_needed', TRUE);
  $link['priority'] = 0.1;
  $this->linkStorage
    ->save($link);
  $this
    ->assertFlag('xmlsitemap_regenerate_needed', TRUE);
  $link['priority'] = 1.0;
  $this->linkStorage
    ->save($link);
  $this
    ->assertFlag('xmlsitemap_regenerate_needed', TRUE);
  $link['priority'] = 1;
  $this->linkStorage
    ->save($link);
  $this
    ->assertFlag('xmlsitemap_regenerate_needed', FALSE);
  $link['priority'] = 0;
  $this->linkStorage
    ->save($link);
  $this
    ->assertFlag('xmlsitemap_regenerate_needed', TRUE);
  $link['priority'] = 0.5;
  $this->linkStorage
    ->save($link);
  $this
    ->assertFlag('xmlsitemap_regenerate_needed', TRUE);
  $link['priority'] = 0.5;
  $link['priority_override'] = 0;
  $link['status'] = 1;
  $this->linkStorage
    ->save($link);
  $this
    ->assertFlag('xmlsitemap_regenerate_needed', FALSE);
}