Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * Test suite for bugs declared in the PHP_CompatInfo class
4
 *
5
 * PHP version 5
6
 *
7
 * @category PHP
8
 * @package  PHP_CompatInfo
9
 * @author   Laurent Laville <pear@laurent-laville.org>
10
 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD
11
 * @version  CVS: $Id: PHP_CompatInfo_TestSuite_Bugs.php,v 1.23 2008/12/18 23:06:45 farell Exp $
12
 * @link     http://pear.php.net/package/PHP_CompatInfo
13
 * @since    File available since Release 1.6.0
14
 */
15
if (!defined("PHPUnit_MAIN_METHOD")) {
16
    define("PHPUnit_MAIN_METHOD", "PHP_CompatInfo_TestSuite_Bugs::main");
17
}
18
 
19
require_once "PHPUnit/Framework/TestCase.php";
20
require_once "PHPUnit/Framework/TestSuite.php";
21
 
22
require_once 'PHP/CompatInfo.php';
23
 
24
/**
25
 * Test suite class to test standard PHP_CompatInfo API.
26
 *
27
 * @category PHP
28
 * @package  PHP_CompatInfo
29
 * @author   Laurent Laville <pear@laurent-laville.org>
30
 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD
31
 * @version  Release: 1.9.0
32
 * @link     http://pear.php.net/package/PHP_CompatInfo
33
 * @since    File available since Release 1.6.0
34
 */
