PhpConditionTest.php in PHP 8
File
src/Tests/Condition/PhpConditionTest.php
View source
<?php
namespace Drupal\php\Tests\Condition;
use Drupal\KernelTests\KernelTestBase;
class PhpConditionTest extends KernelTestBase {
protected $manager;
public static $modules = [
'filter',
'system',
'php',
];
protected function setUp() {
parent::setUp();
$this->manager = $this->container
->get('plugin.manager.condition');
}
public function testConditions() {
$condition = $this->manager
->createInstance('php')
->setConfig('php', '<?php return TRUE; ?>');
$this
->assertTrue((bool) $condition
->execute(), 'PHP condition passes as expected.');
self::assertEquals($condition
->summary(), 'When the given PHP evaluates as TRUE.');
$condition
->setConfig('php', '<?php return FALSE; ?>');
$this
->assertFalse((bool) $condition
->execute(), 'PHP condition fails as expected.');
$condition
->setConfig('negate', TRUE);
self::assertEquals($condition
->summary(), 'When the given PHP evaluates as FALSE.');
$condition
->setConfig('negate', FALSE);
$condition
->setConfig('php', FALSE);
self::assertEquals($condition
->summary(), 'No PHP code has been provided.');
}
}
Classes
Name |
Description |
PhpConditionTest |
Tests that the PHP Condition, provided by php module, is working properly. |