2013-10-24 11:59:22 +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<EFBFBD>bastien Lucas <sebastien@slucas.fr>
|
|
|
|
|
*/
|
2013-10-24 11:59:22 +03:00
|
|
|
|
|
|
|
|
|
require_once (dirname(__FILE__) . "/config_test.php");
|
|
|
|
|
require_once (dirname(__FILE__) . "/../book.php");
|
|
|
|
|
require_once (dirname(__FILE__) . "/../OPDS_renderer.php");
|
|
|
|
|
|
2013-10-24 15:27:01 +03:00
|
|
|
|
define ("OPDS_RELAX_NG", dirname(__FILE__) . "/opds-relax-ng/opds_catalog_1_1.rng");
|
2013-10-24 11:59:22 +03:00
|
|
|
|
define ("JING_JAR", dirname(__FILE__) . "/jing.jar");
|
|
|
|
|
define ("TEST_FEED", dirname(__FILE__) . "/text.atom");
|
|
|
|
|
|
|
|
|
|
class OpdsTest extends PHPUnit_Framework_TestCase
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
function opdsValidateSchema($feed) {
|
|
|
|
|
$path = "";
|
|
|
|
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
|
|
|
|
// huge hack, not proud about it
|
|
|
|
|
$path = "c:\\Progra~1\\Java\\jre7\\bin\\";
|
|
|
|
|
}
|
|
|
|
|
$res = system($path . 'java -jar ' . JING_JAR . ' ' . OPDS_RELAX_NG . ' ' . $feed);
|
|
|
|
|
if ($res != '') {
|
|
|
|
|
echo 'RelaxNG validation error: '.$res;
|
|
|
|
|
return false;
|
|
|
|
|
} else
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testPageIndex ()
|
|
|
|
|
{
|
|
|
|
|
global $config;
|
|
|
|
|
$page = Base::PAGE_INDEX;
|
|
|
|
|
$query = NULL;
|
|
|
|
|
$qid = NULL;
|
|
|
|
|
$n = "1";
|
|
|
|
|
|
|
|
|
|
$_SERVER['QUERY_STRING'] = "";
|
2013-10-24 22:33:49 +03:00
|
|
|
|
$config['cops_subtitle_default'] = "My subtitle";
|
2013-10-24 11:59:22 +03:00
|
|
|
|
|
|
|
|
|
$currentPage = Page::getPage ($page, $qid, $query, $n);
|
|
|
|
|
$currentPage->InitializeContent ();
|
|
|
|
|
|
|
|
|
|
$OPDSRender = new OPDSRenderer ();
|
|
|
|
|
|
|
|
|
|
file_put_contents (TEST_FEED, $OPDSRender->render ($currentPage));
|
|
|
|
|
$this->AssertTrue ($this->opdsValidateSchema (TEST_FEED));
|
|
|
|
|
file_put_contents (TEST_FEED, str_replace ("id>", "ido>", $OPDSRender->render ($currentPage)));
|
|
|
|
|
$this->AssertFalse ($this->opdsValidateSchema (TEST_FEED));
|
|
|
|
|
|
|
|
|
|
$_SERVER['QUERY_STRING'] = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-24 22:33:49 +03:00
|
|
|
|
public function testPageIndexMultipleDatabase ()
|
|
|
|
|
{
|
|
|
|
|
global $config;
|
|
|
|
|
$config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/",
|
|
|
|
|
"One book" => dirname(__FILE__) . "/BaseWithOneBook/");
|
|
|
|
|
$page = Base::PAGE_AUTHOR_DETAIL;
|
|
|
|
|
$query = NULL;
|
|
|
|
|
$qid = "1";
|
|
|
|
|
$n = "1";
|
|
|
|
|
$_SERVER['QUERY_STRING'] = "page=" . Base::PAGE_AUTHOR_DETAIL . "&id=1";
|
|
|
|
|
$_GET ["db"] = "0";
|
|
|
|
|
|
|
|
|
|
$currentPage = Page::getPage ($page, $qid, $query, $n);
|
|
|
|
|
$currentPage->InitializeContent ();
|
|
|
|
|
|
|
|
|
|
$OPDSRender = new OPDSRenderer ();
|
|
|
|
|
|
|
|
|
|
file_put_contents (TEST_FEED, $OPDSRender->render ($currentPage));
|
|
|
|
|
$this->AssertTrue ($this->opdsValidateSchema (TEST_FEED));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testPageAuthorsDetail ()
|
|
|
|
|
{
|
|
|
|
|
global $config;
|
|
|
|
|
$page = Base::PAGE_AUTHOR_DETAIL;
|
|
|
|
|
$query = NULL;
|
|
|
|
|
$qid = "1";
|
|
|
|
|
$n = "1";
|
|
|
|
|
$_SERVER['QUERY_STRING'] = "page=" . Base::PAGE_AUTHOR_DETAIL . "&id=1&n=1";
|
|
|
|
|
|
|
|
|
|
$config['cops_max_item_per_page'] = 2;
|
2013-10-24 22:45:17 +03:00
|
|
|
|
$config['cops_books_filter'] = array ("Only Short Stories" => "Short Stories", "No Short Stories" => "!Short Stories");
|
2013-10-24 22:33:49 +03:00
|
|
|
|
|
|
|
|
|
// First page
|
|
|
|
|
|
|
|
|
|
$currentPage = Page::getPage ($page, $qid, $query, $n);
|
|
|
|
|
$currentPage->InitializeContent ();
|
|
|
|
|
|
|
|
|
|
$OPDSRender = new OPDSRenderer ();
|
|
|
|
|
|
|
|
|
|
file_put_contents (TEST_FEED, $OPDSRender->render ($currentPage));
|
|
|
|
|
$this->AssertTrue ($this->opdsValidateSchema (TEST_FEED));
|
|
|
|
|
|
|
|
|
|
// Second page
|
|
|
|
|
|
|
|
|
|
$n = 2;
|
|
|
|
|
$currentPage = Page::getPage ($page, $qid, $query, $n);
|
|
|
|
|
$currentPage->InitializeContent ();
|
|
|
|
|
|
|
|
|
|
$OPDSRender = new OPDSRenderer ();
|
|
|
|
|
|
|
|
|
|
file_put_contents (TEST_FEED, $OPDSRender->render ($currentPage));
|
|
|
|
|
$this->AssertTrue ($this->opdsValidateSchema (TEST_FEED));
|
|
|
|
|
|
|
|
|
|
// No pagination
|
|
|
|
|
$config['cops_max_item_per_page'] = -1;
|
|
|
|
|
|
|
|
|
|
}
|
2013-10-24 11:59:22 +03:00
|
|
|
|
}
|