View source
<?php
namespace Drupal\language\Tests\Condition;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\KernelTestBase;
class LanguageConditionTest extends KernelTestBase {
protected $manager;
protected $languageManager;
public static $modules = array(
'system',
'language',
);
protected function setUp() {
parent::setUp();
$this
->installConfig(array(
'language',
));
ConfigurableLanguage::createFromLangcode('it')
->save();
$this->manager = $this->container
->get('plugin.manager.condition');
}
public function testConditions() {
$language = \Drupal::languageManager()
->getLanguage('en');
$condition = $this->manager
->createInstance('language')
->setConfig('langcodes', array(
'en' => 'en',
'it' => 'it',
))
->setContextValue('language', $language);
$this
->assertTrue($condition
->execute(), 'Language condition passes as expected.');
$this
->assertEqual($condition
->summary(), 'The language is English, Italian.');
$condition
->setConfig('langcodes', array(
'it' => 'it',
));
$this
->assertFalse($condition
->execute(), 'Language condition fails as expected.');
$this
->assertEqual($condition
->summary(), 'The language is Italian.');
$condition
->setConfig('negate', TRUE);
$this
->assertTrue($condition
->execute(), 'Language condition passes as expected.');
$this
->assertEqual($condition
->summary(), 'The language is not Italian.');
$language = \Drupal::languageManager()
->getLanguage('it');
$condition = $this->manager
->createInstance('language')
->setConfig('langcodes', array(
'en' => 'en',
'it' => 'it',
))
->setContextValue('language', $language);
$this
->assertTrue($condition
->execute(), 'Language condition passes as expected.');
$this
->assertEqual($condition
->summary(), 'The language is English, Italian.');
$condition
->setConfig('langcodes', array(
'it' => 'it',
));
$this
->assertTrue($condition
->execute(), 'Language condition passes as expected.');
$this
->assertEqual($condition
->summary(), 'The language is Italian.');
$condition
->setConfig('negate', TRUE);
$this
->assertFalse($condition
->execute(), 'Language condition fails as expected.');
$this
->assertEqual($condition
->summary(), 'The language is not Italian.');
}
}