InOperatorTest.php

Same filename and directory in other branches
  1. 9 core/modules/views/tests/src/Unit/Plugin/filter/InOperatorTest.php
  2. 8.9.x core/modules/views/tests/src/Unit/Plugin/filter/InOperatorTest.php
  3. 10 core/modules/views/tests/src/Unit/Plugin/filter/InOperatorTest.php

Namespace

Drupal\Tests\views\Unit\Plugin\filter

File

core/modules/views/tests/src/Unit/Plugin/filter/InOperatorTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\views\Unit\Plugin\filter;

use Drupal\Tests\UnitTestCase;
use Drupal\views\Plugin\views\filter\InOperator;

/**
 * @coversDefaultClass \Drupal\views\Plugin\views\filter\InOperator
 * @group views
 */
class InOperatorTest extends UnitTestCase {
  
  /**
   * @covers ::validate
   */
  public function testValidate() : void {
    $definition = [
      'title' => 'Is InOperator Test',
      'group' => 'Test',
      'options callback' => '\\Drupal\\Tests\\views\\Unit\\Plugin\\filter\\InOperatorTest::validate_options_callback',
    ];
    $filter = new InOperator([], 'in_operator', $definition);
    $filter->value = 'string';
    $filter->operator = 'in';
    $translation_stub = $this->getStringTranslationStub();
    $filter->setStringTranslation($translation_stub);
    $errors = $filter->validate();
    $this->assertSame('The value &#039;string&#039; is not an array for in on filter: ' . $filter->adminLabel(TRUE), (string) $errors[0]);
  }
  
  /**
   * Views filter callback: Generate the values for the options.
   *
   * Returns 'yes' and 'no' options.
   *
   * @return array
   *   The options for the filter.
   */
  public static function validate_options_callback() {
    return [
      'Yes',
      'No',
    ];
  }

}

Classes

Title Deprecated Summary
InOperatorTest @coversDefaultClass \Drupal\views\Plugin\views\filter\InOperator[[api-linebreak]] @group views

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.