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