Merge git://github.com/seblucas/cops

Conflicts:
	test/pageTest.php - RESOLVED
This commit is contained in:
At-Libitum 2013-12-02 14:53:10 +01:00
commit f87963ea8a
17 changed files with 337 additions and 36 deletions

View file

@ -38,10 +38,8 @@ class OpdsTest extends PHPUnit_Framework_TestCase
global $config;
$page = Base::PAGE_INDEX;
$query = NULL;
$search = NULL;
$qid = NULL;
$n = "1";
$database = NULL;
$_SERVER['QUERY_STRING'] = "";
$config['cops_subtitle_default'] = "My subtitle";
@ -66,10 +64,8 @@ class OpdsTest extends PHPUnit_Framework_TestCase
"One book" => dirname(__FILE__) . "/BaseWithOneBook/");
$page = Base::PAGE_AUTHOR_DETAIL;
$query = NULL;
$search = NULL;
$qid = "1";
$n = "1";
$database = NULL;
$_SERVER['QUERY_STRING'] = "page=" . Base::PAGE_AUTHOR_DETAIL . "&id=1";
$_GET ["db"] = "0";
@ -87,10 +83,8 @@ class OpdsTest extends PHPUnit_Framework_TestCase
global $config;
$page = Base::PAGE_AUTHOR_DETAIL;
$query = NULL;
$search = NULL;
$qid = "1";
$n = "1";
$database = NULL;
$_SERVER['QUERY_STRING'] = "page=" . Base::PAGE_AUTHOR_DETAIL . "&id=1&n=1";
$config['cops_max_item_per_page'] = 2;

140
test/Sauce.php Normal file
View file

@ -0,0 +1,140 @@
<?php
require_once 'vendor/autoload.php';
class Cops extends Sauce\Sausage\WebDriverTestCase
{
public static $browsers = array(
// run FF15 on Windows 8 on Sauce
array(
'browserName' => 'firefox',
'desiredCapabilities' => array(
'version' => '15',
'platform' => 'Windows 2012',
)
),
// run IE9 on Windows 7 on Sauce
array(
'browserName' => 'internet explorer',
'desiredCapabilities' => array(
'version' => '9',
'platform' => 'Windows 7',
)
),
// run IE10 on Windows 8 on Sauce
array(
'browserName' => 'internet explorer',
'desiredCapabilities' => array(
'version' => '10',
'platform' => 'Windows 8',
)
),
// run Opera 12 on Windows 7 on Sauce
array(
'browserName' => 'opera',
'desiredCapabilities' => array(
'version' => '12',
'platform' => 'Windows 7',
)
),
// run Mobile Safari on iOS
array(
'browserName' => '',
'desiredCapabilities' => array(
'app' => 'safari',
'device' => 'iPhone Simulator',
'version' => '6.1',
'platform' => 'Mac 10.8',
)
),
// run Chrome on Linux on Sauce
array(
'browserName' => 'chrome',
'desiredCapabilities' => array(
'version' => '30',
'platform' => 'Linux'
)
)
// run Mobile Browser on Android
// array(
// 'browserName' => 'Android',
// 'desiredCapabilities' => array(
// 'version' => '4.0',
// 'platform' => 'Linux',
// )
// )
// run Chrome locally
//array(
//'browserName' => 'chrome',
//'local' => true,
//'sessionStrategy' => 'shared'
//)
);
public function setUp()
{
if (isset ($_SERVER["TRAVIS_JOB_NUMBER"])) {
$caps = $this->getDesiredCapabilities();
$caps['build'] = getenv ("TRAVIS_JOB_NUMBER");
$this->setDesiredCapabilities($caps);
}
parent::setUp ();
}
public function setUpPage()
{
if (isset ($_SERVER["TRAVIS_JOB_NUMBER"])) {
$this->url('http://127.0.0.1:8888/index.php');
} else {
$this->url('http://cops-demo.slucas.fr/index.php');
}
$driver = $this;
$title_test = function($value) use ($driver) {
$text = $driver->byXPath('//h1')->text ();
return $text == $value;
};
$this->spinAssert("Home Title", $title_test, [ "COPS DEMO" ]);
}
public function string_to_ascii($string)
{
$ascii = NULL;
for ($i = 0; $i < strlen($string); $i++)
{
$ascii += ord($string[$i]);
}
return mb_detect_encoding($string) . "X" . $ascii;
}
public function testTitle()
{
$driver = $this;
$title_test = function($value) use ($driver) {
$text = $driver->byXPath('//h1')->text ();
return $text == $value;
};
$author = $this->byXPath ('//h2[contains(text(), "Authors")]');
$author->click ();
$this->spinAssert("Author Title", $title_test, [ "AUTHORS" ]);
}
public function testCog()
{
$cog = $this->byId ("searchImage");
$search = $this->byName ("query");
$this->assertFalse ($search->displayed ());
$cog->click ();
$search = $this->byName ("query");
$this->assertTrue ($search->displayed ());
}
}

View file

@ -42,4 +42,19 @@ class BaseTest extends PHPUnit_Framework_TestCase
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = "en";
localize ("authors.title", -1, true);
}
public function testBaseFunction () {
global $config;
$this->assertFalse (Base::isMultipleDatabaseEnabled ());
$this->assertEquals (array ("" => dirname(__FILE__) . "/BaseWithSomeBooks/"), Base::getDbList ());
$config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/",
"One book" => dirname(__FILE__) . "/BaseWithOneBook/");
$this->assertTrue (Base::isMultipleDatabaseEnabled ());
$this->assertEquals ("Some books", Base::getDbName (0));
$this->assertEquals ("One book", Base::getDbName (1));
$this->assertEquals ($config['calibre_directory'], Base::getDbList ());
}
}

