Namespace
  Drupal\Tests\rules\Unit\Integration\Condition
File
  - 
              tests/src/Unit/Integration/Condition/TextComparisonTest.php
    
   
 
  
    View source
  
  <?php
namespace Drupal\Tests\rules\Unit\Integration\Condition;
use Drupal\Tests\rules\Unit\Integration\RulesIntegrationTestBase;
class TextComparisonTest extends RulesIntegrationTestBase {
  
  protected $condition;
  
  protected function setUp() : void {
    parent::setUp();
    $this->condition = $this->conditionManager
      ->createInstance('rules_text_comparison');
  }
  
  public function testConditionEvaluationOperatorStarts() {
    
    
    $this->condition
      ->setContextValue('text', 'my-text')
      ->setContextValue('operator', 'starts')
      ->setContextValue('match', 'my');
    $this->assertTrue($this->condition
      ->evaluate());
    
    
    $this->condition
      ->setContextValue('text', 'my-text')
      ->setContextValue('operator', 'starts')
      ->setContextValue('match', 'text');
    $this->assertFalse($this->condition
      ->evaluate());
  }
  
  public function testConditionEvaluationOperatorEnds() {
    
    
    $this->condition
      ->setContextValue('text', 'my-text')
      ->setContextValue('operator', 'ends')
      ->setContextValue('match', 'text');
    $this->assertTrue($this->condition
      ->evaluate());
    
    
    $this->condition
      ->setContextValue('text', 'my-text')
      ->setContextValue('operator', 'ends')
      ->setContextValue('match', 'my');
    $this->assertFalse($this->condition
      ->evaluate());
  }
  
  public function testConditionEvaluationOperatorContains() {
    
    
    $this->condition
      ->setContextValue('text', 'my-text')
      ->setContextValue('operator', 'contains')
      ->setContextValue('match', 'y-t');
    $this->assertTrue($this->condition
      ->evaluate());
    
    
    $this->condition
      ->setContextValue('text', 'my-text')
      ->setContextValue('operator', 'contains')
      ->setContextValue('match', 't-y');
    $this->assertFalse($this->condition
      ->evaluate());
  }
  
  public function testConditionEvaluationOperatorRegex() {
    
    
    $this->condition
      ->setContextValue('text', 'my-text')
      ->setContextValue('operator', 'regex')
      ->setContextValue('match', 'me?y-texx?t');
    $this->assertTrue($this->condition
      ->evaluate());
    
    
    $this->condition
      ->setContextValue('text', 'my-text')
      ->setContextValue('operator', 'regex')
      ->setContextValue('match', 'me+y-texx?t');
    $this->assertFalse($this->condition
      ->evaluate());
  }
  
  public function testSummary() {
    $this->assertEquals('Text comparison', $this->condition
      ->summary());
  }
}
 
Classes
  
  
  
  
  
  
  
        
      
                                                  | Title | 
                                                  Deprecated | 
                                                  Summary | 
              
    
    
          
                                                                                        | TextComparisonTest           | 
                                                                                                   | 
                                                                                        @coversDefaultClass \Drupal\rules\Plugin\Condition\TextComparison[[api-linebreak]]
@group RulesCondition           |