tests for baseurl detection
[phorkie.git] / tests / phorkie / ToolsTest.php
diff --git a/tests/phorkie/ToolsTest.php b/tests/phorkie/ToolsTest.php
new file mode 100644 (file)
index 0000000..7a5be16
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+namespace phorkie;
+
+class ToolsTest extends \PHPUnit_Framework_TestCase
+{
+    public function testDetectBaseUrlPhar()
+    {
+        $_SERVER['REQUEST_URI'] = '/phar/phorkie-0.4.0.phar/list.php';
+        $_SERVER['SCRIPT_NAME'] = '/phar/phorkie-0.4.0.phar';
+        $this->assertEquals(
+            '/phar/phorkie-0.4.0.phar/',
+            Tools::detectBaseUrl()
+        );
+    }
+
+    public function testDetectBaseUrlRoot()
+    {
+        $_SERVER['REQUEST_URI'] = '/new';
+        $_SERVER['SCRIPT_NAME'] = '/new.php';
+        $this->assertEquals('/', Tools::detectBaseUrl());
+    }
+
+    public function testDetectBaseUrlRootWithPhp()
+    {
+        $_SERVER['REQUEST_URI'] = '/new.php';
+        $_SERVER['SCRIPT_NAME'] = '/new.php';
+        $this->assertEquals('/', Tools::detectBaseUrl());
+    }
+
+    public function testDetectBaseUrlSubdir()
+    {
+        $_SERVER['REQUEST_URI'] = '/foo/new';
+        $_SERVER['SCRIPT_NAME'] = '/new.php';
+        $this->assertEquals('/foo/', Tools::detectBaseUrl());
+    }
+}
+?>