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");
|
2014-01-02 17:56:01 +02:00
|
|
|
|
define ("OPENSEARCHDESCRIPTION_RELAX_NG", dirname(__FILE__) . "/opds-relax-ng/opensearchdescription.rng");
|
2013-10-24 11:59:22 +03:00
|
|
|
|
define ("JING_JAR", dirname(__FILE__) . "/jing.jar");
|
2014-01-02 23:23:24 +02:00
|
|
|
|
define ("OPDSVALIDATOR_JAR", dirname(__FILE__) . "/OPDSValidator.jar");
|
2013-10-24 11:59:22 +03:00
|
|
|
|
define ("TEST_FEED", dirname(__FILE__) . "/text.atom");
|
|
|
|
|
|
|
|
|
|
class OpdsTest extends PHPUnit_Framework_TestCase
|
|
|
|
|
{
|
2013-12-15 15:43:33 +02:00
|
|
|
|
public static function tearDownAfterClass()
|
|
|
|
|
{
|
|
|
|
|
if (!file_exists (TEST_FEED)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
unlink (TEST_FEED);
|
|
|
|
|
}
|
2013-10-24 11:59:22 +03:00
|
|
|
|
|
2014-01-02 23:23:24 +02:00
|
|
|
|
function jingValidateSchema($feed, $relax = OPDS_RELAX_NG) {
|
2013-10-24 11:59:22 +03:00
|
|
|
|
$path = "";
|
|
|
|
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
|
|
|
|
// huge hack, not proud about it
|
|
|
|
|
$path = "c:\\Progra~1\\Java\\jre7\\bin\\";
|
|
|
|
|
}
|
2014-01-02 17:56:01 +02:00
|
|
|
|
$res = system($path . 'java -jar ' . JING_JAR . ' ' . $relax . ' ' . $feed);
|
2013-10-24 11:59:22 +03:00
|
|
|
|
if ($res != '') {
|
|
|
|
|
echo 'RelaxNG validation error: '.$res;
|
|
|
|
|
return false;
|
|
|
|
|
} else
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-02 23:23:24 +02:00
|
|
|
|
function opdsValidator($feed) {
|
|
|
|
|
$oldcwd = getcwd(); // Save the old working directory
|
|
|
|
|
chdir("test");
|
|
|
|
|
$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 ' . OPDSVALIDATOR_JAR . ' ' . $feed);
|
|
|
|
|
chdir($oldcwd);
|
|
|
|
|
if ($res != '') {
|
|
|
|
|
echo 'OPDS validation error: '.$res;
|
|
|
|
|
return false;
|
|
|
|
|
} else
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-10-24 11:59:22 +03:00
|
|
|
|
|
2014-01-02 23:23:24 +02:00
|
|
|
|
function opdsCompleteValidation ($feed) {
|
|
|
|
|
return $this->jingValidateSchema($feed) && $this->opdsValidator($feed);
|
|
|
|
|
}
|
2013-10-24 11:59:22 +03:00
|
|
|
|
|
|
|
|
|
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));
|
2014-01-02 23:23:24 +02:00
|
|
|
|
$this->AssertTrue ($this->opdsCompleteValidation (TEST_FEED));
|
|
|
|
|
|
|
|
|
|
$_SERVER ["HTTP_USER_AGENT"] = "XXX";
|
|
|
|
|
$config['cops_generate_invalid_opds_stream'] = "1";
|
|
|
|
|
|
|
|
|
|
file_put_contents (TEST_FEED, $OPDSRender->render ($currentPage));
|
|
|
|
|
$this->AssertFalse ($this->jingValidateSchema (TEST_FEED));
|
|
|
|
|
$this->AssertFalse ($this->opdsValidator (TEST_FEED));
|
2013-10-24 11:59:22 +03:00
|
|
|
|
|
|
|
|
|
$_SERVER['QUERY_STRING'] = NULL;
|
|
|
|
|
}
|
2014-06-04 22:37:19 +03:00
|
|
|
|
|
2014-01-03 14:53:52 +02:00
|
|
|
|
/**
|
|
|
|
|
* @dataProvider providerPage
|
|
|
|
|
*/
|
|
|
|
|
public function testMostPages ($page, $query)
|
|
|
|
|
{
|
|
|
|
|
$qid = NULL;
|
|
|
|
|
$n = "1";
|
|
|
|
|
$_SERVER['QUERY_STRING'] = "?page={$page}";
|
|
|
|
|
if (!empty ($query)) {
|
|
|
|
|
$_SERVER['QUERY_STRING'] .= "&query={$query}";
|
|
|
|
|
}
|
|
|
|
|
$_SERVER['REQUEST_URI'] = "feed.php" . $_SERVER['QUERY_STRING'];
|
|
|
|
|
|
|
|
|
|
$currentPage = Page::getPage ($page, $qid, $query, $n);
|
|
|
|
|
$currentPage->InitializeContent ();
|
2014-06-04 22:37:19 +03:00
|
|
|
|
|
2014-01-03 14:53:52 +02:00
|
|
|
|
$OPDSRender = new OPDSRenderer ();
|
2014-06-04 22:37:19 +03:00
|
|
|
|
|
2014-01-03 14:53:52 +02:00
|
|
|
|
file_put_contents (TEST_FEED, $OPDSRender->render ($currentPage));
|
|
|
|
|
$this->AssertTrue ($this->opdsCompleteValidation (TEST_FEED));
|
|
|
|
|
}
|
2014-06-04 22:37:19 +03:00
|
|
|
|
|
2014-01-03 14:53:52 +02:00
|
|
|
|
public function providerPage ()
|
|
|
|
|
{
|
|
|
|
|
return array (
|
|
|
|
|
array (Base::PAGE_OPENSEARCH, "car"),
|
|
|
|
|
array (Base::PAGE_ALL_AUTHORS, NULL),
|
|
|
|
|
array (Base::PAGE_ALL_SERIES, NULL),
|
|
|
|
|
array (Base::PAGE_ALL_TAGS, NULL),
|
|
|
|
|
array (Base::PAGE_ALL_PUBLISHERS, NULL),
|
|
|
|
|
array (Base::PAGE_ALL_LANGUAGES, NULL),
|
|
|
|
|
array (Base::PAGE_ALL_RECENT_BOOKS, NULL),
|
|
|
|
|
array (Base::PAGE_ALL_BOOKS, NULL)
|
|
|
|
|
);
|
|
|
|
|
}
|
2014-01-02 23:23:24 +02:00
|
|
|
|
|
|
|
|
|
public function testPageIndexMultipleDatabase ()
|
|
|
|
|
{
|
|
|
|
|
global $config;
|
|
|
|
|
$config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/",
|
|
|
|
|
"One book" => dirname(__FILE__) . "/BaseWithOneBook/");
|
|
|
|
|
$page = Base::PAGE_INDEX;
|
|
|
|
|
$query = NULL;
|
|
|
|
|
$qid = "1";
|
|
|
|
|
$n = "1";
|
|
|
|
|
$_SERVER['QUERY_STRING'] = "";
|
|
|
|
|
|
|
|
|
|
$currentPage = Page::getPage ($page, $qid, $query, $n);
|
|
|
|
|
$currentPage->InitializeContent ();
|
|
|
|
|
|
|
|
|
|
$OPDSRender = new OPDSRenderer ();
|
|
|
|
|
|
|
|
|
|
file_put_contents (TEST_FEED, $OPDSRender->render ($currentPage));
|
|
|
|
|
$this->AssertTrue ($this->opdsCompleteValidation (TEST_FEED));
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-02 17:56:01 +02:00
|
|
|
|
public function testOpenSearchDescription ()
|
|
|
|
|
{
|
|
|
|
|
$_SERVER['QUERY_STRING'] = "";
|
|
|
|
|
|
|
|
|
|
$OPDSRender = new OPDSRenderer ();
|
|
|
|
|
|
|
|
|
|
file_put_contents (TEST_FEED, $OPDSRender->getOpenSearch ());
|
2014-01-02 23:23:24 +02:00
|
|
|
|
$this->AssertTrue ($this->jingValidateSchema (TEST_FEED, OPENSEARCHDESCRIPTION_RELAX_NG));
|
2014-01-02 17:56:01 +02:00
|
|
|
|
|
|
|
|
|
$_SERVER['QUERY_STRING'] = NULL;
|
|
|
|
|
}
|
2013-10-24 11:59:22 +03:00
|
|
|
|
|
2014-01-02 23:23:24 +02:00
|
|
|
|
public function testPageAuthorMultipleDatabase ()
|
2013-10-24 22:33:49 +03:00
|
|
|
|
{
|
|
|
|
|
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));
|
2014-01-02 23:23:24 +02:00
|
|
|
|
$this->AssertTrue ($this->opdsCompleteValidation (TEST_FEED));
|
2013-10-24 22:33:49 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
// First page
|
|
|
|
|
|
|
|
|
|
$currentPage = Page::getPage ($page, $qid, $query, $n);
|
|
|
|
|
$currentPage->InitializeContent ();
|
|
|
|
|
|
|
|
|
|
$OPDSRender = new OPDSRenderer ();
|
|
|
|
|
|
|
|
|
|
file_put_contents (TEST_FEED, $OPDSRender->render ($currentPage));
|
2014-01-02 23:23:24 +02:00
|
|
|
|
$this->AssertTrue ($this->opdsCompleteValidation (TEST_FEED));
|
2013-10-24 22:33:49 +03:00
|
|
|
|
|
|
|
|
|
// Second page
|
|
|
|
|
|
|
|
|
|
$n = 2;
|
|
|
|
|
$currentPage = Page::getPage ($page, $qid, $query, $n);
|
|
|
|
|
$currentPage->InitializeContent ();
|
|
|
|
|
|
|
|
|
|
$OPDSRender = new OPDSRenderer ();
|
|
|
|
|
|
|
|
|
|
file_put_contents (TEST_FEED, $OPDSRender->render ($currentPage));
|
2014-01-02 23:23:24 +02:00
|
|
|
|
$this->AssertTrue ($this->opdsCompleteValidation (TEST_FEED));
|
2013-10-24 22:33:49 +03:00
|
|
|
|
|
|
|
|
|
// No pagination
|
|
|
|
|
$config['cops_max_item_per_page'] = -1;
|
|
|
|
|
|
|
|
|
|
}
|
2014-06-04 23:44:47 +03:00
|
|
|
|
|
|
|
|
|
public function testPageAuthorsDetail_WithFacets ()
|
|
|
|
|
{
|
|
|
|
|
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";
|
|
|
|
|
$_GET["tag"] = "Short Stories";
|
|
|
|
|
|
|
|
|
|
$config['cops_books_filter'] = array ("Only Short Stories" => "Short Stories", "No Short Stories" => "!Short Stories");
|
|
|
|
|
|
|
|
|
|
$currentPage = Page::getPage ($page, $qid, $query, $n);
|
|
|
|
|
$currentPage->InitializeContent ();
|
|
|
|
|
|
|
|
|
|
$OPDSRender = new OPDSRenderer ();
|
|
|
|
|
|
|
|
|
|
file_put_contents (TEST_FEED, $OPDSRender->render ($currentPage));
|
|
|
|
|
$this->AssertTrue ($this->opdsCompleteValidation (TEST_FEED));
|
|
|
|
|
|
|
|
|
|
$config['cops_books_filter'] = array ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testPageAuthorsDetail_WithoutAnyId ()
|
|
|
|
|
{
|
|
|
|
|
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";
|
|
|
|
|
$_SERVER['REQUEST_URI'] = "index.php?XXXX";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$currentPage = Page::getPage ($page, $qid, $query, $n);
|
|
|
|
|
$currentPage->InitializeContent ();
|
|
|
|
|
$currentPage->idPage = NULL;
|
|
|
|
|
|
|
|
|
|
$OPDSRender = new OPDSRenderer ();
|
|
|
|
|
|
|
|
|
|
file_put_contents (TEST_FEED, $OPDSRender->render ($currentPage));
|
|
|
|
|
$this->AssertTrue ($this->opdsCompleteValidation (TEST_FEED));
|
|
|
|
|
|
|
|
|
|
}
|
2013-10-24 11:59:22 +03:00
|
|
|
|
}
|