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 ParserPage->getSourceLocation() method
4
 * @package tests
5
 * @subpackage PhpDocumentorUnitTests
6
 * @author Chuck Burgess
7
 * @since 1.4.0a1
8
 * @todo research possibility of refactoring
9
 *       ParserClass->getSourceLocation() and
10
 *       ParserPage->getSourceLocation()
11
 *       into a common method...
12
 *       also, there might be more occurrences
13
 *       of similar getSourceLocation() methods
14
 *       in other classes.
15
 */
16
 
17
/**
18
 * PHPUnit main() hack
19
 *
20
 * "Call class::main() if this source file is executed directly."
21
 * @since 1.4.0a1
22
 */
23
if (!defined("PHPUnit_MAIN_METHOD")) {
24
    define("PHPUnit_MAIN_METHOD", "ParserPageGetSourceLocationTests::main");
25
}
26
/**
27
 * TestCase
28
 *
29
 * required by PHPUnit
30
 * @since 1.4.0a1
31
 */
32
require_once "PHPUnit/Framework/TestCase.php";
33
/**
34
 * TestSuite
35
 *
36
 * required by PHPUnit
37
 * @since 1.4.0a1
38
 */
39
require_once "PHPUnit/Framework/TestSuite.php";
40
 
41
/**
42
 * Base directory of code
43
 *
44
 * Needed by some of the objects being tested in the suites.
45
 * @since 1.4.1
46
 */
47
chdir(dirname(dirname(__FILE__)));
48
if (!defined("PHPDOCUMENTOR_BASE")) {
49
    define("PHPDOCUMENTOR_BASE", dirname(dirname(__FILE__)));
50
}
51
 
52
/**
53
 * PhpDocumentor Setup
54
 *
55
 * required by PhpDocumentor to instantiate the environment
56
 * @since 1.4.0a1
57
 */
58
require_once 'PhpDocumentor/phpDocumentor/Setup.inc.php';
59
 
60
/**
61
 * Unit Testing of the ParserPage's getSourceLocation() method
62
 * @package tests
63
 * @subpackage PhpDocumentorUnitTests
64
 * @author Chuck Burgess
65
 * @since 1.4.0a1
66
 */
