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,9 +122,12 @@ public function query() { ...@@ -122,9 +122,12 @@ public function query() {
// Restrict the autocomplete options based on what's been typed already. // Restrict the autocomplete options based on what's been typed already.
if (isset($options['match'])) { if (isset($options['match'])) {
$style_options = $this->getOption('style'); $style_options = $this->getOption('style');
$value = db_like($options['match']) . '%'; $value = db_like($options['match']);
if ($options['match_operator'] != 'STARTS_WITH') { if ($options['match_operator'] !== '=') {
$value = '%' . $value; $value = $value . '%';
if ($options['match_operator'] != 'STARTS_WITH') {
$value = '%' . $value;
}
} }
// Multiple search fields are OR'd together. // Multiple search fields are OR'd together.
......
...@@ -103,6 +103,21 @@ protected function setUp() { ...@@ -103,6 +103,21 @@ protected function setUp() {
$this->fieldName => 'text' . $i, $this->fieldName => 'text' . $i,
])->save(); ])->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() { ...@@ -140,6 +155,48 @@ public function testEntityReferenceDisplay() {
$this->assertEqual(count($view->result), 2, 'Search returned two rows'); $this->assertEqual(count($view->result), 2, 'Search returned two rows');
$view->destroy(); $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. // 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('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')); $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