diff --git a/publisher.php b/publisher.php index 12c31ad..e4ba8a2 100644 --- a/publisher.php +++ b/publisher.php @@ -76,13 +76,13 @@ order by publishers.name'); } public static function getAllPublishersByQuery($query) { - $result = parent::getDb ()->prepare('select publishers.id as id, publishers.name as name, count(*) as count -from publishers, books_publishers_link -where publishers.id = publisher and publishers.name like ? + $columns = "publishers.id as id, publishers.name as name, count(*) as count"; + $sql = 'select {0} from publishers, books_publishers_link +where publishers.id = publisher and upper (publishers.name) like ? group by publishers.id, publishers.name -order by publishers.name'); +order by publishers.name'; + list ($totalNumber, $result) = parent::executeQuery ($sql, $columns, "", array ('%' . $query . '%'), -1); $entryArray = array(); - $result->execute (array ('%' . $query . '%')); while ($post = $result->fetchObject ()) { diff --git a/tag.php b/tag.php index c3dfc92..feb14f1 100644 --- a/tag.php +++ b/tag.php @@ -64,7 +64,7 @@ order by tags.name'); public static function getAllTagsByQuery($query, $n, $database = NULL, $numberPerPage = NULL) { $columns = "tags.id as id, tags.name as name, (select count(*) from books_tags_link where tags.id = tag) as count"; - $sql = 'select {0} from tags where tags.name like ? {1} order by tags.name'; + $sql = 'select {0} from tags where upper (tags.name) like ? {1} order by tags.name'; list ($totalNumber, $result) = parent::executeQuery ($sql, $columns, "", array ('%' . $query . '%'), $n, $database, $numberPerPage); $entryArray = array(); while ($post = $result->fetchObject ()) diff --git a/test/BaseWithSomeBooks/metadata.db b/test/BaseWithSomeBooks/metadata.db index f049dd2..ca8af42 100644 Binary files a/test/BaseWithSomeBooks/metadata.db and b/test/BaseWithSomeBooks/metadata.db differ diff --git a/test/pageTest.php b/test/pageTest.php index 7721820..cd6d0da 100644 --- a/test/pageTest.php +++ b/test/pageTest.php @@ -644,29 +644,46 @@ class PageTest extends PHPUnit_Framework_TestCase $this->assertFalse ($currentPage->ContainsBook ()); } - public function testPageSearch_WithAccentuatedCharacters () + + /** + * @dataProvider providerAccentuatedCharacters + */ + public function testPageSearch_WithAccentuatedCharacters ($query, $count, $content) { global $config; $page = Base::PAGE_OPENSEARCH_QUERY; - $query = "curée"; $qid = NULL; $n = "1"; $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - $this->assertEquals ("Search result for *curée*", $currentPage->title); - $this->assertCount (1, $currentPage->entryArray); - $this->assertEquals ("Search result for *curée* in books", $currentPage->entryArray [0]->title); - $this->assertEquals ("1 book", $currentPage->entryArray [0]->content); + $this->assertEquals ("Search result for *$query*", $currentPage->title); + $this->assertCount ($count, $currentPage->entryArray); + if ($count > 0) { + $this->assertEquals ($content, $currentPage->entryArray [0]->content); + } $this->assertFalse ($currentPage->ContainsBook ()); } - public function testPageSearch_WithNormalizedSearch () + public function providerAccentuatedCharacters () + { + return array ( + array ("curée", 1, "1 book"), + array ("Émile zola", 1, "1 author"), + array ("émile zola", 0, NULL), // With standard search upper does not work with diacritics + array ("Littérature", 1, "1 tag"), + array ("Eugène Fasquelle", 1, "1 publisher") + ); + } + + /** + * @dataProvider providerNormalizedSearch + */ + public function testPageSearch_WithNormalizedSearch_Book ($query, $count, $content) { global $config; $page = Base::PAGE_OPENSEARCH_QUERY; - $query = "curee"; $qid = NULL; $n = "1"; $config ['cops_normalized_search'] = "1"; @@ -678,16 +695,29 @@ class PageTest extends PHPUnit_Framework_TestCase $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - $this->assertEquals ("Search result for *curee*", $currentPage->title); - $this->assertCount (1, $currentPage->entryArray); - $this->assertEquals ("Search result for *curee* in books", $currentPage->entryArray [0]->title); - $this->assertEquals ("1 book", $currentPage->entryArray [0]->content); + $this->assertEquals ("Search result for *$query*", $currentPage->title); + $this->assertCount ($count, $currentPage->entryArray); + if ($count > 0) { + $this->assertEquals ($content, $currentPage->entryArray [0]->content); + } $this->assertFalse ($currentPage->ContainsBook ()); $config ['cops_normalized_search'] = "0"; Base::clearDb (); } + public function providerNormalizedSearch () + { + return array ( + array ("curee", 1, "1 book"), + array ("emile zola", 1, "1 author"), + array ("émile zola", 1, "1 author"), + array ("Litterature", 1, "1 tag"), + array ("Litterâture", 1, "1 tag"), + array ("Eugene Fasquelle", 1, "1 publisher") + ); + } + public function testAuthorSearch_ByName () { global $config;