Completed
Pull Request — master (#274)
by Markus
06:46
created

BookTest   C

Complexity

Total Complexity 59

Size/Duplication

Total Lines 580
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 580
rs 6.1904
c 0
b 0
f 0
wmc 59
lcom 1
cbo 4

How to fix   Complexity   

Complex Class

Complex classes like BookTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use BookTest, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * COPS (Calibre OPDS PHP Server) test file
4
 *
5
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6
 * @author     Sébastien Lucas <[email protected]>
7
 */
8
9
require_once (dirname(__FILE__) . "/config_test.php");
10
11
/*
12
Publishers:
13
id:2 (2 books)   Macmillan and Co. London:   Lewis Caroll
14
id:3 (2 books)   D. Appleton and Company     Alexander Dumas
15
id:4 (1 book)    Macmillan Publishers USA:   Jack London
16
id:5 (1 book)    Pierson's Magazine:         H. G. Wells
17
id:6 (8 books)   Strand Magazine:            Arthur Conan Doyle
18
*/
19
20
define ("TEST_THUMBNAIL", dirname(__FILE__) . "/thumbnail.jpg");
21
define ("COVER_WIDTH", 400);
22
define ("COVER_HEIGHT", 600);
23
24
class BookTest extends PHPUnit_Framework_TestCase
25
{
26
    public static function setUpBeforeClass()
27
    {
28
        $book = Book::getBookById(2);
29
        if (!is_dir ($book->path)) {
30
            mkdir ($book->path, 0777, true);
31
        }
32
        $im = imagecreatetruecolor(COVER_WIDTH, COVER_HEIGHT);
33
        $text_color = imagecolorallocate($im, 255, 0, 0);
34
        imagestring($im, 1, 5, 5,  'Book cover', $text_color);
35
        imagejpeg ($im, $book->path . "/cover.jpg", 80);
36
    }
37
38
    public static function tearDownAfterClass()
39
    {
40
        $book = Book::getBookById(2);
41
        if (!file_exists ($book->path . "/cover.jpg")) {
42
            return;
43
        }
44
        unlink ($book->path . "/cover.jpg");
45
        rmdir ($book->path);
46
        rmdir (dirname ($book->path));
47
    }
48
49
    public function testGetBookCount ()
50
    {
51
        $this->assertEquals (15, Book::getBookCount ());
52
    }
53
54
    public function testGetCount ()
55
    {
56
        $entryArray = Book::getCount ();
57
        $this->assertEquals (2, count($entryArray));
58
59
        $entryAllBooks = $entryArray [0];
60
        $this->assertEquals ("Alphabetical index of the 15 books", $entryAllBooks->content);
61
62
        $entryRecentBooks = $entryArray [1];
63
        $this->assertEquals ("50 most recent books", $entryRecentBooks->content);
64
65
    }
66
67
    public function testGetCountRecent ()
68
    {
69
        global $config;
70
        $config['cops_recentbooks_limit'] = 0;
71
        $entryArray = Book::getCount ();
72
73
        $this->assertEquals (1, count($entryArray));
74
75
        $config['cops_recentbooks_limit'] = 2;
76
        $entryArray = Book::getCount ();
77
78
        $entryRecentBooks = $entryArray [1];
79
        $this->assertEquals ("2 most recent books", $entryRecentBooks->content);
80
81
        $config['cops_recentbooks_limit'] = 50;
82
    }
83
84
    public function testGetBooksByAuthor ()
85
    {
86
        // All book by Arthur Conan Doyle
87
        global $config;
88
89
        $config['cops_max_item_per_page'] = 5;
90
        list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, 1);
91
        $this->assertEquals (5, count($entryArray));
92
        $this->assertEquals (8, $totalNumber);
93
94
        list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, 2);
95
        $this->assertEquals (3, count($entryArray));
96
        $this->assertEquals (8, $totalNumber);
97
98
        $config['cops_max_item_per_page'] = -1;
99
        list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, -1);
100
        $this->assertEquals (8, count($entryArray));
101
        $this->assertEquals (-1, $totalNumber);
102
    }
103
104
    public function testGetBooksBySeries ()
