Replace CRLF by LF
This commit is contained in:
parent
40139bd18c
commit
9f5f00e114
46
getJSON.php
46
getJSON.php
|
@ -1,23 +1,23 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* COPS (Calibre OPDS PHP Server) HTML main script
|
* COPS (Calibre OPDS PHP Server) HTML main script
|
||||||
*
|
*
|
||||||
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
||||||
* @author Sébastien Lucas <sebastien@slucas.fr>
|
* @author Sébastien Lucas <sebastien@slucas.fr>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once ("config.php");
|
require_once ("config.php");
|
||||||
require_once ("base.php");
|
require_once ("base.php");
|
||||||
require_once ("author.php");
|
require_once ("author.php");
|
||||||
require_once ("serie.php");
|
require_once ("serie.php");
|
||||||
require_once ("tag.php");
|
require_once ("tag.php");
|
||||||
require_once ("language.php");
|
require_once ("language.php");
|
||||||
require_once ("customcolumn.php");
|
require_once ("customcolumn.php");
|
||||||
require_once ("book.php");
|
require_once ("book.php");
|
||||||
|
|
||||||
header ("Content-Type:application/json;charset=utf-8");
|
header ("Content-Type:application/json;charset=utf-8");
|
||||||
|
|
||||||
|
|
||||||
echo json_encode (getJson ());
|
echo json_encode (getJson ());
|
||||||
|
|
||||||
|
|
138
sendtomail.php
138
sendtomail.php
|
@ -1,69 +1,69 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once ("config.php");
|
require_once ("config.php");
|
||||||
require_once "resources/PHPMailer/class.phpmailer.php";
|
require_once "resources/PHPMailer/class.phpmailer.php";
|
||||||
require_once "book.php";
|
require_once "book.php";
|
||||||
|
|
||||||
if (is_null ($config['cops_mail_configuration']) ||
|
if (is_null ($config['cops_mail_configuration']) ||
|
||||||
!is_array ($config['cops_mail_configuration']) ||
|
!is_array ($config['cops_mail_configuration']) ||
|
||||||
empty ($config['cops_mail_configuration']["smtp.host"]) ||
|
empty ($config['cops_mail_configuration']["smtp.host"]) ||
|
||||||
empty ($config['cops_mail_configuration']["address.from"])) {
|
empty ($config['cops_mail_configuration']["address.from"])) {
|
||||||
echo "NOK. bad configuration of $config ['cops_mail_configuration']";
|
echo "NOK. bad configuration of $config ['cops_mail_configuration']";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$idData = $_REQUEST["data"];
|
$idData = $_REQUEST["data"];
|
||||||
if (empty ($idData)) {
|
if (empty ($idData)) {
|
||||||
echo 'No data sent.';
|
echo 'No data sent.';
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
$emailDest = $_REQUEST["email"];
|
$emailDest = $_REQUEST["email"];
|
||||||
if (empty ($emailDest)) {
|
if (empty ($emailDest)) {
|
||||||
echo 'No email sent.';
|
echo 'No email sent.';
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$book = Book::getBookByDataId($idData);
|
$book = Book::getBookByDataId($idData);
|
||||||
$data = $book->getDataById ($idData);
|
$data = $book->getDataById ($idData);
|
||||||
|
|
||||||
if (filesize ($data->getLocalPath ()) > 10 * 1024 * 1024) {
|
if (filesize ($data->getLocalPath ()) > 10 * 1024 * 1024) {
|
||||||
echo 'Attachement too big';
|
echo 'Attachement too big';
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$mail = new PHPMailer;
|
$mail = new PHPMailer;
|
||||||
|
|
||||||
$mail->IsSMTP();
|
$mail->IsSMTP();
|
||||||
$mail->Timeout = 30; // 30 seconds as some files can be big
|
$mail->Timeout = 30; // 30 seconds as some files can be big
|
||||||
$mail->Host = $config['cops_mail_configuration']["smtp.host"];
|
$mail->Host = $config['cops_mail_configuration']["smtp.host"];
|
||||||
if (!empty ($config['cops_mail_configuration']["smtp.secure"])) {
|
if (!empty ($config['cops_mail_configuration']["smtp.secure"])) {
|
||||||
$mail->SMTPSecure = $config['cops_mail_configuration']["smtp.secure"];
|
$mail->SMTPSecure = $config['cops_mail_configuration']["smtp.secure"];
|
||||||
$mail->Port = 465;
|
$mail->Port = 465;
|
||||||
}
|
}
|
||||||
$mail->SMTPAuth = !empty ($config['cops_mail_configuration']["smtp.username"]);
|
$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.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.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"];
|
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->From = $config['cops_mail_configuration']["address.from"];
|
||||||
$mail->FromName = $config['cops_title_default'];
|
$mail->FromName = $config['cops_title_default'];
|
||||||
|
|
||||||
foreach (explode (";", $emailDest) as $emailAddress) {
|
foreach (explode (";", $emailDest) as $emailAddress) {
|
||||||
if (empty ($emailAddress)) { continue; }
|
if (empty ($emailAddress)) { continue; }
|
||||||
$mail->AddAddress($emailAddress);
|
$mail->AddAddress($emailAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
$mail->AddAttachment($data->getLocalPath ());
|
$mail->AddAttachment($data->getLocalPath ());
|
||||||
|
|
||||||
$mail->IsHTML(false);
|
$mail->IsHTML(false);
|
||||||
$mail->Subject = 'Sent by COPS';
|
$mail->Subject = 'Sent by COPS';
|
||||||
$mail->Body = 'Sent by COPS';
|
$mail->Body = 'Sent by COPS';
|
||||||
|
|
||||||
if(!$mail->Send()) {
|
if(!$mail->Send()) {
|
||||||
echo localize ("mail.messagenotsent");
|
echo localize ("mail.messagenotsent");
|
||||||
echo 'Mailer Error: ' . $mail->ErrorInfo;
|
echo 'Mailer Error: ' . $mail->ErrorInfo;
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
echo localize ("mail.messagesent");
|
echo localize ("mail.messagesent");
|
||||||
|
|
||||||
|
|
|
@ -1,278 +1,278 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* COPS (Calibre OPDS PHP Server) test file
|
* COPS (Calibre OPDS PHP Server) test file
|
||||||
*
|
*
|
||||||
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
||||||
* @author Sébastien Lucas <sebastien@slucas.fr>
|
* @author Sébastien Lucas <sebastien@slucas.fr>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once (dirname(__FILE__) . "/config_test.php");
|
require_once (dirname(__FILE__) . "/config_test.php");
|
||||||
require_once (dirname(__FILE__) . "/../book.php");
|
require_once (dirname(__FILE__) . "/../book.php");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Publishers:
|
Publishers:
|
||||||
id:2 (2 books) Macmillan and Co. London: Lewis Caroll
|
id:2 (2 books) Macmillan and Co. London: Lewis Caroll
|
||||||
id:3 (2 books) D. Appleton and Company Alexander Dumas
|
id:3 (2 books) D. Appleton and Company Alexander Dumas
|
||||||
id:4 (1 book) Macmillan Publishers USA: Jack London
|
id:4 (1 book) Macmillan Publishers USA: Jack London
|
||||||
id:5 (1 book) Pierson's Magazine: H. G. Wells
|
id:5 (1 book) Pierson's Magazine: H. G. Wells
|
||||||
id:6 (8 books) Strand Magazine: Arthur Conan Doyle
|
id:6 (8 books) Strand Magazine: Arthur Conan Doyle
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class BookTest extends PHPUnit_Framework_TestCase
|
class BookTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testGetBookCount ()
|
public function testGetBookCount ()
|
||||||
{
|
{
|
||||||
$this->assertEquals (14, Book::getBookCount ());
|
$this->assertEquals (14, Book::getBookCount ());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetCount ()
|
public function testGetCount ()
|
||||||
{
|
{
|
||||||
$entryArray = Book::getCount ();
|
$entryArray = Book::getCount ();
|
||||||
$this->assertEquals (2, count($entryArray));
|
$this->assertEquals (2, count($entryArray));
|
||||||
|
|
||||||
$entryAllBooks = $entryArray [0];
|
$entryAllBooks = $entryArray [0];
|
||||||
$this->assertEquals ("Alphabetical index of the 14 books", $entryAllBooks->content);
|
$this->assertEquals ("Alphabetical index of the 14 books", $entryAllBooks->content);
|
||||||
|
|
||||||
$entryRecentBooks = $entryArray [1];
|
$entryRecentBooks = $entryArray [1];
|
||||||
$this->assertEquals ("50 most recent books", $entryRecentBooks->content);
|
$this->assertEquals ("50 most recent books", $entryRecentBooks->content);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetCountRecent ()
|
public function testGetCountRecent ()
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
$config['cops_recentbooks_limit'] = 0;
|
$config['cops_recentbooks_limit'] = 0;
|
||||||
$entryArray = Book::getCount ();
|
$entryArray = Book::getCount ();
|
||||||
|
|
||||||
$this->assertEquals (1, count($entryArray));
|
$this->assertEquals (1, count($entryArray));
|
||||||
|
|
||||||
$config['cops_recentbooks_limit'] = 2;
|
$config['cops_recentbooks_limit'] = 2;
|
||||||
$entryArray = Book::getCount ();
|
$entryArray = Book::getCount ();
|
||||||
|
|
||||||
$entryRecentBooks = $entryArray [1];
|
$entryRecentBooks = $entryArray [1];
|
||||||
$this->assertEquals ("2 most recent books", $entryRecentBooks->content);
|
$this->assertEquals ("2 most recent books", $entryRecentBooks->content);
|
||||||
|
|
||||||
$config['cops_recentbooks_limit'] = 50;
|
$config['cops_recentbooks_limit'] = 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetBooksByAuthor ()
|
public function testGetBooksByAuthor ()
|
||||||
{
|
{
|
||||||
// All book by Arthur Conan Doyle
|
// All book by Arthur Conan Doyle
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
$config['cops_max_item_per_page'] = 5;
|
$config['cops_max_item_per_page'] = 5;
|
||||||
list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, 1);
|
list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, 1);
|
||||||
$this->assertEquals (5, count($entryArray));
|
$this->assertEquals (5, count($entryArray));
|
||||||
$this->assertEquals (8, $totalNumber);
|
$this->assertEquals (8, $totalNumber);
|
||||||
|
|
||||||
list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, 2);
|
list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, 2);
|
||||||
$this->assertEquals (3, count($entryArray));
|
$this->assertEquals (3, count($entryArray));
|
||||||
$this->assertEquals (8, $totalNumber);
|
$this->assertEquals (8, $totalNumber);
|
||||||
|
|
||||||
$config['cops_max_item_per_page'] = -1;
|
$config['cops_max_item_per_page'] = -1;
|
||||||
list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, -1);
|
list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, -1);
|
||||||
$this->assertEquals (8, count($entryArray));
|
$this->assertEquals (8, count($entryArray));
|
||||||
$this->assertEquals (-1, $totalNumber);
|
$this->assertEquals (-1, $totalNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetBooksBySeries ()
|
public function testGetBooksBySeries ()
|
||||||
{
|
{
|
||||||
// All book from the Sherlock Holmes series
|
// All book from the Sherlock Holmes series
|
||||||
list ($entryArray, $totalNumber) = Book::getBooksBySeries (1, -1);
|
list ($entryArray, $totalNumber) = Book::getBooksBySeries (1, -1);
|
||||||
$this->assertEquals (7, count($entryArray));
|
$this->assertEquals (7, count($entryArray));
|
||||||
$this->assertEquals (-1, $totalNumber);
|
$this->assertEquals (-1, $totalNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetBooksByPublisher ()
|
public function testGetBooksByPublisher ()
|
||||||
{
|
{
|
||||||
// All books from Strand Magazine
|
// All books from Strand Magazine
|
||||||
list ($entryArray, $totalNumber) = Book::getBooksByPublisher (6, -1);
|
list ($entryArray, $totalNumber) = Book::getBooksByPublisher (6, -1);
|
||||||
$this->assertEquals (8, count($entryArray));
|
$this->assertEquals (8, count($entryArray));
|
||||||
$this->assertEquals (-1, $totalNumber);
|
$this->assertEquals (-1, $totalNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetBooksByTag ()
|
public function testGetBooksByTag ()
|
||||||
{
|
{
|
||||||
// All book with the Fiction tag
|
// All book with the Fiction tag
|
||||||
list ($entryArray, $totalNumber) = Book::getBooksByTag (1, -1);
|
list ($entryArray, $totalNumber) = Book::getBooksByTag (1, -1);
|
||||||
$this->assertEquals (14, count($entryArray));
|
$this->assertEquals (14, count($entryArray));
|
||||||
$this->assertEquals (-1, $totalNumber);
|
$this->assertEquals (-1, $totalNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetBooksByLanguage ()
|
public function testGetBooksByLanguage ()
|
||||||
{
|
{
|
||||||
// All english book (= all books)
|
// All english book (= all books)
|
||||||
list ($entryArray, $totalNumber) = Book::getBooksByLanguage (1, -1);
|
list ($entryArray, $totalNumber) = Book::getBooksByLanguage (1, -1);
|
||||||
$this->assertEquals (14, count($entryArray));
|
$this->assertEquals (14, count($entryArray));
|
||||||
$this->assertEquals (-1, $totalNumber);
|
$this->assertEquals (-1, $totalNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetAllBooks ()
|
public function testGetAllBooks ()
|
||||||
{
|
{
|
||||||
// All books by first letter
|
// All books by first letter
|
||||||
$entryArray = Book::getAllBooks ();
|
$entryArray = Book::getAllBooks ();
|
||||||
$this->assertCount (9, $entryArray);
|
$this->assertCount (9, $entryArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetBooksByStartingLetter ()
|
public function testGetBooksByStartingLetter ()
|
||||||
{
|
{
|
||||||
// All books by first letter
|
// All books by first letter
|
||||||
list ($entryArray, $totalNumber) = Book::getBooksByStartingLetter ("T", -1);
|
list ($entryArray, $totalNumber) = Book::getBooksByStartingLetter ("T", -1);
|
||||||
$this->assertEquals (-1, $totalNumber);
|
$this->assertEquals (-1, $totalNumber);
|
||||||
$this->assertCount (3, $entryArray);
|
$this->assertCount (3, $entryArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetBookByDataId ()
|
public function testGetBookByDataId ()
|
||||||
{
|
{
|
||||||
$book = Book::getBookByDataId (17);
|
$book = Book::getBookByDataId (17);
|
||||||
|
|
||||||
$this->assertEquals ("Alice's Adventures in Wonderland", $book->getTitle ());
|
$this->assertEquals ("Alice's Adventures in Wonderland", $book->getTitle ());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetAllRecentBooks ()
|
public function testGetAllRecentBooks ()
|
||||||
{
|
{
|
||||||
// All recent books
|
// All recent books
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
$config['cops_recentbooks_limit'] = 2;
|
$config['cops_recentbooks_limit'] = 2;
|
||||||
|
|
||||||
$entryArray = Book::getAllRecentBooks ();
|
$entryArray = Book::getAllRecentBooks ();
|
||||||
$this->assertCount (2, $entryArray);
|
$this->assertCount (2, $entryArray);
|
||||||
|
|
||||||
$config['cops_recentbooks_limit'] = 50;
|
$config['cops_recentbooks_limit'] = 50;
|
||||||
|
|
||||||
$entryArray = Book::getAllRecentBooks ();
|
$entryArray = Book::getAllRecentBooks ();
|
||||||
$this->assertCount (14, $entryArray);
|
$this->assertCount (14, $entryArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetBookById ()
|
public function testGetBookById ()
|
||||||
{
|
{
|
||||||
// also check most of book's class methods
|
// also check most of book's class methods
|
||||||
$book = Book::getBookById(2);
|
$book = Book::getBookById(2);
|
||||||
$this->assertEquals ("The Return of Sherlock Holmes", $book->getTitle ());
|
$this->assertEquals ("The Return of Sherlock Holmes", $book->getTitle ());
|
||||||
$this->assertEquals ("urn:uuid:87ddbdeb-1e27-4d06-b79b-4b2a3bfc6a5f", $book->getEntryId ());
|
$this->assertEquals ("urn:uuid:87ddbdeb-1e27-4d06-b79b-4b2a3bfc6a5f", $book->getEntryId ());
|
||||||
$this->assertEquals ("index.php?page=13&id=2", $book->getDetailUrl ());
|
$this->assertEquals ("index.php?page=13&id=2", $book->getDetailUrl ());
|
||||||
$this->assertEquals ("Doyle, Arthur Conan", $book->getAuthorsName ());
|
$this->assertEquals ("Doyle, Arthur Conan", $book->getAuthorsName ());
|
||||||
$this->assertEquals ("Fiction, Mystery & Detective, Short Stories", $book->getTagsName ());
|
$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 & 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 1901–1902 (although setting it before Holmes\' death) Doyle came under intense pressure to revive his famous character.</p>', $book->getComment (false));
|
$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 & 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 1901–1902 (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 ("English", $book->getLanguages ());
|
||||||
$this->assertEquals ("", $book->getRating ());
|
$this->assertEquals ("", $book->getRating ());
|
||||||
$book->rating = 8;
|
$book->rating = 8;
|
||||||
// 4 filled stars and one empty
|
// 4 filled stars and one empty
|
||||||
$this->assertEquals ("★★★★☆", $book->getRating ());
|
$this->assertEquals ("★★★★☆", $book->getRating ());
|
||||||
$this->assertEquals ("Strand Magazine", $book->getPublisher()->name);
|
$this->assertEquals ("Strand Magazine", $book->getPublisher()->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetMostInterestingDataToSendToKindle ()
|
public function testGetMostInterestingDataToSendToKindle ()
|
||||||
{
|
{
|
||||||
// Get Alice (available as MOBI, PDF, EPUB in that order)
|
// Get Alice (available as MOBI, PDF, EPUB in that order)
|
||||||
$book = Book::getBookById(17);
|
$book = Book::getBookById(17);
|
||||||
$data = $book->GetMostInterestingDataToSendToKindle ();
|
$data = $book->GetMostInterestingDataToSendToKindle ();
|
||||||
$this->assertEquals ("MOBI", $data->format);
|
$this->assertEquals ("MOBI", $data->format);
|
||||||
array_shift ($book->datas);
|
array_shift ($book->datas);
|
||||||
$data = $book->GetMostInterestingDataToSendToKindle ();
|
$data = $book->GetMostInterestingDataToSendToKindle ();
|
||||||
$this->assertEquals ("PDF", $data->format);
|
$this->assertEquals ("PDF", $data->format);
|
||||||
array_shift ($book->datas);
|
array_shift ($book->datas);
|
||||||
$data = $book->GetMostInterestingDataToSendToKindle ();
|
$data = $book->GetMostInterestingDataToSendToKindle ();
|
||||||
$this->assertEquals ("EPUB", $data->format);
|
$this->assertEquals ("EPUB", $data->format);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetDataById ()
|
public function testGetDataById ()
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
// Get Alice MOBI=>17, PDF=>19, EPUB=>20
|
// Get Alice MOBI=>17, PDF=>19, EPUB=>20
|
||||||
$book = Book::getBookById(17);
|
$book = Book::getBookById(17);
|
||||||
$data = $book->getDataById (17);
|
$data = $book->getDataById (17);
|
||||||
$this->assertEquals ("MOBI", $data->format);
|
$this->assertEquals ("MOBI", $data->format);
|
||||||
$data = $book->getDataById (20);
|
$data = $book->getDataById (20);
|
||||||
$this->assertEquals ("EPUB", $data->format);
|
$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.epub", $data->getUpdatedFilenameEpub ());
|
||||||
$this->assertEquals ("Carroll, Lewis - Alice's Adventures in Wonderland.kepub.epub", $data->getUpdatedFilenameKepub ());
|
$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 ());
|
$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_use_url_rewriting'] = "1";
|
||||||
$config['cops_provide_kepub'] = "1";
|
$config['cops_provide_kepub'] = "1";
|
||||||
$_SERVER["HTTP_USER_AGENT"] = "Kobo";
|
$_SERVER["HTTP_USER_AGENT"] = "Kobo";
|
||||||
$this->assertEquals ("download/20/Carroll%2C+Lewis+-+Alice%27s+Adventures+in+Wonderland.kepub.epub", $data->getHtmlLink ());
|
$this->assertEquals ("download/20/Carroll%2C+Lewis+-+Alice%27s+Adventures+in+Wonderland.kepub.epub", $data->getHtmlLink ());
|
||||||
$_SERVER["HTTP_USER_AGENT"] = "Firefox";
|
$_SERVER["HTTP_USER_AGENT"] = "Firefox";
|
||||||
$this->assertEquals ("download/20/Alice%27s+Adventures+in+Wonderland+-+Lewis+Carroll.epub", $data->getHtmlLink ());
|
$this->assertEquals ("download/20/Alice%27s+Adventures+in+Wonderland+-+Lewis+Carroll.epub", $data->getHtmlLink ());
|
||||||
$config['cops_use_url_rewriting'] = "0";
|
$config['cops_use_url_rewriting'] = "0";
|
||||||
$this->assertEquals ("fetch.php?data=20&type=epub&id=17", $data->getHtmlLink ());
|
$this->assertEquals ("fetch.php?data=20&type=epub&id=17", $data->getHtmlLink ());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTypeaheadSearch ()
|
public function testTypeaheadSearch ()
|
||||||
{
|
{
|
||||||
$_GET["query"] = "fic";
|
$_GET["query"] = "fic";
|
||||||
$_GET["search"] = "1";
|
$_GET["search"] = "1";
|
||||||
|
|
||||||
$array = getJson ();
|
$array = getJson ();
|
||||||
|
|
||||||
$this->assertCount (3, $array);
|
$this->assertCount (3, $array);
|
||||||
$this->assertEquals ("2 tags", $array[0]["title"]);
|
$this->assertEquals ("2 tags", $array[0]["title"]);
|
||||||
$this->assertEquals ("Fiction", $array[1]["title"]);
|
$this->assertEquals ("Fiction", $array[1]["title"]);
|
||||||
$this->assertEquals ("Science Fiction", $array[2]["title"]);
|
$this->assertEquals ("Science Fiction", $array[2]["title"]);
|
||||||
|
|
||||||
$_GET["query"] = "car";
|
$_GET["query"] = "car";
|
||||||
$_GET["search"] = "1";
|
$_GET["search"] = "1";
|
||||||
|
|
||||||
$array = getJson ();
|
$array = getJson ();
|
||||||
|
|
||||||
$this->assertCount (4, $array);
|
$this->assertCount (4, $array);
|
||||||
$this->assertEquals ("1 book", $array[0]["title"]);
|
$this->assertEquals ("1 book", $array[0]["title"]);
|
||||||
$this->assertEquals ("A Study in Scarlet", $array[1]["title"]);
|
$this->assertEquals ("A Study in Scarlet", $array[1]["title"]);
|
||||||
$this->assertEquals ("1 author", $array[2]["title"]);
|
$this->assertEquals ("1 author", $array[2]["title"]);
|
||||||
$this->assertEquals ("Carroll, Lewis", $array[3]["title"]);
|
$this->assertEquals ("Carroll, Lewis", $array[3]["title"]);
|
||||||
|
|
||||||
$_GET["query"] = "art";
|
$_GET["query"] = "art";
|
||||||
$_GET["search"] = "1";
|
$_GET["search"] = "1";
|
||||||
|
|
||||||
$array = getJson ();
|
$array = getJson ();
|
||||||
|
|
||||||
$this->assertCount (4, $array);
|
$this->assertCount (4, $array);
|
||||||
$this->assertEquals ("1 author", $array[0]["title"]);
|
$this->assertEquals ("1 author", $array[0]["title"]);
|
||||||
$this->assertEquals ("Doyle, Arthur Conan", $array[1]["title"]);
|
$this->assertEquals ("Doyle, Arthur Conan", $array[1]["title"]);
|
||||||
$this->assertEquals ("1 series", $array[2]["title"]);
|
$this->assertEquals ("1 series", $array[2]["title"]);
|
||||||
$this->assertEquals ("D'Artagnan Romances", $array[3]["title"]);
|
$this->assertEquals ("D'Artagnan Romances", $array[3]["title"]);
|
||||||
|
|
||||||
$_GET["query"] = "Macmillan";
|
$_GET["query"] = "Macmillan";
|
||||||
$_GET["search"] = "1";
|
$_GET["search"] = "1";
|
||||||
|
|
||||||
$array = getJson ();
|
$array = getJson ();
|
||||||
|
|
||||||
$this->assertCount (3, $array);
|
$this->assertCount (3, $array);
|
||||||
$this->assertEquals ("2 publishers", $array[0]["title"]);
|
$this->assertEquals ("2 publishers", $array[0]["title"]);
|
||||||
$this->assertEquals ("Macmillan and Co. London", $array[1]["title"]);
|
$this->assertEquals ("Macmillan and Co. London", $array[1]["title"]);
|
||||||
$this->assertEquals ("Macmillan Publishers USA", $array[2]["title"]);
|
$this->assertEquals ("Macmillan Publishers USA", $array[2]["title"]);
|
||||||
|
|
||||||
$_GET["query"] = NULL;
|
$_GET["query"] = NULL;
|
||||||
$_GET["search"] = NULL;
|
$_GET["search"] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTypeaheadSearchMultiDatabase ()
|
public function testTypeaheadSearchMultiDatabase ()
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
$_GET["query"] = "art";
|
$_GET["query"] = "art";
|
||||||
$_GET["search"] = "1";
|
$_GET["search"] = "1";
|
||||||
$_GET["multi"] = "1";
|
$_GET["multi"] = "1";
|
||||||
|
|
||||||
$config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/",
|
$config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/",
|
||||||
"One book" => dirname(__FILE__) . "/BaseWithOneBook/");
|
"One book" => dirname(__FILE__) . "/BaseWithOneBook/");
|
||||||
|
|
||||||
$array = getJson ();
|
$array = getJson ();
|
||||||
|
|
||||||
$this->assertCount (4, $array);
|
$this->assertCount (4, $array);
|
||||||
$this->assertEquals ("Some books", $array[0]["title"]);
|
$this->assertEquals ("Some books", $array[0]["title"]);
|
||||||
$this->assertEquals ("No book", $array[1]["title"]);
|
$this->assertEquals ("No book", $array[1]["title"]);
|
||||||
$this->assertEquals ("One book", $array[2]["title"]);
|
$this->assertEquals ("One book", $array[2]["title"]);
|
||||||
$this->assertEquals ("1 book", $array[3]["title"]);
|
$this->assertEquals ("1 book", $array[3]["title"]);
|
||||||
|
|
||||||
$_GET["query"] = NULL;
|
$_GET["query"] = NULL;
|
||||||
$_GET["search"] = NULL;
|
$_GET["search"] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown () {
|
public function tearDown () {
|
||||||
Base::clearDb ();
|
Base::clearDb ();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,42 +1,42 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Code coverage checker. Analyzes a given `clover.xml` report produced
|
* Code coverage checker. Analyzes a given `clover.xml` report produced
|
||||||
* by PHPUnit and checks if coverage fits expected ratio
|
* by PHPUnit and checks if coverage fits expected ratio
|
||||||
*
|
*
|
||||||
* Usage:
|
* Usage:
|
||||||
* php coverage-checker <path-to-clover> <pass-percentage>
|
* php coverage-checker <path-to-clover> <pass-percentage>
|
||||||
*
|
*
|
||||||
* @author Marco Pivetta <ocramius@gmail.com>
|
* @author Marco Pivetta <ocramius@gmail.com>
|
||||||
* @see http://ocramius.github.io/blog/automated-code-coverage-check-for-github-pull-requests-with-travis/
|
* @see http://ocramius.github.io/blog/automated-code-coverage-check-for-github-pull-requests-with-travis/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$inputFile = $argv[1];
|
$inputFile = $argv[1];
|
||||||
$percentage = min(100, max(0, (int) $argv[2]));
|
$percentage = min(100, max(0, (int) $argv[2]));
|
||||||
|
|
||||||
if (!file_exists($inputFile)) {
|
if (!file_exists($inputFile)) {
|
||||||
throw new InvalidArgumentException('Invalid input file provided');
|
throw new InvalidArgumentException('Invalid input file provided');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$percentage) {
|
if (!$percentage) {
|
||||||
throw new InvalidArgumentException('An integer checked percentage must be given as second parameter');
|
throw new InvalidArgumentException('An integer checked percentage must be given as second parameter');
|
||||||
}
|
}
|
||||||
|
|
||||||
$xml = new SimpleXMLElement(file_get_contents($inputFile));
|
$xml = new SimpleXMLElement(file_get_contents($inputFile));
|
||||||
$metrics = $xml->xpath('//metrics');
|
$metrics = $xml->xpath('//metrics');
|
||||||
$totalElements = 0;
|
$totalElements = 0;
|
||||||
$checkedElements = 0;
|
$checkedElements = 0;
|
||||||
|
|
||||||
foreach ($metrics as $metric) {
|
foreach ($metrics as $metric) {
|
||||||
$totalElements += (int) $metric['elements'];
|
$totalElements += (int) $metric['elements'];
|
||||||
$checkedElements += (int) $metric['coveredelements'];
|
$checkedElements += (int) $metric['coveredelements'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$coverage = ($checkedElements / $totalElements) * 100;
|
$coverage = ($checkedElements / $totalElements) * 100;
|
||||||
|
|
||||||
if ($coverage < $percentage) {
|
if ($coverage < $percentage) {
|
||||||
echo 'Code coverage is ' . $coverage . '%, which is below the accepted ' . $percentage . '%' . PHP_EOL;
|
echo 'Code coverage is ' . $coverage . '%, which is below the accepted ' . $percentage . '%' . PHP_EOL;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
echo 'Code coverage is ' . $coverage . '% - OK!' . PHP_EOL;
|
echo 'Code coverage is ' . $coverage . '% - OK!' . PHP_EOL;
|
||||||
|
|
|
@ -1,62 +1,62 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* COPS (Calibre OPDS PHP Server) test file
|
* COPS (Calibre OPDS PHP Server) test file
|
||||||
*
|
*
|
||||||
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
||||||
* @author Sébastien Lucas <sebastien@slucas.fr>
|
* @author Sébastien Lucas <sebastien@slucas.fr>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once (dirname(__FILE__) . "/config_test.php");
|
require_once (dirname(__FILE__) . "/config_test.php");
|
||||||
require_once (dirname(__FILE__) . "/../book.php");
|
require_once (dirname(__FILE__) . "/../book.php");
|
||||||
|
|
||||||
class PageMultiDatabaseTest extends PHPUnit_Framework_TestCase
|
class PageMultiDatabaseTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testPageIndex ()
|
public function testPageIndex ()
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
$config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/",
|
$config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/",
|
||||||
"One book" => dirname(__FILE__) . "/BaseWithOneBook/");
|
"One book" => dirname(__FILE__) . "/BaseWithOneBook/");
|
||||||
$page = Base::PAGE_INDEX;
|
$page = Base::PAGE_INDEX;
|
||||||
$query = NULL;
|
$query = NULL;
|
||||||
$qid = NULL;
|
$qid = NULL;
|
||||||
$n = "1";
|
$n = "1";
|
||||||
|
|
||||||
$currentPage = Page::getPage ($page, $qid, $query, $n);
|
$currentPage = Page::getPage ($page, $qid, $query, $n);
|
||||||
$currentPage->InitializeContent ();
|
$currentPage->InitializeContent ();
|
||||||
|
|
||||||
$this->assertEquals ($config['cops_title_default'], $currentPage->title);
|
$this->assertEquals ($config['cops_title_default'], $currentPage->title);
|
||||||
$this->assertCount (2, $currentPage->entryArray);
|
$this->assertCount (2, $currentPage->entryArray);
|
||||||
$this->assertEquals ("Some books", $currentPage->entryArray [0]->title);
|
$this->assertEquals ("Some books", $currentPage->entryArray [0]->title);
|
||||||
$this->assertEquals ("14 books", $currentPage->entryArray [0]->content);
|
$this->assertEquals ("14 books", $currentPage->entryArray [0]->content);
|
||||||
$this->assertEquals ("One book", $currentPage->entryArray [1]->title);
|
$this->assertEquals ("One book", $currentPage->entryArray [1]->title);
|
||||||
$this->assertEquals ("1 book", $currentPage->entryArray [1]->content);
|
$this->assertEquals ("1 book", $currentPage->entryArray [1]->content);
|
||||||
$this->assertFalse ($currentPage->ContainsBook ());
|
$this->assertFalse ($currentPage->ContainsBook ());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPageSearchXXX ()
|
public function testPageSearchXXX ()
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
$config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/",
|
$config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/",
|
||||||
"One book" => dirname(__FILE__) . "/BaseWithOneBook/");
|
"One book" => dirname(__FILE__) . "/BaseWithOneBook/");
|
||||||
$page = Base::PAGE_OPENSEARCH_QUERY;
|
$page = Base::PAGE_OPENSEARCH_QUERY;
|
||||||
$query = "art";
|
$query = "art";
|
||||||
$qid = NULL;
|
$qid = NULL;
|
||||||
$n = "1";
|
$n = "1";
|
||||||
|
|
||||||
$currentPage = Page::getPage ($page, $qid, $query, $n);
|
$currentPage = Page::getPage ($page, $qid, $query, $n);
|
||||||
$currentPage->InitializeContent ();
|
$currentPage->InitializeContent ();
|
||||||
|
|
||||||
$this->assertEquals ("Search result for *art*", $currentPage->title);
|
$this->assertEquals ("Search result for *art*", $currentPage->title);
|
||||||
$this->assertCount (2, $currentPage->entryArray);
|
$this->assertCount (2, $currentPage->entryArray);
|
||||||
$this->assertEquals ("Some books", $currentPage->entryArray [0]->title);
|
$this->assertEquals ("Some books", $currentPage->entryArray [0]->title);
|
||||||
$this->assertEquals ("10 books", $currentPage->entryArray [0]->content);
|
$this->assertEquals ("10 books", $currentPage->entryArray [0]->content);
|
||||||
$this->assertEquals ("One book", $currentPage->entryArray [1]->title);
|
$this->assertEquals ("One book", $currentPage->entryArray [1]->title);
|
||||||
$this->assertEquals ("1 book", $currentPage->entryArray [1]->content);
|
$this->assertEquals ("1 book", $currentPage->entryArray [1]->content);
|
||||||
$this->assertFalse ($currentPage->ContainsBook ());
|
$this->assertFalse ($currentPage->ContainsBook ());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function tearDownAfterClass () {
|
public static function tearDownAfterClass () {
|
||||||
Base::clearDb ();
|
Base::clearDb ();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
1236
test/pageTest.php
1236
test/pageTest.php
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue