You are here

class IgnoreCaseTest in Search API 8

Tests the "Ignore case" processor.

@group search_api

Hierarchy

Expanded class hierarchy of IgnoreCaseTest

See also

\Drupal\search_api\Plugin\search_api\processor\IgnoreCase

File

tests/src/Unit/Processor/IgnoreCaseTest.php, line 18

Namespace

Drupal\Tests\search_api\Unit\Processor
View source
class IgnoreCaseTest extends UnitTestCase {
  use ProcessorTestTrait;
  use TestItemsTrait;

  /**
   * Creates a new processor object for use in the tests.
   */
  protected function setUp() {
    parent::setUp();
    $this->processor = new IgnoreCase([], 'string', []);
  }

  /**
   * Tests the process() method.
   *
   * @param string $passed_value
   *   The value that should be passed into process().
   * @param string $expected_value
   *   The expected processed value.
   *
   * @dataProvider processDataProvider
   */
  public function testProcess($passed_value, $expected_value) {
    $this
      ->invokeMethod('process', [
      &$passed_value,
    ]);
    $this
      ->assertEquals($passed_value, $expected_value);
  }

  /**
   * Provides sets of arguments for testProcess().
   *
   * @return array[]
   *   Arrays of arguments for testProcess().
   */
  public function processDataProvider() {
    return [
      [
        'Foo bar',
        'foo bar',
      ],
      [
        'foo Bar',
        'foo bar',
      ],
      [
        'Foo Bar',
        'foo bar',
      ],
      [
        'Foo bar BaZ, ÄÖÜÀÁ<>»«.',
        'foo bar baz, äöüàá<>»«.',
      ],
    ];
  }

  /**
   * Tests whether "IS NULL" conditions are correctly kept.
   *
   * @see https://www.drupal.org/project/search_api/issues/3212925
   */
  public function testIsNullConditions() {
    $this
      ->setUpMockContainer();
    $index = $this
      ->createMock(IndexInterface::class);
    $index
      ->method('getFields')
      ->willReturn([
      'field' => (new Field($index, 'field'))
        ->setType('string'),
    ]);
    $this->processor
      ->setIndex($index);
    $passed_value = NULL;
    $this
      ->invokeMethod('processConditionValue', [
      &$passed_value,
    ]);
    $this
      ->assertSame(NULL, $passed_value);
    $condition = new Condition('field', NULL);
    $conditions = [
      $condition,
    ];
    $this
      ->invokeMethod('processConditions', [
      &$conditions,
    ]);
    $this
      ->assertSame([
      $condition,
    ], $conditions);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
IgnoreCaseTest::processDataProvider public function Provides sets of arguments for testProcess().
IgnoreCaseTest::setUp protected function Creates a new processor object for use in the tests. Overrides UnitTestCase::setUp
IgnoreCaseTest::testIsNullConditions public function Tests whether "IS NULL" conditions are correctly kept.
IgnoreCaseTest::testProcess public function Tests the process() method.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
ProcessorTestTrait::$processor protected property The tested processor.
ProcessorTestTrait::invokeMethod protected function Invokes a method on the processor.
TestItemsTrait::$container protected property The class container.
TestItemsTrait::$itemIds protected property The used item IDs for test items.
TestItemsTrait::createItems public function Creates a certain number of test items.
TestItemsTrait::createSingleFieldItem public function Creates an array with a single item which has the given field.
TestItemsTrait::setUpMockContainer protected function Adds a container with several mock services commonly needed by our tests.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.