105
    {
106
        // All book from the Sherlock Holmes series
107
        list ($entryArray, $totalNumber) = Book::getBooksBySeries (1, -1);
108
        $this->assertEquals (7, count($entryArray));
109
        $this->assertEquals (-1, $totalNumber);
110
    }
111
112
    public function testGetBooksByPublisher ()
113
    {
114
        // All books from Strand Magazine
115
        list ($entryArray, $totalNumber) = Book::getBooksByPublisher (6, -1);
116
        $this->assertEquals (8, count($entryArray));
117
        $this->assertEquals (-1, $totalNumber);
118
    }
119
120
    public function testGetBooksByTag ()
121
    {
122
        // All book with the Fiction tag
123
        list ($entryArray, $totalNumber) = Book::getBooksByTag (1, -1);
124
        $this->assertEquals (14, count($entryArray));
125
        $this->assertEquals (-1, $totalNumber);
126
    }
127
128
    public function testGetBooksByLanguage ()
129
    {
130
        // All english book (= all books)
131
        list ($entryArray, $totalNumber) = Book::getBooksByLanguage (1, -1);
132
        $this->assertEquals (14, count($entryArray));
133
        $this->assertEquals (-1, $totalNumber);
134
    }
135
136
    public function testGetAllBooks ()
137
    {
138
        // All books by first letter
139
        $entryArray = Book::getAllBooks ();
140
        $this->assertCount (9, $entryArray);
141
    }
142
143
    public function testGetBooksByStartingLetter ()
144
    {
145
        // All books by first letter
146
        list ($entryArray, $totalNumber) = Book::getBooksByStartingLetter ("T", -1);
147
        $this->assertEquals (-1, $totalNumber);
148
        $this->assertCount (3, $entryArray);
149
    }
150
151
    public function testGetBookByDataId ()
152
    {
153
        $book = Book::getBookByDataId (17);
154
155
        $this->assertEquals ("Alice's Adventures in Wonderland", $book->getTitle ());
156
    }
157
158
    public function testGetAllRecentBooks ()
159
    {
160
        // All recent books
161
        global $config;
162
163
        $config['cops_recentbooks_limit'] = 2;
164
165
        $entryArray = Book::getAllRecentBooks ();
166
        $this->assertCount (2, $entryArray);
167
168
        $config['cops_recentbooks_limit'] = 50;
169
170
        $entryArray = Book::getAllRecentBooks ();
171
        $this->assertCount (15, $entryArray);
172
    }
173
174
    /**
175
     * @dataProvider providerPublicationDate
176
     */
177
    public function testGetPubDate ($pubdate, $expectedYear)
178
    {
179
        $book = Book::getBookById(2);
180
        $book->pubdate = $pubdate;
181
        $this->assertEquals($expectedYear, $book->getPubDate());
182
    }
183
184
    public function providerPublicationDate() {
185
        return array(
186
            array('2010-10-05 22:00:00+00:00', '2010'),
187
            array('1982-11-15 13:05:29.908657+00:00', '1982'),
188
            array('1562-10-05 00:00:00+00:00', '1562'),
189
            array('0100-12-31 23:00:00+00:00', ''),
190
            array('', ''),
191
            array(NULL, '')
192
            );
193
    }
194
195
    public function testGetBookById ()
196
    {
197
        // also check most of book's class methods
198
        $book = Book::getBookById(2);
199
200
        $linkArray = $book->getLinkArray ();
201
        $this->assertCount (5, $linkArray);
202
203
        $this->assertEquals ("The Return of Sherlock Holmes", $book->getTitle ());
204
        $this->assertEquals ("urn:uuid:87ddbdeb-1e27-4d06-b79b-4b2a3bfc6a5f", $book->getEntryId ());
205
        $this->assertEquals ("index.php?page=13&id=2", $book->getDetailUrl ());
206
        $this->assertEquals ("Arthur Conan Doyle", $book->getAuthorsName ());
207
        $this->assertEquals ("Fiction, Mystery & Detective, Short Stories", $book->getTagsName ());
208
        $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 1901–1902 (although setting it before Holmes\' death) Doyle came under intense pressure to revive his famous character.</p>', $book->getComment (false));
209
        $this->assertEquals ("English", $book->getLanguages ());
210
        $this->assertEquals ("Strand Magazine", $book->getPublisher()->name);
211
    }
