Replace CRLF by LF

This commit is contained in:
Sébastien Lucas 2013-12-05 10:50:53 +01:00
parent 40139bd18c
commit 9f5f00e114
6 changed files with 1091 additions and 1091 deletions

View File

@ -1,23 +1,23 @@
<?php
/**
* COPS (Calibre OPDS PHP Server) HTML main script
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Sébastien Lucas <sebastien@slucas.fr>
*
*/
require_once ("config.php");
require_once ("base.php");
require_once ("author.php");
require_once ("serie.php");
require_once ("tag.php");
require_once ("language.php");
require_once ("customcolumn.php");
require_once ("book.php");
header ("Content-Type:application/json;charset=utf-8");
echo json_encode (getJson ());
<?php
/**
* COPS (Calibre OPDS PHP Server) HTML main script
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Sébastien Lucas <sebastien@slucas.fr>
*
*/
require_once ("config.php");
require_once ("base.php");
require_once ("author.php");
require_once ("serie.php");
require_once ("tag.php");
require_once ("language.php");
require_once ("customcolumn.php");
require_once ("book.php");
header ("Content-Type:application/json;charset=utf-8");
echo json_encode (getJson ());

View File

@ -1,69 +1,69 @@
<?php
require_once ("config.php");
require_once "resources/PHPMailer/class.phpmailer.php";
require_once "book.php";
if (is_null ($config['cops_mail_configuration']) ||
!is_array ($config['cops_mail_configuration']) ||
empty ($config['cops_mail_configuration']["smtp.host"]) ||
empty ($config['cops_mail_configuration']["address.from"])) {
echo "NOK. bad configuration of $config ['cops_mail_configuration']";
exit;
}
$idData = $_REQUEST["data"];
if (empty ($idData)) {
echo 'No data sent.';
exit;
}
$emailDest = $_REQUEST["email"];
if (empty ($emailDest)) {
echo 'No email sent.';
exit;
}
$book = Book::getBookByDataId($idData);
$data = $book->getDataById ($idData);
if (filesize ($data->getLocalPath ()) > 10 * 1024 * 1024) {
echo 'Attachement too big';
exit;
}
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->Timeout = 30; // 30 seconds as some files can be big
$mail->Host = $config['cops_mail_configuration']["smtp.host"];
if (!empty ($config['cops_mail_configuration']["smtp.secure"])) {
$mail->SMTPSecure = $config['cops_mail_configuration']["smtp.secure"];
$mail->Port = 465;
}
$mail->SMTPAuth = !empty ($config['cops_mail_configuration']["smtp.username"]);
if (!empty ($config['cops_mail_configuration']["smtp.username"])) $mail->Username = $config['cops_mail_configuration']["smtp.username"];
if (!empty ($config['cops_mail_configuration']["smtp.password"])) $mail->Password = $config['cops_mail_configuration']["smtp.password"];
if (!empty ($config['cops_mail_configuration']["smtp.secure"])) $mail->SMTPSecure = $config['cops_mail_configuration']["smtp.secure"];
$mail->From = $config['cops_mail_configuration']["address.from"];
$mail->FromName = $config['cops_title_default'];
foreach (explode (";", $emailDest) as $emailAddress) {
if (empty ($emailAddress)) { continue; }
$mail->AddAddress($emailAddress);
}
$mail->AddAttachment($data->getLocalPath ());
$mail->IsHTML(false);
$mail->Subject = 'Sent by COPS';
$mail->Body = 'Sent by COPS';
if(!$mail->Send()) {
echo localize ("mail.messagenotsent");
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo localize ("mail.messagesent");
<?php
require_once ("config.php");
require_once "resources/PHPMailer/class.phpmailer.php";
require_once "book.php";
if (is_null ($config['cops_mail_configuration']) ||
!is_array ($config['cops_mail_configuration']) ||
empty ($config['cops_mail_configuration']["smtp.host"]) ||
empty ($config['cops_mail_configuration']["address.from"])) {
echo "NOK. bad configuration of $config ['cops_mail_configuration']";
exit;
}
$idData = $_REQUEST["data"];
if (empty ($idData)) {
echo 'No data sent.';
exit;
}
$emailDest = $_REQUEST["email"];
if (empty ($emailDest)) {
echo 'No email sent.';
exit;
}
$book = Book::getBookByDataId($idData);
$data = $book->getDataById ($idData);
if (filesize ($data->getLocalPath ()) > 10 * 1024 * 1024) {
echo 'Attachement too big';
exit;
}
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->Timeout = 30; // 30 seconds as some files can be big
$mail->Host = $config['cops_mail_configuration']["smtp.host"];
if (!empty ($config['cops_mail_configuration']["smtp.secure"])) {
$mail->SMTPSecure = $config['cops_mail_configuration']["smtp.secure"];
$mail->Port = 465;
}
$mail->SMTPAuth = !empty ($config['cops_mail_configuration']["smtp.username"]);
if (!empty ($config['cops_mail_configuration']["smtp.username"])) $mail->Username = $config['cops_mail_configuration']["smtp.username"];
if (!empty ($config['cops_mail_configuration']["smtp.password"])) $mail->Password = $config['cops_mail_configuration']["smtp.password"];
if (!empty ($config['cops_mail_configuration']["smtp.secure"])) $mail->SMTPSecure = $config['cops_mail_configuration']["smtp.secure"];
$mail->From = $config['cops_mail_configuration']["address.from"];
$mail->FromName = $config['cops_title_default'];
foreach (explode (";", $emailDest) as $emailAddress) {
if (empty ($emailAddress)) { continue; }
$mail->AddAddress($emailAddress);
}
$mail->AddAttachment($data->getLocalPath ());
$mail->IsHTML(false);
$mail->Subject = 'Sent by COPS';
$mail->Body = 'Sent by COPS';
if(!$mail->Send()) {
echo localize ("mail.messagenotsent");
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo localize ("mail.messagesent");

View File

@ -1,278 +1,278 @@
<?php
/**
* COPS (Calibre OPDS PHP Server) test file
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Sébastien Lucas <sebastien@slucas.fr>
*/
require_once (dirname(__FILE__) . "/config_test.php");
require_once (dirname(__FILE__) . "/../book.php");
/*
Publishers:
id:2 (2 books) Macmillan and Co. London: Lewis Caroll
id:3 (2 books) D. Appleton and Company Alexander Dumas
id:4 (1 book) Macmillan Publishers USA: Jack London
id:5 (1 book) Pierson's Magazine: H. G. Wells
id:6 (8 books) Strand Magazine: Arthur Conan Doyle
*/
class BookTest extends PHPUnit_Framework_TestCase
{
public function testGetBookCount ()
{
$this->assertEquals (14, Book::getBookCount ());
}
public function testGetCount ()
{
$entryArray = Book::getCount ();
$this->assertEquals (2, count($entryArray));
$entryAllBooks = $entryArray [0];
$this->assertEquals ("Alphabetical index of the 14 books", $entryAllBooks->content);
$entryRecentBooks = $entryArray [1];
$this->assertEquals ("50 most recent books", $entryRecentBooks->content);
}
public function testGetCountRecent ()
{
global $config;
$config['cops_recentbooks_limit'] = 0;
$entryArray = Book::getCount ();
$this->assertEquals (1, count($entryArray));
$config['cops_recentbooks_limit'] = 2;
$entryArray = Book::getCount ();
$entryRecentBooks = $entryArray [1];
$this->assertEquals ("2 most recent books", $entryRecentBooks->content);
$config['cops_recentbooks_limit'] = 50;
}
public function testGetBooksByAuthor ()
{
// All book by Arthur Conan Doyle
global $config;
$config['cops_max_item_per_page'] = 5;
list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, 1);
$this->assertEquals (5, count($entryArray));
$this->assertEquals (8, $totalNumber);
list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, 2);
$this->assertEquals (3, count($entryArray));
$this->assertEquals (8, $totalNumber);
$config['cops_max_item_per_page'] = -1;
list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, -1);
$this->assertEquals (8, count($entryArray));
$this->assertEquals (-1, $totalNumber);
}
public function testGetBooksBySeries ()
{
// All book from the Sherlock Holmes series
list ($entryArray, $totalNumber) = Book::getBooksBySeries (1, -1);
$this->assertEquals (7, count($entryArray));
$this->assertEquals (-1, $totalNumber);
}
public function testGetBooksByPublisher ()
{
// All books from Strand Magazine
list ($entryArray, $totalNumber) = Book::getBooksByPublisher (6, -1);
$this->assertEquals (8, count($entryArray));
$this->assertEquals (-1, $totalNumber);
}
public function testGetBooksByTag ()
{
// All book with the Fiction tag
list ($entryArray, $totalNumber) = Book::getBooksByTag (1, -1);
$this->assertEquals (14, count($entryArray));
$this->assertEquals (-1, $totalNumber);
}
public function testGetBooksByLanguage ()
{
// All english book (= all books)
list ($entryArray, $totalNumber) = Book::getBooksByLanguage (1, -1);
$this->assertEquals (14, count($entryArray));
$this->assertEquals (-1, $totalNumber);
}
public function testGetAllBooks ()
{
// All books by first letter
$entryArray = Book::getAllBooks ();
$this->assertCount (9, $entryArray);
}
public function testGetBooksByStartingLetter ()
{
// All books by first letter
list ($entryArray, $totalNumber) = Book::getBooksByStartingLetter ("T", -1);
$this->assertEquals (-1, $totalNumber);
$this->assertCount (3, $entryArray);
}
public function testGetBookByDataId ()
{
$book = Book::getBookByDataId (17);
$this->assertEquals ("Alice's Adventures in Wonderland", $book->getTitle ());
}
public function testGetAllRecentBooks ()
{
// All recent books
global $config;
$config['cops_recentbooks_limit'] = 2;
$entryArray = Book::getAllRecentBooks ();
$this->assertCount (2, $entryArray);
$config['cops_recentbooks_limit'] = 50;
$entryArray = Book::getAllRecentBooks ();
$this->assertCount (14, $entryArray);
}
public function testGetBookById ()
{
// also check most of book's class methods
$book = Book::getBookById(2);
$this->assertEquals ("The Return of Sherlock Holmes", $book->getTitle ());
$this->assertEquals ("urn:uuid:87ddbdeb-1e27-4d06-b79b-4b2a3bfc6a5f", $book->getEntryId ());
$this->assertEquals ("index.php?page=13&id=2", $book->getDetailUrl ());
$this->assertEquals ("Doyle, Arthur Conan", $book->getAuthorsName ());
$this->assertEquals ("Fiction, Mystery & Detective, Short Stories", $book->getTagsName ());
$this->assertEquals ('<p class="description">The Return of Sherlock Holmes is a collection of 13 Sherlock Holmes stories, originally published in 1903-1904, by Arthur Conan Doyle.<br />The book was first published on March 7, 1905 by Georges Newnes, Ltd and in a Colonial edition by Longmans. 30,000 copies were made of the initial print run. The US edition by McClure, Phillips &amp; Co. added another 28,000 to the run.<br />This was the first Holmes collection since 1893, when Holmes had "died" in "The Adventure of the Final Problem". Having published The Hound of the Baskervilles in 19011902 (although setting it before Holmes\' death) Doyle came under intense pressure to revive his famous character.</p>', $book->getComment (false));
$this->assertEquals ("English", $book->getLanguages ());
$this->assertEquals ("", $book->getRating ());
$book->rating = 8;
// 4 filled stars and one empty
$this->assertEquals ("&#9733;&#9733;&#9733;&#9733;&#9734;", $book->getRating ());
$this->assertEquals ("Strand Magazine", $book->getPublisher()->name);
}
public function testGetMostInterestingDataToSendToKindle ()
{
// Get Alice (available as MOBI, PDF, EPUB in that order)
$book = Book::getBookById(17);
$data = $book->GetMostInterestingDataToSendToKindle ();
$this->assertEquals ("MOBI", $data->format);
array_shift ($book->datas);
$data = $book->GetMostInterestingDataToSendToKindle ();
$this->assertEquals ("PDF", $data->format);
array_shift ($book->datas);
$data = $book->GetMostInterestingDataToSendToKindle ();
$this->assertEquals ("EPUB", $data->format);
}
public function testGetDataById ()
{
global $config;
// Get Alice MOBI=>17, PDF=>19, EPUB=>20
$book = Book::getBookById(17);
$data = $book->getDataById (17);
$this->assertEquals ("MOBI", $data->format);
$data = $book->getDataById (20);
$this->assertEquals ("EPUB", $data->format);
$this->assertEquals ("Carroll, Lewis - Alice's Adventures in Wonderland.epub", $data->getUpdatedFilenameEpub ());
$this->assertEquals ("Carroll, Lewis - Alice's Adventures in Wonderland.kepub.epub", $data->getUpdatedFilenameKepub ());
$this->assertEquals (dirname(__FILE__) . "/BaseWithSomeBooks/Lewis Carroll/Alice's Adventures in Wonderland (17)/Alice's Adventures in Wonderland - Lewis Carroll.epub", $data->getLocalPath ());
$config['cops_use_url_rewriting'] = "1";
$config['cops_provide_kepub'] = "1";
$_SERVER["HTTP_USER_AGENT"] = "Kobo";
$this->assertEquals ("download/20/Carroll%2C+Lewis+-+Alice%27s+Adventures+in+Wonderland.kepub.epub", $data->getHtmlLink ());
$_SERVER["HTTP_USER_AGENT"] = "Firefox";
$this->assertEquals ("download/20/Alice%27s+Adventures+in+Wonderland+-+Lewis+Carroll.epub", $data->getHtmlLink ());
$config['cops_use_url_rewriting'] = "0";
$this->assertEquals ("fetch.php?data=20&type=epub&id=17", $data->getHtmlLink ());
}
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"] = "Macmillan";
$_GET["search"] = "1";
$array = getJson ();
$this->assertCount (3, $array);
$this->assertEquals ("2 publishers", $array[0]["title"]);
$this->assertEquals ("Macmillan and Co. London", $array[1]["title"]);
$this->assertEquals ("Macmillan Publishers USA", $array[2]["title"]);
$_GET["query"] = NULL;
$_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 ();
}
<?php
/**
* COPS (Calibre OPDS PHP Server) test file
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Sébastien Lucas <sebastien@slucas.fr>
*/
require_once (dirname(__FILE__) . "/config_test.php");
require_once (dirname(__FILE__) . "/../book.php");
/*
Publishers:
id:2 (2 books) Macmillan and Co. London: Lewis Caroll
id:3 (2 books) D. Appleton and Company Alexander Dumas
id:4 (1 book) Macmillan Publishers USA: Jack London
id:5 (1 book) Pierson's Magazine: H. G. Wells
id:6 (8 books) Strand Magazine: Arthur Conan Doyle
*/
class BookTest extends PHPUnit_Framework_TestCase
{
public function testGetBookCount ()
{
$this->assertEquals (14, Book::getBookCount ());
}
public function testGetCount ()
{
$entryArray = Book::getCount ();
$this->assertEquals (2, count($entryArray));
$entryAllBooks = $entryArray [0];
$this->assertEquals ("Alphabetical index of the 14 books", $entryAllBooks->content);
$entryRecentBooks = $entryArray [1];
$this->assertEquals ("50 most recent books", $entryRecentBooks->content);
}
public function testGetCountRecent ()
{
global $config;
$config['cops_recentbooks_limit'] = 0;
$entryArray = Book::getCount ();
$this->assertEquals (1, count($entryArray));
$config['cops_recentbooks_limit'] = 2;
$entryArray = Book::getCount ();
$entryRecentBooks = $entryArray [1];
$this->assertEquals ("2 most recent books", $entryRecentBooks->content);
$config['cops_recentbooks_limit'] = 50;
}
public function testGetBooksByAuthor ()
{
// All book by Arthur Conan Doyle
global $config;
$config['cops_max_item_per_page'] = 5;
list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, 1);
$this->assertEquals (5, count($entryArray));
$this->assertEquals (8, $totalNumber);
list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, 2);
$this->assertEquals (3, count($entryArray));
$this->assertEquals (8, $totalNumber);
$config['cops_max_item_per_page'] = -1;
list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, -1);
$this->assertEquals (8, count($entryArray));
$this->assertEquals (-1, $totalNumber);
}
public function testGetBooksBySeries ()
{
// All book from the Sherlock Holmes series
list ($entryArray, $totalNumber) = Book::getBooksBySeries (1, -1);
$this->assertEquals (7, count($entryArray));
$this->assertEquals (-1, $totalNumber);
}
public function testGetBooksByPublisher ()
{
// All books from Strand Magazine
list ($entryArray, $totalNumber) = Book::getBooksByPublisher (6, -1);
$this->assertEquals (8, count($entryArray));
$this->assertEquals (-1, $totalNumber);
}
public function testGetBooksByTag ()
{
// All book with the Fiction tag
list ($entryArray, $totalNumber) = Book::getBooksByTag (1, -1);
$this->assertEquals (14, count($entryArray));
$this->assertEquals (-1, $totalNumber);
}
public function testGetBooksByLanguage ()
{
// All english book (= all books)
list ($entryArray, $totalNumber) = Book::getBooksByLanguage (1, -1);
$this->assertEquals (14, count($entryArray));
$this->assertEquals (-1, $totalNumber);
}
public function testGetAllBooks ()
{
// All books by first letter
$entryArray = Book::getAllBooks ();
$this->assertCount (9, $entryArray);
}
public function testGetBooksByStartingLetter ()
{
// All books by first letter
list ($entryArray, $totalNumber) = Book::getBooksByStartingLetter ("T", -1);
$this->assertEquals (-1, $totalNumber);
$this->assertCount (3, $entryArray);
}
public function testGetBookByDataId ()
{
$book = Book::getBookByDataId (17);
$this->assertEquals ("Alice's Adventures in Wonderland", $book->getTitle ());
}
public function testGetAllRecentBooks ()
{
// All recent books
global $config;
$config['cops_recentbooks_limit'] = 2;
$entryArray = Book::getAllRecentBooks ();
$this->assertCount (2, $entryArray);
$config['cops_recentbooks_limit'] = 50;
$entryArray = Book::getAllRecentBooks ();
$this->assertCount (14, $entryArray);
}
public function testGetBookById ()
{
// also check most of book's class methods
$book = Book::getBookById(2);
$this->assertEquals ("The Return of Sherlock Holmes", $book->getTitle ());
$this->assertEquals ("urn:uuid:87ddbdeb-1e27-4d06-b79b-4b2a3bfc6a5f", $book->getEntryId ());
$this->assertEquals ("index.php?page=13&id=2", $book->getDetailUrl ());
$this->assertEquals ("Doyle, Arthur Conan", $book->getAuthorsName ());
$this->assertEquals ("Fiction, Mystery & Detective, Short Stories", $book->getTagsName ());
$this->assertEquals ('<p class="description">The Return of Sherlock Holmes is a collection of 13 Sherlock Holmes stories, originally published in 1903-1904, by Arthur Conan Doyle.<br />The book was first published on March 7, 1905 by Georges Newnes, Ltd and in a Colonial edition by Longmans. 30,000 copies were made of the initial print run. The US edition by McClure, Phillips &amp; Co. added another 28,000 to the run.<br />This was the first Holmes collection since 1893, when Holmes had "died" in "The Adventure of the Final Problem". Having published The Hound of the Baskervilles in 19011902 (although setting it before Holmes\' death) Doyle came under intense pressure to revive his famous character.</p>', $book->getComment (false));
$this->assertEquals ("English", $book->getLanguages ());
$this->assertEquals ("", $book->getRating ());
$book->rating = 8;
// 4 filled stars and one empty
$this->assertEquals ("&#9733;&#9733;&#9733;&#9733;&#9734;", $book->getRating ());
$this->assertEquals ("Strand Magazine", $book->getPublisher()->name);
}
public function testGetMostInterestingDataToSendToKindle ()
{
// Get Alice (available as MOBI, PDF, EPUB in that order)
$book = Book::getBookById(17);
$data = $book->GetMostInterestingDataToSendToKindle ();
$this->assertEquals ("MOBI", $data->format);
array_shift ($book->datas);
$data = $book->GetMostInterestingDataToSendToKindle ();
$this->assertEquals ("PDF", $data->format);
array_shift ($book->datas);
$data = $book->GetMostInterestingDataToSendToKindle ();
$this->assertEquals ("EPUB", $data->format);
}
public function testGetDataById ()
{
global $config;
// Get Alice MOBI=>17, PDF=>19, EPUB=>20
$book = Book::getBookById(17);
$data = $book->getDataById (17);
$this->assertEquals ("MOBI", $data->format);
$data = $book->getDataById (20);
$this->assertEquals ("EPUB", $data->format);
$this->assertEquals ("Carroll, Lewis - Alice's Adventures in Wonderland.epub", $data->getUpdatedFilenameEpub ());
$this->assertEquals ("Carroll, Lewis - Alice's Adventures in Wonderland.kepub.epub", $data->getUpdatedFilenameKepub ());
$this->assertEquals (dirname(__FILE__) . "/BaseWithSomeBooks/Lewis Carroll/Alice's Adventures in Wonderland (17)/Alice's Adventures in Wonderland - Lewis Carroll.epub", $data->getLocalPath ());
$config['cops_use_url_rewriting'] = "1";
$config['cops_provide_kepub'] = "1";
$_SERVER["HTTP_USER_AGENT"] = "Kobo";
$this->assertEquals ("download/20/Carroll%2C+Lewis+-+Alice%27s+Adventures+in+Wonderland.kepub.epub", $data->getHtmlLink ());
$_SERVER["HTTP_USER_AGENT"] = "Firefox";
$this->assertEquals ("download/20/Alice%27s+Adventures+in+Wonderland+-+Lewis+Carroll.epub", $data->getHtmlLink ());
$config['cops_use_url_rewriting'] = "0";
$this->assertEquals ("fetch.php?data=20&type=epub&id=17", $data->getHtmlLink ());
}
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"] = "Macmillan";
$_GET["search"] = "1";
$array = getJson ();
$this->assertCount (3, $array);
$this->assertEquals ("2 publishers", $array[0]["title"]);
$this->assertEquals ("Macmillan and Co. London", $array[1]["title"]);
$this->assertEquals ("Macmillan Publishers USA", $array[2]["title"]);
$_GET["query"] = NULL;
$_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

