config file setup instructions
[phorkie.git] / tests / phorkie / ToolsTest.php
1 <?php
2 namespace phorkie;
3
4 class ToolsTest extends \PHPUnit_Framework_TestCase
5 {
6     public function testDetectBaseUrlPhar()
7     {
8         $_SERVER['REQUEST_URI'] = '/phar/phorkie-0.4.0.phar/list.php';
9         $_SERVER['SCRIPT_NAME'] = '/phar/phorkie-0.4.0.phar';
10         $this->assertEquals(
11             '/phar/phorkie-0.4.0.phar/',
12             Tools::detectBaseUrl()
13         );
14     }
15
16     public function testDetectBaseUrlRoot()
17     {
18         $_SERVER['REQUEST_URI'] = '/new';
19         $_SERVER['SCRIPT_NAME'] = '/new.php';
20         $this->assertEquals('/', Tools::detectBaseUrl());
21     }
22
23     public function testDetectBaseUrlRootWithPhp()
24     {
25         $_SERVER['REQUEST_URI'] = '/new.php';
26         $_SERVER['SCRIPT_NAME'] = '/new.php';
27         $this->assertEquals('/', Tools::detectBaseUrl());
28     }
29
30     public function testDetectBaseUrlSubdir()
31     {
32         $_SERVER['REQUEST_URI'] = '/foo/new';
33         $_SERVER['SCRIPT_NAME'] = '/new.php';
34         $this->assertEquals('/foo/', Tools::detectBaseUrl());
35     }
36
37     public function testFoldPathParentSingle()
38     {
39         $this->assertEquals(
40             '/path/to/foo',
41             Tools::foldPath('/path/to/bar/../foo')
42         );
43     }
44
45     public function testFoldPathParentDouble()
46     {
47         $this->assertEquals(
48             '/path/to/foo',
49             Tools::foldPath('/path/to/foo/bar/../../foo')
50         );
51     }
52
53     public function testFoldPathCurrentSingle()
54     {
55         $this->assertEquals(
56             '/path/to/foo/',
57             Tools::foldPath('/path/to/foo/./')
58         );
59     }
60
61     public function testFoldPathCurrentThrice()
62     {
63         $this->assertEquals(
64             '/path/to/foo/',
65             Tools::foldPath('/path/././to/foo/./')
66         );
67     }
68 }
69 ?>