212
213
    public function testGetBookById_NotFound ()
214
    {
215
        $book = Book::getBookById(666);
216
217
        $this->assertNull ($book);
218
    }
219
220
    public function testGetRating_FiveStars ()
221
    {
222
        $book = Book::getBookById(2);
223
224
        $this->assertEquals ("&#9733;&#9733;&#9733;&#9733;&#9733;", $book->getRating ());
225
    }
226
227
    public function testGetRating_FourStars ()
228
    {
229
        $book = Book::getBookById(2);
230
        $book->rating = 8;
231
232
        // 4 filled stars and one empty
233
        $this->assertEquals ("&#9733;&#9733;&#9733;&#9733;&#9734;", $book->getRating ());
234
    }
235
236
    public function testGetRating_NoStars_Zero ()
237
    {
238
        $book = Book::getBookById(2);
239
        $book->rating = 0;
240
241
        $this->assertEquals ("", $book->getRating ());
242
    }
243
244
    public function testGetRating_NoStars_Null ()
245
    {
246
        $book = Book::getBookById(2);
247
        $book->rating = NULL;
248
249
        $this->assertEquals ("", $book->getRating ());
250
    }
251
252
    public function testBookGetLinkArrayWithUrlRewriting ()
253
    {
254
        global $config;
255
256
        $book = Book::getBookById(2);
257
        $config['cops_use_url_rewriting'] = "1";
258
259
        $linkArray = $book->getLinkArray ();
260
        foreach ($linkArray as $link) {
261
            if ($link->rel == Link::OPDS_ACQUISITION_TYPE && $link->title == "EPUB" ) {
262
                $this->assertEquals ("download/1/The%20Return%20of%20Sherlock%20Holmes%20-%20Arthur%20Conan%20Doyle.epub", $link->href);
263
                return;
264
            }
265
        }
266
        $this->fail ();
267
    }
268
269
    public function testBookGetLinkArrayWithoutUrlRewriting ()
270
    {
271
        global $config;
272
273
        $book = Book::getBookById(2);
274
        $config['cops_use_url_rewriting'] = "0";
275
276
        $linkArray = $book->getLinkArray ();
277
        foreach ($linkArray as $link) {
278
            if ($link->rel == Link::OPDS_ACQUISITION_TYPE && $link->title == "EPUB" ) {
279
                $this->assertEquals ("fetch.php?data=1&type=epub&id=2", $link->href);
280
                return;
281
            }
282
        }
283
        $this->fail ();
284
    }
285
286
    public function testGetThumbnailNotNeeded ()
287
    {
288
        $book = Book::getBookById(2);
289
290
        $this->assertFalse ($book->getThumbnail (NULL, NULL, NULL));
291
292
        // Current cover is 400*600
293
        $this->assertFalse ($book->getThumbnail (COVER_WIDTH, NULL, NULL));
294
        $this->assertFalse ($book->getThumbnail (COVER_WIDTH + 1, NULL, NULL));
295
        $this->assertFalse ($book->getThumbnail (NULL, COVER_HEIGHT, NULL));
296
        $this->assertFalse ($book->getThumbnail (NULL, COVER_HEIGHT + 1, NULL));
297
    }
298
299
    /**
300
     * @dataProvider providerThumbnail
301
     */
302
    public function testGetThumbnailByWidth ($width, $height, $expectedWidth, $expectedHeight)
303
    {
304
        $book = Book::getBookById(2);
305
306
        $this->assertTrue ($book->getThumbnail ($width, $height, TEST_THUMBNAIL));
307
308
        $size = GetImageSize(TEST_THUMBNAIL);
309
        $this->assertEquals ($expectedWidth, $size [0]);
310
        $this->assertEquals ($expectedHeight, $size [1]);
311
312
        unlink (TEST_THUMBNAIL);
313
    }
314
315
    public function providerThumbnail ()
316
    {
317
        return array (
318
            array (164, NULL, 164, 246),
319
            array (NULL, 164, 109, 164)
320
        );
321
    }
322
323
    public function testGetMostInterestingDataToSendToKindle_WithMOBI ()
