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 ParserClass->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", "ParserClassGetSourceLocationTests::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 ParserClass's getSourceLocation() method
62
 * @package tests
63
 * @subpackage PhpDocumentorUnitTests
64
 * @author Chuck Burgess
65
 * @since 1.4.0a1
66
 */
67
class tests_ParserClassGetSourceLocationTests extends PHPUnit_Framework_TestCase {
68
 
69
    /**
70
     * phpDocumentor_setup object
71
     * @access private
72
     * @since 1.4.0a1
73
     */
74
    private $ps;
75
    /**
76
     * ParserClass object
77
     * @access private
78
     * @since 1.4.0a1
79
     */
80
    private $pc;
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_ParserClassGetSourceLocationTests");
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->pc = new parserClass;
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->pc);
118
        unset($this->ps);
119
    }
120
 
121
 
122
    /**
123
     * NOW LIST THE TEST CASES -------------------------------------------------------|
124
     */
125
 
126
    /**
127
     * normal, expected cases ------------------------------------------|
128
     */
129
 
130
    /**
131
     * demonstrate the correct behavior -----------------------|
132
     */
133
 
134
    /**
135
     * Shows correct behavior when
136
     * sourceLocation is not set yet
137
     * with no pearize value set
138
     * @since 1.4.0a1
139
     */
140
    public function testWhenLocationNotSetAndPearizeNull() {
141
        $this->assertEquals($this->pc->getSourceLocation($this->ps->render), false);
142
    }
143
    /**
144
     * Shows correct behavior when
145
     * sourceLocation is not set yet
146
     * with pearize explicitly false
147
     * @since 1.4.0a1
148
     */
149
    public function testWhenLocationNotSetAndPearizeFalse() {
150
        $this->assertEquals($this->pc->getSourceLocation($this->ps->render, false), false);
151
    }
152
    /**
153
     * Shows correct behavior when
154
     * sourceLocation is not set yet
155
     * with pearize explicitly true
156
     * @since 1.4.0a1
157
     */
158
    public function testWhenLocationNotSetAndPearizeTrue() {
159
        $this->assertEquals($this->pc->getSourceLocation($this->ps->render, true), false);
160
    }
161
 
162
    /**
163
     * Shows correct behavior when
164
     * sourceLocation is set to an absolute path that is not a "pear" location,
165
     * with no pearize value set
166
     * @since 1.4.0a1
167
     */
168
    public function testWhenNonPearLocationSetAndPearizeNull() {
169
        $this->pc->setSourceLocation('/where/on/earth/are/we');
170
        $this->assertEquals($this->pc->getSourceLocation($this->ps->render), '/where/on/earth/are/we');
171
    }
172
    /**
173
     * Shows correct behavior when
174
     * sourceLocation is set to an absolute path that is not a "pear" location,
175
     * with pearize explicitly false
176
     * @since 1.4.0a1
177
     */
178
    public function testWhenNonPearLocationSetAndPearizeFalse() {
179
        $this->pc->setSourceLocation('/where/on/earth/are/we');
180
        $this->assertEquals($this->pc->getSourceLocation($this->ps->render, false), '/where/on/earth/are/we');
181
    }
182
    /**
183
     * Shows correct behavior when
184
     * sourceLocation is set to an absolute path that is not a "pear" location,
185
     * with pearize explicitly true
186
     * @since 1.4.0a1
187
     */
188
    public function testWhenNonPearLocationSetAndPearizeTrue() {
189
        $this->pc->setSourceLocation('/where/on/earth/are/we');
190
        $this->assertEquals($this->pc->getSourceLocation($this->ps->render, true), '/where/on/earth/are/we');
191
    }
192
 
193
    /**
194
     * Show correct behavior when
195
     * sourceLocation is set to an absolute path that IS a "pear" location,
196
     * with pearize not set
197
     * @since 1.4.0a1
198
     */
199
    public function testWhenPearLocationSetAndPearizeNull() {
200
        $this->pc->sourceLocation = '/outside/pear/inside';
201
        $this->assertEquals($this->pc->getSourceLocation($this->ps->render), '/outside/pear/inside');
202
    }
203
    /**
204
     * Show correct behavior when
205
     * sourceLocation is set to an absolute path that IS a "pear" location,
206
     * with pearize explicitly false
207
     * @since 1.4.0a1
208
     */
209
    public function testWhenPearLocationSetAndPearizeFalse() {
210
        $this->pc->sourceLocation = '/outside/pear/inside';
211
        $this->assertEquals($this->pc->getSourceLocation($this->ps->render, false), '/outside/pear/inside');
212
    }
213
    /**
214
     * Show correct behavior when
215
     * sourceLocation is set to an absolute path that IS a "pear" location,
216
     * with pearize explicitly true
217
     * @since 1.4.0a1
218
     */
219
    public function testWhenPearLocationSetAndPearizeTrue() {
220
        $this->pc->sourceLocation = '/outside/pear/inside';
221
        $this->assertEquals($this->pc->getSourceLocation($this->ps->render, true), 'inside');
222
    }
223
 
224
    /**
225
     * Include a ".." in an absolute, non-PEAR path,
226
     * with pearize not set
227
     * @since 1.4.0a1
228
     */
229
    public function testWhenNonPearLocationSetIncludingDotsAndPearizeNull() {
230
        $this->pc->sourceLocation = '/outside/plum/inside/../inside';
231
        $this->assertEquals($this->pc->getSourceLocation($this->ps->render), '/outside/plum/inside/../inside');
232
    }
233
    /**
234
     * Include a ".." in an absolute, non-PEAR path,
235
     * with pearize explicitly false
236
     * @since 1.4.0a1
237
     */
