forked from ben-xo/dir2cast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettingsHandlerTest.php
687 lines (617 loc) · 23.6 KB
/
SettingsHandlerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
<?php declare(strict_types = 1);
use PHPUnit\Framework\TestCase;
class SettingsHandlerTest extends TestCase
{
static $DEFINE_LIST = array(
// from boostrap
'DIR2CAST_BASE',
'MIN_CACHE_TIME',
'FORCE_PASSWORD',
'TMP_DIR',
'MP3_BASE',
'MP3_DIR',
// from defaults
'MP3_URL',
'TITLE',
'LINK',
'RSS_LINK',
'DESCRIPTION',
'ATOM_TYPE',
'LANGUAGE',
'COPYRIGHT',
'TTL',
'ITEM_COUNT',
'ITUNES_SUBTITLE',
'ITUNES_SUMMARY',
'IMAGE',
'ITUNES_IMAGE',
'ITUNES_OWNER_NAME',
'ITUNES_OWNER_EMAIL',
'WEBMASTER',
'ITUNES_AUTHOR',
'ITUNES_CATEGORIES',
'ITUNES_EXPLICIT',
'LONG_TITLES',
'ITUNES_SUBTITLE_SUFFIX',
'ITUNES_TYPE',
'DESCRIPTION_SOURCE',
'RECURSIVE_DIRECTORY_ITERATOR',
'AUTO_SAVE_COVER_ART',
'DONT_UNCACHE_IF_OUTPUT_FILE',
'MIN_FILE_AGE',
);
public $temp_file = false;
public $starting_dir = false;
public function setUp(): void
{
$this->temp_file = false;
$this->starting_dir = false;
}
public function test_getopt_hook()
{
$argv_copy = $GLOBALS['argv'];
$argc_copy = $GLOBALS['argc'];
$short_options = '';
$long_options = array('help', 'media-dir::', 'bootstrap');
$cli_options = SettingsHandler::getopt(
array(),
$short_options, $long_options
);
$this->assertEquals($cli_options, array());
$cli_options = SettingsHandler::getopt(
array('dir2cast.php'),
$short_options, $long_options
);
$this->assertEquals($cli_options, array());
$cli_options = SettingsHandler::getopt(
array('dir2cast.php', '--help'),
$short_options, $long_options
);
$this->assertEquals($cli_options, array('help' => false));
$cli_options = SettingsHandler::getopt(
array('dir2cast.php', '--media-dir=test1'),
$short_options, $long_options
);
$this->assertEquals($cli_options, array('media-dir' => 'test1'));
$cli_options = SettingsHandler::getopt(
array('dir2cast.php', '--media-dir=test2', '--bootstrap'),
$short_options, $long_options
);
$this->assertEquals($cli_options, array('media-dir' => 'test2', 'bootstrap' => false));
$cli_options = SettingsHandler::getopt(
array('dir2cast.php', '--bootstrap', '--media-dir=test3'),
$short_options, $long_options
);
$this->assertEquals($cli_options, array('media-dir' => 'test3', 'bootstrap' => false));
$this->assertEquals($argv_copy, $GLOBALS['argv']);
$this->assertEquals($argc_copy, $GLOBALS['argc']);
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_default_defines_set()
{
$this->assertFalse(Dir_Podcast::$EMPTY_PODCAST_IS_ERROR);
$this->assertFalse(Dir_Podcast::$RECURSIVE_DIRECTORY_ITERATOR);
$this->assertEquals(10, Dir_Podcast::$ITEM_COUNT);
$this->assertEquals(0, Dir_Podcast::$MIN_FILE_AGE);
$this->assertEquals(5, Cached_Dir_Podcast::$MIN_CACHE_TIME);
$this->assertFalse(getID3_Podcast_Helper::$AUTO_SAVE_COVER_ART);
$this->assertEmpty(RSS_File_Item::$FILES_URL);
$this->assertEmpty(RSS_File_Item::$FILES_DIR);
$this->assertEmpty(iTunes_Podcast_Helper::$ITUNES_SUBTITLE_SUFFIX);
$this->assertEquals('episodic', iTunes_Podcast_Helper::$ITUNES_TYPE);
$this->assertFalse(Media_RSS_Item::$LONG_TITLES);
$this->assertEquals('comment', Media_RSS_Item::$DESCRIPTION_SOURCE);
foreach(self::$DEFINE_LIST as $define_name)
{
$this->assertFalse(defined($define_name));
}
SettingsHandler::bootstrap(
/* $SERVER */ array(),
/* $GET */ array(),
/* $argv */ array()
);
SettingsHandler::defaults(array());
foreach(self::$DEFINE_LIST as $define_name)
{
$this->assertTrue(defined($define_name));
}
// should not be defined as $argv was empty
$this->assertFalse(defined('CLI_ONLY'));
$this->assertEquals(DIR2CAST_BASE(), slashdir(realpath('..'))); // from bootstrap.php
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_pre_defined_slashed()
{
define('DIR2CAST_BASE', '/tmp/');
$this->assertEquals(DIR2CAST_BASE(), '/tmp/');
define('MP3_BASE', '/tmp/');
$this->assertEquals(DIR2CAST_BASE(), '/tmp/');
define('MP3_PATH', '/tmp/');
$this->assertEquals(DIR2CAST_BASE(), '/tmp/');
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_pre_defined_slashless()
{
define('DIR2CAST_BASE', '/tmp');
$this->assertEquals(DIR2CAST_BASE(), '/tmp/');
define('MP3_BASE', '/tmp');
$this->assertEquals(DIR2CAST_BASE(), '/tmp/');
define('MP3_PATH', '/tmp');
$this->assertEquals(DIR2CAST_BASE(), '/tmp/');
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_behaves_if_anything_is_already_defined()
{
foreach(self::$DEFINE_LIST as $define_name)
{
if($define_name != 'DIR2CAST_BASE') // always defined by bootstrap()
define($define_name, $define_name);
}
SettingsHandler::bootstrap(array(), array(), array());
SettingsHandler::defaults(array());
foreach(self::$DEFINE_LIST as $define_name)
{
if($define_name != 'DIR2CAST_BASE')
$this->assertEquals($define_name, constant($define_name));
}
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_defines_CLI_ONLY_if_argv0()
{
// opposite test is in test_default_defines_set() above
$this->assertFalse(defined('CLI_ONLY'));
SettingsHandler::bootstrap(array(), array(), array('dir2cast.php'));
$this->assertTrue(defined('CLI_ONLY'));
$this->assertEquals(DIR2CAST_BASE(), slashdir(getcwd())); // from fake $argv
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
* @testWith [null, null]
* ["dir2cast.php", null]
* ["dir2cast.php", "--media-dir="]
*/
public function test_bootstrap_sets_sensible_global_defaults_for_entire_installation($argv0, $argv1)
{
SettingsHandler::bootstrap(array(), array(), array($argv0, $argv1));
$this->assertEquals(MIN_CACHE_TIME, 5);
$this->assertEquals(FORCE_PASSWORD, '');
$this->assertEquals(TMP_DIR, DIR2CAST_BASE() . 'temp');
$this->assertEquals(MP3_BASE(), DIR2CAST_BASE());
$this->assertEquals(MP3_DIR(), DIR2CAST_BASE());
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_when_SERVER_HTTP_HOST_then_MP3_BASE_defaults_to_same_dir()
{
$SERVER = array(
'HTTP_HOST' => 'www.example.com',
'SCRIPT_FILENAME' => '/var/www/dir2cast.php',
);
SettingsHandler::bootstrap(
$SERVER,
/* $GET */ array(),
/* $argv */ array()
);
$this->assertEquals(MP3_BASE(), '/var/www/');
$this->assertEquals(MP3_DIR(), '/var/www/');
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_cli_media_404()
{
$this->temp_file = basename(tempnam('./', 'test_cli_media_404'));
$this->assertFalse(strpos($this->temp_file, '/'));
unlink($this->temp_file);
$this->expectException("ExitException");
$this->expectExceptionMessage("Not Found: {$this->temp_file}");
$this->expectExceptionCode(-2);
SettingsHandler::bootstrap(array(), array(), array("dir2cast.php", "--media-dir={$this->temp_file}"));
$this->assertFalse(http_response_code());
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_GET_media_404()
{
$this->temp_file = basename(tempnam('../', 'test_GET_media_404'));
$this->assertFalse(strpos($this->temp_file, '/'));
unlink('../' . $this->temp_file);
$this->expectException("ExitException");
$this->expectExceptionMessage("Not Found: {$this->temp_file}");
$this->expectExceptionCode(-2);
SettingsHandler::bootstrap(array(), array("dir" => $this->temp_file), array());
$this->assertEquals(http_response_code(), 404);
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_cli_media_not_dir_404()
{
$this->temp_file = basename(tempnam('./', 'test_cli_media_not_dir_404'));
$this->expectException("ExitException");
$this->expectExceptionMessage("Not Found: {$this->temp_file}");
$this->expectExceptionCode(-2);
SettingsHandler::bootstrap(array(), array(), array("dir2cast.php", "--media-dir={$this->temp_file}"));
$this->assertFalse(http_response_code());
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_GET_media_not_dir_404()
{
$this->temp_file = basename(tempnam('../', 'test_GET_media_not_dir_404'));
$this->expectException("ExitException");
$this->expectExceptionMessage("Not Found: {$this->temp_file}");
$this->expectExceptionCode(-2);
SettingsHandler::bootstrap(array(), array("dir" => $this->temp_file), array());
$this->assertEquals(http_response_code(), 404);
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_cli_media_dir_but_no_permissions_404()
{
$this->temp_file = basename(tempnam('./', 'test_cli_media_dir_but_no_permissions_404'));
unlink($this->temp_file);
mkdir($this->temp_file);
chmod($this->temp_file, 0);
$this->expectException("ExitException");
$this->expectExceptionMessage("Not Found: {$this->temp_file}");
$this->expectExceptionCode(-2);
SettingsHandler::bootstrap(array(), array(), array("dir2cast.php", "--media-dir={$this->temp_file}"));
$this->assertFalse(http_response_code());
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_GET_media_dir_but_no_permissions_404()
{
$this->temp_file = basename(tempnam('../', 'test_GET_media_dir_but_no_permissions_404'));
unlink('../' . $this->temp_file);
mkdir('../' . $this->temp_file);
chmod('../' . $this->temp_file, 0);
$this->expectException("ExitException");
$this->expectExceptionMessage("Not Found: {$this->temp_file}");
$this->expectExceptionCode(-2);
SettingsHandler::bootstrap(array(), array("dir" => $this->temp_file), array());
$this->assertEquals(http_response_code(), 404);
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_cli_media_dir_a_ok()
{
$this->temp_file = basename(tempnam('./', 'test_cli_media_dir_a_ok'));
unlink($this->temp_file);
mkdir($this->temp_file);
SettingsHandler::bootstrap(array(), array(), array("dir2cast.php", "--media-dir={$this->temp_file}"));
$this->assertEquals(MP3_BASE(), slashdir(realpath('.')));
$this->assertEquals(MP3_DIR(), slashdir(realpath($this->temp_file)));
$this->assertFalse(http_response_code());
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_GET_media_dir_a_ok()
{
$this->temp_file = basename(tempnam('../', 'test_GET_media_dir_a_ok'));
unlink('../' . $this->temp_file);
mkdir('../' . $this->temp_file);
SettingsHandler::bootstrap(array(), array("dir" => $this->temp_file), array());
$this->assertEquals(MP3_BASE(), slashdir(realpath('..'))); // due to bootstrap.php chdir
$this->assertEquals(MP3_DIR(), slashdir(realpath('../' . $this->temp_file)));
$this->assertFalse(http_response_code());
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_GET_media_dir_safe_dot_dot_1()
{
$this->starting_dir = getcwd();
mkdir('deep');
mkdir('deep/root');
chdir('deep/root');
SettingsHandler::bootstrap(array(), array("dir" => ".."), array());
$this->assertEquals(MP3_BASE(), slashdir(realpath("{$this->starting_dir}/.."))); // due to bootstrap.php chdir
$this->assertEquals(MP3_DIR(), MP3_BASE());
$this->assertFalse(http_response_code());
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_GET_media_dir_safe_dot_dot_2()
{
$this->starting_dir = getcwd();
mkdir('deep');
mkdir('deep/root');
chdir('deep/root');
SettingsHandler::bootstrap(array(), array("dir" => "../../.."), array());
$this->assertEquals(MP3_BASE(), slashdir(realpath("{$this->starting_dir}/.."))); // due to bootstrap.php chdir
$this->assertEquals(MP3_DIR(), MP3_BASE());
$this->assertFalse(http_response_code());
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_GET_media_dir_safe_slash_dir()
{
$this->starting_dir = getcwd();
mkdir('deep');
mkdir('deep/root');
chdir('deep/root');
$this->expectException("ExitException");
$this->expectExceptionMessage("Not Found: /etc");
$this->expectExceptionCode(-2);
SettingsHandler::bootstrap(array(), array("dir" => "/etc"), array());
$this->assertEquals(http_response_code(), 404);
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_GET_media_dir_safe_slash_dir_2()
{
$this->starting_dir = getcwd();
mkdir('deep');
mkdir('deep/root');
chdir('deep/root');
$this->expectException("ExitException");
$this->expectExceptionMessage("Not Found: ////etc");
$this->expectExceptionCode(-2);
SettingsHandler::bootstrap(array(), array("dir" => "////etc"), array());
$this->assertEquals(http_response_code(), 404);
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_GET_media_dir_safe_dir_with_good_base()
{
$this->starting_dir = getcwd();
mkdir('deep');
mkdir('deep/root');
chdir('deep/root');
define('MP3_BASE', realpath('..'));
SettingsHandler::bootstrap(array(), array("dir" => "root"), array());
$this->assertEquals(MP3_BASE(), realpath("..") . '/');
$this->assertEquals(MP3_DIR(), realpath('.') . '/');
$this->assertFalse(http_response_code());
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_GET_media_dir_unsafe_slash_dir_with_good_base()
{
$this->starting_dir = getcwd();
mkdir('deep');
mkdir('deep/root');
chdir('deep/root');
define('MP3_BASE', realpath('..'));
$this->expectException("ExitException");
$this->expectExceptionMessage("Not Found: ../deep/root");
$this->expectExceptionCode(-2);
SettingsHandler::bootstrap(array(), array("dir" => "../deep/root"), array());
$this->assertEquals(http_response_code(), 404);
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
// public function test_cli_arg_parsing()
// {
// }
// TODO: test HTTP_HOST + GET dir
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
* @testWith [null]
* ["dir2cast.php"]
*/
public function test_sensible_defaults($argv0)
{
SettingsHandler::bootstrap(array(), array(), array($argv0));
SettingsHandler::defaults(array());
$this->assertEquals(DESCRIPTION, 'Podcast');
$this->assertEquals(ATOM_TYPE, 'application/rss+xml');
$this->assertEquals(LANGUAGE, 'en-us');
$this->assertEquals(COPYRIGHT, date('Y'));
$this->assertEquals(TTL, 60);
$this->assertEquals(ITEM_COUNT, 10);
$this->assertEquals(ITUNES_OWNER_NAME, '');
$this->assertEquals(ITUNES_OWNER_EMAIL, '');
$this->assertEquals(WEBMASTER, '');
$this->assertEquals(ITUNES_AUTHOR, '');
$this->assertEquals(ITUNES_CATEGORIES, '');
$this->assertEquals(ITUNES_EXPLICIT, '');
$this->assertEquals(LONG_TITLES, false);
$this->assertEquals(ITUNES_SUBTITLE_SUFFIX, '');
$this->assertEquals(ITUNES_TYPE, 'episodic');
$this->assertEquals(DESCRIPTION_SOURCE, 'comment');
$this->assertEquals(RECURSIVE_DIRECTORY_ITERATOR, false);
$this->assertEquals(AUTO_SAVE_COVER_ART, true);
$this->assertEquals(DONT_UNCACHE_IF_OUTPUT_FILE, false);
$this->assertEquals(MIN_FILE_AGE, 30);
$this->assertSame(Dir_Podcast::$EMPTY_PODCAST_IS_ERROR, empty($argv0));
$this->assertSame(Dir_Podcast::$RECURSIVE_DIRECTORY_ITERATOR, RECURSIVE_DIRECTORY_ITERATOR);
$this->assertSame(Dir_Podcast::$ITEM_COUNT, ITEM_COUNT);
$this->assertSame(Dir_Podcast::$MIN_FILE_AGE, MIN_FILE_AGE);
$this->assertSame(Cached_Dir_Podcast::$MIN_CACHE_TIME, MIN_CACHE_TIME);
$this->assertSame(getID3_Podcast_Helper::$AUTO_SAVE_COVER_ART, AUTO_SAVE_COVER_ART);
$this->assertSame(iTunes_Podcast_Helper::$ITUNES_SUBTITLE_SUFFIX, ITUNES_SUBTITLE_SUFFIX);
$this->assertSame(iTunes_Podcast_Helper::$ITUNES_TYPE, ITUNES_TYPE);
$this->assertSame(RSS_File_Item::$FILES_URL, MP3_URL);
$this->assertSame(RSS_File_Item::$FILES_DIR, MP3_DIR());
$this->assertSame(Media_RSS_Item::$LONG_TITLES, LONG_TITLES);
$this->assertSame(Media_RSS_Item::$DESCRIPTION_SOURCE, DESCRIPTION_SOURCE);
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
* @testWith [null]
* ["dir2cast.php"]
*/
public function test_webmaster_default_if_itunes_author($argv0)
{
define('ITUNES_OWNER_NAME', 'Ben');
define('ITUNES_OWNER_EMAIL', '[email protected]');
SettingsHandler::bootstrap(array(), array(), array($argv0));
SettingsHandler::defaults(array());
$this->assertEquals('[email protected] (Ben)', WEBMASTER);
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_CLI_ONLY_sensible_defaults()
{
SettingsHandler::bootstrap(array(), array(), array('dir2cast.php'));
SettingsHandler::defaults(array());
$this->assertEquals(MP3_URL, 'file://' . getcwd() . '/');
$this->assertEquals(LINK, 'http://www.example.com/');
$this->assertEquals(RSS_LINK, 'http://www.example.com/rss');
$this->assertEquals(TITLE, 'test'); // name of this folder
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_HTTP_HOST_sensible_defaults()
{
$SERVER = array(
'HTTP_HOST' => 'www.example.com',
'SCRIPT_FILENAME' => realpath('..') . '/dir2cast.php',
'PHP_SELF' => '/dir2cast.php',
'DOCUMENT_ROOT' => realpath('..'),
);
SettingsHandler::bootstrap(
$SERVER,
/* $GET */ array(),
/* $argv */ array()
);
SettingsHandler::defaults(
$SERVER
);
// note that with HTTP_HOST we trust SCRIPT_FILENAME over dirname(__FILE__)
// because it could be a symlink or a mapping inside the web server config.
$this->assertEquals('http://www.example.com/', MP3_URL);
$this->assertEquals('http://www.example.com/dir2cast.php', LINK);
$this->assertEquals('http://www.example.com/dir2cast.php', RSS_LINK);
$this->assertEquals(basename(realpath('..')), TITLE); // name of fodler from SCRIPT_FILENAME
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_picks_up_feed_text_files_if_they_exist()
{
file_put_contents('description.txt', 'test description');
file_put_contents('itunes_subtitle.txt', 'test itunes subtitle');
file_put_contents('itunes_summary.txt', 'test itunes summary');
touch('image.jpg');
touch('itunes_image.jpg');
$SERVER = array(
'HTTP_HOST' => 'www.example.com',
'SCRIPT_FILENAME' => realpath('.') . '/dir2cast.php',
'PHP_SELF' => '/dir2cast.php',
'DOCUMENT_ROOT' => realpath('.'),
);
SettingsHandler::bootstrap(
$SERVER,
/* $GET */ array(),
/* $argv */ array()
);
SettingsHandler::defaults(
$SERVER
);
$this->assertEquals('test description', DESCRIPTION);
$this->assertEquals('test itunes subtitle', ITUNES_SUBTITLE);
$this->assertEquals('test itunes summary', ITUNES_SUMMARY);
$this->assertEquals('http://www.example.com/image.jpg', IMAGE);
$this->assertEquals('http://www.example.com/itunes_image.jpg', ITUNES_IMAGE);
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_HTTPS_URLs_exist()
{
touch('image.jpg');
touch('itunes_image.jpg');
$SERVER = array(
'HTTP_HOST' => 'www.example.com',
'SCRIPT_FILENAME' => realpath('.') . '/dir2cast.php',
'PHP_SELF' => '/dir2cast.php',
'DOCUMENT_ROOT' => realpath('.'),
'HTTPS' => 1,
);
SettingsHandler::bootstrap(
$SERVER,
/* $GET */ array(),
/* $argv */ array()
);
SettingsHandler::defaults(
$SERVER
);
$this->assertEquals('https://www.example.com/', MP3_URL);
$this->assertEquals('https://www.example.com/dir2cast.php', LINK);
$this->assertEquals('https://www.example.com/dir2cast.php', RSS_LINK);
$this->assertEquals('https://www.example.com/image.jpg', IMAGE);
$this->assertEquals('https://www.example.com/itunes_image.jpg', ITUNES_IMAGE);
}
public function tearDown(): void
{
if($this->starting_dir) {
chdir($this->starting_dir);
rmrf('deep');
}
file_exists('description.txt') && unlink('description.txt');
file_exists('itunes_subtitle.txt') && unlink('itunes_subtitle.txt');
file_exists('itunes_summary.txt') && unlink('itunes_summary.txt');
file_exists('image.jpg') && unlink('image.jpg');
file_exists('itunes_image.jpg') && unlink('itunes_image.jpg');
if($this->temp_file)
{
if(file_exists($this->temp_file)) {
chmod($this->temp_file, 755);
if(is_dir($this->temp_file)) rmdir($this->temp_file);
else unlink($this->temp_file);
}
elseif(file_exists('../'.$this->temp_file)) {
chmod('../'.$this->temp_file, 755);
if(is_dir('../'.$this->temp_file)) rmdir('../'.$this->temp_file);
else unlink('../'.$this->temp_file);
}
}
}
}