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