67
class tests_ParserPageGetSourceLocationTests extends PHPUnit_Framework_TestCase {
68
 
69
    /**
70
     * phpDocumentor_setup object
71
     * @access private
72
     * @since 1.4.0a1
73
     */
74
    private $ps;
75
    /**
76
     * ParserPage object
77
     * @access private
78
     * @since 1.4.0a1
79
     */
80
    private $pp;
81
 
82
    /**
83
     * Runs the test methods of this class.
84
     * @access public
85
     * @static
86
     * @since 1.4.0a1
87
     */
88
    public static function main() {
89
        require_once "PHPUnit/TextUI/TestRunner.php";
90
 
91
        $suite  = new PHPUnit_Framework_TestSuite("tests_ParserPageGetSourceLocationTests");
92
        $result = PHPUnit_TextUI_TestRunner::run($suite);
93
    }
94
 
95
    /**
96
     * Sets up the fixture, for example, open a network connection.
97
     * This method is called before a test is executed.
98
     * @access protected
99
     * @since 1.4.0a1
100
     */
101
    protected function setUp() {
102
        $GLOBALS['_phpDocumentor_install_dir'] = PHPDOCUMENTOR_BASE;
103
        $GLOBALS['_phpDocumentor_setting']['quiet'] = "true";
104
        $this->ps = new phpDocumentor_setup;
105
        $this->ps->setTitle("Unit Testing");    // this step is necessary to ensure ps->render is instantiated
106
 
107
        $this->pp = new ParserPage();
108
    }
109
 
110
    /**
111
     * Tears down the fixture, for example, close a network connection.
112
     * This method is called after a test is executed.
113
     * @access protected
114
     * @since 1.4.0a1
115
     */
116
    protected function tearDown() {
117
        unset($this->pp);
118
        unset($this->ps);
119
    }
120
 
121
    /**
122
     * NOW LIST THE TEST CASES -------------------------------------------------------|
123
     */
124
 
125
    /**
126
     * normal, expected cases ------------------------------------------|
127
     */
128
 
129
    /**
130
     * demonstrate the correct behavior -----------------------|
131
     */
132
 
133
    /**
134
     * Shows correct behavior when
135
     * sourceLocation is not set yet
136
     * with no pearize value set
137
     * @since 1.4.0a1
138
     */
139
    public function testWhenLocationNotSetAndPearizeNull() {
140
        $this->assertEquals($this->pp->getSourceLocation($this->ps->render), false);
141
    }
142
    /**
143
     * Shows correct behavior when
144
     * sourceLocation is not set yet
145
     * with pearize explicitly false
146
     * @since 1.4.0a1
147
     */
148
    public function testWhenLocationNotSetAndPearizeFalse() {
149
        $this->assertEquals($this->pp->getSourceLocation($this->ps->render, false), false);
150
    }
151
    /**
152
     * Shows correct behavior when
153
     * sourceLocation is not set yet
154
     * with pearize explicitly true
155
     * @since 1.4.0a1
156
     */
157
    public function testWhenLocationNotSetAndPearizeTrue() {
158
        $this->assertEquals($this->pp->getSourceLocation($this->ps->render, true), false);
159
    }
160
 
161
    /**
162
     * Shows correct behavior when
163
     * sourceLocation is set to an absolute path that is not a "pear" location,
164
     * with no pearize value set
165
     * @since 1.4.0a1
166
     */
167
    public function testWhenNonPearLocationSetAndPearizeNull() {
168
        $this->pp->setSourceLocation('/where/on/earth/are/we');
169
        $this->assertEquals($this->pp->getSourceLocation($this->ps->render), '/where/on/earth/are/we');
170
    }
171
    /**
172
     * Shows correct behavior when
173
     * sourceLocation is set to an absolute path that is not a "pear" location,
174
     * with pearize explicitly false
175
     * @since 1.4.0a1
176
     */
177
    public function testWhenNonPearLocationSetAndPearizeFalse() {
178
        $this->pp->setSourceLocation('/where/on/earth/are/we');
179
        $this->assertEquals($this->pp->getSourceLocation($this->ps->render, false), '/where/on/earth/are/we');
180
    }
181
    /**
182
     * Shows correct behavior when
183
     * sourceLocation is set to an absolute path that is not a "pear" location,
184
     * with pearize explicitly true
185
     * @since 1.4.0a1
186
     * @todo Revisit this test... I think it highlights a bug in the getSourceLocation method.
187
     *       Compare it with the same test in bug1574047.php
188
     *       against similar method parserClass->getSourceLocation().
189
     */
190
    public function testWhenNonPearLocationSetAndPearizeTrue() {
191
        $this->pp->setSourceLocation('/where/on/earth/are/we');
192
        $this->assertEquals($this->pp->getSourceLocation($this->ps->render, true), 'whereoneartharewe');
193
    }
194
 
195
    /**
196
     * Show correct behavior when
197
     * sourceLocation is set to an absolute path that IS a "pear" location,
198
     * with pearize not set
199
     * @since 1.4.0a1
200
     */
201
    public function testWhenPearLocationSetAndPearizeNull() {
202
        $this->pp->sourceLocation = '/outside/pear/inside';
203
        $this->assertEquals($this->pp->getSourceLocation($this->ps->render), '/outside/pear/inside');
204
    }
205
    /**
206
     * Show correct behavior when
207
     * sourceLocation is set to an absolute path that IS a "pear" location,
208
     * with pearize explicitly false
209
     * @since 1.4.0a1
210
     */
211
    public function testWhenPearLocationSetAndPearizeFalse() {
212
        $this->pp->sourceLocation = '/outside/pear/inside';
213
        $this->assertEquals($this->pp->getSourceLocation($this->ps->render, false), '/outside/pear/inside');
214
    }
215
    /**
216
     * Show correct behavior when
217
     * sourceLocation is set to an absolute path that IS a "pear" location,
218
     * with pearize explicitly true
219
     * @since 1.4.0a1
220
     */
221
    public function testWhenPearLocationSetAndPearizeTrue() {
222
        $this->pp->sourceLocation = '/outside/pear/inside';
223
        $this->assertEquals($this->pp->getSourceLocation($this->ps->render, true), 'inside');
224
    }
225
 
226
    /**
227
     * Include a ".." in an absolute, non-PEAR path,
228
     * with pearize not set
229
     * @since 1.4.0a1
230
     */
231
    public function testWhenNonPearLocationSetIncludingDotsAndPearizeNull() {
232
        $this->pp->sourceLocation = '/outside/plum/inside/../inside';
233
        $this->assertEquals($this->pp->getSourceLocation($this->ps->render), '/outside/plum/inside/../inside');
234
    }
235
    /**
236
     * Include a ".." in an absolute, non-PEAR path,
237
     * with pearize explicitly false
238
     * @since 1.4.0a1
239
     */
240
    public function testWhenNonPearLocationSetIncludingDotsAndPearizeFalse() {
241
        $this->pp->sourceLocation = '/outside/plum/inside/../inside';
242
        $this->assertEquals($this->pp->getSourceLocation($this->ps->render, false), '/outside/plum/inside/../inside');
243
    }
244
    /**
245
     * Include a ".." in an absolute, non-PEAR path,
246
     * with pearize explicitly true
247
     * @since 1.4.0a1
248
     * @todo Revisit this test... I think it highlights a bug in the getSourceLocation method.
249
     *       Compare it with the same test in bug1574047.php
250
     *       against similar method parserClass->getSourceLocation().
251
     */
252
    public function testWhenNonPearLocationSetIncludingDotsAndPearizeTrue() {
253
        $this->pp->sourceLocation = '/outside/plum/inside/../inside';
254
        $this->assertEquals($this->pp->getSourceLocation($this->ps->render, true), 'outsidepluminside..inside');
255
    }
256
 
257
    /**
258
     * Include a ".." in a relative, non-PEAR path,
259
     * with pearize not set
260
     * @since 1.4.0a1
261
     */
262
    public function testWhenNonPearRelativeLocationSetAndPearizeNull() {
263
        $this->pp->sourceLocation = 'outside/plum/inside/../inside';
264
        $this->assertEquals($this->pp->getSourceLocation($this->ps->render), 'outside/plum/inside/../inside');
265
    }
266
    /**
267
     * Include a ".." in a relative, non-PEAR path,
268
     * with pearize explicitly false
269
     * @since 1.4.0a1
270
     */
271
    public function testWhenNonPearRelativeLocationSetAndPearizeFalse() {
272
        $this->pp->sourceLocation = 'outside/plum/inside/../inside';
273
        $this->assertEquals($this->pp->getSourceLocation($this->ps->render, false), 'outside/plum/inside/../inside');
274
    }
275
    /**
276
     * Include a ".." in a relative, non-PEAR path,
277
     * with pearize explicitly false
278
     * @since 1.4.0a1
279
     * @todo Revisit this test... I think it highlights a bug in the getSourceLocation method.
280
     *       Compare it with the same test in bug1574047.php
281
     *       against similar method parserClass->getSourceLocation().
282
     */
283
    public function testWhenNonPearRelativeLocationSetAndPearizeTrue() {
284
        $this->pp->sourceLocation = 'outside/plum/inside/../inside';
285
        $this->assertEquals($this->pp->getSourceLocation($this->ps->render, true), 'outsidepluminside..inside');
286
    }
287
 
288
    /**
289
     * Include a ".." in an absolute, PEAR path,
290
     * with pearize not set
291
     * @since 1.4.0a1
292
     */
293
    public function testWhenPearLocationSetIncludingDotsAndPearizeNull() {
294
        $this->pp->sourceLocation = '/outside/pear/inside/../inside';
295
        $this->assertEquals($this->pp->getSourceLocation($this->ps->render), '/outside/pear/inside/../inside');
296
    }
297
    /**
298
     * Include a ".." in an absolute, PEAR path,
299
     * with pearize explicitly false
300
     * @since 1.4.0a1
301
     */
302
    public function testWhenPearLocationSetIncludingDotsAndPearizeFalse() {
303
        $this->pp->sourceLocation = '/outside/pear/inside/../inside';
304
        $this->assertEquals($this->pp->getSourceLocation($this->ps->render, false), '/outside/pear/inside/../inside');
305
    }
306
    /**
307
     * Include a ".." in an absolute, PEAR path,
308
     * with pearize explicitly true
309
     * @since 1.4.0a1
310
     */
311
    public function testWhenPearLocationSetIncludingDotsAndPearizeTrue() {
312
        $this->pp->sourceLocation = '/outside/pear/inside/../inside';
313
        $this->assertEquals($this->pp->getSourceLocation($this->ps->render, true), 'inside/../inside');
314
    }
315
 
316
    /**
317
     * Include a ".." in a relative, PEAR path,
318
     * with pearize not set
319
     * @since 1.4.0a1
320
     */
321
    public function testWhenPearRelativeLocationSetAndPearizeNull() {
322
        $this->pp->sourceLocation = 'outside/pear/inside/../inside';
323
        $this->assertEquals($this->pp->getSourceLocation($this->ps->render), 'outside/pear/inside/../inside');
324
    }
325
    /**
326
     * Include a ".." in a relative, PEAR path,
327
     * with pearize explicitly false
328
     * @since 1.4.0a1
329
     */
330
    public function testWhenPearRelativeLocationSetAndPearizeFalse() {
331
        $this->pp->sourceLocation = 'outside/pear/inside/../inside';
332
        $this->assertEquals($this->pp->getSourceLocation($this->ps->render, false), 'outside/pear/inside/../inside');
333
    }
334
    /**
335
     * Include a ".." in a relative, PEAR path,
336
     * with pearize explicitly true
337
     * @since 1.4.0a1
338
     */
339
    public function testWhenPearRelativeLocationSetAndPearizeTrue() {
340
        $this->pp->sourceLocation = 'outside/pear/inside/../inside';
341
        $this->assertEquals($this->pp->getSourceLocation($this->ps->render, true), 'inside/../inside');
342
    }
343
 
344
    /**
345
     * END OF "demonstrate the correct behavior" --------------|
346
     */
347
 
348
    /**
349
     * END OF "normal, expected cases" ---------------------------------|
350
     */
351
 
352
 
353
    /**
354
     * odd, edge cases -------------------------------------------------|
355
     */
356
    /**
357
     * END OF "odd, edge cases" ----------------------------------------|
358
     * @todo write some "edge" test cases
359
     */
360
 
361
    /**
362
     * END OF "NOW LIST THE TEST CASES" ----------------------------------------------|
363
     */
364
 
365
}
366
 
367
/**
368
 * PHPUnit main() hack
369
 * "Call class::main() if this source file is executed directly."
370
 * @since 1.4.0a1
371
 */
372
if (PHPUnit_MAIN_METHOD == "ParserPageGetSourceLocationTests::main") {
373
    tests_ParserPageGetSourceLocationTests::main();
374
}
375
?>