35
class PHP_CompatInfo_TestSuite_Bugs extends PHPUnit_Framework_TestCase
36
{
37
    /**
38
     * A PCI object
39
     * @var  object
40
     */
41
    protected $pci;
42
 
43
    /**
44
     * Filename where to write results of debug pci events notification
45
     * @var   string
46
     * @since 1.8.0RC1
47
     */
48
    private $destLogFile;
49
 
50
    /**
51
     * Runs the test methods of this class.
52
     *
53
     * @return void
54
     */
55
    public static function main()
56
    {
57
        include_once "PHPUnit/TextUI/TestRunner.php";
58
 
59
        $suite = new PHPUnit_Framework_TestSuite('PHP_CompatInfo Bugs Tests');
60
        PHPUnit_TextUI_TestRunner::run($suite);
61
    }
62
 
63
    /**
64
     * Sets up the fixture.
65
     * This method is called before a test is executed.
66
     *
67
     * @return void
68
     */
69
    protected function setUp()
70
    {
71
        $this->destLogFile = dirname(__FILE__) . DIRECTORY_SEPARATOR .
72
                             __CLASS__ . '.log';
73
 
74
        $this->pci = new PHP_CompatInfo('null');
75
        $this->pci->addListener(array(&$this, 'debugNotify'));
76
    }
77
 
78
    /**
79
     * Tears down the fixture.
80
     * This method is called after a test is executed.
81
     *
82
     * @return void
83
     */
84
    protected function tearDown()
85
    {
86
        unset($this->pci);
87
    }
88
 
89
    /**
90
     * PCI Events notification observer for debug purpose only
91
     *
92
     * @param object &$auditEvent Instance of Event_Notification object
93
     *
94
     * @return void
95
     */
96
    public function debugNotify(&$auditEvent)
97
    {
98
        $notifyName = $auditEvent->getNotificationName();
99
        $notifyInfo = $auditEvent->getNotificationInfo();
100
 
101
        if ($notifyName == PHP_COMPATINFO_EVENT_AUDITSTARTED) {
102
            $dbt = debug_backtrace();
103
            error_log('backtrace: '. $dbt[7]['function'] . PHP_EOL,
104
                      3, $this->destLogFile);
105
            error_log($notifyName.':'. PHP_EOL .
106
                      var_export($notifyInfo, true) . PHP_EOL,
107
                      3, $this->destLogFile);
108
 
109
        } elseif ($notifyName == PHP_COMPATINFO_EVENT_AUDITFINISHED) {
110
            error_log($notifyName.':'. PHP_EOL .
111
                      var_export($notifyInfo, true) . PHP_EOL,
112
                      3, $this->destLogFile);
113
        }
114
    }
115
 
116
    /**
117
     * Retrieve files list to be ignore by parsing process
118
     *
119
     * @param string $dir     Directory to parse
120
     * @param array  $options Parser options
121
     *
122
     * @return array
123
     * @since  version 1.8.0RC1
124
     */
125
    private function getIgnoredFileList($dir, $options)
126
    {
127
        $files = $this->pci->parser->getFileList($dir, $options);
128
 
129
        $ff               = new File_Find();
130
        $ff->dirsep       = DIRECTORY_SEPARATOR;
131
        list(, $allfiles) = $ff->maptree($dir);
132
 
133
        $ignored_files = PHP_CompatInfo_Parser::_arrayDiff($allfiles, $files);
134
        return $ignored_files;
135
    }
136
 
137
    /**
138
     * Test if a dictionary for an Extension is available or not
139
     *
140
     * @param array  $resources   List of Extension dictionaries
141
     *                            that should be present to perform a unit test
142
     * @param array &$testSkipped Reasons of tests skipped
143
     *
144
     * @return bool
145
     * @since  version 1.9.0b2
146
     */
147
    private function isResourceAvailable($resources, &$testSkipped)
148
    {
149
        $dict = array();
150
        foreach ($resources as $ext) {
151
            if (!isset($GLOBALS['_PHP_COMPATINFO_FUNC_'.strtoupper($ext)])) {
152
                $dict[] = $ext;
153
            }
154
        }
155
        if (count($dict) == 1) {
156
            $testSkipped[] = 'The '. $dict[0] .
157
                             ' function dictionary is not available.';
158
        } elseif (count($dict) > 1) {
159
            $testSkipped[] = 'The '. implode(',', $dict) .
160
                             ' function dictionaries are not available.';
161
        }
162
        return (count($testSkipped) == 0);
163
    }
164
 
165
    /**
166
     * Regression test for bug #1626
167
     *
168
     * @return void
169
     * @link   http://pear.php.net/bugs/bug.php?id=1626
170
     *         Class calls are seen wrong
171
     * @covers PHP_CompatInfo::parseString
172
     * @group  parseString
173
     */
174
    public function testBug1626()
175
    {
176
        $str = '<?php
177
include("File.php");
178
File::write("test", "test");
179
?>';
180
        $r   = $this->pci->parseString($str);
181
        $exp = array('ignored_files' => array(),
182
                     'ignored_functions' => array(),
183
                     'ignored_extensions' => array(),
184
                     'ignored_constants' => array(),
185
                     'max_version' => '',
186
                     'version' => '4.0.0',
187
                     'classes' => array(),
188
                     'functions' => array(),
189
                     'extensions' => array(),
190
                     'constants' => array(),
191
                     'tokens' => array(),
192
                     'cond_code' => array(0));
193
        $this->assertSame($exp, $r);
194
    }
195
 
196
    /**
197
     * Regression test for bug #2771
198
     *
199
     * @return void
200
     * @link   http://pear.php.net/bugs/bug.php?id=2771
201
     *         Substr($var,4) not working for SAPI_ extensions
202
     * @covers PHP_CompatInfo::parseString
203
     * @group  parseString
204
     */
205
    public function testBug2771()
206
    {
207
        $str = '<?php
208
apache_request_headers();
209
apache_response_headers();
210
?>';
211
        $r   = $this->pci->parseString($str);
212
        $exp = array('ignored_files' => array(),
213
                     'ignored_functions' => array(),
214
                     'ignored_extensions' => array(),
215
                     'ignored_constants' => array(),
216
                     'max_version' => '',
217
                     'version' => '4.3.0',
218
                     'classes' => array(),
219
                     'functions' => array('apache_request_headers',
220
                                          'apache_response_headers'),
221
                     'extensions' => array(),
222
                     'constants' => array(),
223
                     'tokens' => array(),
224
                     'cond_code' => array(0));
225
        $this->assertSame($exp, $r);
226
    }
227
 
228
    /**
229
     * Regression test for bug #7813
230
     *
231
     * Parse source file of PEAR_PackageUpdate 0.5.0
232
     *
233
     * @return void
234
     * @link   http://pear.php.net/bugs/bug.php?id=7813
235
     *         wrong PHP minimum version detection
236
     * @covers PHP_CompatInfo::parseFile
237
     * @group  parseFile
238
     */
239
    public function testBug7813()
240
    {
241
        $ds  = DIRECTORY_SEPARATOR;
242
        $fn  = dirname(__FILE__) . $ds . 'parseFile' . $ds . 'PackageUpdate.php';
243
        $opt = array('debug' => true,
244
                     'ignore_functions' => array('debug_backtrace'));
245
        $r   = $this->pci->parseFile($fn, $opt);
246
        $exp = array('ignored_files' => array(),
247
                     'ignored_functions' => array('debug_backtrace'),
248
                     'ignored_extensions' => array(),
249
                     'ignored_constants' => array(),
250
                     'max_version' => '',
251
                     'version' => '4.3.0',
252
                     'classes' => array('PEAR_Config'),
253
                     'functions' => array('array_keys',
254
                                          'array_shift',
255
                                          'class_exists',
256
                                          'count',
257
                                          'debug_backtrace',
258
                                          'define',
259
                                          'explode',
260
                                          'factory',
261
                                          'fclose',
262
                                          'file_exists',
263
                                          'file_get_contents',
264
                                          'fopen',
265
                                          'function_exists',
266
                                          'fwrite',
267
                                          'get_class',
268
                                          'get_include_path',
269
                                          'getenv',
270
                                          'is_array',
271
                                          'is_int',
272
                                          'is_readable',
273
                                          'reset',
274
                                          'serialize',
275
                                          'settype',
276
                                          'strlen',
277
                                          'unserialize',
278
                                          'version_compare'),
279
                     'extensions' => array(),
280
                     'constants' => array('DIRECTORY_SEPARATOR',
281
                                          'E_COMPILE_ERROR',
282
                                          'E_COMPILE_WARNING',
283
                                          'E_CORE_ERROR',
284
                                          'E_CORE_WARNING',
285
                                          'E_ERROR',
286
                                          'E_NOTICE',
287
                                          'E_PARSE',
288
                                          'E_USER_ERROR',
289
                                          'E_USER_NOTICE',
290
                                          'E_USER_WARNING',
291
                                          'E_WARNING',
292
                                          'FALSE',
293
                                          'NULL',
294
                                          'PATH_SEPARATOR',
295
                                          'TRUE'),
296
                     'tokens' => array(),
297
                     'cond_code' => array(1, array(array('debug_backtrace'),
298
                                                   array(),
299
                                                   array())),
300
                     '4.0.0' =>
301
                     array(
302
 
303
                       array(
304
                         'function' => 'define',
305
                         'extension' => false,
306
                         'pecl' => false
307
                       ),
308
                       1 =>
309
                       array (
310
                         'function' => 'get_class',
311
                         'extension' => false,
312
                         'pecl' => false
313
                       ),
314
                       2 =>
315
                       array (
316
                         'function' => 'function_exists',
317
                         'extension' => false,
318
                         'pecl' => false
319
                       ),
320
                       3 =>
321
                       array (
322
                         'function' => 'count',
323
                         'extension' => false,
324
                         'pecl' => false
325
                       ),
326
                       4 =>
327
                       array (
328
                         'function' => 'class_exists',
329
                         'extension' => false,
330
                         'pecl' => false
331
                       ),
332
                       5 =>
333
                       array (
334
                         'function' => 'explode',
335
                         'extension' => false,
336
                         'pecl' => false
337
                       ),
338
                       6 =>
339
                       array (
340
                         'function' => 'file_exists',
341
                         'extension' => false,
342
                         'pecl' => false
343
                       ),
344
                       7 =>
345
                       array (
346
                         'function' => 'is_readable',
347
                         'extension' => false,
348
                         'pecl' => false
349
                       ),
350
                       8 =>
351
                       array (
352
                         'function' => 'unserialize',
353
                         'extension' => false,
354
                         'pecl' => false
355
                       ),
356
                       9 =>
357
                       array (
358
                         'function' => 'strlen',
359
                         'extension' => false,
360
                         'pecl' => false
361
                       ),
362
                       10 =>
363
                       array (
364
                         'function' => 'getenv',
365
                         'extension' => false,
366
                         'pecl' => false
367
                       ),
368
                       11 =>
369
                       array (
370
                         'function' => 'reset',
371
                         'extension' => false,
372
                         'pecl' => false
373
                       ),
374
                       12 =>
375
                       array (
376
                         'function' => 'array_keys',
377
                         'extension' => false,
378
                         'pecl' => false
379
                       ),
380
                       13 =>
381
                       array (
382
                         'function' => 'fopen',
383
                         'extension' => false,
384
                         'pecl' => false
385
                       ),
386
                       14 =>
387
                       array (
388
                         'function' => 'serialize',
389
                         'extension' => false,
390
                         'pecl' => false
391
                       ),
392
                       15 =>
393
                       array (
394
                         'function' => 'fwrite',
395
                         'extension' => false,
396
                         'pecl' => false
397
                       ),
398
                       16 =>
399
                       array (
400
                         'function' => 'fclose',
401
                         'extension' => false,
402
                         'pecl' => false
403
                       ),
404
                       17 =>
405
                       array (
406
                         'function' => 'settype',
407
                         'extension' => false,
408
                         'pecl' => false
409
                       ),
410
                       18 =>
411
                       array (
412
                         'function' => 'is_int',
413
                         'extension' => false,
414
                         'pecl' => false
415
                       ),
416
                       19 =>
417
                       array (
418
                         'function' => 'is_array',
419
                         'extension' => false,
420
                         'pecl' => false,
421
                       ),
422
                       20 =>
423
                       array (
424
                         'function' => 'array_shift',
425
                         'extension' => false,
426
                         'pecl' => false
427
                       )
428
                     ),
429
                     '4.0.7' =>
430
                     array (
431
 
432
                       array (
433
                         'function' => 'version_compare',
434
                         'extension' => false,
435
                         'pecl' => false
436
                       )
437
                     ),
438
                     '4.3.0' =>
439
                     array (
440
 
441
                       array (
442
                         'function' => 'get_include_path',
443
                         'extension' => false,
444
                         'pecl' => false,
445
                       ),
446
                       1 =>
447
                       array (
448
                         'function' => 'file_get_contents',
449
                         'extension' => false,
450
                         'pecl' => false
451
                       )
452
                     ));
453
 
454
        $this->assertSame($exp, $r);
455
    }
456
 
457
    /**
458
     * Regression test for bug #8559
459
     *
460
     * @return void
461
     * @link   http://pear.php.net/bugs/bug.php?id=8559
462
     *         PHP_CompatInfo fails to scan if it finds empty file in path
463
     * @covers PHP_CompatInfo::parseDir
464
     * @group  parseDir
465
     */
466
    public function testBug8559()
467
    {
468
        $dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'emptyDir';
469
        $r   = $this->pci->parseDir($dir);
470
        $this->assertFalse($r);
471
    }
472
 
473
    /**
474
     * Regression test for bug #10100
475
     *
476
     * @return void
477
     * @link   http://pear.php.net/bugs/bug.php?id=10100
478
     *         Wrong parsing of possible attributes in strings
479
     * @covers PHP_CompatInfo::parseString
480
     * @group  parseString
481
     * @group  bugs
482
     */
483
    public function testBug10100()
484
    {
485
        $str = '<?php
486
$test = "public$link";
487
?>';
488
        $r   = $this->pci->parseString($str);
489
        $exp = array('ignored_files' => array(),
490
                     'ignored_functions' => array(),
491
                     'ignored_extensions' => array(),
492
                     'ignored_constants' => array(),
493
                     'max_version' => '',
494
                     'version' => '4.0.0',
495
                     'classes' => array(),
496
                     'functions' => array(),
497
                     'extensions' => array(),
498
                     'constants' => array(),
499
                     'tokens' => array(),
500
                     'cond_code' => array(0));
501
        $this->assertSame($exp, $r);
502
    }
503
 
504
    /**
505
     * Regression test for bug #13873
506
     *
507
     * @return void
508
     * @link   http://pear.php.net/bugs/bug.php?id=13873
509
     *         PHP_CompatInfo fails to scan conditional code
510
     *         if it finds other than encapsed string
511
     * @covers PHP_CompatInfo::parseFolder
512
     * @group  parseDir
513
     * @group  bugs
514
     */
515
    public function testBug13873()
516
    {
517
        $resources   = array('date', 'pcre');
518
        $testSkipped = array();
519
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
520
            foreach ($testSkipped as $reason) {
521
                $this->markTestSkipped($reason);
522
            }
523
        }
524
 
525
        $ds  = DIRECTORY_SEPARATOR;
526
        $dir = dirname(__FILE__) . $ds . 'beehiveforum082' . $ds . 'forum';
527
        $opt = array();
528
        $r   = $this->pci->parseFolder($dir, $opt);
529
        $exp = array('ignored_files' => $this->getIgnoredFileList($dir, $opt),
530
                     'ignored_functions' => array(),
531
                     'ignored_extensions' => array(),
532
                     'ignored_constants' => array(),
533
                     'max_version' => '',
534
                     'version' => '4.0.6',
535
                     'classes' => array(),
536
                     'functions' => array('_htmlentities',
537
                                          '_stripslashes',
538
                                          'array_map',
539
                                          'array_merge',
540
                                          'basename',
541
                                          'bh_session_check_perm',
542
                                          'bh_session_get_value',
543
                                          'bh_setcookie',
544
                                          'db_affected_rows',
545
                                          'db_connect',
546
                                          'db_escape_string',
547
                                          'db_fetch_array',
548
                                          'db_insert_id',
549
                                          'db_num_rows',
550
                                          'db_query',
551
                                          'db_trigger_error',
552
                                          'defined',
553
                                          'delete_attachment_by_aid',
554
                                          'explode',
555
                                          'fclose',
556
                                          'file_exists',
557
                                          'filesize',
558
                                          'fix_html',
559
                                          'floor',
560
                                          'folder_get_available_by_forum',
561
                                          'fopen',
562
                                          'form_checkbox',
563
                                          'form_input_hidden',
564
                                          'form_input_password',
565
                                          'form_submit',
566
                                          'forum_apply_user_permissions',
567
                                          'forum_check_global_setting_name',
568
                                          'forum_check_password',
569
                                          'forum_check_setting_name',
570
                                          'forum_closed_message',
571
                                          'forum_delete',
572
                                          'forum_delete_tables',
573
                                          'forum_get_all_prefixes',
574
                                          'forum_get_global_settings',
575
                                          'forum_get_password',
576
                                          'forum_get_saved_password',
577
                                          'forum_get_setting',
578
                                          'forum_get_settings_by_fid',
579
                                          'forum_process_unread_cutoff',
580
                                          'forum_restricted_message',
581
                                          'forum_search',
582
                                          'forum_start_page_get_html',
583
                                          'fread',
584
                                          'function_exists',
585
                                          'fwrite',
586
                                          'get_forum_data',
587
                                          'get_request_uri',
588
                                          'get_table_prefix',
589
                                          'get_webtag',
590
                                          'header',
591
                                          'html_display_error_msg',
592
                                          'html_display_warning_msg',
593
                                          'html_draw_bottom',
594
                                          'html_draw_top',
595
                                          'html_get_top_frame_name',
596
                                          'implode',
597
                                          'in_array',
598
                                          'install_get_table_conflicts',
599
                                          'intval',
600
                                          'is_array',
601
                                          'is_dir',
602
                                          'is_md5',
603
                                          'is_null',
604
                                          'is_numeric',
605
                                          'load_language_file',
606
                                          'md5',
607
                                          'mkdir',
608
                                          'mt_rand',
609
                                          'ob_end_clean',
610
                                          'ob_get_contents',
611
                                          'ob_start',
612
                                          'perm_group_get_users',
613
                                          'preg_match',
614
                                          'sizeof',
615
                                          'sprintf',
616
                                          'str_replace',
617
                                          'stristr',
618
                                          'strlen',
619
                                          'strtoupper',
620
                                          'time',
621
                                          'trim',
622
                                          'user_get_logon',
623
                                          'word_filter_rem_ob_tags'),
624
                     'extensions' => array('date', 'pcre'),
625
                     'constants' => array('FALSE',
626
                                          'TRUE',
627
                                          '__FILE__'),
628
                     'tokens' => array(),
629
                     'cond_code' => array(4)
630
                    );
631
        $this->assertSame($exp, $r);
632
    }
