3 namespace Drupal\php\Tests\Condition;
5 use Drupal\KernelTests\KernelTestBase;
8 * Tests that the PHP Condition, provided by php module, is working properly.
12 class PhpConditionTest extends KernelTestBase {
15 * The condition plugin manager.
17 * @var \Drupal\Core\Condition\ConditionManager
26 public static $modules = ['filter', 'system', 'php'];
31 protected function setUp() {
34 $this->manager = $this->container->get('plugin.manager.condition');
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.');
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.');
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.');
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.');