You are here

public function XmlSitemapUnitTest::testGetChangefreq in XML sitemap 2.x

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

Tests for xmlsitemap_get_changefreq().

File

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

Class

XmlSitemapUnitTest
Unit tests for the XML sitemap module.

Namespace

Drupal\Tests\xmlsitemap\Functional

Code

public function testGetChangefreq() {

  // The test values.
  $values = [
    0,
    mt_rand(1, XMLSITEMAP_FREQUENCY_ALWAYS),
    mt_rand(XMLSITEMAP_FREQUENCY_ALWAYS + 1, XMLSITEMAP_FREQUENCY_HOURLY),
    mt_rand(XMLSITEMAP_FREQUENCY_HOURLY + 1, XMLSITEMAP_FREQUENCY_DAILY),
    mt_rand(XMLSITEMAP_FREQUENCY_DAILY + 1, XMLSITEMAP_FREQUENCY_WEEKLY),
    mt_rand(XMLSITEMAP_FREQUENCY_WEEKLY + 1, XMLSITEMAP_FREQUENCY_MONTHLY),
    mt_rand(XMLSITEMAP_FREQUENCY_MONTHLY + 1, XMLSITEMAP_FREQUENCY_YEARLY),
    mt_rand(XMLSITEMAP_FREQUENCY_YEARLY + 1, mt_getrandmax()),
  ];

  // The expected values.
  $expected = [
    FALSE,
    'always',
    'hourly',
    'daily',
    'weekly',
    'monthly',
    'yearly',
    'never',
  ];
  foreach ($values as $i => $value) {
    $actual = xmlsitemap_get_changefreq($value);
    $this
      ->assertSame($expected[$i], $actual);
  }
}