DisableLanguageManagerTest.php in Disable language 8
File
tests/src/Kernel/DisableLanguageManagerTest.php
View source
<?php
namespace Drupal\Tests\disable_language\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\language\Entity\ConfigurableLanguage;
class DisableLanguageManagerTest extends KernelTestBase {
protected $disableLanguageManager;
public static $modules = [
'system',
'language',
'disable_language',
];
protected function setUp() {
parent::setUp();
$this->disableLanguageManager = \Drupal::service('disable_language.disable_language_manager');
$this
->installConfig([
'language',
]);
$this
->installConfig([
'disable_language',
]);
ConfigurableLanguage::load('en')
->setWeight(0)
->save();
ConfigurableLanguage::createFromLangcode('nl')
->setWeight(1)
->save();
ConfigurableLanguage::createFromLangcode('fr')
->setWeight(2)
->setThirdPartySetting('disable_language', 'disable', 1)
->setThirdPartySetting('disable_language', 'redirect_language', 'nl')
->save();
}
public function testGetConfigurableLanguages() {
$available_languages = \Drupal::languageManager()
->getLanguages();
$configurable_languages = $this->disableLanguageManager
->getConfigurableLanguages();
$this
->assertEquals(array_keys($available_languages), array_keys($configurable_languages));
}
public function testGetDisabledLanguages() {
$disabled_languages = $this->disableLanguageManager
->getDisabledLanguages();
$this
->assertTrue(count($disabled_languages) === 1 && array_key_exists('fr', $disabled_languages));
}
public function testEnabledLanguages() {
$enabled_languages = $this->disableLanguageManager
->getEnabledLanguages();
$this
->assertTrue(count($enabled_languages) && !array_diff([
'en',
'nl',
], array_keys($enabled_languages)));
}
public function testIsCurrentLanguageDisabledAndHasFallback() {
$this
->assertFalse($this->disableLanguageManager
->isCurrentLanguageDisabled());
$this
->assertFalse($this->disableLanguageManager
->getFallbackLanguage());
\Drupal::configFactory()
->getEditable('system.site')
->set('default_langcode', 'fr')
->save();
$this
->assertTrue($this->disableLanguageManager
->isCurrentLanguageDisabled());
$this
->assertTrue($this->disableLanguageManager
->getFallbackLanguage() === 'nl');
}
public function testGetFirstEnabledLanguage() {
$this
->assertTrue($this->disableLanguageManager
->getFirstEnabledLanguage()
->getId() === 'en');
}
}