2013-10-03 16:22:21 +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 16:22:21 +03:00
require_once ( dirname ( __FILE__ ) . " /config_test.php " );
require_once ( dirname ( __FILE__ ) . " /../book.php " );
**2012-11-22**
**Added global support for publishers**
Files modified:
*base.php*
- changed class Entry,
- adding a constant ```cops:publishers``` to the icon array for the feed.
- changed class Page
- added branches to the page selector switch
- changed Page->public function InitializeContent
- added call to pull publisher count from database
- changed class PageAllBooks
- changed it so ```getCurrentOption``` is actually used...
- added page descendant class ```PageAllPublishers```
- handles pulling the publishers category from database
- added page descendant class ```PagePublisherDetail```
- handles pulling the books per publisher data from database
- changed class PageQueryResult
- added constant and switches for publisher search scope
- abstract class Base
- added constants for the publisher pages
*book.php*
- added require statement for publisher.php
- added ```SQL_BOOKS_BY_PUBLISHER``` query to retrieve books by publisher.
- changed class Book
- added query constant
- added publisher item
- added test in case no known publisher
- added publishername and url array elements for the JSON output
- added public function ```getPublisher```
- added public static function ```getBooksByPublisher``` to fire the query
- changed function getJson
- added publisher category to search
- added publishername (single) and publishertitle(plural) localization entries to i18n translation array
*index.php*
- added require statement for publisher.php
*lang/Localization_en.json
- added new localization entries for publisher labels (see below)
```
"publisher.alphabetical.many":"Alphabetical index of the {0} publishers",
"publisher.alphabetical.none":"Alphabetical index of absolutely no publisher",
"publisher.alphabetical.one":"Alphabetical index of the single publisher",
"publisher.name":"Publisher",
"publisher.title":"Publishers",
"publisherword.many":"{0} publishers",
"publisherword.none":"No publisher",
"publisherword.one":"1 publisher",
"search.result.publisher":"Search result for *{0}* in publishers",
```
*templates\bookdetail.html*
- added publisher label and item to bookdetail popup
*test\bookTest.php*
- added indices and names of publishers added to testdatabase as comment
- added test function ```testGetBooksByPublisher```
- changed test function testGetBookById to add assertion for publisher name
- changed test function testTypeaheadSearch to add search on partial publisher name.
*test\pageTest.php*
- changed test function testPageIndex to insert publisher category and adjust page indices
- changed test function testPageIndexWithCustomColum to adjust for the changed page indices
- added test function testPageAllPublishers
- added test function testPagePublishersDetail
- added test function testPageSearchScopePublishers
*test\BaseWithSomeBooks\metadata.db*
- added 5 publishers spread across all 14 books, replacing the original publisher Feedbooks
Files added:
*publisher.php*
2013-11-22 23:08:09 +02:00
/*
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
*/
2013-10-12 08:13:41 +03:00
class BookTest extends PHPUnit_Framework_TestCase
2013-10-03 16:22:21 +03:00
{
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 ;
}
2013-10-03 19:27:36 +03:00
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 );
}
2013-10-04 09:17:42 +03:00
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 );
}
**2012-11-22**
**Added global support for publishers**
Files modified:
*base.php*
- changed class Entry,
- adding a constant ```cops:publishers``` to the icon array for the feed.
- changed class Page
- added branches to the page selector switch
- changed Page->public function InitializeContent
- added call to pull publisher count from database
- changed class PageAllBooks
- changed it so ```getCurrentOption``` is actually used...
- added page descendant class ```PageAllPublishers```
- handles pulling the publishers category from database
- added page descendant class ```PagePublisherDetail```
- handles pulling the books per publisher data from database
- changed class PageQueryResult
- added constant and switches for publisher search scope
- abstract class Base
- added constants for the publisher pages
*book.php*
- added require statement for publisher.php
- added ```SQL_BOOKS_BY_PUBLISHER``` query to retrieve books by publisher.
- changed class Book
- added query constant
- added publisher item
- added test in case no known publisher
- added publishername and url array elements for the JSON output
- added public function ```getPublisher```
- added public static function ```getBooksByPublisher``` to fire the query
- changed function getJson
- added publisher category to search
- added publishername (single) and publishertitle(plural) localization entries to i18n translation array
*index.php*
- added require statement for publisher.php
*lang/Localization_en.json
- added new localization entries for publisher labels (see below)
```
"publisher.alphabetical.many":"Alphabetical index of the {0} publishers",
"publisher.alphabetical.none":"Alphabetical index of absolutely no publisher",
"publisher.alphabetical.one":"Alphabetical index of the single publisher",
"publisher.name":"Publisher",
"publisher.title":"Publishers",
"publisherword.many":"{0} publishers",
"publisherword.none":"No publisher",
"publisherword.one":"1 publisher",
"search.result.publisher":"Search result for *{0}* in publishers",
```
*templates\bookdetail.html*
- added publisher label and item to bookdetail popup
*test\bookTest.php*
- added indices and names of publishers added to testdatabase as comment
- added test function ```testGetBooksByPublisher```
- changed test function testGetBookById to add assertion for publisher name
- changed test function testTypeaheadSearch to add search on partial publisher name.
*test\pageTest.php*
- changed test function testPageIndex to insert publisher category and adjust page indices
- changed test function testPageIndexWithCustomColum to adjust for the changed page indices
- added test function testPageAllPublishers
- added test function testPagePublishersDetail
- added test function testPageSearchScopePublishers
*test\BaseWithSomeBooks\metadata.db*
- added 5 publishers spread across all 14 books, replacing the original publisher Feedbooks
Files added:
*publisher.php*
2013-11-22 23:08:09 +02:00
public function testGetBooksByPublisher ()
{
// All books from Strand Magazine
list ( $entryArray , $totalNumber ) = Book :: getBooksByPublisher ( 6 , - 1 );
$this -> assertEquals ( 8 , count ( $entryArray ));
$this -> assertEquals ( - 1 , $totalNumber );
}
2013-10-04 09:17:42 +03:00
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 );
}
2013-10-04 13:19:34 +03:00
public function testGetAllBooks ()
{
// All books by first letter
2013-10-04 13:30:11 +03:00
$entryArray = Book :: getAllBooks ();
2013-10-04 13:19:34 +03:00
$this -> assertCount ( 9 , $entryArray );
}
2013-10-04 13:30:11 +03:00
public function testGetBooksByStartingLetter ()
{
// All books by first letter
list ( $entryArray , $totalNumber ) = Book :: getBooksByStartingLetter ( " T " , - 1 );
2013-11-26 19:20:55 +02:00
$this -> assertEquals ( - 1 , $totalNumber );
2013-10-04 13:30:11 +03:00
$this -> assertCount ( 3 , $entryArray );
}
2013-12-03 19:35:48 +02:00
public function testGetBookByDataId ()
{
$book = Book :: getBookByDataId ( 17 );
$this -> assertEquals ( " Alice's Adventures in Wonderland " , $book -> getTitle ());
}
2013-10-04 13:30:11 +03:00
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 );
}
2013-10-03 16:22:21 +03:00
2013-10-04 09:17:42 +03:00
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 & 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 ));
2013-10-04 13:19:34 +03:00
$this -> assertEquals ( " English " , $book -> getLanguages ());
$this -> assertEquals ( " " , $book -> getRating ());
2013-12-03 19:31:56 +02:00
$book -> rating = 8 ;
// 4 filled stars and one empty
$this -> assertEquals ( " ★★★★☆ " , $book -> getRating ());
**2012-11-22**
**Added global support for publishers**
Files modified:
*base.php*
- changed class Entry,
- adding a constant ```cops:publishers``` to the icon array for the feed.
- changed class Page
- added branches to the page selector switch
- changed Page->public function InitializeContent
- added call to pull publisher count from database
- changed class PageAllBooks
- changed it so ```getCurrentOption``` is actually used...
- added page descendant class ```PageAllPublishers```
- handles pulling the publishers category from database
- added page descendant class ```PagePublisherDetail```
- handles pulling the books per publisher data from database
- changed class PageQueryResult
- added constant and switches for publisher search scope
- abstract class Base
- added constants for the publisher pages
*book.php*
- added require statement for publisher.php
- added ```SQL_BOOKS_BY_PUBLISHER``` query to retrieve books by publisher.
- changed class Book
- added query constant
- added publisher item
- added test in case no known publisher
- added publishername and url array elements for the JSON output
- added public function ```getPublisher```
- added public static function ```getBooksByPublisher``` to fire the query
- changed function getJson
- added publisher category to search
- added publishername (single) and publishertitle(plural) localization entries to i18n translation array
*index.php*
- added require statement for publisher.php
*lang/Localization_en.json
- added new localization entries for publisher labels (see below)
```
"publisher.alphabetical.many":"Alphabetical index of the {0} publishers",
"publisher.alphabetical.none":"Alphabetical index of absolutely no publisher",
"publisher.alphabetical.one":"Alphabetical index of the single publisher",
"publisher.name":"Publisher",
"publisher.title":"Publishers",
"publisherword.many":"{0} publishers",
"publisherword.none":"No publisher",
"publisherword.one":"1 publisher",
"search.result.publisher":"Search result for *{0}* in publishers",
```
*templates\bookdetail.html*
- added publisher label and item to bookdetail popup
*test\bookTest.php*
- added indices and names of publishers added to testdatabase as comment
- added test function ```testGetBooksByPublisher```
- changed test function testGetBookById to add assertion for publisher name
- changed test function testTypeaheadSearch to add search on partial publisher name.
*test\pageTest.php*
- changed test function testPageIndex to insert publisher category and adjust page indices
- changed test function testPageIndexWithCustomColum to adjust for the changed page indices
- added test function testPageAllPublishers
- added test function testPagePublishersDetail
- added test function testPageSearchScopePublishers
*test\BaseWithSomeBooks\metadata.db*
- added 5 publishers spread across all 14 books, replacing the original publisher Feedbooks
Files added:
*publisher.php*
2013-11-22 23:08:09 +02:00
$this -> assertEquals ( " Strand Magazine " , $book -> getPublisher () -> name );
2013-10-04 09:17:42 +03:00
}
2013-12-03 19:26:01 +02:00
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 );
}
2013-12-03 19:29:28 +02:00
public function testGetDataById ()
{
// 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 );
}
2013-10-15 09:31:26 +03:00
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 " ]);
**2012-11-22**
**Added global support for publishers**
Files modified:
*base.php*
- changed class Entry,
- adding a constant ```cops:publishers``` to the icon array for the feed.
- changed class Page
- added branches to the page selector switch
- changed Page->public function InitializeContent
- added call to pull publisher count from database
- changed class PageAllBooks
- changed it so ```getCurrentOption``` is actually used...
- added page descendant class ```PageAllPublishers```
- handles pulling the publishers category from database
- added page descendant class ```PagePublisherDetail```
- handles pulling the books per publisher data from database
- changed class PageQueryResult
- added constant and switches for publisher search scope
- abstract class Base
- added constants for the publisher pages
*book.php*
- added require statement for publisher.php
- added ```SQL_BOOKS_BY_PUBLISHER``` query to retrieve books by publisher.
- changed class Book
- added query constant
- added publisher item
- added test in case no known publisher
- added publishername and url array elements for the JSON output
- added public function ```getPublisher```
- added public static function ```getBooksByPublisher``` to fire the query
- changed function getJson
- added publisher category to search
- added publishername (single) and publishertitle(plural) localization entries to i18n translation array
*index.php*
- added require statement for publisher.php
*lang/Localization_en.json
- added new localization entries for publisher labels (see below)
```
"publisher.alphabetical.many":"Alphabetical index of the {0} publishers",
"publisher.alphabetical.none":"Alphabetical index of absolutely no publisher",
"publisher.alphabetical.one":"Alphabetical index of the single publisher",
"publisher.name":"Publisher",
"publisher.title":"Publishers",
"publisherword.many":"{0} publishers",
"publisherword.none":"No publisher",
"publisherword.one":"1 publisher",
"search.result.publisher":"Search result for *{0}* in publishers",
```
*templates\bookdetail.html*
- added publisher label and item to bookdetail popup
*test\bookTest.php*
- added indices and names of publishers added to testdatabase as comment
- added test function ```testGetBooksByPublisher```
- changed test function testGetBookById to add assertion for publisher name
- changed test function testTypeaheadSearch to add search on partial publisher name.
*test\pageTest.php*
- changed test function testPageIndex to insert publisher category and adjust page indices
- changed test function testPageIndexWithCustomColum to adjust for the changed page indices
- added test function testPageAllPublishers
- added test function testPagePublishersDetail
- added test function testPageSearchScopePublishers
*test\BaseWithSomeBooks\metadata.db*
- added 5 publishers spread across all 14 books, replacing the original publisher Feedbooks
Files added:
*publisher.php*
2013-11-22 23:08:09 +02:00
$_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 " ]);
2013-10-15 09:31:26 +03:00
$_GET [ " query " ] = NULL ;
$_GET [ " search " ] = NULL ;
}
2013-11-26 18:39:17 +02:00
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 ();
}
2013-10-03 16:22:21 +03:00
}