@ -1,42 +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;
<?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

@ -1,62 +1,62 @@
<?php
/**
* COPS (Calibre OPDS PHP Server) test file
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Sébastien Lucas <sebastien@slucas.fr>
*/
require_once (dirname(__FILE__) . "/config_test.php");
require_once (dirname(__FILE__) . "/../book.php");
class PageMultiDatabaseTest extends PHPUnit_Framework_TestCase
{
public function testPageIndex ()
{
global $config;
$config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/",
"One book" => dirname(__FILE__) . "/BaseWithOneBook/");
$page = Base::PAGE_INDEX;
$query = NULL;
$qid = NULL;
$n = "1";
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
$this->assertEquals ($config['cops_title_default'], $currentPage->title);
$this->assertCount (2, $currentPage->entryArray);
$this->assertEquals ("Some books", $currentPage->entryArray [0]->title);
$this->assertEquals ("14 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 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 ();
}
}
<?php
/**
* COPS (Calibre OPDS PHP Server) test file
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Sébastien Lucas <sebastien@slucas.fr>
*/
require_once (dirname(__FILE__) . "/config_test.php");
require_once (dirname(__FILE__) . "/../book.php");
class PageMultiDatabaseTest extends PHPUnit_Framework_TestCase
{
public function testPageIndex ()
{
global $config;
$config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/",
"One book" => dirname(__FILE__) . "/BaseWithOneBook/");
$page = Base::PAGE_INDEX;
$query = NULL;
$qid = NULL;
$n = "1";
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
$this->assertEquals ($config['cops_title_default'], $currentPage->title);
$this->assertCount (2, $currentPage->entryArray);
$this->assertEquals ("Some books", $currentPage->entryArray [0]->title);
$this->assertEquals ("14 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 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 ();
}
}

File diff suppressed because it is too large Load Diff