function DataComparisonTest::testConditionEvaluationOperatorEquals

Tests evaluating the condition with the "equals" operator.

@covers ::evaluate

File

tests/src/Unit/Integration/Condition/DataComparisonTest.php, line 35

Class

DataComparisonTest
@coversDefaultClass \Drupal\rules\Plugin\Condition\DataComparison @group RulesCondition

Namespace

Drupal\Tests\rules\Unit\Integration\Condition

Code

public function testConditionEvaluationOperatorEquals() {
    // Test that when a boolean data does not equal a boolean value
    // and the operator is not set - should fallback to '=='.
    $this->condition
        ->setContextValue('data', TRUE)
        ->setContextValue('value', FALSE);
    $this->assertFalse($this->condition
        ->evaluate());
    // Test that when both data and value are false booleans
    // and the operator is not set - should fallback to '=='.
    $this->condition
        ->setContextValue('data', FALSE)
        ->setContextValue('value', FALSE);
    $this->assertTrue($this->condition
        ->evaluate());
    // Test that when the data string equals the value string and the operator
    // is '==', TRUE is returned.
    $this->condition
        ->setContextValue('data', 'Llama')
        ->setContextValue('operation', '==')
        ->setContextValue('value', 'Llama');
    $this->assertTrue($this->condition
        ->evaluate());
    // Test that when the data string does not equal the value string and the
    // operation is '==', FALSE is returned.
    $this->condition
        ->setContextValue('data', 'Kitten')
        ->setContextValue('operation', '==')
        ->setContextValue('value', 'Llama');
    $this->assertFalse($this->condition
        ->evaluate());
    // Test that when both data and value are false booleans and the operation
    // is '==', TRUE is returned.
    $this->condition
        ->setContextValue('data', FALSE)
        ->setContextValue('operation', '==')
        ->setContextValue('value', FALSE);
    $this->assertTrue($this->condition
        ->evaluate());
    // Test that when a boolean data does not equal a boolean value
    // and the operation is '==', FALSE is returned.
    $this->condition
        ->setContextValue('data', TRUE)
        ->setContextValue('operation', '==')
        ->setContextValue('value', FALSE);
    $this->assertFalse($this->condition
        ->evaluate());
}