Further modules included.
[yaffs-website] / web / modules / contrib / php / src / Tests / Condition / PhpConditionTest.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\php\Tests\Condition\PhpConditionTest.
6  */
7
8 namespace Drupal\php\Tests\Condition;
9
10 use \Drupal\KernelTests\KernelTestBase;
11
12 /**
13  * Tests that the PHP Condition, provided by php module, is working properly.
14  *
15  * @group PHP
16  */
17 class PhpConditionTest extends KernelTestBase {
18
19   /**
20    * The condition plugin manager.
21    *
22    * @var \Drupal\Core\Condition\ConditionManager
23    */
24   protected $manager;
25
26   /**
27    * Modules to enable.
28    *
29    * @var array
30    */
31   public static $modules = ['system', 'php'];
32
33   /**
34    * {@inheritdoc}
35    */
36   protected function setUp() {
37     parent::setUp();
38
39     $this->manager = $this->container->get('plugin.manager.condition');
40   }
41
42   /**
43    * Tests conditions.
44    */
45   public function testConditions() {
46     // Grab the PHP condition and configure it to check against a php snippet.
47     $condition = $this->manager->createInstance('php')
48       ->setConfig('php', '<?php return TRUE; ?>');
49     $this->assertTrue($condition->execute(), 'PHP condition passes as expected.');
50     // Check for the proper summary.
51     self::assertEquals($condition->summary(), 'When the given PHP evaluates as TRUE.');
52
53     // Set the PHP snippet to return FALSE.
54     $condition->setConfig('php', '<?php return FALSE; ?>');
55     $this->assertFalse($condition->execute(), 'PHP condition fails as expected.');
56
57     // Negate the condition.
58     $condition->setConfig('negate', TRUE);
59     // Check for the proper summary.
60     self::assertEquals($condition->summary(), 'When the given PHP evaluates as FALSE.');
61
62     // Reverse the negation.
63     $condition->setConfig('negate', FALSE);
64     // Set and empty snippet.
65     $condition->setConfig('php', FALSE);
66     // Check for the proper summary.
67     self::assertEquals($condition->summary(), 'No PHP code has been provided.');
68   }
69
70 }