2013-10-03 12:48:02 +03:00
|
|
|
<?php
|
2013-10-24 15:23:32 +03:00
|
|
|
/**
|
|
|
|
* COPS (Calibre OPDS PHP Server) test file
|
|
|
|
*
|
|
|
|
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
|
|
|
* @author Sébastien Lucas <sebastien@slucas.fr>
|
|
|
|
*/
|
2013-10-03 12:48:02 +03:00
|
|
|
|
|
|
|
require_once (dirname(__FILE__) . "/config_test.php");
|
2014-01-06 22:24:11 +02:00
|
|
|
require_once (dirname(__FILE__) . "/../resources/doT-php/doT.php");
|
2013-10-03 12:48:02 +03:00
|
|
|
require_once (dirname(__FILE__) . "/../base.php");
|
|
|
|
|
2013-10-03 16:22:21 +03:00
|
|
|
class BaseTest extends PHPUnit_Framework_TestCase
|
2013-12-05 11:52:51 +02:00
|
|
|
{
|
2013-10-03 12:48:02 +03:00
|
|
|
public function testAddURLParameter ()
|
|
|
|
{
|
|
|
|
$this->assertEquals ("?db=0", addURLParameter ("?", "db", "0"));
|
|
|
|
$this->assertEquals ("?key=value&db=0", addURLParameter ("?key=value", "db", "0"));
|
|
|
|
$this->assertEquals ("?key=value&otherKey=&db=0", addURLParameter ("?key=value&otherKey", "db", "0"));
|
|
|
|
}
|
2014-02-06 21:48:46 +02:00
|
|
|
|
|
|
|
/* For now I can't manage to make phpunit fail if a syntax error happens ... */
|
2014-01-06 22:24:11 +02:00
|
|
|
public function testServerSideRender ()
|
|
|
|
{
|
|
|
|
$this->assertNull (serverSideRender (NULL));
|
|
|
|
}
|
2013-12-05 11:52:51 +02:00
|
|
|
|
2013-10-04 13:20:34 +03:00
|
|
|
public function testLocalize ()
|
|
|
|
{
|
|
|
|
$this->assertEquals ("Authors", localize ("authors.title"));
|
2013-12-05 11:52:51 +02:00
|
|
|
|
2013-10-15 09:31:12 +03:00
|
|
|
$this->assertEquals ("unknow.key", localize ("unknow.key"));
|
2013-10-04 13:20:34 +03:00
|
|
|
}
|
2013-12-05 11:52:51 +02:00
|
|
|
|
2013-10-04 13:20:34 +03:00
|
|
|
public function testLocalizeFr ()
|
|
|
|
{
|
|
|
|
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = "fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3";
|
|
|
|
$this->assertEquals ("Auteurs", localize ("authors.title", -1, true));
|
2013-12-05 11:52:51 +02:00
|
|
|
|
2013-10-04 13:20:34 +03:00
|
|
|
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = "en";
|
|
|
|
localize ("authors.title", -1, true);
|
|
|
|
}
|
2013-12-05 11:52:51 +02:00
|
|
|
|
2013-10-04 13:20:34 +03:00
|
|
|
public function testLocalizeUnknown ()
|
|
|
|
{
|
|
|
|
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = "aa";
|
|
|
|
$this->assertEquals ("Authors", localize ("authors.title", -1, true));
|
2013-12-05 11:52:51 +02:00
|
|
|
|
2013-10-04 13:20:34 +03:00
|
|
|
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = "en";
|
|
|
|
localize ("authors.title", -1, true);
|
|
|
|
}
|
2013-12-05 11:52:51 +02:00
|
|
|
|
2013-11-26 18:17:22 +02:00
|
|
|
public function testBaseFunction () {
|
|
|
|
global $config;
|
2013-12-05 11:52:51 +02:00
|
|
|
|
2013-11-26 18:17:22 +02:00
|
|
|
$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 ());
|
|
|
|
}
|
2013-12-14 19:48:34 +02:00
|
|
|
|
|
|
|
public function testCheckDatabaseAvailability_1 () {
|
|
|
|
$this->assertTrue (Base::checkDatabaseAvailability ());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCheckDatabaseAvailability_2 () {
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
$config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/",
|
|
|
|
"One book" => dirname(__FILE__) . "/BaseWithOneBook/");
|
|
|
|
|
|
|
|
$this->assertTrue (Base::checkDatabaseAvailability ());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException Exception
|
|
|
|
* @expectedExceptionMessage not found
|
|
|
|
*/
|
|
|
|
public function testCheckDatabaseAvailability_Exception1 () {
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
$config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/",
|
|
|
|
"One book" => dirname(__FILE__) . "/OneBook/");
|
|
|
|
|
|
|
|
$this->assertTrue (Base::checkDatabaseAvailability ());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException Exception
|
|
|
|
* @expectedExceptionMessage not found
|
|
|
|
*/
|
|
|
|
public function testCheckDatabaseAvailability_Exception2 () {
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
$config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/SomeBooks/",
|
|
|
|
"One book" => dirname(__FILE__) . "/BaseWithOneBook/");
|
|
|
|
|
|
|
|
$this->assertTrue (Base::checkDatabaseAvailability ());
|
|
|
|
}
|
2013-10-03 09:38:58 +03:00
|
|
|
}
|