From a4d9e28cdb35e9359160e4236f4f4c3d675036a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Tue, 22 Oct 2013 14:38:39 +0200 Subject: [PATCH 1/3] Add new test for search page. re #96 --- test/pageTest.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/pageTest.php b/test/pageTest.php index 3a0d4a0..377c298 100644 --- a/test/pageTest.php +++ b/test/pageTest.php @@ -482,4 +482,36 @@ class PageTest extends PHPUnit_Framework_TestCase $this->assertFalse ($currentPage->ContainsBook ()); } + public function testPageSearch () + { + global $config; + $page = Base::PAGE_OPENSEARCH_QUERY; + $query = "alice"; + $search = NULL; + $qid = NULL; + $n = "1"; + $database = NULL; + + // Only books returned + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Search result for *alice*", $currentPage->title); + $this->assertCount (2, $currentPage->entryArray); + $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title); + $this->assertEquals ("Through the Looking Glass (And What Alice Found There)", $currentPage->entryArray [1]->title); + $this->assertTrue ($currentPage->ContainsBook ()); + + // Only books returned + $query = "car"; + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Search result for *car*", $currentPage->title); + $this->assertCount (3, $currentPage->entryArray); + $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title); + $this->assertEquals ("A Study in Scarlet", $currentPage->entryArray [1]->title); + $this->assertEquals ("Through the Looking Glass (And What Alice Found There)", $currentPage->entryArray [2]->title); + $this->assertTrue ($currentPage->ContainsBook ()); + } } \ No newline at end of file From cb00c0b3a37dfb4172f4227a122b5d76256b09c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Tue, 22 Oct 2013 14:39:25 +0200 Subject: [PATCH 2/3] Fix comment. re #96 --- test/pageTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/pageTest.php b/test/pageTest.php index 377c298..27ea8e7 100644 --- a/test/pageTest.php +++ b/test/pageTest.php @@ -502,7 +502,7 @@ class PageTest extends PHPUnit_Framework_TestCase $this->assertEquals ("Through the Looking Glass (And What Alice Found There)", $currentPage->entryArray [1]->title); $this->assertTrue ($currentPage->ContainsBook ()); - // Only books returned + // Match Lewis Caroll & Scarlet $query = "car"; $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); From 4624cc2c32468fe330fc4c377d77d90770ae658d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Tue, 22 Oct 2013 16:51:55 +0200 Subject: [PATCH 3/3] Add search test with scope. re #96 --- test/pageTest.php | 90 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/test/pageTest.php b/test/pageTest.php index 27ea8e7..eeeab9c 100644 --- a/test/pageTest.php +++ b/test/pageTest.php @@ -514,4 +514,94 @@ class PageTest extends PHPUnit_Framework_TestCase $this->assertEquals ("Through the Looking Glass (And What Alice Found There)", $currentPage->entryArray [2]->title); $this->assertTrue ($currentPage->ContainsBook ()); } + + public function testPageSearchScopeAuthors () + { + global $config; + $page = Base::PAGE_OPENSEARCH_QUERY; + $search = NULL; + $qid = NULL; + $n = "1"; + $database = NULL; + $_GET ["scope"] = "author"; + + // Match Lewis Carroll + $query = "car"; + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Search result for *car* in authors", $currentPage->title); + $this->assertCount (1, $currentPage->entryArray); + $this->assertEquals ("Carroll, Lewis", $currentPage->entryArray [0]->title); + $this->assertFalse ($currentPage->ContainsBook ()); + + $_GET ["scope"] = NULL; + } + + public function testPageSearchScopeSeries () + { + global $config; + $page = Base::PAGE_OPENSEARCH_QUERY; + $search = NULL; + $qid = NULL; + $n = "1"; + $database = NULL; + $_GET ["scope"] = "series"; + + // Match Holmes + $query = "hol"; + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Search result for *hol* in series", $currentPage->title); + $this->assertCount (1, $currentPage->entryArray); + $this->assertEquals ("Sherlock Holmes", $currentPage->entryArray [0]->title); + $this->assertFalse ($currentPage->ContainsBook ()); + + $_GET ["scope"] = NULL; + } + + public function testPageSearchScopeBooks () + { + global $config; + $page = Base::PAGE_OPENSEARCH_QUERY; + $search = NULL; + $qid = NULL; + $n = "1"; + $database = NULL; + $_GET ["scope"] = "book"; + + // Match Holmes + $query = "hol"; + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Search result for *hol* in books", $currentPage->title); + $this->assertCount (4, $currentPage->entryArray); + $this->assertTrue ($currentPage->ContainsBook ()); + + $_GET ["scope"] = NULL; + } + + public function testPageSearchScopeTags () + { + global $config; + $page = Base::PAGE_OPENSEARCH_QUERY; + $search = NULL; + $qid = NULL; + $n = "1"; + $database = NULL; + $_GET ["scope"] = "tag"; + + // Match Holmes + $query = "fic"; + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Search result for *fic* in tags", $currentPage->title); + $this->assertCount (2, $currentPage->entryArray); + $this->assertFalse ($currentPage->ContainsBook ()); + + $_GET ["scope"] = NULL; + } } \ No newline at end of file