1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2025-01-18 07:52:21 +01:00

Case insensitive search in contacts - fixes #813, owncloud/mail#197

This commit is contained in:
Thomas Müller 2015-07-01 15:47:27 +02:00
parent bd807389ca
commit 9a1b5f31a2
2 changed files with 18 additions and 6 deletions

View File

@ -123,7 +123,7 @@ SQL;
foreach ($searchProperties as $property) { foreach ($searchProperties as $property) {
$params[] = $property; $params[] = $property;
$params[] = '%' . $pattern . '%'; $params[] = '%' . $pattern . '%';
$query .= '(`name` = ? AND `value` LIKE ?) OR '; $query .= '(`name` = ? AND `value` ILIKE ?) OR ';
} }
$query = substr($query, 0, strlen($query) - 4); $query = substr($query, 0, strlen($query) - 4);
$query .= ')'; $query .= ')';

View File

@ -58,7 +58,7 @@ class AddressBookProviderTest extends TestCase {
$card->add('FN', 'Jan Janssens'); $card->add('FN', 'Jan Janssens');
$id = $this->ab->addChild($card); $id = $this->ab->addChild($card);
Utils\Properties::updateIndex($id, $card); Utils\Properties::updateIndex($id, $card);
$this->ab->deleteChild($id); $this->contactIds[] = $id;
} }
public function tearDown() { public function tearDown() {
@ -69,13 +69,25 @@ class AddressBookProviderTest extends TestCase {
parent::tearDown(); parent::tearDown();
} }
public function testSearch() { /**
$result = $this->provider->search('',array('FN'), array()); * @dataProvider providesSearchData
*/
public function testSearch($expected, $pattern) {
$result = $this->provider->search($pattern, ['FN'], array());
$this->assertTrue(is_array($result)); $this->assertTrue(is_array($result));
$this->assertEquals(1, count($result)); $this->assertEquals(count($expected), count($result));
$this->assertEquals('Max Mustermann', $result[0]['FN']); $result = array_map(function($c){
return $c['FN'];
}, $result);
$this->assertEquals($expected, $result);
} }
public function providesSearchData() {
return [
'empty pattern' => [['Max Mustermann', 'Jan Janssens'], ''],
'case insensitive' => [['Max Mustermann'], 'max'],
];
}
} }