LanguageAccessTest.php in Language access 8
File
tests/src/Functional/LanguageAccessTest.php
View source
<?php
namespace Drupal\Tests\language_access\Functional;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\StreamWrapper\PublicStream;
class LanguageAccessTest extends LanguageAccessTestBase {
protected static $modules = [
'block',
];
protected function setUp() : void {
parent::setUp();
$this
->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_INTERFACE);
}
public function testLanguageAccess() : void {
$this
->drupalLogin($this->userEn);
$this
->drupalGet('en/node/1');
$this
->assertSession()
->statusCodeEquals(200);
$this
->drupalGet('nl/node/1');
$this
->assertSession()
->statusCodeEquals(403);
}
public function testDisableDefaultLanguage() : void {
$this
->drupalLogin($this->userNl);
$this
->drupalGet('en/node/1');
$this
->assertSession()
->statusCodeEquals(403);
$this
->drupalGet('nl/node/1');
$this
->assertSession()
->statusCodeEquals(200);
}
public function testExcludedPages() : void {
$this
->drupalLogin($this->userNl);
$this
->drupalGet('en/user/' . $this->userNl
->id());
$this
->assertSession()
->statusCodeEquals(200);
$this
->drupalGet('nl/user/' . $this->userNl
->id());
$this
->assertSession()
->statusCodeEquals(200);
$this
->drupalGet(PublicStream::basePath() . '/styles/large/test.png');
$this
->assertSession()
->statusCodeEquals(404);
}
public function testLanguageSwitchingBlock() : void {
$this
->drupalLogin($this->userEn);
$this
->drupalGet('<front>');
$this
->assertSession()
->linkExists('English');
$this
->assertSession()
->linkNotExists('Dutch');
$this
->drupalLogin($this->userNl);
$this
->drupalGet('<front>');
$this
->assertSession()
->linkNotExists('English');
$this
->assertSession()
->linkExists('Dutch');
}
public function testHreflangTagAccess() {
$this
->drupalLogin($this->userEn);
$this
->drupalGet('en/node/1');
$this
->assertSession()
->elementExists('css', 'link[rel="alternate"][hreflang="en"]');
$this
->assertSession()
->elementNotExists('css', 'link[rel="alternate"][hreflang="nl"]');
$this
->drupalLogin($this->userNl);
$this
->drupalGet('nl/node/1');
$this
->assertSession()
->elementExists('css', 'link[rel="alternate"][hreflang="nl"]');
$this
->assertSession()
->elementNotExists('css', 'link[rel="alternate"][hreflang="en"]');
}
}