Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / language / tests / src / Kernel / Condition / LanguageConditionTest.php
1 <?php
2
3 namespace Drupal\Tests\language\Kernel\Condition;
4
5 use Drupal\language\Entity\ConfigurableLanguage;
6 use Drupal\KernelTests\KernelTestBase;
7
8 /**
9  * Tests that the language condition, provided by the language module, is
10  * working properly.
11  *
12  * @group language
13  */
14 class LanguageConditionTest extends KernelTestBase {
15
16   /**
17    * The condition plugin manager.
18    *
19    * @var \Drupal\Core\Condition\ConditionManager
20    */
21   protected $manager;
22
23   /**
24    * The language manager.
25    *
26    * @var \Drupal\Core\Language\LanguageManagerInterface
27    */
28   protected $languageManager;
29
30   /**
31    * Modules to enable.
32    *
33    * @var array
34    */
35   public static $modules = ['system', 'language'];
36
37   protected function setUp() {
38     parent::setUp();
39
40     $this->installConfig(['language']);
41     // Setup Italian.
42     ConfigurableLanguage::createFromLangcode('it')->save();
43
44     $this->manager = $this->container->get('plugin.manager.condition');
45   }
46
47   /**
48    * Test the language condition.
49    */
50   public function testConditions() {
51     // Grab the language condition and configure it to check the content
52     // language.
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.');
60
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.');
66
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.');
72
73     // Change the default language to Italian.
74     $language = \Drupal::languageManager()->getLanguage('it');
75
76     $condition = $this->manager->createInstance('language')
77       ->setConfig('langcodes', ['en' => 'en', 'it' => 'it'])
78       ->setContextValue('language', $language);
79
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.');
83
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.');
89
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.');
95   }
96
97 }