View source
<?php
namespace Drupal\Tests\rules\Unit\Integration\Condition;
use Drupal\Tests\rules\Unit\Integration\RulesIntegrationTestBase;
class ListCountIsTest extends RulesIntegrationTestBase {
protected $condition;
protected function setUp() : void {
parent::setUp();
$this->condition = $this->conditionManager
->createInstance('rules_list_count_is');
}
public function testConditionEvaluation() {
$condition = $this->condition
->setContextValue('list', [
1,
2,
3,
4,
])
->setContextValue('operator', '>')
->setContextValue('value', '2');
$this
->assertTrue($condition
->evaluate());
$condition = $this->condition
->setContextValue('list', [
1,
2,
3,
])
->setContextValue('operator', '<')
->setContextValue('value', '4');
$this
->assertTrue($condition
->evaluate());
$condition = $this->condition
->setContextValue('list', [
1,
2,
3,
])
->setContextValue('operator', '==')
->setContextValue('value', '3');
$this
->assertTrue($condition
->evaluate());
$condition = $this->condition
->setContextValue('list', [])
->setContextValue('operator', '==')
->setContextValue('value', '0');
$this
->assertTrue($condition
->evaluate());
$condition = $this->condition
->setContextValue('list', [
1,
2,
])
->setContextValue('operator', '<')
->setContextValue('value', '2');
$this
->assertFalse($condition
->evaluate());
$condition = $this->condition
->setContextValue('list', [
1,
2,
3,
])
->setContextValue('operator', '>')
->setContextValue('value', '5');
$this
->assertFalse($condition
->evaluate());
$condition = $this->condition
->setContextValue('list', [
1,
2,
3,
])
->setContextValue('operator', '==')
->setContextValue('value', '0');
$this
->assertFalse($condition
->evaluate());
}
}