3 namespace Drupal\Tests\language\Kernel\Condition;
5 use Drupal\language\Entity\ConfigurableLanguage;
6 use Drupal\KernelTests\KernelTestBase;
9 * Tests that the language condition, provided by the language module, is
14 class LanguageConditionTest extends KernelTestBase {
17 * The condition plugin manager.
19 * @var \Drupal\Core\Condition\ConditionManager
24 * The language manager.
26 * @var \Drupal\Core\Language\LanguageManagerInterface
28 protected $languageManager;
35 public static $modules = ['system', 'language'];
37 protected function setUp() {
40 $this->installConfig(['language']);
42 ConfigurableLanguage::createFromLangcode('it')->save();
44 $this->manager = $this->container->get('plugin.manager.condition');
48 * Test the language condition.
50 public function testConditions() {
51 // Grab the language condition and configure it to check the content
53 $language = \Drupal::languageManager()->getLanguage('en');
54 $condition = $this->manager->createInstance('language')
55 ->setConfig('langcodes', ['en' => 'en', 'it' => 'it'])
56 ->setContextValue('language', $language);
57 $this->assertTrue($condition->execute(), 'Language condition passes as expected.');
58 // Check for the proper summary.
59 $this->assertEqual($condition->summary(), 'The language is English, Italian.');
61 // Change to Italian only.
62 $condition->setConfig('langcodes', ['it' => 'it']);
63 $this->assertFalse($condition->execute(), 'Language condition fails as expected.');
64 // Check for the proper summary.
65 $this->assertEqual($condition->summary(), 'The language is Italian.');
67 // Negate the condition
68 $condition->setConfig('negate', TRUE);
69 $this->assertTrue($condition->execute(), 'Language condition passes as expected.');
70 // Check for the proper summary.
71 $this->assertEqual($condition->summary(), 'The language is not Italian.');
73 // Change the default language to Italian.
74 $language = \Drupal::languageManager()->getLanguage('it');
76 $condition = $this->manager->createInstance('language')
77 ->setConfig('langcodes', ['en' => 'en', 'it' => 'it'])
78 ->setContextValue('language', $language);
80 $this->assertTrue($condition->execute(), 'Language condition passes as expected.');
81 // Check for the proper summary.
82 $this->assertEqual($condition->summary(), 'The language is English, Italian.');
84 // Change to Italian only.
85 $condition->setConfig('langcodes', ['it' => 'it']);
86 $this->assertTrue($condition->execute(), 'Language condition passes as expected.');
87 // Check for the proper summary.
88 $this->assertEqual($condition->summary(), 'The language is Italian.');
90 // Negate the condition
91 $condition->setConfig('negate', TRUE);
92 $this->assertFalse($condition->execute(), 'Language condition fails as expected.');
93 // Check for the proper summary.
94 $this->assertEqual($condition->summary(), 'The language is not Italian.');