633
 
634
    /**
635
     * Regression test for bug #14696
636
     *
637
     * @return void
638
     * @link   http://pear.php.net/bugs/bug.php?id=14696
639
     *         PHP_CompatInfo fails to scan code line when not ended with ;
640
     * @covers PHP_CompatInfo::parseFile
641
     * @group  parseFile
642
     * @group  bugs
643
     */
644
    public function testBug14696()
645
    {
646
        $ds  = DIRECTORY_SEPARATOR;
647
        $fn  = dirname(__FILE__) . $ds . 'kohana22'
648
                                 . $ds . 'modules' . $ds . 'gmaps'
649
                                 . $ds . 'javascript.php';
650
 
651
        $r   = $this->pci->parseFile($fn);
652
        $exp = array('ignored_files' => array(),
653
                     'ignored_functions' => array(),
654
                     'ignored_extensions' => array(),
655
                     'ignored_constants' => array(),
656
                     'max_version' => '',
657
                     'version' => '4.0.0',
658
                     'classes' => array(),
659
                     'functions' => array('substr'),
660
                     'extensions' => array(),
661
                     'constants' => array(),
662
                     'tokens' => array(),
663
                     'cond_code' => array(0)
664
                     );
665
 
666
        $this->assertSame($exp, $r);
667
    }
668
}
669
 
670
// Call PHP_CompatInfo_TestSuite_Bugs::main() if file is executed directly.
671
if (PHPUnit_MAIN_METHOD == "PHP_CompatInfo_TestSuite_Bugs::main") {
672
    PHP_CompatInfo_TestSuite_Bugs::main();
673
}
674
?>