function DataComparisonTest::testConditionEvaluationOperatorContains

Tests evaluating the condition with the "contains" operation.

@covers ::evaluate

File

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

Class

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

Namespace

Drupal\Tests\rules\Unit\Integration\Condition

Code

public function testConditionEvaluationOperatorContains() {
    // Test that when the data string contains the value string, and the
    // operation is 'CONTAINS', TRUE is returned.
    $this->condition
        ->setContextValue('data', 'Big Llama')
        ->setContextValue('operation', 'contains')
        ->setContextValue('value', 'Llama');
    $this->assertTrue($this->condition
        ->evaluate());
    // Test that when the data string does not contain the value string, and
    // the operation is 'contains', TRUE is returned.
    $this->condition
        ->setContextValue('data', 'Big Kitten')
        ->setContextValue('operation', 'contains')
        ->setContextValue('value', 'Big Kitten');
    $this->assertTrue($this->condition
        ->evaluate());
    // Test that when a data array contains the value string, and the operation
    // is 'CONTAINS', TRUE is returned.
    $this->condition
        ->setContextValue('data', [
        'Llama',
        'Kitten',
    ])
        ->setContextValue('operation', 'contains')
        ->setContextValue('value', 'Llama');
    $this->assertTrue($this->condition
        ->evaluate());
    // Test that when a data array does not contain the value array, and the
    // operation is 'CONTAINS', TRUE is returned.
    $this->condition
        ->setContextValue('data', [
        'Kitten',
    ])
        ->setContextValue('operation', 'contains')
        ->setContextValue('value', [
        'Llama',
    ]);
    $this->assertFalse($this->condition
        ->evaluate());
}