/** * Tests whether overriding processConditionValue() works correctly. */ public function testProcessConditionValueOverride() { $override = function (&$value) { if (isset($value)) { $value = ''; } }; $this->processor->setMethodOverride('processConditionValue', $override); $query = Utility::createQuery($this->index); $query->addCondition('text_field', 'foo'); $query->addCondition('string_field', NULL, '<>'); $query->addCondition('integer_field', 'bar'); $this->processor->preprocessSearchQuery($query); $expected = array(new Condition('string_field', NULL, '<>'), new Condition('integer_field', 'bar')); $this->assertEquals($expected, array_merge($query->getConditionGroup()->getConditions()), 'Conditions were preprocessed correctly.'); }
/** * Tests whether tokenized text is handled correctly. */ public function testProcessFieldsTokenized() { $override = function (&$value, &$type) { if ($type != 'tokenized_text') { $value = TestFieldsProcessorPlugin::createTokenizedText($value, NULL); $type = 'tokenized_text'; } elseif ($value == 'bar') { $value = array(array('value' => '*bar')); } elseif ($value != 'baz') { $value = "*$value"; } else { $value = ''; } }; $this->processor->setMethodOverride('processFieldValue', $override); $fields = array( 'field1' => array( 'type' => 'tokenized_text', 'values' => array( TestFieldsProcessorPlugin::createTokenizedText('foo bar baz', 3), TestFieldsProcessorPlugin::createTokenizedText('foobar'), ), ), 'field2' => array( 'type' => 'text', 'values' => array( 'foo bar baz', 'foobar', ), ), ); $items = $this->createItems($this->index, 1, $fields); $this->processor->preprocessIndexItems($items); $item_fields = $items[$this->itemIds[0]]->getFields(); $expected = array( TestFieldsProcessorPlugin::createTokenizedText('*foo *bar', 3), TestFieldsProcessorPlugin::createTokenizedText('*foobar'), ); $this->assertEquals($expected, $item_fields['field1']->getValues(), 'tokenized_text field correctly processed.'); $expected = array( TestFieldsProcessorPlugin::createTokenizedText('foo bar baz'), TestFieldsProcessorPlugin::createTokenizedText('foobar'), ); $this->assertEquals($expected, $item_fields['field2']->getValues(), 'text field correctly processed and tokenized.'); }