Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * Unit Tests for the phpDocumentor_setup->cleanConverterNamePiece() method
4
 * @package tests
5
 * @subpackage PhpDocumentorUnitTests
6
 * @author Chuck Burgess
7
 * @since 1.3.2
8
 */
9
 
10
/**
11
 * PHPUnit main() hack
12
 *
13
 * "Call class::main() if this source file is executed directly."
14
 * @since 1.3.2
15
 */
16
if (!defined("PHPUnit_MAIN_METHOD")) {
17
    define("PHPUnit_MAIN_METHOD", "phpDocumentorSetupCleanConverterNamePieceTests::main");
18
}
19
/**
20
 * TestCase
21
 *
22
 * required by PHPUnit
23
 * @since 1.3.2
24
 */
25
require_once "PHPUnit/Framework/TestCase.php";
26
/**
27
 * TestSuite
28
 *
29
 * required by PHPUnit
30
 * @since 1.3.2
31
 */
32
require_once "PHPUnit/Framework/TestSuite.php";
33
 
34
/**
35
 * Base directory of code
36
 *
37
 * Needed by some of the objects being tested in the suites.
38
 * @since 1.4.1
39
 */
40
chdir(dirname(dirname(__FILE__)));
41
if (!defined("PHPDOCUMENTOR_BASE")) {
42
    define("PHPDOCUMENTOR_BASE", dirname(dirname(__FILE__)));
43
}
44
 
45
/**
46
 * PhpDocumentor Setup
47
 *
48
 * required by PhpDocumentor to instantiate the environment
49
 * @since 1.3.2
50
 */
51
require_once 'PhpDocumentor/phpDocumentor/Setup.inc.php';
52
 
53
 
54
/**
55
 * Unit Testing of the phpDocumentor_setup's cleanConverterNamePiece() method
56
 * @package tests
57
 * @subpackage PhpDocumentorUnitTests
58
 * @author Chuck Burgess
59
 * @since 1.3.2
60
 */
61
class tests_phpDocumentorSetupCleanConverterNamePieceTests extends PHPUnit_Framework_TestCase {
62
 
63
    /**
64
     * phpDocumentor_setup object
65
     * @access private
66
     * @since 1.3.2
67
     */
68
    private $ps;
69
    /**
70
     * container for list of allowed special characters
71
     * in "primary" piece of converter names
72
     * @access private
73
     * @since 1.3.2
74
     */
75
    private $CHARACTERS_ALLOWED_IN_PRIMARY = '';
76
    /**
77
     * container for list of allowed special characters
78
     * in "secondary" piece of converter names
79
     * @access private
80
     * @since 1.3.2
81
     */
82
    private $CHARACTERS_ALLOWED_IN_SECONDARY = '\/';
83
    /**
84
     * container for list of allowed special characters
85
     * in "tertiary" piece of converter names
86
     * @access private
87
     * @since 1.3.2
88
     */
89
    private $CHARACTERS_ALLOWED_IN_TERTIARY = '.\/';
90
 
91
    /**
92
     * Runs the test methods of this class.
93
     * @access public
94
     * @static
95
     * @since 1.3.2
96
     */
97
    public static function main() {
98
        require_once "PHPUnit/TextUI/TestRunner.php";
99
 
100
        $suite  = new PHPUnit_Framework_TestSuite("tests_phpDocumentorSetupCleanConverterNamePieceTests");
101
        $result = PHPUnit_TextUI_TestRunner::run($suite);
102
    }
103
 
104
    /**
105
     * Sets up the fixture, for example, open a network connection.
106
     * This method is called before a test is executed.
107
     * @access protected
108
     * @since 1.3.2
109
     */
110
    protected function setUp() {
111
        $GLOBALS['_phpDocumentor_install_dir'] = PHPDOCUMENTOR_BASE;
112
        $GLOBALS['_phpDocumentor_setting']['quiet'] = "true";
113
        $this->ps = new phpDocumentor_setup;
114
        $this->ps->setTitle("Unit Testing");    // this step is necessary to ensure ps->render is instantiated
115
    }
116
 
117
    /**
118
     * Tears down the fixture, for example, close a network connection.
119
     * This method is called after a test is executed.
120
     * @access protected
121
     * @since 1.3.2
122
     */
123
    protected function tearDown() {
124
        unset($this->CHARACTERS_ALLOWED_IN_PRIMARY);
125
        unset($this->CHARACTERS_ALLOWED_IN_SECONDARY);
126
        unset($this->CHARACTERS_ALLOWED_IN_TERTIARY);
127
        unset($this->ps);
128
    }
129
 
130
 
131
    /**
132
     * NOW LIST THE TEST CASES -------------------------------------------------------|
133
     */
134
 
135
    /**
136
     * normal, expected cases ------------------------------------------|
137
     */
138
 
139
    /**
140
     * demonstrate the correct behavior -----------------------|
141
     */
142
 
143
    /**
144
     * Shows correct behavior for handling the perfect expected "CHM" primary value
145
     * when called with one arg
146
     * @since 1.3.2
147
     */
148
    public function testNormalWithOneArgPrimaryCHM() {
149
        $this->assertEquals("CHM",              $this->ps->cleanConverterNamePiece("CHM"));
150
    }
151
    /**
152
     * Shows correct behavior for handling the perfect expected "HTML" primary value
153
     * when called with one arg
154
     * @since 1.3.2
155
     */
156
    public function testNormalWithOneArgPrimaryHTML() {
157
        $this->assertEquals("HTML",             $this->ps->cleanConverterNamePiece("HTML"));
158
    }
159
    /**
160
     * Shows correct behavior for handling the perfect expected "PDF" primary value
161
     * when called with one arg
162
     * @since 1.3.2
163
     */
164
    public function testNormalWithOneArgPrimaryPDF() {
165
        $this->assertEquals("PDF",              $this->ps->cleanConverterNamePiece("PDF"));
166
    }
167
    /**
168
     * Shows correct behavior for handling the perfect expected "XML" primary value
169
     * when called with one arg
170
     * @since 1.3.2
171
     */
172
    public function testNormalWithOneArgPrimaryXML() {
173
        $this->assertEquals("XML",              $this->ps->cleanConverterNamePiece("XML"));
174
    }
175
 
176
    /**
177
     * Shows correct behavior for handling the perfect expected "CHM" primary value
178
     * when called with two args
179
     * @since 1.3.2
180
     */
181
    public function testNormalWithTwoArgsPrimaryCHM() {
182
        $this->assertEquals("CHM",              $this->ps->cleanConverterNamePiece("CHM",       $this->CHARACTERS_ALLOWED_IN_PRIMARY));
183
    }
184
    /**
185
     * Shows correct behavior for handling the perfect expected "HTML" primary value
186
     * when called with two args
187
     * @since 1.3.2
188
     */
189
    public function testNormalWithTwoArgsPrimaryHTML() {
190
        $this->assertEquals("HTML",             $this->ps->cleanConverterNamePiece("HTML",      $this->CHARACTERS_ALLOWED_IN_PRIMARY));
191
    }
192
    /**
193
     * Shows correct behavior for handling the perfect expected "PDF" primary value
194
     * when called with two args
195
     * @since 1.3.2
196
     */
197
    public function testNormalWithTwoArgsPrimaryPDF() {
198
        $this->assertEquals("PDF",              $this->ps->cleanConverterNamePiece("PDF",       $this->CHARACTERS_ALLOWED_IN_PRIMARY));
199
    }
200
    /**
201
     * Shows correct behavior for handling the perfect expected "XML" primary value
202
     * when called with two args
203
     * @since 1.3.2
204
     */
205
    public function testNormalWithTwoArgsPrimaryXML() {
206
        $this->assertEquals("XML",              $this->ps->cleanConverterNamePiece("XML",       $this->CHARACTERS_ALLOWED_IN_PRIMARY));
207
    }
208
 
209
    /**
210
     * Shows correct behavior for handling the perfect expected "frames" secondary value
211
     * when called with two args
212
     * @since 1.3.2
213
     */
214
    public function testNormalSecondaryFrames() {
215
        $this->assertEquals("frames",           $this->ps->cleanConverterNamePiece("frames",    $this->CHARACTERS_ALLOWED_IN_SECONDARY));
216
    }
217
    /**
218
     * Shows correct behavior for handling the perfect expected "Smarty" secondary value
219
     * when called with two args
220
     * @since 1.3.2
221
     */
222
    public function testNormalSecondarySmarty() {
223
        $this->assertEquals("Smarty",           $this->ps->cleanConverterNamePiece("Smarty",    $this->CHARACTERS_ALLOWED_IN_SECONDARY));
224
    }
225
    /**
226
     * Shows correct behavior for handling the perfect expected "default" secondary value
227
     * when called with two args
228
     * @since 1.3.2
229
     */
230
    public function testNormalSecondaryDefault() {
231
        $this->assertEquals("default",          $this->ps->cleanConverterNamePiece("default",   $this->CHARACTERS_ALLOWED_IN_SECONDARY));
232
    }
233
    /**
234
     * Shows correct behavior for handling the perfect expected "DocBook/peardoc2" secondary value
235
     * when called with two args
236
     * @since 1.3.2
237
     */
238
    public function testNormalSecondaryDocbookPeardoc2() {
239
        $this->assertEquals("DocBook/peardoc2", $this->ps->cleanConverterNamePiece("DocBook/peardoc2", $this->CHARACTERS_ALLOWED_IN_SECONDARY));
240
    }
241
 
242
    /**
243
     * Shows correct behavior for handling the perfect expected "default" tertiary  value
244
     * when called with two args
245
     * @since 1.3.2
246
     */
247
    public function testNormalTertiaryDefault() {
248
        $this->assertEquals("default",          $this->ps->cleanConverterNamePiece("default",   $this->CHARACTERS_ALLOWED_IN_TERTIARY));
249
    }
250
    /**
251
     * Shows correct behavior for handling the perfect expected "earthli" tertiary  value
252
     * when called with two args
253
     * @since 1.3.2
254
     */
255
    public function testNormalTertiaryEarthli() {
256
        $this->assertEquals("earthli",          $this->ps->cleanConverterNamePiece("earthli",   $this->CHARACTERS_ALLOWED_IN_TERTIARY));
257
    }
258
    /**
259
     * Shows correct behavior for handling the perfect expected "l0l33t" tertiary  value
260
     * when called with two args
261
     * @since 1.3.2
262
     */
263
    public function testNormalTertiaryL0l33t() {
264
        $this->assertEquals("l0l33t",           $this->ps->cleanConverterNamePiece("l0l33t",    $this->CHARACTERS_ALLOWED_IN_TERTIARY));
265
    }
266
    /**
267
     * Shows correct behavior for handling the perfect expected "phpdoc.de" tertiary  value
268
     * when called with two args
269
     * @since 1.3.2
270
     */
271
    public function testNormalTertiaryPhpdocde() {
272
        $this->assertEquals("phpdoc.de",        $this->ps->cleanConverterNamePiece("phpdoc.de", $this->CHARACTERS_ALLOWED_IN_TERTIARY));
273
    }
274
    /**
275
     * Shows correct behavior for handling the perfect expected "phphtmllib" tertiary  value
276
     * when called with two args
277
     * @since 1.3.2
278
     */
279
    public function testNormalTertiaryPhphtmllib() {
280
        $this->assertEquals("phphtmllib",       $this->ps->cleanConverterNamePiece("phphtmllib",$this->CHARACTERS_ALLOWED_IN_TERTIARY));
281
    }
282
    /**
283
     * Shows correct behavior for handling the perfect expected "HandS" tertiary  value
284
     * when called with two args
285
     * @since 1.3.2
286
     */
287
    public function testNormalTertiaryHands() {
288
        $this->assertEquals("HandS",            $this->ps->cleanConverterNamePiece("HandS",     $this->CHARACTERS_ALLOWED_IN_TERTIARY));
289
    }
290
    /**
291
     * Shows correct behavior for handling the perfect expected "PEAR" tertiary  value
292
     * when called with two args
293
     * @since 1.3.2
294
     */
295
    public function testNormalTertiaryPear() {
296
        $this->assertEquals("PEAR",             $this->ps->cleanConverterNamePiece("PEAR",      $this->CHARACTERS_ALLOWED_IN_TERTIARY));
297
    }
298
    /**
299
     * Shows correct behavior for handling the perfect expected "PHP" tertiary  value
300
     * when called with two args
301
     * @since 1.3.2
302
     */
303
    public function testNormalTertiaryPhp() {
304
        $this->assertEquals("PHP",              $this->ps->cleanConverterNamePiece("PHP",       $this->CHARACTERS_ALLOWED_IN_TERTIARY));
305
    }
306
 
307
    /**
308
     * Shows correct behavior for handling the perfect expected "DOM/default" tertiary  value
309
     * when called with two args
310
     * @since 1.3.2
311
     */
312
    public function testNormalTertiaryDomDefault() {
313
        $this->assertEquals("DOM/default",      $this->ps->cleanConverterNamePiece("DOM/default",    $this->CHARACTERS_ALLOWED_IN_TERTIARY));
314
    }
315
    /**
316
     * Shows correct behavior for handling the perfect expected "DOM/earthli" tertiary  value
317
     * when called with two args
318
     * @since 1.3.2
319
     */
320
    public function testNormalTertiaryDomEarthli() {
321
        $this->assertEquals("DOM/earthli",      $this->ps->cleanConverterNamePiece("DOM/earthli",    $this->CHARACTERS_ALLOWED_IN_TERTIARY));
322
    }
323
    /**
324
     * Shows correct behavior for handling the perfect expected "DOM/l0l33t" tertiary  value
325
     * when called with two args
326
     * @since 1.3.2
327
     */
328
    public function testNormalTertiaryDomL0l33t() {
329
        $this->assertEquals("DOM/l0l33t",       $this->ps->cleanConverterNamePiece("DOM/l0l33t",     $this->CHARACTERS_ALLOWED_IN_TERTIARY));
330
    }
331
    /**
332
     * Shows correct behavior for handling the perfect expected "DOM/phpdoc.de" tertiary  value
333
     * when called with two args
334
     * @since 1.3.2
335
     */
336
    public function testNormalTertiaryDomPhpdocde() {
337
        $this->assertEquals("DOM/phpdoc.de",    $this->ps->cleanConverterNamePiece("DOM/phpdoc.de",  $this->CHARACTERS_ALLOWED_IN_TERTIARY));
338
    }
339
    /**
340
     * Shows correct behavior for handling the perfect expected "DOM/phphtmllib" tertiary  value
341
     * when called with two args
342
     * @since 1.3.2
343
     */
344
    public function testNormalTertiaryDomPhphtmllib() {
345
        $this->assertEquals("DOM/phphtmllib",   $this->ps->cleanConverterNamePiece("DOM/phphtmllib", $this->CHARACTERS_ALLOWED_IN_TERTIARY));
346
    }
347
    /**
348
     * Shows correct behavior for handling the perfect expected "b2evo.v-1-10" tertiary value
349
     * (an example of a user-defined template not packaged with PhpDocumentor)
350
     * when called with two args
351
     * @since 1.4.0
352
     */
353
    public function testUserDefinedTertiaryValue() {
354
        $this->assertEquals("b2evo.v-1-10",   $this->ps->cleanConverterNamePiece("b2evo.v-1-10", $this->CHARACTERS_ALLOWED_IN_TERTIARY));
355
    }
356
 
357
    /**
358
     * END OF "demonstrate the correct behavior" --------------|
359
     */
360
    /**
361
     * END OF "normal, expected cases" ---------------------------------|
362
     */
363
 
364
 
365
    /**
366
     * odd, edge cases -------------------------------------------------|
367
     */
368
 
369
    /**
370
     * Verify no up-to-parent pathing is allowed...
371
     * the resulting converter names are generally invalid.
372
     * This test uses one arg with value of "../../HTML"
373
     * @since 1.3.2
374
     */
375
    public function testPreventUpToParentPathingOnPrimaryWithOneArg() {
376
        $this->assertEquals("HTML",             $this->ps->cleanConverterNamePiece("../../HTML"));
377
    }
378
    /**
379
     * Verify no up-to-parent pathing is allowed...
380
     * the resulting converter names are generally invalid.
381
     * This test uses two args with value of "../../HTML"
382
     * @since 1.3.2
383
     */
384
    public function testPreventUpToParentPathingOnPrimaryWithTwoArgs() {
385
        $this->assertEquals("HTML",             $this->ps->cleanConverterNamePiece("../../HTML",   $this->CHARACTERS_ALLOWED_IN_PRIMARY));
386
    }
387
    /**
388
     * Verify no up-to-parent pathing is allowed...
389
     * the resulting converter names are generally invalid.
390
     * This test uses two args with value of "../../frames"
391
     * @since 1.3.2
392
     */
393
    public function testPreventUpToParentPathingOnSecondary() {
394
        $this->assertEquals("//frames",         $this->ps->cleanConverterNamePiece("../../frames", $this->CHARACTERS_ALLOWED_IN_SECONDARY));
395
    }
396
    /**
397
     * Verify no up-to-parent pathing is allowed...
398
     * the resulting converter names are generally invalid.
399
     * This test uses two args with value of "../../default"
400
     * @since 1.3.2
401
     */
402
    public function testPreventUpToParentPathingOnTertiary() {
403
        //    when '.' is allowed to remain, a '..' always returns false to avoid directory traversal
404
        $this->assertEquals(false,              $this->ps->cleanConverterNamePiece("../../default",$this->CHARACTERS_ALLOWED_IN_TERTIARY));
405
    }
406
    /**
407
     * Verify no up-to-parent pathing is allowed...
408
     * the resulting converter names are generally invalid.
409
     * This test uses one arg with value of "/var/log/HTML"
410
     * @since 1.3.2
411
     */
412
    public function testDoNotAllowTruePathingOnPrimaryWithOneArg() {
413
        $this->assertEquals("varlogHTML",       $this->ps->cleanConverterNamePiece("/var/log/HTML"));
414
    }
415
    /**
416
     * Verify no up-to-parent pathing is allowed...
417
     * the resulting converter names are generally invalid.
418
     * This test uses two args with value of "/var/log/HTML"
419
     * @since 1.3.2
420
     */
421
    public function testDoNotAllowTruePathingOnPrimaryWithTwoArgs() {
422
        $this->assertEquals("varlogHTML",       $this->ps->cleanConverterNamePiece("/var/log/HTML",   $this->CHARACTERS_ALLOWED_IN_PRIMARY));
423
    }
424
    /**
425
     * Verify no up-to-parent pathing is allowed...
426
     * the resulting converter names are generally invalid.
427
     * This test uses two args with value of "/var/log/frames"
428
     * @since 1.3.2
429
     */
430
    public function testDoNotAllowTruePathingOnSecondary() {
431
        $this->assertEquals("/var/log/frames",  $this->ps->cleanConverterNamePiece("/var/log/frames", $this->CHARACTERS_ALLOWED_IN_SECONDARY));
432
    }
433
    /**
434
     * Verify no up-to-parent pathing is allowed...
435
     * the resulting converter names are generally invalid.
436
     * This test uses two args with value of "/var/log/default"
437
     * @since 1.3.2
438
     */
439
    public function testDoNotAllowTruePathingOnTertiary() {
440
        $this->assertEquals("/var/log/default", $this->ps->cleanConverterNamePiece("/var/log/default",$this->CHARACTERS_ALLOWED_IN_TERTIARY));
441
    }
442
 
443
 
444
 
445
    /**
446
     * Extreme example of messy input...
447
     * the resulting converter names are generally invalid.
448
     * This test uses one arg with value of "H/.T./M##L"
449
     * @since 1.3.2
450
     */
451
    public function testExtremeExampleButValidPrimaryWithOneArg() {
452
        $this->assertEquals("HTML",             $this->ps->cleanConverterNamePiece("H/.T./M##L"));
453
    }
454
    /**
455
     * Extreme example of messy input...
456
     * the resulting converter names are generally invalid.
457
     * This test uses two args with value of "H/.T./M##L"
458
     * @since 1.3.2
459
     */
460
    public function testExtremeExampleButValidPrimaryWithTwoArgs() {
461
        $this->assertEquals("HTML",             $this->ps->cleanConverterNamePiece("H/.T./M##L", $this->CHARACTERS_ALLOWED_IN_PRIMARY));
462
    }
463
    /**
464
     * Extreme example of messy input...
465
     * the resulting converter names are generally invalid.
466
     * This test uses two args with value of "....frames"
467
     * @since 1.3.2
468
     */
469
    public function testExtremeExampleButValidSecondary() {
470
        $this->assertEquals("frames",           $this->ps->cleanConverterNamePiece("....frames", $this->CHARACTERS_ALLOWED_IN_SECONDARY));
471
    }
472
    /**
473
     * Extreme example of messy input...
474
     * the resulting converter names are generally invalid.
475
     * This test uses two args with value of "..//.frames"
476
     * @since 1.3.2
477
     */
478
    public function testExtremeExampleAndInvalidSecondary() {
479
        $this->assertEquals("//frames",         $this->ps->cleanConverterNamePiece("..//.frames",     $this->CHARACTERS_ALLOWED_IN_SECONDARY));
480
    }
481
    /**
482
     * Extreme example of messy input...
483
     * the resulting converter names are generally invalid.
484
     * This test uses two arg with value of "/./default/.##/"
485
     * @since 1.3.2
486
     */
487
    public function testExtremeExampleAndInvalidTertiaryA() {
488
        $this->assertEquals("/./default/./",    $this->ps->cleanConverterNamePiece("/./default/.##/", $this->CHARACTERS_ALLOWED_IN_TERTIARY));
489
    }
490
    /**
491
     * Extreme example of messy input...
492
     * the resulting converter names are generally invalid.
493
     * This test uses two arg with value of "//default//"
494
     * @since 1.3.2
495
     */
496
    public function testExtremeExampleAndInvalidTertiaryB() {
497
        $this->assertEquals("//default//",      $this->ps->cleanConverterNamePiece("//default//",     $this->CHARACTERS_ALLOWED_IN_TERTIARY));
498
    }
499
 
500
    /**
501
     * END OF "odd, edge cases" ----------------------------------------|
502
     */
503
 
504
    /**
505
     * END OF "NOW LIST THE TEST CASES" ----------------------------------------------|
506
     */
507
}
508
 
509
/**
510
 * PHPUnit main() hack
511
 * "Call class::main() if this source file is executed directly."
512
 * @since 1.3.2
513
 */
514
if (PHPUnit_MAIN_METHOD == "phpDocumentorSetupCleanConverterNamePieceTests::main") {
515
    tests_phpDocumentorSetupCleanConverterNamePieceTests::main();
516
}
517
?>