View source
<?php
namespace Drupal\Tests\language_access\Functional;
use Drupal\language\Entity\ContentLanguageSettings;
class LanguageAccessAdminTest extends LanguageAccessTestBase {
protected static $modules = [
'block_content',
'taxonomy',
'user',
];
protected function setUp() : void {
parent::setUp();
$this->entityTypeManager = $this->container
->get('entity_type.manager');
$this->entityTypeManager
->getStorage('taxonomy_vocabulary')
->create([
'vid' => 'tags',
'name' => 'Tags',
])
->save();
$config = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', 'tags');
$config
->setDefaultLangcode('en')
->setLanguageAlterable(TRUE)
->save();
$this->entityTypeManager
->getStorage('block_content_type')
->create([
'id' => 'basic',
'label' => 'Basic',
])
->save();
$config = ContentLanguageSettings::loadByEntityTypeBundle('block_content', 'basic');
$config
->setDefaultLangcode('en')
->setLanguageAlterable(TRUE)
->save();
$role_id = $this
->drupalCreateRole([
'administer blocks',
'create page content',
'create terms in tags',
'administer users',
]);
$this->userEn
->addRole($role_id);
$this->userEn
->save();
$this->userNl
->addRole($role_id);
$this->userNl
->save();
}
public function testNodeForm() : void {
$this
->drupalLogin($this->userEn);
$this
->drupalGet('en/node/add/page');
$this
->assertSession()
->optionExists('langcode[0][value]', 'en');
$this
->assertSession()
->optionExists('langcode[0][value]', 'und');
$this
->assertSession()
->optionExists('langcode[0][value]', 'zxx');
$this
->assertSession()
->optionNotExists('langcode[0][value]', 'nl');
$this
->drupalLogin($this->userNl);
$this
->drupalGet('nl/node/add/page');
$this
->assertSession()
->optionExists('langcode[0][value]', 'nl');
$this
->assertSession()
->optionExists('langcode[0][value]', 'und');
$this
->assertSession()
->optionExists('langcode[0][value]', 'zxx');
$this
->assertSession()
->optionNotExists('langcode[0][value]', 'en');
}
public function testTaxonomyTermForm() : void {
$this
->drupalLogin($this->userEn);
$this
->drupalGet('en/admin/structure/taxonomy/manage/tags/add');
$this
->assertSession()
->optionExists('langcode[0][value]', 'en');
$this
->assertSession()
->optionExists('langcode[0][value]', 'und');
$this
->assertSession()
->optionExists('langcode[0][value]', 'zxx');
$this
->assertSession()
->optionNotExists('langcode[0][value]', 'nl');
$this
->drupalLogin($this->userNl);
$this
->drupalGet('nl/admin/structure/taxonomy/manage/tags/add');
$this
->assertSession()
->optionExists('langcode[0][value]', 'nl');
$this
->assertSession()
->optionExists('langcode[0][value]', 'und');
$this
->assertSession()
->optionExists('langcode[0][value]', 'zxx');
$this
->assertSession()
->optionNotExists('langcode[0][value]', 'en');
}
public function testUserForm() : void {
$this
->drupalLogin($this->userEn);
$this
->drupalGet('en/user/' . $this->userEn
->id() . '/edit');
$this
->assertSession()
->optionExists('preferred_langcode', 'en');
$this
->assertSession()
->optionNotExists('preferred_langcode', 'nl');
$this
->drupalLogin($this->userNl);
$this
->drupalGet('en/user/' . $this->userNl
->id() . '/edit');
$this
->assertSession()
->optionExists('preferred_langcode', 'nl');
$this
->assertSession()
->optionNotExists('preferred_langcode', 'en');
}
public function testBlockForm() : void {
$this
->drupalLogin($this->userEn);
$this
->drupalGet('en/block/add/basic');
$this
->assertSession()
->optionExists('langcode[0][value]', 'en');
$this
->assertSession()
->optionExists('langcode[0][value]', 'und');
$this
->assertSession()
->optionExists('langcode[0][value]', 'zxx');
$this
->assertSession()
->optionNotExists('langcode[0][value]', 'nl');
$this
->drupalLogin($this->userNl);
$this
->drupalGet('nl/block/add/basic');
$this
->assertSession()
->optionExists('langcode[0][value]', 'nl');
$this
->assertSession()
->optionExists('langcode[0][value]', 'und');
$this
->assertSession()
->optionExists('langcode[0][value]', 'zxx');
$this
->assertSession()
->optionNotExists('langcode[0][value]', 'en');
}
}