You are here

public function LanguageAccessSimpleSitemapTest::testSimpleSitemap in Language access 8

Test that URL's are hidden in the sitemap.

File

tests/src/Functional/LanguageAccessSimpleSitemapTest.php, line 48

Class

LanguageAccessSimpleSitemapTest
Test language access in combination with simple_sitemap.

Namespace

Drupal\Tests\language_access\Functional

Code

public function testSimpleSitemap() {

  // By default, the anonymous user has access to the default language (en).
  $this->generator
    ->generateSitemap(QueueWorker::GENERATE_TYPE_BACKEND);
  $this
    ->drupalGet('sitemap.xml');
  $this
    ->assertSession()
    ->responseContains('/test-en');
  $this
    ->assertSession()
    ->responseNotContains('/test-nl');

  // Revoke permission to EN and grant permission to NL.
  $anonymous_role = Role::load('anonymous');
  $anonymous_role
    ->revokePermission('access language en');
  $anonymous_role
    ->grantPermission('access language nl');
  $anonymous_role
    ->save();

  // Check that only NL URL's are now available.
  $this->generator
    ->generateSitemap(QueueWorker::GENERATE_TYPE_BACKEND);
  $this
    ->drupalGet('sitemap.xml');
  $this
    ->assertSession()
    ->responseContains('/test-nl');
  $this
    ->assertSession()
    ->responseNotContains('/test-en');
}