Remove trailing whitespace.
[xhtml-compiler.git] / tests / XHTMLCompiler / DirectoryTest.php
blob590e7ead5c73b2689e76ffdab2e8366f47733955
1 <?php
3 class XHTMLCompiler_DirectoryTest extends XHTMLCompiler_FileSystemHarness
6 function testSlashNormalization() {
7 mkdir('foo');
8 $dir = new XHTMLCompiler_Directory('foo');
9 $this->assertIdentical($dir->getName(), 'foo');
10 $dir = new XHTMLCompiler_Directory('foo/');
11 $this->assertIdentical($dir->getName(), 'foo');
12 $dir = new XHTMLCompiler_Directory('foo\\');
13 $this->assertIdentical($dir->getName(), 'foo');
14 rmdir('foo');
17 function testNonexistent() {
18 $this->expectException();
19 $dir = new XHTMLCompiler_Directory('null');
22 function test_getTree() {
23 mkdir('1'); mkdir('1/2'); mkdir('1/4');
24 file_put_contents('1/2/3.txt', 'foobar');
25 $dir = new XHTMLCompiler_Directory('');
26 $tree = $dir->getTree();
27 $this->assertEqual($tree, array(
28 '1' => array(
29 '2' => array(
30 '3.txt' => 6,
32 '4' => array(),
34 ));
35 unlink('1/2/3.txt');
36 rmdir('1/4'); rmdir('1/2'); rmdir('1');
39 function test_scan() {
40 $dir = new XHTMLCompiler_Directory('');
42 file_put_contents('1.txt', '1');
43 file_put_contents('2.txt', '2');
44 file_put_contents('3.txt', '3');
45 $list = array('1.txt', '2.txt', '3.txt');
46 $this->assertEqual($dir->scanRecursively('.txt'), $list);
47 $this->assertEqual($dir->scanFlat('.txt'), $list);
49 mkdir('foo');
50 file_put_contents('foo/1.txt', '1');
51 $this->assertEqual($dir->scanRecursively('.txt'), $a = array(
52 '1.txt', '2.txt', '3.txt', 'foo/1.txt'
53 ));
54 $this->assertEqual($dir->scanFlat('.txt'), $list);
56 file_put_contents('foo/1.log', '1'); // not matched
57 $this->assertEqual($dir->scanRecursively('.txt'), $a);
58 $this->assertEqual($dir->scan('.txt', 1), $a);
59 $this->assertEqual($dir->scanFlat('.txt'), $list);
60 $this->assertEqual($dir->scan('.txt', 0), $list);
62 $dir = new XHTMLCompiler_Directory('foo');
63 $this->assertEqual($dir->scan('.txt', true), array('foo/1.txt'));
65 // cleanup
66 unlink('foo/1.log'); unlink('foo/1.txt.');
67 rmdir('foo');
68 unlink('1.txt'); unlink('2.txt'); unlink('3.txt');