This commit is contained in:
Sébastien Lucas 2013-10-15 14:38:08 +02:00
commit 0dda0052e3
4 changed files with 217 additions and 0 deletions

View file

@ -15,6 +15,8 @@ class BaseTest extends PHPUnit_Framework_TestCase
public function testLocalize ()
{
$this->assertEquals ("Authors", localize ("authors.title"));
$this->assertEquals ("unknow.key", localize ("unknow.key"));
}
public function testLocalizeFr ()

View file

@ -128,4 +128,42 @@ class BookTest extends PHPUnit_Framework_TestCase
$this->assertEquals ("", $book->getRating ());
}
public function testTypeaheadSearch ()
{
$_GET["query"] = "fic";
$_GET["search"] = "1";
$array = getJson ();
$this->assertCount (3, $array);
$this->assertEquals ("2 tags", $array[0]["title"]);
$this->assertEquals ("Fiction", $array[1]["title"]);
$this->assertEquals ("Science Fiction", $array[2]["title"]);
$_GET["query"] = "car";
$_GET["search"] = "1";
$array = getJson ();
$this->assertCount (4, $array);
$this->assertEquals ("1 book", $array[0]["title"]);
$this->assertEquals ("A Study in Scarlet", $array[1]["title"]);
$this->assertEquals ("1 author", $array[2]["title"]);
$this->assertEquals ("Carroll, Lewis", $array[3]["title"]);
$_GET["query"] = "art";
$_GET["search"] = "1";
$array = getJson ();
$this->assertCount (4, $array);
$this->assertEquals ("1 author", $array[0]["title"]);
$this->assertEquals ("Doyle, Arthur Conan", $array[1]["title"]);
$this->assertEquals ("1 series", $array[2]["title"]);
$this->assertEquals ("D'Artagnan Romances", $array[3]["title"]);
$_GET["query"] = NULL;
$_GET["search"] = NULL;
}
}

42
test/coverage-checker.php Normal file
View file

@ -0,0 +1,42 @@
<?php
/**
* Code coverage checker. Analyzes a given `clover.xml` report produced
* by PHPUnit and checks if coverage fits expected ratio
*
* Usage:
* php coverage-checker <path-to-clover> <pass-percentage>
*
* @author Marco Pivetta <ocramius@gmail.com>
* @see http://ocramius.github.io/blog/automated-code-coverage-check-for-github-pull-requests-with-travis/
*/
$inputFile = $argv[1];
$percentage = min(100, max(0, (int) $argv[2]));
if (!file_exists($inputFile)) {
throw new InvalidArgumentException('Invalid input file provided');
}
if (!$percentage) {
throw new InvalidArgumentException('An integer checked percentage must be given as second parameter');
}
$xml = new SimpleXMLElement(file_get_contents($inputFile));
$metrics = $xml->xpath('//metrics');
$totalElements = 0;
$checkedElements = 0;
foreach ($metrics as $metric) {
$totalElements += (int) $metric['elements'];
$checkedElements += (int) $metric['coveredelements'];
}
$coverage = ($checkedElements / $totalElements) * 100;
if ($coverage < $percentage) {
echo 'Code coverage is ' . $coverage . '%, which is below the accepted ' . $percentage . '%' . PHP_EOL;
exit(1);
}
echo 'Code coverage is ' . $coverage . '% - OK!' . PHP_EOL;

View file

@ -213,4 +213,139 @@ class PageTest extends PHPUnit_Framework_TestCase
$this->assertTrue ($currentPage->ContainsBook ());
}
public function testPageAllTags ()
{
global $config;
$page = Base::PAGE_ALL_TAGS;
$query = NULL;
$search = NULL;
$qid = NULL;
$n = "1";
$database = NULL;
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
$this->assertEquals ("Tags", $currentPage->title);
$this->assertCount (10, $currentPage->entryArray);
$this->assertEquals ("Action & Adventure", $currentPage->entryArray [0]->title);
$this->assertFalse ($currentPage->ContainsBook ());
}
public function testPageTagDetail ()
{
global $config;
$page = Base::PAGE_TAG_DETAIL;
$query = NULL;
$search = NULL;
$qid = "1";
$n = "1";
$database = NULL;
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
$this->assertEquals ("Fiction", $currentPage->title);
$this->assertCount (14, $currentPage->entryArray);
$this->assertEquals ("The Adventures of Sherlock Holmes", $currentPage->entryArray [0]->title);
$this->assertTrue ($currentPage->ContainsBook ());
}
public function testPageAllLanguages ()
{
global $config;
$page = Base::PAGE_ALL_LANGUAGES;
$query = NULL;
$search = NULL;
$qid = NULL;
$n = "1";
$database = NULL;
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
$this->assertEquals ("Languages", $currentPage->title);
$this->assertCount (1, $currentPage->entryArray);
$this->assertEquals ("English", $currentPage->entryArray [0]->title);
$this->assertFalse ($currentPage->ContainsBook ());
}
public function testPageLanguageDetail ()
{
global $config;
$page = Base::PAGE_LANGUAGE_DETAIL;
$query = NULL;
$search = NULL;
$qid = "1";
$n = "1";
$database = NULL;
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
$this->assertEquals ("English", $currentPage->title);
$this->assertCount (14, $currentPage->entryArray);
$this->assertEquals ("The Adventures of Sherlock Holmes", $currentPage->entryArray [0]->title);
$this->assertTrue ($currentPage->ContainsBook ());
}
public function testPageRecent ()
{
global $config;
$page = Base::PAGE_ALL_RECENT_BOOKS;
$query = NULL;
$search = NULL;
$qid = NULL;
$n = "1";
$database = NULL;
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
$this->assertEquals ("Recent additions", $currentPage->title);
$this->assertCount (14, $currentPage->entryArray);
$this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title);
$this->assertTrue ($currentPage->ContainsBook ());
// Test facets
$_GET["tag"] = "Historical";
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
$this->assertEquals ("Recent additions", $currentPage->title);
$this->assertCount (2, $currentPage->entryArray);
$this->assertEquals ("Twenty Years After", $currentPage->entryArray [0]->title);
$this->assertTrue ($currentPage->ContainsBook ());
$_GET["tag"] = "!Romance";
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
$this->assertEquals ("Recent additions", $currentPage->title);
$this->assertCount (12, $currentPage->entryArray);
$this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title);
$this->assertTrue ($currentPage->ContainsBook ());
$_GET["tag"] = NULL;
}
public function testPageBookDetail ()
{
global $config;
$page = Base::PAGE_BOOK_DETAIL;
$query = NULL;
$search = NULL;
$qid = "2";
$n = "1";
$database = NULL;
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
$this->assertEquals ("The Return of Sherlock Holmes", $currentPage->title);
$this->assertCount (0, $currentPage->entryArray);
$this->assertFalse ($currentPage->ContainsBook ());
}
}