Commit f6b3dd94 authored by catch's avatar catch

Issue #2809555 by jonathanjfshaw, alexpott, amateescu, Lendude, catch: ER...

Issue #2809555 by jonathanjfshaw, alexpott, amateescu, Lendude, catch: ER views autocomplete fail to recognise exact matches typed in
parent 329c020e
......@@ -122,10 +122,13 @@ public function query() {
// Restrict the autocomplete options based on what's been typed already.
if (isset($options['match'])) {
$style_options = $this->getOption('style');
$value = db_like($options['match']) . '%';
$value = db_like($options['match']);
if ($options['match_operator'] !== '=') {
$value = $value . '%';
if ($options['match_operator'] != 'STARTS_WITH') {
$value = '%' . $value;
}
}
// Multiple search fields are OR'd together.
$conditions = db_or();
......
......@@ -103,6 +103,21 @@ protected function setUp() {
$this->fieldName => 'text' . $i,
])->save();
}
EntityTest::create([
'bundle' => 'entity_test',
'name' => 'name',
$this->fieldName => 'tex',
])->save();
EntityTest::create([
'bundle' => 'entity_test',
'name' => 'name',
$this->fieldName => 'TEX',
])->save();
EntityTest::create([
'bundle' => 'entity_test',
'name' => 'name',
$this->fieldName => 'sometext',
])->save();
}
/**
......@@ -140,6 +155,48 @@ public function testEntityReferenceDisplay() {
$this->assertEqual(count($view->result), 2, 'Search returned two rows');
$view->destroy();
// Test the 'CONTAINS' match_operator.
$view = Views::getView('test_display_entity_reference');
$view->setDisplay('entity_reference_1');
$options = [
'match' => 'tex',
'match_operator' => 'CONTAINS',
'limit' => 0,
'ids' => NULL,
];
$view->display_handler->setOption('entity_reference_options', $options);
$this->executeView($view);
$this->assertEqual(count($view->result), 13, 'Search returned thirteen rows');
$view->destroy();
// Test the 'STARTS_WITH' match_operator.
$view = Views::getView('test_display_entity_reference');
$view->setDisplay('entity_reference_1');
$options = [
'match' => 'tex',
'match_operator' => 'STARTS_WITH',
'limit' => 0,
'ids' => NULL,
];
$view->display_handler->setOption('entity_reference_options', $options);
$this->executeView($view);
$this->assertEqual(count($view->result), 12, 'Search returned twelve rows');
$view->destroy();
// Test the '=' match_operator.
$view = Views::getView('test_display_entity_reference');
$view->setDisplay('entity_reference_1');
$options = [
'match' => 'tex',
'match_operator' => '=',
'limit' => 0,
'ids' => NULL,
];
$view->display_handler->setOption('entity_reference_options', $options);
$this->executeView($view);
$this->assertEqual(count($view->result), 2, 'Search returned two rows');
$view->destroy();
// Add a relationship and a field using that relationship.
$this->drupalPostForm('admin/structure/views/nojs/add-handler/test_display_entity_reference/default/relationship', ['name[entity_test.user_id]' => TRUE], t('Add and configure relationships'));
$this->drupalPostForm(NULL, [], t('Apply'));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment