clarify that we support two ways to embed pastes
[phorkie.git] / tests / phorkie / ToolsTest.php
1 <?php
2 namespace phorkie;
3
4 class ToolsTest extends \PHPUnit_Framework_TestCase
5 {
6     public function setUp()
7     {
8         $_GET[] = array();
9     }
10
11     public function testDetectBaseUrlPhar()
12     {
13         $_SERVER['REQUEST_URI'] = '/phar/phorkie-0.4.0.phar/list.php';
14         $_SERVER['SCRIPT_NAME'] = '/phar/phorkie-0.4.0.phar';
15         $this->assertEquals(
16             '/phar/phorkie-0.4.0.phar/',
17             Tools::detectBaseUrl()
18         );
19     }
20
21     public function testDetectBaseUrlRoot()
22     {
23         $_SERVER['REQUEST_URI'] = '/new';
24         $_SERVER['SCRIPT_NAME'] = '/new.php';
25         $this->assertEquals('/', Tools::detectBaseUrl());
26     }
27
28     public function testDetectBaseUrlRootWithPhp()
29     {
30         $_SERVER['REQUEST_URI'] = '/new.php';
31         $_SERVER['SCRIPT_NAME'] = '/new.php';
32         $this->assertEquals('/', Tools::detectBaseUrl());
33     }
34
35     public function testDetectBaseUrlSubdir()
36     {
37         $_SERVER['REQUEST_URI'] = '/foo/new';
38         $_SERVER['SCRIPT_NAME'] = '/new.php';
39         $this->assertEquals('/foo/', Tools::detectBaseUrl());
40     }
41
42     public function testDetectBaseUrlEdit()
43     {
44         $_GET['id'] = 82;
45         $_SERVER['REQUEST_URI'] = '/82/edit';
46         $_SERVER['SCRIPT_NAME'] = '/edit.php';
47         $this->assertEquals('/', Tools::detectBaseUrl());
48     }
49
50     public function testDetectBaseUrlEditSubdir()
51     {
52         $_GET['id'] = 82;
53         $_SERVER['REQUEST_URI'] = '/foo/82/edit';
54         $_SERVER['SCRIPT_NAME'] = '/edit.php';
55         $this->assertEquals('/foo/', Tools::detectBaseUrl());
56     }
57
58     public function testFoldPathParentSingle()
59     {
60         $this->assertEquals(
61             '/path/to/foo',
62             Tools::foldPath('/path/to/bar/../foo')
63         );
64     }
65
66     public function testFoldPathParentDouble()
67     {
68         $this->assertEquals(
69             '/path/to/foo',
70             Tools::foldPath('/path/to/foo/bar/../../foo')
71         );
72     }
73
74     public function testFoldPathCurrentSingle()
75     {
76         $this->assertEquals(
77             '/path/to/foo/',
78             Tools::foldPath('/path/to/foo/./')
79         );
80     }
81
82     public function testFoldPathCurrentThrice()
83     {
84         $this->assertEquals(
85             '/path/to/foo/',
86             Tools::foldPath('/path/././to/foo/./')
87         );
88     }
89 }
90 ?>