View file

@ -118,6 +118,7 @@ class BookTest extends PHPUnit_Framework_TestCase
{
// All books by first letter
list ($entryArray, $totalNumber) = Book::getBooksByStartingLetter ("T", -1);
$this->assertEquals (-1, $totalNumber);
$this->assertCount (3, $entryArray);
}
@ -200,4 +201,30 @@ class BookTest extends PHPUnit_Framework_TestCase
$_GET["search"] = NULL;
}
public function testTypeaheadSearchMultiDatabase ()
{
global $config;
$_GET["query"] = "art";
$_GET["search"] = "1";
$_GET["multi"] = "1";
$config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/",
"One book" => dirname(__FILE__) . "/BaseWithOneBook/");
$array = getJson ();
$this->assertCount (4, $array);
$this->assertEquals ("Some books", $array[0]["title"]);
$this->assertEquals ("No book", $array[1]["title"]);
$this->assertEquals ("One book", $array[2]["title"]);
$this->assertEquals ("1 book", $array[3]["title"]);
$_GET["query"] = NULL;
$_GET["search"] = NULL;
}
public function tearDown () {
Base::clearDb ();
}
}

View file

@ -0,0 +1,17 @@
<?php
if (!isset($config))
$config = array();
/*
* The directory containing calibre's metadata.db file, with sub-directories
* containing all the formats.
* BEWARE : it has to end with a /
*/
$config['calibre_directory'] = './test/BaseWithSomeBooks/';
/*
* Catalog's title
*/
$config['cops_title_default'] = "COPS DEMO";
// $config['cops_server_side_render'] = ".";

View file

@ -18,10 +18,8 @@ class PageMultiDatabaseTest extends PHPUnit_Framework_TestCase
"One book" => dirname(__FILE__) . "/BaseWithOneBook/");
$page = Base::PAGE_INDEX;
$query = NULL;
$search = NULL;
$qid = NULL;
$n = "1";
$database = NULL;
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
@ -34,4 +32,31 @@ class PageMultiDatabaseTest extends PHPUnit_Framework_TestCase
$this->assertEquals ("1 book", $currentPage->entryArray [1]->content);
$this->assertFalse ($currentPage->ContainsBook ());
}
}
public function testPageSearchXXX ()
{
global $config;
$config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/",
"One book" => dirname(__FILE__) . "/BaseWithOneBook/");
$page = Base::PAGE_OPENSEARCH_QUERY;
$query = "art";
$qid = NULL;
$n = "1";
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
$this->assertEquals ("Search result for *art*", $currentPage->title);
$this->assertCount (2, $currentPage->entryArray);
$this->assertEquals ("Some books", $currentPage->entryArray [0]->title);
$this->assertEquals ("10 books", $currentPage->entryArray [0]->content);
$this->assertEquals ("One book", $currentPage->entryArray [1]->title);
$this->assertEquals ("1 book", $currentPage->entryArray [1]->content);
$this->assertFalse ($currentPage->ContainsBook ());
}
public static function tearDownAfterClass () {
Base::clearDb ();
}
}

View file

@ -328,8 +328,7 @@ class PageTest extends PHPUnit_Framework_TestCase
$page = Base::PAGE_SERIE_DETAIL;
$query = NULL;
$qid = "1";
$n = "1";
$n = "1";
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
@ -374,7 +373,6 @@ class PageTest extends PHPUnit_Framework_TestCase
public function testPageAllTags ()
{
global $config;
$page = Base::PAGE_ALL_TAGS;
$query = NULL;
$qid = NULL;
@ -522,7 +520,6 @@ class PageTest extends PHPUnit_Framework_TestCase
public function testPageSearchScopeAuthors ()
{
global $config;
$page = Base::PAGE_OPENSEARCH_QUERY;
$qid = NULL;
$n = "1";
@ -543,7 +540,6 @@ class PageTest extends PHPUnit_Framework_TestCase
public function testPageSearchScopeSeries ()
{
global $config;
$page = Base::PAGE_OPENSEARCH_QUERY;
$qid = NULL;
$n = "1";
@ -564,7 +560,6 @@ class PageTest extends PHPUnit_Framework_TestCase
public function testPageSearchScopeBooks ()
{
global $config;
$page = Base::PAGE_OPENSEARCH_QUERY;
$qid = NULL;
$n = "1";
@ -584,7 +579,6 @@ class PageTest extends PHPUnit_Framework_TestCase
public function testPageSearchScopePublishers ()
{
global $config;
$page = Base::PAGE_OPENSEARCH_QUERY;
$qid = NULL;
$n = "1";

27
test/prepareSauceTest.sh Normal file
View file

@ -0,0 +1,27 @@
#!/usr/bin/env bash
if [[ -z $SAUCE_ACCESS_KEY ]]
then
echo "No Sauce Api Key (Pull request)"
exit
fi
PHP_VERSION=`php -v|grep --only-matching --perl-regexp "PHP 5\.\\d+"`
echo $PHP_VERSION
if [[ $PHP_VERSION != "PHP 5.4" ]]
then
echo "Bad PHP version"
exit
fi
echo "Good PHP version"
curl https://gist.github.com/seblucas/7692094/raw/e2a090e6ea639a0d700e6d02cee048fa2f6c8617/sauce_connect_setup.sh | bash
curl -s https://raw.github.com/jlipps/sausage-bun/master/givememysausage.php | php
cp -v test/config_local.php.sauce config_local.php
php -S 127.0.0.1:8888 &
vendor/bin/phpunit --no-configuration test/Sauce.php