324
    {
325
        // Get Alice (available as MOBI, PDF, EPUB in that order)
326
        $book = Book::getBookById(17);
327
        $data = $book->GetMostInterestingDataToSendToKindle ();
328
        $this->assertEquals ("MOBI", $data->format);
329
    }
330
331
    public function testGetMostInterestingDataToSendToKindle_WithPdf ()
332
    {
333
        // Get Alice (available as MOBI, PDF, EPUB in that order)
334
        $book = Book::getBookById(17);
335
        $book->GetMostInterestingDataToSendToKindle ();
336
        array_shift ($book->datas);
337
        $data = $book->GetMostInterestingDataToSendToKindle ();
338
        $this->assertEquals ("PDF", $data->format);
339
    }
340
341
    public function testGetMostInterestingDataToSendToKindle_WithEPUB ()
342
    {
343
        // Get Alice (available as MOBI, PDF, EPUB in that order)
344
        $book = Book::getBookById(17);
345
        $book->GetMostInterestingDataToSendToKindle ();
346
        array_shift ($book->datas);
347
        array_shift ($book->datas);
348
        $data = $book->GetMostInterestingDataToSendToKindle ();
349
        $this->assertEquals ("EPUB", $data->format);
350
    }
351
352
    public function testGetDataById ()
353
    {
354
        global $config;
355
356
        // Get Alice MOBI=>17, PDF=>19, EPUB=>20
357
        $book = Book::getBookById(17);
358
        $mobi = $book->getDataById (17);
359
        $this->assertEquals ("MOBI", $mobi->format);
360
        $epub = $book->getDataById (20);
361
        $this->assertEquals ("EPUB", $epub->format);
362
        $this->assertEquals ("Carroll, Lewis - Alice's Adventures in Wonderland.epub", $epub->getUpdatedFilenameEpub ());
363
        $this->assertEquals ("Carroll, Lewis - Alice's Adventures in Wonderland.kepub.epub", $epub->getUpdatedFilenameKepub ());
364
        $this->assertEquals (dirname(__FILE__) . "/BaseWithSomeBooks/Lewis Carroll/Alice's Adventures in Wonderland (17)/Alice's Adventures in Wonderland - Lewis Carroll.epub", $epub->getLocalPath ());
365
366
        $config['cops_use_url_rewriting'] = "1";
367
        $config['cops_provide_kepub'] = "1";
368
        $_SERVER["HTTP_USER_AGENT"] = "Kobo";
369
        $this->assertEquals ("download/20/Carroll%2C%20Lewis%20-%20Alice%27s%20Adventures%20in%20Wonderland.kepub.epub", $epub->getHtmlLink ());
370
        $this->assertEquals ("download/17/Alice%27s%20Adventures%20in%20Wonderland%20-%20Lewis%20Carroll.mobi", $mobi->getHtmlLink ());
371
        $_SERVER["HTTP_USER_AGENT"] = "Firefox";
372
        $this->assertEquals ("download/20/Alice%27s%20Adventures%20in%20Wonderland%20-%20Lewis%20Carroll.epub", $epub->getHtmlLink ());
373
        $config['cops_use_url_rewriting'] = "0";
374
        $this->assertEquals ("fetch.php?data=20&type=epub&id=17", $epub->getHtmlLink ());
375
    }
376
377
    public function testGetFilePath_Cover () {
378
        $book = Book::getBookById(17);
379
380
        $this->assertEquals ("Lewis Carroll/Alice's Adventures in Wonderland (17)/cover.jpg", $book->getFilePath ("jpg", NULL, true));
381
    }
382
383
    public function testGetFilePath_Epub () {
384
        $book = Book::getBookById(17);
385
386
        $this->assertEquals ("Lewis Carroll/Alice's Adventures in Wonderland (17)/Alice's Adventures in Wonderland - Lewis Carroll.epub", $book->getFilePath ("epub", 20, true));
387
    }
388
389
    public function testGetFilePath_Mobi () {
390
        $book = Book::getBookById(17);
391
392
        $this->assertEquals ("Lewis Carroll/Alice's Adventures in Wonderland (17)/Alice's Adventures in Wonderland - Lewis Carroll.mobi", $book->getFilePath ("mobi", 17, true));
393
    }
394
395
    public function testGetDataFormat_EPUB () {
396
        $book = Book::getBookById(17);
397
398
        // Get Alice MOBI=>17, PDF=>19, EPUB=>20
399
        $data = $book->getDataFormat ("EPUB");
400
        $this->assertEquals (20, $data->id);
401
    }
402
403
    public function testGetDataFormat_MOBI () {
404
        $book = Book::getBookById(17);
405
406
        // Get Alice MOBI=>17, PDF=>19, EPUB=>20
407
        $data = $book->getDataFormat ("MOBI");
408
        $this->assertEquals (17, $data->id);
409
    }
410
411
    public function testGetDataFormat_PDF () {
412
        $book = Book::getBookById(17);
413
414
        // Get Alice MOBI=>17, PDF=>19, EPUB=>20
415
        $data = $book->getDataFormat ("PDF");
416
        $this->assertEquals (19, $data->id);
417
    }
418
419
    public function testGetDataFormat_NonAvailable () {
420
        $book = Book::getBookById(17);
421
422
        // Get Alice MOBI=>17, PDF=>19, EPUB=>20
423
        $this->assertFalse ($book->getDataFormat ("FB2"));
424
    }
425
426
    public function testGetMimeType_EPUB () {
427
        $book = Book::getBookById(17);
428
429
        // Get Alice MOBI=>17, PDF=>19, EPUB=>20
430
        $data = $book->getDataFormat ("EPUB");
431
        $this->assertEquals ("application/epub+zip", $data->getMimeType ());
432
    }
433
434
    public function testGetMimeType_MOBI () {
435
        $book = Book::getBookById(17);
436
437
        // Get Alice MOBI=>17, PDF=>19, EPUB=>20
438
        $data = $book->getDataFormat ("MOBI");
439
        $this->assertEquals ("application/x-mobipocket-ebook", $data->getMimeType ());
440
    }
441
442
    public function testGetMimeType_PDF  () {
443
        $book = Book::getBookById(17);
444
445
        // Get Alice MOBI=>17, PDF=>19, EPUB=>20
446
        $data = $book->getDataFormat ("PDF");
447
        $this->assertEquals ("application/pdf", $data->getMimeType ());
448
    }
449
450
    public function testGetMimeType_Finfo () {
451
        $book = Book::getBookById(17);
452
453
        // Get Alice MOBI=>17, PDF=>19, EPUB=>20
454
        $data = $book->getDataFormat ("PDF");
455
        $this->assertEquals ("application/pdf", $data->getMimeType ());
456
457
        // Alter a data to make a test for finfo_file if enabled
458
        $data->extension = "ico";
459
        $data->format = "ICO";
460
        $data->name = "favicon";
461
        $data->book->path = realpath (dirname(__FILE__) . "/../");
462
        if (function_exists('finfo_open') === true) {
463
            $this->assertEquals ("image/x-icon", $data->getMimeType ());
464
        } else {
465
            $this->assertEquals ("application/octet-stream", $data->getMimeType ());
466
        }
467
    }
468
469
    public function testTypeaheadSearch_Tag ()
470
    {
471
        $_GET["page"] = Base::PAGE_OPENSEARCH_QUERY;
472
        $_GET["query"] = "fic";
473
        $_GET["search"] = "1";
474
475
        $array = JSONRenderer::getJson ();
476
477
        $this->assertCount (3, $array);
478
        $this->assertEquals ("2 tags", $array[0]["title"]);
479
        $this->assertEquals ("Fiction", $array[1]["title"]);
480
        $this->assertEquals ("Science Fiction", $array[2]["title"]);
481
482
        $_GET["query"] = NULL;
483
        $_GET["search"] = NULL;
484
    }
485
486
    public function testTypeaheadSearch_BookAndAuthor ()
487
    {
488
        $_GET["page"] = Base::PAGE_OPENSEARCH_QUERY;
489
        $_GET["query"] = "car";
490
        $_GET["search"] = "1";
491
492
        $array = JSONRenderer::getJson ();
493
494
        $this->assertCount (4, $array);
495
        $this->assertEquals ("1 book", $array[0]["title"]);
496
        $this->assertEquals ("A Study in Scarlet", $array[1]["title"]);
497
        $this->assertEquals ("1 author", $array[2]["title"]);
498
        $this->assertEquals ("Carroll, Lewis", $array[3]["title"]);
499
500
        $_GET["query"] = NULL;
501
        $_GET["search"] = NULL;
502
    }
