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

CustomColumnTest   B

Complexity

Total Complexity 40

Size/Duplication

Total Lines 1092
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
dl 0
loc 1092
rs 7.5149
c 0
b 0
f 0
wmc 40
lcom 1
cbo 9

How to fix   Complexity   

Complex Class

Complex classes like CustomColumnTest 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 CustomColumnTest, 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
class CustomColumnTest extends PHPUnit_Framework_TestCase
12
{
13
    public function testColumnType01()
14
    {
15
        global $config;
16
17
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
18
        $config['cops_calibre_custom_column'] = array("custom_01");
19
        Base::clearDb();
20
21
        $coltype = CustomColumnType::createByCustomID(8);
22
23
        $this->assertEquals($coltype, CustomColumnType::createByLookup("custom_01"));
24
25
        $this->assertEquals(8, $coltype->customId);
26
        $this->assertEquals("custom_01", $coltype->columnTitle);
27
        $this->assertEquals("text", $coltype->datatype);
28
        $this->assertEquals("CustomColumnTypeText", get_class($coltype));
29
30
        $this->assertCount(3, $coltype->getAllCustomValues());
31
        $this->assertEquals("?page=14&custom=8", $coltype->getUriAllCustoms());
32
        $this->assertEquals("cops:custom:8", $coltype->getAllCustomsId());
33
        $this->assertEquals("custom_01", $coltype->getTitle());
34
        $this->assertEquals("Custom column example 01 (text)", $coltype->getDatabaseDescription());
35
        $this->assertEquals("Custom column example 01 (text)", $coltype->getDescription());
36
        $this->assertEquals(true, $coltype->isSearchable());
37
38
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
39
        $config['cops_calibre_custom_column'] = array();
40
        Base::clearDb();
41
    }
42
43
    public function testColumnType01b()
44
    {
45
        global $config;
46
47
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
48
        $config['cops_calibre_custom_column'] = array("custom_01b");
49
        Base::clearDb();
50
51
        $coltype = CustomColumnType::createByCustomID(16);
52
53
        $this->assertEquals($coltype, CustomColumnType::createByLookup("custom_01b"));
54
55
        $this->assertEquals(16, $coltype->customId);
56
        $this->assertEquals("custom_01b", $coltype->columnTitle);
57
        $this->assertEquals("text", $coltype->datatype);
58
        $this->assertEquals("CustomColumnTypeText", get_class($coltype));
59
60
        $this->assertCount(3, $coltype->getAllCustomValues());
61
        $this->assertEquals("?page=14&custom=16", $coltype->getUriAllCustoms());
62
        $this->assertEquals("cops:custom:16", $coltype->getAllCustomsId());
63
        $this->assertEquals("custom_01b", $coltype->getTitle());
64
        $this->assertEquals(NULL, $coltype->getDatabaseDescription());
65
        $this->assertEquals("Custom column 'custom_01b'", $coltype->getDescription());
66
        $this->assertEquals(true, $coltype->isSearchable());
67
68
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
69
        $config['cops_calibre_custom_column'] = array();
70
        Base::clearDb();
71
    }
72
73
    public function testColumnType02()
74
    {
75
        global $config;
76
77
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
78
        $config['cops_calibre_custom_column'] = array("custom_02");
79
        Base::clearDb();
80
81
        $coltype = CustomColumnType::createByCustomID(6);
82
83
        $this->assertEquals($coltype, CustomColumnType::createByLookup("custom_02"));
84
85
        $this->assertEquals(6, $coltype->customId);
86
        $this->assertEquals("custom_02", $coltype->columnTitle);
87
        $this->assertEquals("text", $coltype->datatype);
88
        $this->assertEquals("CustomColumnTypeText", get_class($coltype));
89
90
        $this->assertCount(3, $coltype->getAllCustomValues());
91
        $this->assertEquals("?page=14&custom=6", $coltype->getUriAllCustoms());
92
        $this->assertEquals("cops:custom:6", $coltype->getAllCustomsId());
93
        $this->assertEquals("custom_02", $coltype->getTitle());
94
        $this->assertEquals("Custom column example 02 (csv)", $coltype->getDatabaseDescription());
95
        $this->assertEquals("Custom column example 02 (csv)", $coltype->getDescription());
96
        $this->assertEquals(true, $coltype->isSearchable());
97
98
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
99
        $config['cops_calibre_custom_column'] = array();
100
        Base::clearDb();
101
    }
102
103
    public function testColumnType03()
104
    {
105
        global $config;
106
107
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
108
        $config['cops_calibre_custom_column'] = array("custom_03");
109
        Base::clearDb();
110
111
        $coltype = CustomColumnType::createByCustomID(7);
112
113
        $this->assertEquals($coltype, CustomColumnType::createByLookup("custom_03"));
114
115
        $this->assertEquals(7, $coltype->customId);
116
        $this->assertEquals("custom_03", $coltype->columnTitle);
117
        $this->assertEquals("comments", $coltype->datatype);
118
        $this->assertEquals("CustomColumnTypeComment", get_class($coltype));
119
120
        $this->assertEquals("?page=14&custom=7", $coltype->getUriAllCustoms());
121
        $this->assertEquals("cops:custom:7", $coltype->getAllCustomsId());
122
        $this->assertEquals("custom_03", $coltype->getTitle());
123
        $this->assertEquals("Custom column example 03 (long_text)", $coltype->getDatabaseDescription());
124
        $this->assertEquals("Custom column example 03 (long_text)", $coltype->getDescription());
125
        $this->assertEquals(false, $coltype->isSearchable());
126
127
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
128
        $config['cops_calibre_custom_column'] = array();
129
        Base::clearDb();
130
    }
131
132
    public function testColumnType04()
133
    {
134
        global $config;
135
136
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
137
        $config['cops_calibre_custom_column'] = array("custom_04");
138
        Base::clearDb();
139
140
        $coltype = CustomColumnType::createByCustomID(4);
141
142
        $this->assertEquals($coltype, CustomColumnType::createByLookup("custom_04"));
143
144
        $this->assertEquals(4, $coltype->customId);
145
        $this->assertEquals("custom_04", $coltype->columnTitle);
146
        $this->assertEquals("series", $coltype->datatype);
147
        $this->assertEquals("CustomColumnTypeSeries", get_class($coltype));
148
149
        $this->assertCount(3, $coltype->getAllCustomValues());
150
        $this->assertEquals("?page=14&custom=4", $coltype->getUriAllCustoms());
151
        $this->assertEquals("cops:custom:4", $coltype->getAllCustomsId());
152
        $this->assertEquals("custom_04", $coltype->getTitle());
153
        $this->assertEquals("Custom column example 04 (series_text)", $coltype->getDatabaseDescription());
154
        $this->assertEquals("Alphabetical index of the 3 series", $coltype->getDescription());
155
        $this->assertEquals(true, $coltype->isSearchable());
156
157
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
158
        $config['cops_calibre_custom_column'] = array();
159
        Base::clearDb();
160
    }
161
162
    public function testColumnType05()
163
    {
164
        global $config;
165
166
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
167
        $config['cops_calibre_custom_column'] = array("custom_05");
168
        Base::clearDb();
169
170
        $coltype = CustomColumnType::createByCustomID(5);
171
172
        $this->assertEquals($coltype, CustomColumnType::createByLookup("custom_05"));
173
174
        $this->assertEquals(5, $coltype->customId);
175
        $this->assertEquals("custom_05", $coltype->columnTitle);
176
        $this->assertEquals("enumeration", $coltype->datatype);
177
        $this->assertEquals("CustomColumnTypeEnumeration", get_class($coltype));
178
179
        $this->assertCount(4, $coltype->getAllCustomValues());
180
        $this->assertEquals("?page=14&custom=5", $coltype->getUriAllCustoms());
181
        $this->assertEquals("cops:custom:5", $coltype->getAllCustomsId());
182
        $this->assertEquals("custom_05", $coltype->getTitle());
183
        $this->assertEquals("Custom column example 05 (enum)", $coltype->getDatabaseDescription());
184
        $this->assertEquals("Alphabetical index of the 4 values", $coltype->getDescription());
185
        $this->assertEquals(true, $coltype->isSearchable());
186
187
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
188
        $config['cops_calibre_custom_column'] = array();
189
        Base::clearDb();
190
    }
191
192
    public function testColumnType06()
193
    {
194
        global $config;
195
196
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
197
        $config['cops_calibre_custom_column'] = array("custom_06");
198
        Base::clearDb();
199
200
        $coltype = CustomColumnType::createByCustomID(12);
201
202
        $this->assertEquals($coltype, CustomColumnType::createByLookup("custom_06"));
203
204
        $this->assertEquals(12, $coltype->customId);
205
        $this->assertEquals("custom_06", $coltype->columnTitle);
206
        $this->assertEquals("datetime", $coltype->datatype);
207
        $this->assertEquals("CustomColumnTypeDate", get_class($coltype));
208
209
        $this->assertCount(5, $coltype->getAllCustomValues());
210
        $this->assertEquals("?page=14&custom=12", $coltype->getUriAllCustoms());
211
        $this->assertEquals("cops:custom:12", $coltype->getAllCustomsId());
212
        $this->assertEquals("custom_06", $coltype->getTitle());
213
        $this->assertEquals("Custom column example 06 (date)", $coltype->getDatabaseDescription());
214
        $this->assertEquals("Custom column example 06 (date)", $coltype->getDescription());
215
        $this->assertEquals(true, $coltype->isSearchable());
216
217
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
218
        $config['cops_calibre_custom_column'] = array();
219
        Base::clearDb();
220
    }
221
222
    public function testColumnType07()
223
    {
224
        global $config;
225
226
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
227
        $config['cops_calibre_custom_column'] = array("custom_07");
228
        Base::clearDb();
229
230
        $coltype = CustomColumnType::createByCustomID(14);
231
232
        $this->assertEquals($coltype, CustomColumnType::createByLookup("custom_07"));
233
234
        $this->assertEquals(14, $coltype->customId);
235
        $this->assertEquals("custom_07", $coltype->columnTitle);
236
        $this->assertEquals("float", $coltype->datatype);
237
        $this->assertEquals("CustomColumnTypeFloat", get_class($coltype));
238
239
        $this->assertCount(6, $coltype->getAllCustomValues());
240
        $this->assertEquals("?page=14&custom=14", $coltype->getUriAllCustoms());
241
        $this->assertEquals("cops:custom:14", $coltype->getAllCustomsId());
242
        $this->assertEquals("custom_07", $coltype->getTitle());
243
        $this->assertEquals("Custom column example 07 (float)", $coltype->getDatabaseDescription());
244
        $this->assertEquals("Custom column example 07 (float)", $coltype->getDescription());
245
        $this->assertEquals(true, $coltype->isSearchable());
246
247
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
248
        $config['cops_calibre_custom_column'] = array();
249
        Base::clearDb();
250
    }
251
252
    public function testColumnType08()
253
    {
254
        global $config;
255
256
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
257
        $config['cops_calibre_custom_column'] = array("custom_08");
258
        Base::clearDb();
259
260
        $coltype = CustomColumnType::createByCustomID(10);
261
262
        $this->assertEquals($coltype, CustomColumnType::createByLookup("custom_08"));
263
264
        $this->assertEquals(10, $coltype->customId);
265
        $this->assertEquals("custom_08", $coltype->columnTitle);
266
        $this->assertEquals("int", $coltype->datatype);
267
        $this->assertEquals("CustomColumnTypeInteger", get_class($coltype));
268
269
        $this->assertCount(4, $coltype->getAllCustomValues());
270
        $this->assertEquals("?page=14&custom=10", $coltype->getUriAllCustoms());
271
        $this->assertEquals("cops:custom:10", $coltype->getAllCustomsId());
272
        $this->assertEquals("custom_08", $coltype->getTitle());
273
        $this->assertEquals("Custom column example 08 (int)", $coltype->getDatabaseDescription());
274
        $this->assertEquals("Custom column example 08 (int)", $coltype->getDescription());
275
        $this->assertEquals(true, $coltype->isSearchable());
276
277
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
278
        $config['cops_calibre_custom_column'] = array();
279
        Base::clearDb();
280
    }
281
282
    public function testColumnType09()
283
    {
284
        global $config;
285
286
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
287
        $config['cops_calibre_custom_column'] = array("custom_09");
288
        Base::clearDb();
289
290
        $coltype = CustomColumnType::createByCustomID(9);
291
292
        $this->assertEquals($coltype, CustomColumnType::createByLookup("custom_09"));
293
294
        $this->assertEquals(9, $coltype->customId);
295
        $this->assertEquals("custom_09", $coltype->columnTitle);
296
        $this->assertEquals("rating", $coltype->datatype);
297
        $this->assertEquals("CustomColumnTypeRating", get_class($coltype));
298
299
        $this->assertCount(6, $coltype->getAllCustomValues());
300
        $this->assertEquals("?page=14&custom=9", $coltype->getUriAllCustoms());
301
        $this->assertEquals("cops:custom:9", $coltype->getAllCustomsId());
302
        $this->assertEquals("custom_09", $coltype->getTitle());
303
        $this->assertEquals("Custom column example 09 (rating)", $coltype->getDatabaseDescription());
304
        $this->assertEquals("Index of ratings", $coltype->getDescription());
305
        $this->assertEquals(true, $coltype->isSearchable());
306
307
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
308
        $config['cops_calibre_custom_column'] = array();
309
        Base::clearDb();
310
    }
311
312
    public function testColumnType10()
313
    {
314
        global $config;
315
316
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
317
        $config['cops_calibre_custom_column'] = array("custom_10");
318
        Base::clearDb();
319
320
        $coltype = CustomColumnType::createByCustomID(11);
321
322
        $this->assertEquals($coltype, CustomColumnType::createByLookup("custom_10"));
323
324
        $this->assertEquals(11, $coltype->customId);
325
        $this->assertEquals("custom_10", $coltype->columnTitle);
326
        $this->assertEquals("bool", $coltype->datatype);
327
        $this->assertEquals("CustomColumnTypeBool", get_class($coltype));
328
329
        $this->assertCount(3, $coltype->getAllCustomValues());
330
        $this->assertEquals("?page=14&custom=11", $coltype->getUriAllCustoms());
331
        $this->assertEquals("cops:custom:11", $coltype->getAllCustomsId());
332
        $this->assertEquals("custom_10", $coltype->getTitle());
333
        $this->assertEquals("Custom column example 10 (bool)", $coltype->getDatabaseDescription());
334
        $this->assertEquals("Index of a boolean value", $coltype->getDescription());
335
        $this->assertEquals(true, $coltype->isSearchable());
336
337
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
338
        $config['cops_calibre_custom_column'] = array();
339
        Base::clearDb();
340
    }
341
342
    public function testColumnType11()
343
    {
344
        global $config;
345
346
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
347
        $config['cops_calibre_custom_column'] = array("custom_11");
348
        Base::clearDb();
349
350
        $coltype = CustomColumnType::createByCustomID(15);
351
352
        $this->assertEquals($coltype, CustomColumnType::createByLookup("custom_11"));
353
354
        $this->assertEquals(NULL, $coltype);
355
356
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
357
        $config['cops_calibre_custom_column'] = array();
358
        Base::clearDb();
359
    }
360
361
    public function testColumnType12()
362
    {
363
        global $config;
364
365
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
366
        $config['cops_calibre_custom_column'] = array("custom_12");
367
        Base::clearDb();
368
369
        $coltype = CustomColumnType::createByCustomID(13);
370
371
        $this->assertEquals($coltype, CustomColumnType::createByLookup("custom_12"));
372
373
        $this->assertEquals(NULL, $coltype);
374
375
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
376
        $config['cops_calibre_custom_column'] = array();
377
        Base::clearDb();
378
    }
379
380
    public function testInvalidColumn1()
381
    {
382
        global $config;
383
384
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
385
        $config['cops_calibre_custom_column'] = array("custom_12");
386
        Base::clearDb();
387
388
        $catch = false;
389
        try {
390
            CustomColumnType::createByCustomID(999);
391
        } catch (Exception $e) {
392
            $catch = true;
393
        }
394
395
        $this->assertTrue($catch);
396
397
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
398
        $config['cops_calibre_custom_column'] = array();
399
        Base::clearDb();
400
    }
401
402
    public function testInvalidColumn2()
403
    {
404
        global $config;
405
406
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
407
        $config['cops_calibre_custom_column'] = array("custom_12");
408
        Base::clearDb();
409
410
        $coltype = CustomColumnType::createByLookup("__ERR__");
411
412
        $this->assertEquals(NULL, $coltype);
413
414
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
415
        $config['cops_calibre_custom_column'] = array();
416
        Base::clearDb();
417
    }
418
419
    public function testIndexTypeAll()
420
    {
421
        global $config;
422
423
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
424
        $config['cops_calibre_custom_column'] = array("custom_01", "custom_02", "custom_03", "custom_04", "custom_05", "custom_06", "custom_07", "custom_08", "custom_09", "custom_10");
425
        Base::clearDb();
426
427
        $currentPage = Page::getPage(Base::PAGE_INDEX, NULL, NULL, "1");
428
        $currentPage->InitializeContent();
429
430
        $this->assertCount(15, $currentPage->entryArray); // Authors, Series, Publishers, Languages, custom, All, Recent
431
        $this->assertEquals("custom_01", $currentPage->entryArray[ 4]->title);
432
        $this->assertEquals("custom_02", $currentPage->entryArray[ 5]->title);
433
        $this->assertEquals("custom_04", $currentPage->entryArray[ 6]->title);
434
        $this->assertEquals("custom_05", $currentPage->entryArray[ 7]->title);
435
        $this->assertEquals("custom_06", $currentPage->entryArray[ 8]->title);
436
        $this->assertEquals("custom_07", $currentPage->entryArray[ 9]->title);
437
        $this->assertEquals("custom_08", $currentPage->entryArray[10]->title);
438
        $this->assertEquals("custom_09", $currentPage->entryArray[11]->title);
439
        $this->assertEquals("custom_10", $currentPage->entryArray[12]->title);
440
441
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
442
        $config['cops_calibre_custom_column'] = array();
443
        Base::clearDb();
444
    }
445
446
    public function testIndexType01()
447
    {
448
        global $config;
449
450
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
451
        $config['cops_calibre_custom_column'] = array("custom_01");
452
        Base::clearDb();
453
454
        $currentPage = Page::getPage(Base::PAGE_INDEX, NULL, NULL, "1");
455
        $currentPage->InitializeContent();
456
457
        $this->assertCount(7, $currentPage->entryArray); // Authors, Series, Publishers, Languages, custom, All, Recent
458
        $this->assertEquals("custom_01", $currentPage->entryArray[4]->title);
459
        $this->assertEquals("cops:custom:8", $currentPage->entryArray[4]->id);
460
        $this->assertEquals("Custom column example 01 (text)", $currentPage->entryArray[4]->content);
461
        $this->assertEquals(3, $currentPage->entryArray[4]->numberOfElement);
462
        $this->assertEquals("text", $currentPage->entryArray[4]->contentType);
463
        $this->assertEquals($currentPage->entryArray[4], CustomColumnType::createByCustomID(8)->getCount());
464
465
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
466
        $config['cops_calibre_custom_column'] = array();
467
        Base::clearDb();
468
    }
469
470
    public function testIndexType02()
471
    {
472
        global $config;
473
474
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
475
        $config['cops_calibre_custom_column'] = array("custom_02");
476
        Base::clearDb();
477
478
        $currentPage = Page::getPage(Base::PAGE_INDEX, NULL, NULL, "1");
479
        $currentPage->InitializeContent();
480
481
        $this->assertCount(7, $currentPage->entryArray); // Authors, Series, Publishers, Languages, custom, All, Recent
482
        $this->assertEquals("custom_02", $currentPage->entryArray[4]->title);
483
        $this->assertEquals("cops:custom:6", $currentPage->entryArray[4]->id);
484
        $this->assertEquals("Custom column example 02 (csv)", $currentPage->entryArray[4]->content);
485
        $this->assertEquals(3, $currentPage->entryArray[4]->numberOfElement);
486
        $this->assertEquals("text", $currentPage->entryArray[4]->contentType);
487
        $this->assertEquals($currentPage->entryArray[4], CustomColumnType::createByCustomID(6)->getCount());
488
489
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
490
        $config['cops_calibre_custom_column'] = array();
491
        Base::clearDb();
492
    }
493
494
    public function testIndexType03()
495
    {
496
        global $config;
497
498
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
499
        $config['cops_calibre_custom_column'] = array("custom_03");
500
        Base::clearDb();
501
502
        $currentPage = Page::getPage(Base::PAGE_INDEX, NULL, NULL, "1");
503
        $currentPage->InitializeContent();
504
505
        $this->assertCount(6, $currentPage->entryArray); // Authors, Series, Publishers, Languages, All, Recent
506
507
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
508
        $config['cops_calibre_custom_column'] = array();
509
        Base::clearDb();
510
    }
511
512
    public function testIndexType04()
513
    {
514
        global $config;
515
516
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
517
        $config['cops_calibre_custom_column'] = array("custom_04");
518
        Base::clearDb();
519
520
        $currentPage = Page::getPage(Base::PAGE_INDEX, NULL, NULL, "1");
521
        $currentPage->InitializeContent();
522
523
        $this->assertCount(7, $currentPage->entryArray); // Authors, Series, Publishers, Languages, custom, All, Recent
524
        $this->assertEquals("custom_04", $currentPage->entryArray[4]->title);
525
        $this->assertEquals("cops:custom:4", $currentPage->entryArray[4]->id);
526
        $this->assertEquals("Alphabetical index of the 3 series", $currentPage->entryArray[4]->content);
527
        $this->assertEquals(3, $currentPage->entryArray[4]->numberOfElement);
528
        $this->assertEquals("series", $currentPage->entryArray[4]->contentType);
529
        $this->assertEquals($currentPage->entryArray[4], CustomColumnType::createByCustomID(4)->getCount());
530
531
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
532
        $config['cops_calibre_custom_column'] = array();
533
        Base::clearDb();
534
    }
535
536
    public function testIndexType05()
537
    {
538
        global $config;
539
540
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
541
        $config['cops_calibre_custom_column'] = array("custom_05");
542
        Base::clearDb();
543
544
        $currentPage = Page::getPage(Base::PAGE_INDEX, NULL, NULL, "1");
545
        $currentPage->InitializeContent();
546
547
        $this->assertCount(7, $currentPage->entryArray); // Authors, Series, Publishers, Languages, custom, All, Recent
548
        $this->assertEquals("custom_05", $currentPage->entryArray[4]->title);
549
        $this->assertEquals("cops:custom:5", $currentPage->entryArray[4]->id);
550
        $this->assertEquals("Alphabetical index of the 4 values", $currentPage->entryArray[4]->content);
551
        $this->assertEquals(4, $currentPage->entryArray[4]->numberOfElement);
552
        $this->assertEquals("enumeration", $currentPage->entryArray[4]->contentType);
553
        $this->assertEquals($currentPage->entryArray[4], CustomColumnType::createByCustomID(5)->getCount());
554
555
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
556
        $config['cops_calibre_custom_column'] = array();
557
        Base::clearDb();
558
    }
559
560
    public function testIndexType06()
561
    {
562
        global $config;
563
564
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
565
        $config['cops_calibre_custom_column'] = array("custom_06");
566
        Base::clearDb();
567
568
        $currentPage = Page::getPage(Base::PAGE_INDEX, NULL, NULL, "1");
569
        $currentPage->InitializeContent();
570
571
        $this->assertCount(7, $currentPage->entryArray); // Authors, Series, Publishers, Languages, custom, All, Recent
572
        $this->assertEquals("custom_06", $currentPage->entryArray[4]->title);
573
        $this->assertEquals("cops:custom:12", $currentPage->entryArray[4]->id);
574
        $this->assertEquals("Custom column example 06 (date)", $currentPage->entryArray[4]->content);
575
        $this->assertEquals(5, $currentPage->entryArray[4]->numberOfElement);
576
        $this->assertEquals("datetime", $currentPage->entryArray[4]->contentType);
577
        $this->assertEquals($currentPage->entryArray[4], CustomColumnType::createByCustomID(12)->getCount());
578
579
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
580
        $config['cops_calibre_custom_column'] = array();
581
        Base::clearDb();
582
    }
583
584
    public function testIndexType07()
585
    {
586
        global $config;
587
588
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
589
        $config['cops_calibre_custom_column'] = array("custom_07");
590
        Base::clearDb();
591
592
        $currentPage = Page::getPage(Base::PAGE_INDEX, NULL, NULL, "1");
593
        $currentPage->InitializeContent();
594
595
        $this->assertCount(7, $currentPage->entryArray); // Authors, Series, Publishers, Languages, custom, All, Recent
596
        $this->assertEquals("custom_07", $currentPage->entryArray[4]->title);
597
        $this->assertEquals("cops:custom:14", $currentPage->entryArray[4]->id);
598
        $this->assertEquals("Custom column example 07 (float)", $currentPage->entryArray[4]->content);
599
        $this->assertEquals(6, $currentPage->entryArray[4]->numberOfElement);
600
        $this->assertEquals("float", $currentPage->entryArray[4]->contentType);
601
        $this->assertEquals($currentPage->entryArray[4], CustomColumnType::createByCustomID(14)->getCount());
602
603
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
604
        $config['cops_calibre_custom_column'] = array();
605
        Base::clearDb();
606
    }
607
608
    public function testIndexType08()
609
    {
610
        global $config;
611
612
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
613
        $config['cops_calibre_custom_column'] = array("custom_08");
614
        Base::clearDb();
615
616
        $currentPage = Page::getPage(Base::PAGE_INDEX, NULL, NULL, "1");
617
        $currentPage->InitializeContent();
618
619
        $this->assertCount(7, $currentPage->entryArray); // Authors, Series, Publishers, Languages, custom, All, Recent
620
        $this->assertEquals("custom_08", $currentPage->entryArray[4]->title);
621
        $this->assertEquals("cops:custom:10", $currentPage->entryArray[4]->id);
622
        $this->assertEquals("Custom column example 08 (int)", $currentPage->entryArray[4]->content);
623
        $this->assertEquals(4, $currentPage->entryArray[4]->numberOfElement);
624
        $this->assertEquals("int", $currentPage->entryArray[4]->contentType);
625
        $this->assertEquals($currentPage->entryArray[4], CustomColumnType::createByCustomID(10)->getCount());
626
627
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
628
        $config['cops_calibre_custom_column'] = array();
629
        Base::clearDb();
630
    }
631
632
    public function testIndexType09()
633
    {
634
        global $config;
635
636
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
637
        $config['cops_calibre_custom_column'] = array("custom_09");
638
        Base::clearDb();
639
640
        $currentPage = Page::getPage(Base::PAGE_INDEX, NULL, NULL, "1");
641
        $currentPage->InitializeContent();
642
643
        $this->assertCount(7, $currentPage->entryArray); // Authors, Series, Publishers, Languages, custom, All, Recent
644
        $this->assertEquals("custom_09", $currentPage->entryArray[4]->title);
645
        $this->assertEquals("cops:custom:9", $currentPage->entryArray[4]->id);
646
        $this->assertEquals("Index of ratings", $currentPage->entryArray[4]->content);
647
        $this->assertEquals(6, $currentPage->entryArray[4]->numberOfElement);
648
        $this->assertEquals("rating", $currentPage->entryArray[4]->contentType);
649
        $this->assertEquals($currentPage->entryArray[4], CustomColumnType::createByCustomID(9)->getCount());
650
651
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
652
        $config['cops_calibre_custom_column'] = array();
653
        Base::clearDb();
654
    }
655
656
    public function testIndexType10()
657
    {
658
        global $config;
659
660
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
661
        $config['cops_calibre_custom_column'] = array("custom_10");
662
        Base::clearDb();
663
664
        $currentPage = Page::getPage(Base::PAGE_INDEX, NULL, NULL, "1");
665
        $currentPage->InitializeContent();
666
667
        $this->assertCount(7, $currentPage->entryArray); // Authors, Series, Publishers, Languages, custom, All, Recent
668
        $this->assertEquals("custom_10", $currentPage->entryArray[4]->title);
669
        $this->assertEquals("cops:custom:11", $currentPage->entryArray[4]->id);
670
        $this->assertEquals("Index of a boolean value", $currentPage->entryArray[4]->content);
671
        $this->assertEquals(3, $currentPage->entryArray[4]->numberOfElement);
672
        $this->assertEquals("bool", $currentPage->entryArray[4]->contentType);
673
        $this->assertEquals($currentPage->entryArray[4], CustomColumnType::createByCustomID(11)->getCount());
674
675
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
676
        $config['cops_calibre_custom_column'] = array();
677
        Base::clearDb();
678
    }
679
680
    public function testAllCustomsType01()
681
    {
682
        global $config;
683
684
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
685
        $_GET["custom"] = "8";
686
        Base::clearDb();
687
        $currentPage = Page::getPage(Base::PAGE_ALL_CUSTOMS, NULL, NULL, "1");
688
        $currentPage->InitializeContent();
689
690
691
        $this->assertEquals("custom_01", $currentPage->title);
692
        $this->assertCount(3, $currentPage->entryArray);
693
        $this->assertEquals("cops:custom:8:3", $currentPage->entryArray[0]->id);
694
        $this->assertEquals("cops:custom:8:1", $currentPage->entryArray[1]->id);
695
        $this->assertEquals("cops:custom:8:2", $currentPage->entryArray[2]->id);
696
697
698
        $_GET["custom"] = NULL;
699
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
700
        Base::clearDb();
701
    }
702
703
    public function testAllCustomsType02()
704
    {
705
        global $config;
706
707
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
708
        $_GET["custom"] = "6";
709
        Base::clearDb();
710
        $currentPage = Page::getPage(Base::PAGE_ALL_CUSTOMS, NULL, NULL, "1");
711
        $currentPage->InitializeContent();
712
713
714
        $this->assertEquals("custom_02", $currentPage->title);
715
        $this->assertCount(3, $currentPage->entryArray);
716
        $this->assertEquals("cops:custom:6:1", $currentPage->entryArray[0]->id);
717
        $this->assertEquals("cops:custom:6:2", $currentPage->entryArray[1]->id);
718
        $this->assertEquals("cops:custom:6:3", $currentPage->entryArray[2]->id);
719
720
721
        $_GET["custom"] = NULL;
722
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
723
        Base::clearDb();
724
    }
725
726
    public function testAllCustomsType04()
727
    {
728
        global $config;
729
730
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
731
        $_GET["custom"] = "4";
732
        Base::clearDb();
733
        $currentPage = Page::getPage(Base::PAGE_ALL_CUSTOMS, NULL, NULL, "1");
734
        $currentPage->InitializeContent();
735
736
737
        $this->assertEquals("custom_04", $currentPage->title);
738
        $this->assertCount(3, $currentPage->entryArray);
739
        $this->assertEquals("cops:custom:4:4", $currentPage->entryArray[0]->id);
740
        $this->assertEquals("cops:custom:4:5", $currentPage->entryArray[1]->id);
741
        $this->assertEquals("cops:custom:4:6", $currentPage->entryArray[2]->id);
742
743
744
        $_GET["custom"] = NULL;
745
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
746
        Base::clearDb();
747
    }
748
749
    public function testAllCustomsType05()
750
    {
751
        global $config;
752
753
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
754
        $_GET["custom"] = "5";
755
        Base::clearDb();
756
        $currentPage = Page::getPage(Base::PAGE_ALL_CUSTOMS, NULL, NULL, "1");
757
        $currentPage->InitializeContent();
758
759
760
        $this->assertEquals("custom_05", $currentPage->title);
761
        $this->assertCount(4, $currentPage->entryArray);
762
        $this->assertEquals("cops:custom:5:3", $currentPage->entryArray[0]->id);
763
        $this->assertEquals("cops:custom:5:4", $currentPage->entryArray[1]->id);
764
        $this->assertEquals("cops:custom:5:5", $currentPage->entryArray[2]->id);
765
        $this->assertEquals("cops:custom:5:6", $currentPage->entryArray[3]->id);
766
767
768
        $_GET["custom"] = NULL;
769
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
770
        Base::clearDb();
771
    }
772
773
    public function testAllCustomsType06()
774
    {
775
        global $config;
776
777
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
778
        $_GET["custom"] = "12";
779
        Base::clearDb();
780
        $currentPage = Page::getPage(Base::PAGE_ALL_CUSTOMS, NULL, NULL, "1");
781
        $currentPage->InitializeContent();
782
783
784
        $this->assertEquals("custom_06", $currentPage->title);
785
        $this->assertCount(5, $currentPage->entryArray);
786
        $this->assertEquals("cops:custom:12:2000-01-01", $currentPage->entryArray[0]->id);
787
        $this->assertEquals("cops:custom:12:2000-01-02", $currentPage->entryArray[1]->id);
788
        $this->assertEquals("cops:custom:12:2000-01-03", $currentPage->entryArray[2]->id);
789
        $this->assertEquals("cops:custom:12:2016-04-20", $currentPage->entryArray[3]->id);
790
        $this->assertEquals("cops:custom:12:2016-04-24", $currentPage->entryArray[4]->id);
791
792
793
        $_GET["custom"] = NULL;
794
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
795
        Base::clearDb();
796
    }
797
798
    public function testAllCustomsType07()
799
    {
800
        global $config;
801
802
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
803
        $_GET["custom"] = "14";
804
        Base::clearDb();
805
        $currentPage = Page::getPage(Base::PAGE_ALL_CUSTOMS, NULL, NULL, "1");
806
        $currentPage->InitializeContent();
807
808
809
        $this->assertEquals("custom_07", $currentPage->title);
810
        $this->assertCount(6, $currentPage->entryArray);
811
        $this->assertEquals("cops:custom:14:-99.0", $currentPage->entryArray[0]->id);
812
        $this->assertEquals("cops:custom:14:0.0", $currentPage->entryArray[1]->id);
813
        $this->assertEquals("cops:custom:14:0.1", $currentPage->entryArray[2]->id);
814
        $this->assertEquals("cops:custom:14:0.2", $currentPage->entryArray[3]->id);
815
        $this->assertEquals("cops:custom:14:11.0", $currentPage->entryArray[4]->id);
816
        $this->assertEquals("cops:custom:14:100000.0", $currentPage->entryArray[5]->id);
817
818
819
        $_GET["custom"] = NULL;
820
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
821
        Base::clearDb();
822
    }
823
824
    public function testAllCustomsType08()
825
    {
826
        global $config;
827
828
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
829
        $_GET["custom"] = "10";
830
        Base::clearDb();
831
        $currentPage = Page::getPage(Base::PAGE_ALL_CUSTOMS, NULL, NULL, "1");
832
        $currentPage->InitializeContent();
833
834
835
        $this->assertEquals("custom_08", $currentPage->title);
836
        $this->assertCount(4, $currentPage->entryArray);
837
        $this->assertEquals("cops:custom:10:-2", $currentPage->entryArray[0]->id);
838
        $this->assertEquals("cops:custom:10:-1", $currentPage->entryArray[1]->id);
839
        $this->assertEquals("cops:custom:10:1",  $currentPage->entryArray[2]->id);
840
        $this->assertEquals("cops:custom:10:2",  $currentPage->entryArray[3]->id);
841
842
843
        $_GET["custom"] = NULL;
844
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
845
        Base::clearDb();
846
    }
847
848
    public function testAllCustomsType09()
849
    {
850
        global $config;
851
852
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
853
        $_GET["custom"] = "9";
854
        Base::clearDb();
855
        $currentPage = Page::getPage(Base::PAGE_ALL_CUSTOMS, NULL, NULL, "1");
856
        $currentPage->InitializeContent();
857
858
859
        $this->assertEquals("custom_09", $currentPage->title);
860
        $this->assertCount(6, $currentPage->entryArray);
861
        $this->assertEquals("cops:custom:9:0",  $currentPage->entryArray[0]->id);
862
        $this->assertEquals("cops:custom:9:2",  $currentPage->entryArray[1]->id);
863
        $this->assertEquals("cops:custom:9:4",  $currentPage->entryArray[2]->id);
864
        $this->assertEquals("cops:custom:9:6",  $currentPage->entryArray[3]->id);
865
        $this->assertEquals("cops:custom:9:8",  $currentPage->entryArray[4]->id);
866
        $this->assertEquals("cops:custom:9:10", $currentPage->entryArray[5]->id);
867
868
869
        $_GET["custom"] = NULL;
870
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
871
        Base::clearDb();
872
    }
873
874
    public function testAllCustomsType10()
875
    {
876
        global $config;
877
878
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
879
        $_GET["custom"] = "11";
880
        Base::clearDb();
881
        $currentPage = Page::getPage(Base::PAGE_ALL_CUSTOMS, NULL, NULL, "1");
882
        $currentPage->InitializeContent();
883
884
885
        $this->assertEquals("custom_10", $currentPage->title);
886
        $this->assertCount(3, $currentPage->entryArray);
887
        $this->assertEquals("cops:custom:11:-1", $currentPage->entryArray[0]->id);
888
        $this->assertEquals("cops:custom:11:0",  $currentPage->entryArray[1]->id);
889
        $this->assertEquals("cops:custom:11:1",  $currentPage->entryArray[2]->id);
890
891
892
        $_GET["custom"] = NULL;
893
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
894
        Base::clearDb();
895
    }
896
897
    public function testDetailTypeAllEntryIDs()
898
    {
899
        global $config;
900
901
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
902
        $_GET["custom"] = "11";
903
        $config['cops_calibre_custom_column'] = array("custom_01", "custom_02", "custom_03", "custom_04", "custom_05", "custom_06", "custom_07", "custom_08", "custom_09", "custom_10", "custom_11");
904
        Base::clearDb();
905
906
        $currentPage = Page::getPage(Base::PAGE_CUSTOM_DETAIL, "0", NULL, "1");
907
        $currentPage->InitializeContent();
908
909
        /* @var EntryBook[] $entries */
910
        $entries = $currentPage->entryArray;
911
912
        $this->assertCount(6, $entries);
913
914
        $customcolumnValues = $entries[0]->book->getCustomColumnValues($config['cops_calibre_custom_column']);
915
916
        $this->assertCount(10, $customcolumnValues);
917
918
        $this->assertEquals("cops:custom:8:1", $customcolumnValues[0]->getEntryId());
919
        $this->assertEquals("cops:custom:6:3", $customcolumnValues[1]->getEntryId());
920
        $this->assertEquals("cops:custom:7:3", $customcolumnValues[2]->getEntryId());
921
        $this->assertEquals("cops:custom:4:4", $customcolumnValues[3]->getEntryId());
922
        $this->assertEquals("cops:custom:5:6", $customcolumnValues[4]->getEntryId());
923
        $this->assertEquals("cops:custom:12:2016-04-24", $customcolumnValues[5]->getEntryId());
924
        $this->assertEquals("cops:custom:14:11.0", $customcolumnValues[6]->getEntryId());
925
        $this->assertEquals("cops:custom:10:-2", $customcolumnValues[7]->getEntryId());
926
        $this->assertEquals("cops:custom:9:2", $customcolumnValues[8]->getEntryId());
927
        $this->assertEquals("cops:custom:11:0", $customcolumnValues[9]->getEntryId());
928
929
        $_GET["custom"] = NULL;
930
        $config['cops_calibre_custom_column'] = array();
931
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
932
        Base::clearDb();
933
    }
934
935
    public function testRenderCustomColumns()
936
    {
937
        global $config;
938
939
        $_SERVER["HTTP_USER_AGENT"] = "Firefox";
940
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
941
        $_GET["custom"] = "11";
942
        $config['cops_calibre_custom_column'] = array("custom_01", "custom_02", "custom_03", "custom_04", "custom_05", "custom_06", "custom_07", "custom_08", "custom_09", "custom_10", "custom_11");
943
        $config['cops_calibre_custom_column_list'] = array("custom_01", "custom_02", "custom_03", "custom_04", "custom_05", "custom_06", "custom_07", "custom_08", "custom_09", "custom_10", "custom_11");
944
        $config['cops_calibre_custom_column_preview'] = array("custom_01", "custom_02", "custom_03", "custom_04", "custom_05", "custom_06", "custom_07", "custom_08", "custom_09", "custom_10", "custom_11");
945
        Base::clearDb();
946
947
948
        $book = Book::getBookById(223);
949
        $json = JSONRenderer::getBookContentArray($book);
950
951
        /* @var CustomColumn[] $custom */
952
        $custom = $json["customcolumns_list"];
953
954
        $this->assertEquals("custom_01", $custom[0]['customColumnType']['columnTitle']);
955
        $this->assertEquals("text_2", $custom[0]['htmlvalue']);
956
957
        $this->assertEquals("custom_02", $custom[1]['customColumnType']['columnTitle']);
958
        $this->assertEquals("a", $custom[1]['htmlvalue']);
959
960
        $this->assertEquals("custom_03", $custom[2]['customColumnType']['columnTitle']);
961
        $this->assertEquals("<div>Not Set</div>", $custom[2]['htmlvalue']);
962
963
        $this->assertEquals("custom_04", $custom[3]['customColumnType']['columnTitle']);
964
        $this->assertEquals("", $custom[3]['htmlvalue']);
965
966
        $this->assertEquals("custom_05", $custom[4]['customColumnType']['columnTitle']);
967
        $this->assertEquals("val05", $custom[4]['htmlvalue']);
968
969
        $this->assertEquals("custom_06", $custom[5]['customColumnType']['columnTitle']);
970
        $this->assertEquals("Not Set", $custom[5]['htmlvalue']);
971
972
        $this->assertEquals("custom_07", $custom[6]['customColumnType']['columnTitle']);
973
        $this->assertEquals("100000.0", $custom[6]['htmlvalue']);
974
975
        $this->assertEquals("custom_08", $custom[7]['customColumnType']['columnTitle']);
976
        $this->assertEquals("Not Set", $custom[7]['htmlvalue']);
977
978
        $this->assertEquals("custom_09", $custom[8]['customColumnType']['columnTitle']);
979
        $this->assertEquals("Not Set", $custom[8]['htmlvalue']);
980
981
        $this->assertEquals("custom_10", $custom[9]['customColumnType']['columnTitle']);
982
        $this->assertEquals("No", $custom[9]['htmlvalue']);
983
984
        $_SERVER["HTTP_USER_AGENT"] = "";
985
        $_GET["custom"] = NULL;
986
        $config['cops_calibre_custom_column'] = array();
987
        $config['cops_calibre_custom_column_list'] = array();
988
        $config['cops_calibre_custom_column_preview'] = array();
989
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
990
        Base::clearDb();
991
    }
992
993
    public function testQueries()
994
    {
995
        global $config;
996
997
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
998
        $_GET["custom"] = "11";
999
        $config['cops_calibre_custom_column'] = array("custom_01", "custom_02", "custom_03", "custom_04", "custom_05", "custom_06", "custom_07", "custom_08", "custom_09", "custom_10", "custom_11");
1000
        Base::clearDb();
1001
1002
1003
        list($query, $params) = CustomColumnType::createByLookup("custom_01")->getCustom("1")->getQuery();
1004
        Book::getEntryArray($query, $params, 1);
1005
1006
        list($query, $params) = CustomColumnType::createByLookup("custom_02")->getCustom("3")->getQuery();
1007
        Book::getEntryArray($query, $params, 1);
1008
1009
        list($query, $params) = CustomColumnType::createByLookup("custom_03")->getCustom("3")->getQuery();
1010
        Book::getEntryArray($query, $params, 1);
1011
1012
        list($query, $params) = CustomColumnType::createByLookup("custom_04")->getCustom("4")->getQuery();
1013
        Book::getEntryArray($query, $params, 1);
1014
1015
        list($query, $params) = CustomColumnType::createByLookup("custom_05")->getCustom("6")->getQuery();
1016
        Book::getEntryArray($query, $params, 1);
1017
1018
        list($query, $params) = CustomColumnType::createByLookup("custom_06")->getCustom("2016-04-24")->getQuery();
1019
        Book::getEntryArray($query, $params, 1);
1020
1021
        list($query, $params) = CustomColumnType::createByLookup("custom_07")->getCustom("11.0")->getQuery();
1022
        Book::getEntryArray($query, $params, 1);
1023
1024
        list($query, $params) = CustomColumnType::createByLookup("custom_08")->getCustom("-2")->getQuery();
1025
        Book::getEntryArray($query, $params, 1);
1026
1027
        list($query, $params) = CustomColumnType::createByLookup("custom_09")->getCustom("0")->getQuery();
1028
        Book::getEntryArray($query, $params, 1);
1029
1030
        list($query, $params) = CustomColumnType::createByLookup("custom_09")->getCustom("1")->getQuery();
1031
        Book::getEntryArray($query, $params, 1);
1032
1033
        list($query, $params) = CustomColumnType::createByLookup("custom_10")->getCustom("-1")->getQuery();
1034
        Book::getEntryArray($query, $params, 1);
1035
1036
        list($query, $params) = CustomColumnType::createByLookup("custom_10")->getCustom("0")->getQuery();
1037
        Book::getEntryArray($query, $params, 1);
1038
1039
        list($query, $params) = CustomColumnType::createByLookup("custom_10")->getCustom("1")->getQuery();
1040
        Book::getEntryArray($query, $params, 1);
1041
1042
        $_GET["custom"] = NULL;
1043
        $config['cops_calibre_custom_column'] = array();
1044
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
1045
        Base::clearDb();
1046
    }
1047
1048
    public function testGetURI()
1049
    {
1050
        global $config;
1051
1052
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
1053
        $_GET["custom"] = "11";
1054
        $config['cops_calibre_custom_column'] = array("custom_01", "custom_02", "custom_03", "custom_04", "custom_05", "custom_06", "custom_07", "custom_08", "custom_09", "custom_10", "custom_11");
1055
        Base::clearDb();
1056
1057
1058
        $custom = CustomColumnType::createByLookup("custom_01")->getCustom("1");
1059
        $this->assertEquals($custom->customColumnType->getQuery("1"), $custom->getQuery());
1060
1061
        $custom = CustomColumnType::createByLookup("custom_02")->getCustom("3");
1062
        $this->assertEquals($custom->customColumnType->getQuery("3"), $custom->getQuery());
1063
1064
        $custom = CustomColumnType::createByLookup("custom_03")->getCustom("3");
1065
        $this->assertEquals($custom->customColumnType->getQuery("3"), $custom->getQuery());
1066
1067
        $custom = CustomColumnType::createByLookup("custom_04")->getCustom("4");
1068
        $this->assertEquals($custom->customColumnType->getQuery("4"), $custom->getQuery());
1069
1070
        $custom = CustomColumnType::createByLookup("custom_05")->getCustom("6");
1071
        $this->assertEquals($custom->customColumnType->getQuery("6"), $custom->getQuery());
1072
1073
        $custom = CustomColumnType::createByLookup("custom_06")->getCustom("2016-04-24");
1074
        $this->assertEquals($custom->customColumnType->getQuery("2016-04-24"), $custom->getQuery());
1075
1076
        $custom = CustomColumnType::createByLookup("custom_07")->getCustom("11.0");
1077
        $this->assertEquals($custom->customColumnType->getQuery("11.0"), $custom->getQuery());
1078
1079
        $custom = CustomColumnType::createByLookup("custom_08")->getCustom("-2");
1080
        $this->assertEquals($custom->customColumnType->getQuery("-2"), $custom->getQuery());
1081
1082
        $custom = CustomColumnType::createByLookup("custom_09")->getCustom("0");
1083
        $this->assertEquals($custom->customColumnType->getQuery("0"), $custom->getQuery());
1084
1085
        $custom = CustomColumnType::createByLookup("custom_09")->getCustom("1");
1086
        $this->assertEquals($custom->customColumnType->getQuery("1"), $custom->getQuery());
1087
1088
        $custom = CustomColumnType::createByLookup("custom_10")->getCustom("-1");
1089
        $this->assertEquals($custom->customColumnType->getQuery("-1"), $custom->getQuery());
1090
1091
        $custom = CustomColumnType::createByLookup("custom_10")->getCustom("0");
1092
        $this->assertEquals($custom->customColumnType->getQuery("0"), $custom->getQuery());
1093
1094
        $custom = CustomColumnType::createByLookup("custom_10")->getCustom("1");
1095
        $this->assertEquals($custom->customColumnType->getQuery("1"), $custom->getQuery());
1096
1097
        $_GET["custom"] = NULL;
1098
        $config['cops_calibre_custom_column'] = array();
1099
        $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
1100
        Base::clearDb();
1101
    }
1102
}