238
    public function testWhenNonPearLocationSetIncludingDotsAndPearizeFalse() {
239
        $this->pc->sourceLocation = '/outside/plum/inside/../inside';
240
        $this->assertEquals($this->pc->getSourceLocation($this->ps->render, false), '/outside/plum/inside/../inside');
241
    }
242
    /**
243
     * Include a ".." in an absolute, non-PEAR path,
244
     * with pearize explicitly true
245
     * @since 1.4.0a1
246
     */
247
    public function testWhenNonPearLocationSetIncludingDotsAndPearizeTrue() {
248
        $this->pc->sourceLocation = '/outside/plum/inside/../inside';
249
        $this->assertEquals($this->pc->getSourceLocation($this->ps->render, true), '/outside/plum/inside/../inside');
250
    }
251
 
252
    /**
253
     * Include a ".." in a relative, non-PEAR path,
254
     * with pearize not set
255
     * @since 1.4.0a1
256
     */
257
    public function testWhenNonPearRelativeLocationSetAndPearizeNull() {
258
        $this->pc->sourceLocation = 'outside/plum/inside/../inside';
259
        $this->assertEquals($this->pc->getSourceLocation($this->ps->render), 'outside/plum/inside/../inside');
260
    }
261
    /**
262
     * Include a ".." in a relative, non-PEAR path,
263
     * with pearize explicitly false
264
     * @since 1.4.0a1
265
     */
266
    public function testWhenNonPearRelativeLocationSetAndPearizeFalse() {
267
        $this->pc->sourceLocation = 'outside/plum/inside/../inside';
268
        $this->assertEquals($this->pc->getSourceLocation($this->ps->render, false), 'outside/plum/inside/../inside');
269
    }
270
    /**
271
     * Include a ".." in a relative, non-PEAR path,
272
     * with pearize explicitly false
273
     * @since 1.4.0a1
274
     */
275
    public function testWhenNonPearRelativeLocationSetAndPearizeTrue() {
276
        $this->pc->sourceLocation = 'outside/plum/inside/../inside';
277
        $this->assertEquals($this->pc->getSourceLocation($this->ps->render, true), 'outside/plum/inside/../inside');
278
    }
279
 
280
    /**
281
     * Include a ".." in an absolute, PEAR path,
282
     * with pearize not set
283
     * @since 1.4.0a1
284
     */
285
    public function testWhenPearLocationSetIncludingDotsAndPearizeNull() {
286
        $this->pc->sourceLocation = '/outside/pear/inside/../inside';
287
        $this->assertEquals($this->pc->getSourceLocation($this->ps->render), '/outside/pear/inside/../inside');
288
    }
289
    /**
290
     * Include a ".." in an absolute, PEAR path,
291
     * with pearize explicitly false
292
     * @since 1.4.0a1
293
     */
294
    public function testWhenPearLocationSetIncludingDotsAndPearizeFalse() {
295
        $this->pc->sourceLocation = '/outside/pear/inside/../inside';
296
        $this->assertEquals($this->pc->getSourceLocation($this->ps->render, false), '/outside/pear/inside/../inside');
297
    }
298
    /**
299
     * Include a ".." in an absolute, PEAR path,
300
     * with pearize explicitly true
301
     * @since 1.4.0a1
302
     */
303
    public function testWhenPearLocationSetIncludingDotsAndPearizeTrue() {
304
        $this->pc->sourceLocation = '/outside/pear/inside/../inside';
305
        $this->assertEquals($this->pc->getSourceLocation($this->ps->render, true), 'inside/../inside');
306
    }
307
 
308
    /**
309
     * Include a ".." in a relative, PEAR path,
310
     * with pearize not set
311
     * @since 1.4.0a1
312
     */
313
    public function testWhenPearRelativeLocationSetAndPearizeNull() {
314
        $this->pc->sourceLocation = 'outside/pear/inside/../inside';
315
        $this->assertEquals($this->pc->getSourceLocation($this->ps->render), 'outside/pear/inside/../inside');
316
    }
317
    /**
318
     * Include a ".." in a relative, PEAR path,
319
     * with pearize explicitly false
320
     * @since 1.4.0a1
321
     */
322
    public function testWhenPearRelativeLocationSetAndPearizeFalse() {
323
        $this->pc->sourceLocation = 'outside/pear/inside/../inside';
324
        $this->assertEquals($this->pc->getSourceLocation($this->ps->render, false), 'outside/pear/inside/../inside');
325
    }
326
    /**
327
     * Include a ".." in a relative, PEAR path,
328
     * with pearize explicitly true
329
     * @since 1.4.0a1
330
     */
331
    public function testWhenPearRelativeLocationSetAndPearizeTrue() {
332
        $this->pc->sourceLocation = 'outside/pear/inside/../inside';
333
        $this->assertEquals($this->pc->getSourceLocation($this->ps->render, true), 'inside/../inside');
334
    }
335
 
336
    /**
337
     * END OF "demonstrate the correct behavior" --------------|
338
     */
339
 
340
    /**
341
     * END OF "normal, expected cases" ---------------------------------|
342
     */
343
 
344
 
345
    /**
346
     * odd, edge cases -------------------------------------------------|
347
     */
348
    /**
349
     * END OF "odd, edge cases" ----------------------------------------|
350
     * @todo write some "edge" test cases
351
     */
352
 
353
    /**
354
     * END OF "NOW LIST THE TEST CASES" ----------------------------------------------|
355
     */
356
 
357
}
358
 
359
/**
360
 * PHPUnit main() hack
361
 * "Call class::main() if this source file is executed directly."
362
 * @since 1.4.0a1
363
 */
364
if (PHPUnit_MAIN_METHOD == "ParserClassGetSourceLocationTests::main") {
365
    tests_ParserClassGetSourceLocationTests::main();
366
}
367
?>