class IgnoreCharacterTest in Search API 8
Tests the "Ignore characters" processor.
@group search_api
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\search_api\Unit\Processor\IgnoreCharacterTest uses ProcessorTestTrait, TestItemsTrait
Expanded class hierarchy of IgnoreCharacterTest
See also
\Drupal\search_api\Plugin\search_api\processor\IgnoreCharacter
File
- tests/
src/ Unit/ Processor/ IgnoreCharacterTest.php, line 18
Namespace
Drupal\Tests\search_api\Unit\ProcessorView source
class IgnoreCharacterTest extends UnitTestCase {
use ProcessorTestTrait;
use TestItemsTrait;
/**
* Creates a new processor object for use in the tests.
*/
protected function setUp() {
parent::setUp();
$this->processor = new IgnoreCharacters([
'ignorable' => '',
], 'ignore_character', []);
}
/**
* Tests preprocessing with different ignorable character sets.
*
* @param string $passed_value
* The value that should be passed into process().
* @param string $expected_value
* The expected processed value.
* @param string[] $character_classes
* The "ignorable_classes" setting to set on the processor.
*
* @dataProvider ignoreCharacterSetsDataProvider
*/
public function testIgnoreCharacterSets($passed_value, $expected_value, array $character_classes) {
$this->processor
->setConfiguration([
'ignorable_classes' => $character_classes,
]);
$this
->invokeMethod('process', [
&$passed_value,
'text',
]);
$this
->assertEquals($expected_value, $passed_value);
}
/**
* Data provider for testValueConfiguration().
*/
public function ignoreCharacterSetsDataProvider() {
return [
[
'word_s',
'words',
[
'Pc' => 'Pc',
],
],
[
'word⁔s',
'words',
[
'Pc' => 'Pc',
],
],
[
'word〜s',
'words',
[
'Pd' => 'Pd',
],
],
[
'w–ord⸗s',
'words',
[
'Pd' => 'Pd',
],
],
[
'word⌉s',
'words',
[
'Pe' => 'Pe',
],
],
[
'word⦊s〕',
'words',
[
'Pe' => 'Pe',
],
],
[
'word»s',
'words',
[
'Pf' => 'Pf',
],
],
[
'word⸍s',
'words',
[
'Pf' => 'Pf',
],
],
[
'word⸂s',
'words',
[
'Pi' => 'Pi',
],
],
[
'w«ord⸉s',
'words',
[
'Pi' => 'Pi',
],
],
[
'words%',
'words',
[
'Po' => 'Po',
],
],
[
'wo*rd/s',
'words',
[
'Po' => 'Po',
],
],
[
'word༺s',
'words',
[
'Ps' => 'Ps',
],
],
[
'w❮ord⌈s',
'words',
[
'Ps' => 'Ps',
],
],
[
'word៛s',
'words',
[
'Sc' => 'Sc',
],
],
[
'wo₥rd₦s',
'words',
[
'Sc' => 'Sc',
],
],
[
'w˓ords',
'words',
[
'Sk' => 'Sk',
],
],
[
'wo˘rd˳s',
'words',
[
'Sk' => 'Sk',
],
],
[
'word×s',
'words',
[
'Sm' => 'Sm',
],
],
[
'wo±rd؈s',
'words',
[
'Sm' => 'Sm',
],
],
[
'wo᧧rds',
'words',
[
'So' => 'So',
],
],
[
'w᧶ord᧲s',
'words',
[
'So' => 'So',
],
],
[
"wor\nds",
'words',
[
'Cc' => 'Cc',
],
],
[
"wo\frds",
'words',
[
'Cc' => 'Cc',
],
],
[
'words',
'words',
[
'Cf' => 'Cf',
],
],
[
'words',
'words',
[
'Cf' => 'Cf',
],
],
[
'words',
'words',
[
'Co' => 'Co',
],
],
[
'words',
'words',
[
'Co' => 'Co',
],
],
[
'wordॊs',
'words',
[
'Mc' => 'Mc',
],
],
[
'worौdংs',
'words',
[
'Mc' => 'Mc',
],
],
[
'wo⃞rds',
'words',
[
'Me' => 'Me',
],
],
[
'wor⃤⃟ds',
'words',
[
'Me' => 'Me',
],
],
[
'woྰrds',
'words',
[
'Mn' => 'Mn',
],
],
[
'worྵdྶs',
'words',
[
'Mn' => 'Mn',
],
],
[
'woྰrds',
'words',
[
'Mn' => 'Mn',
'Pd' => 'Pd',
'Pe' => 'Pe',
],
],
[
'worྵdྶs',
'words',
[
'Mn' => 'Mn',
'Pd' => 'Pd',
'Pe' => 'Pe',
],
],
];
}
/**
* Tests preprocessing with the "Ignorable characters" setting.
*
* @param string $passed_value
* The value that should be passed into process().
* @param string $expected_value
* The expected processed value.
* @param string $ignorable
* The "ignorable" setting to set on the processor.
*
* @dataProvider ignorableCharactersDataProvider
*/
public function testIgnorableCharacters($passed_value, $expected_value, $ignorable) {
$this->processor
->setConfiguration([
'ignorable' => $ignorable,
'ignorable_classes' => [],
]);
$this
->invokeMethod('process', [
&$passed_value,
'text',
]);
$this
->assertSame($expected_value, $passed_value);
}
/**
* Provides sets of test parameters for testIgnorableCharacters().
*
* @return array
* Sets of arguments for testIgnorableCharacters().
*/
public function ignorableCharactersDataProvider() {
return [
[
'abcde',
'ace',
'[bd]',
],
[
[
'abcde',
'abcdef',
],
[
'ace',
'ace',
],
'[bdf]',
],
[
"ab.c'de",
"a.'de",
'[b-c]',
],
[
'foo 13$%& (bar)[93]',
'foo $%& (bar)[]',
'\\d',
],
];
}
/**
* 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
IgnoreCharacterTest:: |
public | function | Provides sets of test parameters for testIgnorableCharacters(). | |
IgnoreCharacterTest:: |
public | function | Data provider for testValueConfiguration(). | |
IgnoreCharacterTest:: |
protected | function |
Creates a new processor object for use in the tests. Overrides UnitTestCase:: |
|
IgnoreCharacterTest:: |
public | function | Tests preprocessing with the "Ignorable characters" setting. | |
IgnoreCharacterTest:: |
public | function | Tests preprocessing with different ignorable character sets. | |
IgnoreCharacterTest:: |
public | function | Tests whether "IS NULL" conditions are correctly kept. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
ProcessorTestTrait:: |
protected | property | The tested processor. | |
ProcessorTestTrait:: |
protected | function | Invokes a method on the processor. | |
TestItemsTrait:: |
protected | property | The class container. | |
TestItemsTrait:: |
protected | property | The used item IDs for test items. | |
TestItemsTrait:: |
public | function | Creates a certain number of test items. | |
TestItemsTrait:: |
public | function | Creates an array with a single item which has the given field. | |
TestItemsTrait:: |
protected | function | Adds a container with several mock services commonly needed by our tests. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |