From 9a1b5f31a2372001c53cc2f3a295762072fa0bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Wed, 1 Jul 2015 15:47:27 +0200 Subject: [PATCH] Case insensitive search in contacts - fixes #813, owncloud/mail#197 --- lib/addressbookprovider.php | 2 +- tests/lib/addressbookprovider_test.php | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/addressbookprovider.php b/lib/addressbookprovider.php index 4c480551..6b1065cc 100644 --- a/lib/addressbookprovider.php +++ b/lib/addressbookprovider.php @@ -123,7 +123,7 @@ SQL; foreach ($searchProperties as $property) { $params[] = $property; $params[] = '%' . $pattern . '%'; - $query .= '(`name` = ? AND `value` LIKE ?) OR '; + $query .= '(`name` = ? AND `value` ILIKE ?) OR '; } $query = substr($query, 0, strlen($query) - 4); $query .= ')'; diff --git a/tests/lib/addressbookprovider_test.php b/tests/lib/addressbookprovider_test.php index d978716a..6e5bbb53 100644 --- a/tests/lib/addressbookprovider_test.php +++ b/tests/lib/addressbookprovider_test.php @@ -58,7 +58,7 @@ class AddressBookProviderTest extends TestCase { $card->add('FN', 'Jan Janssens'); $id = $this->ab->addChild($card); Utils\Properties::updateIndex($id, $card); - $this->ab->deleteChild($id); + $this->contactIds[] = $id; } public function tearDown() { @@ -69,13 +69,25 @@ class AddressBookProviderTest extends TestCase { 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->assertEquals(1, count($result)); - $this->assertEquals('Max Mustermann', $result[0]['FN']); + $this->assertEquals(count($expected), count($result)); + $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'], + ]; + } }