503
504
    public function testTypeaheadSearch_AuthorAndSeries ()
505
    {
506
        $_GET["page"] = Base::PAGE_OPENSEARCH_QUERY;
507
        $_GET["query"] = "art";
508
        $_GET["search"] = "1";
509
510
        $array = JSONRenderer::getJson ();
511
512
        $this->assertCount (5, $array);
513
        $this->assertEquals ("1 author", $array[0]["title"]);
514
        $this->assertEquals ("Doyle, Arthur Conan", $array[1]["title"]);
515
        $this->assertEquals ("2 series", $array[2]["title"]);
516
        $this->assertEquals ("D'Artagnan Romances", $array[3]["title"]);
517
518
        $_GET["query"] = NULL;
519
        $_GET["search"] = NULL;
520
    }
521
522
    public function testTypeaheadSearch_Publisher ()
523
    {
524
        $_GET["page"] = Base::PAGE_OPENSEARCH_QUERY;
525
        $_GET["query"] = "Macmillan";
526
        $_GET["search"] = "1";
527
528
        $array = JSONRenderer::getJson ();
529
530
        $this->assertCount (3, $array);
531
        $this->assertEquals ("2 publishers", $array[0]["title"]);
532
        $this->assertEquals ("Macmillan and Co. London", $array[1]["title"]);
533
        $this->assertEquals ("Macmillan Publishers USA", $array[2]["title"]);
534
535
        $_GET["query"] = NULL;
536
        $_GET["search"] = NULL;
537
    }
538
539
    public function testTypeaheadSearchWithIgnored_SingleCategory ()
540
    {
541
        global $config;
542
        $_GET["page"] = Base::PAGE_OPENSEARCH_QUERY;
543
        $_GET["query"] = "car";
544
        $_GET["search"] = "1";
545
546
        $config ['cops_ignored_categories'] = array ("author");
547
        $array = JSONRenderer::getJson ();
548
549
        $this->assertCount (2, $array);
550
        $this->assertEquals ("1 book", $array[0]["title"]);
551
        $this->assertEquals ("A Study in Scarlet", $array[1]["title"]);
552
553
        $_GET["query"] = NULL;
554
        $_GET["search"] = NULL;
555
    }
556
557
    public function testTypeaheadSearchWithIgnored_MultipleCategory ()
558
    {
559
        global $config;
560
        $_GET["page"] = Base::PAGE_OPENSEARCH_QUERY;
561
        $_GET["query"] = "art";
562
        $_GET["search"] = "1";
563
564
        $config ['cops_ignored_categories'] = array ("series");
565
        $array = JSONRenderer::getJson ();
566
567
        $this->assertCount (2, $array);
568
        $this->assertEquals ("1 author", $array[0]["title"]);
569
        $this->assertEquals ("Doyle, Arthur Conan", $array[1]["title"]);
570
571
        $_GET["query"] = NULL;
572
        $_GET["search"] = NULL;
573
    }
574
575
    public function testTypeaheadSearchMultiDatabase ()
576
    {
577
        global $config;
578
        $_GET["page"] = Base::PAGE_OPENSEARCH_QUERY;
579
        $_GET["query"] = "art";
580
        $_GET["search"] = "1";
581
        $_GET["multi"] = "1";
582
583
        $config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/",
584
                                              "One book" => dirname(__FILE__) . "/BaseWithOneBook/");
585
586
        $array = JSONRenderer::getJson ();
587
588
        $this->assertCount (5, $array);
589
        $this->assertEquals ("Some books", $array[0]["title"]);
590
        $this->assertEquals ("1 author", $array[1]["title"]);
591
        $this->assertEquals ("2 series", $array[2]["title"]);
592
        $this->assertEquals ("One book", $array[3]["title"]);
593
        $this->assertEquals ("1 book", $array[4]["title"]);
594
595
        $_GET["query"] = NULL;
596
        $_GET["search"] = NULL;
597
    }
598
599
    public function tearDown () {
600
        Base::clearDb ();
601
    }
602
603
}