You are here

public function ListCountIsTest::testConditionEvaluation in Rules 8.3

Tests evaluating the condition.

@covers ::evaluate

File

tests/src/Unit/Integration/Condition/ListCountIsTest.php, line 34

Class

ListCountIsTest
@coversDefaultClass \Drupal\rules\Plugin\Condition\DataListCountIs @group RulesCondition

Namespace

Drupal\Tests\rules\Unit\Integration\Condition

Code

public function testConditionEvaluation() {

  // Test that the list count is greater than 2.
  $condition = $this->condition
    ->setContextValue('list', [
    1,
    2,
    3,
    4,
  ])
    ->setContextValue('operator', '>')
    ->setContextValue('value', '2');
  $this
    ->assertTrue($condition
    ->evaluate());

  // Test that the list count is less than 4.
  $condition = $this->condition
    ->setContextValue('list', [
    1,
    2,
    3,
  ])
    ->setContextValue('operator', '<')
    ->setContextValue('value', '4');
  $this
    ->assertTrue($condition
    ->evaluate());

  // Test that the list count is equal to 3.
  $condition = $this->condition
    ->setContextValue('list', [
    1,
    2,
    3,
  ])
    ->setContextValue('operator', '==')
    ->setContextValue('value', '3');
  $this
    ->assertTrue($condition
    ->evaluate());

  // Test that the list count is equal to 0.
  $condition = $this->condition
    ->setContextValue('list', [])
    ->setContextValue('operator', '==')
    ->setContextValue('value', '0');
  $this
    ->assertTrue($condition
    ->evaluate());

  // Test that the list count is not less than 2.
  $condition = $this->condition
    ->setContextValue('list', [
    1,
    2,
  ])
    ->setContextValue('operator', '<')
    ->setContextValue('value', '2');
  $this
    ->assertFalse($condition
    ->evaluate());

  // Test that list count is not greater than 5.
  $condition = $this->condition
    ->setContextValue('list', [
    1,
    2,
    3,
  ])
    ->setContextValue('operator', '>')
    ->setContextValue('value', '5');
  $this
    ->assertFalse($condition
    ->evaluate());

  // Test that the list count is not equal to 0.
  $condition = $this->condition
    ->setContextValue('list', [
    1,
    2,
    3,
  ])
    ->setContextValue('operator', '==')
    ->setContextValue('value', '0');
  $this
    ->assertFalse($condition
    ->evaluate());
}