Add unit tests for utility functions
Add unit tests for utility functions

file:b/test/UtilTest.php (new)
--- /dev/null
+++ b/test/UtilTest.php
@@ -1,1 +1,94 @@
+<?php
+/**
+ * Utility test class
+ *
+ * @author Christopher Han <xiphux@gmail.com>
+ * @copyright Copyright (c) 2012 Christopher Han
+ * @package GitPHP
+ * @subpackage Test
+ */
+class GitPHP_UtilTest extends PHPUnit_Framework_TestCase
+{
+	public function testAddSlash()
+	{
+		$this->assertEmpty(GitPHP_Util::AddSlash(''));
 
+		$this->assertEquals('/url/with/slash/', GitPHP_Util::AddSlash('/url/with/slash/'));
+		$this->assertEquals('/url/without/slash/', GitPHP_Util::AddSlash('/url/without/slash'));
+
+		$this->assertEquals('/url/with/colon:', GitPHP_Util::AddSlash('/url/with/colon:'));
+		$this->assertEquals('/', GitPHP_Util::AddSlash('/'));
+	}
+
+	public function testAddSlashNix()
+	{
+		if (GitPHP_Util::IsWindows()) {
+			$this->markTestSkipped();
+		}
+
+		$this->assertEquals('/path/with/slash/', GitPHP_Util::AddSlash('/path/with/slash/', true));
+		$this->assertEquals('/path/without/slash/', GitPHP_Util::AddSlash('/path/without/slash', true));
+		$this->assertEquals('/path/with/backslash\\/', GitPHP_Util::AddSlash('/path/with/backslash\\', true));
+		$this->assertEquals('/path/with/colon:', GitPHP_Util::AddSlash('/path/with/colon:', true));
+		$this->assertEquals('/', GitPHP_Util::AddSlash('/', true));
+		$this->assertEquals('\\/', GitPHP_Util::AddSlash('\\', true));
+	}
+
+	public function testAddSlashWin()
+	{
+		if (!GitPHP_Util::IsWindows()) {
+			$this->markTestSkipped();
+		}
+
+		$this->assertEquals('path\\with\\backslash\\', GitPHP_Util::AddSlash('path\\with\\backslash\\', true));
+		$this->assertEquals('path\\without\\backslash\\', GitPHP_Util::AddSlash('path\\without\\backslash', true));
+		$this->assertEquals('path\\with\\slash/', GitPHP_Util::AddSlash('path\\with\\slash/', true));
+		$this->assertEquals('/path/with/colon:', GitPHP_Util::AddSlash('/path/with/colon:', true));
+		$this->assertEquals('\\', GitPHP_Util::AddSlash('\\', true));
+		$this->assertEquals('/', GitPHP_Util::AddSlash('/', true));
+	}
+
+	public function testMakeSlug()
+	{
+		$this->assertEquals('some-path', GitPHP_Util::MakeSlug('some/path'));
+		$this->assertEquals('somepath', GitPHP_Util::MakeSlug('somepath'));
+	}
+
+	public function testBaseNameNix()
+	{
+		if (GitPHP_Util::IsWindows()) {
+			$this->markTestSkipped();
+		}
+
+		$this->assertEquals('file', GitPHP_Util::BaseName('/some/path/to/file'));
+		$this->assertEquals('file', GitPHP_Util::BaseName('/some/path/to/file/'));
+		$this->assertEquals('file', GitPHP_Util::BaseName('/some/path/to/file.ext', '.ext'));
+		$this->assertEquals('.extfile', GitPHP_Util::BaseName('/some/path/to/.extfile.ext', '.ext'));
+	}
+
+	public function testBaseNameWin()
+	{
+		if (!GitPHP_Util::IsWindows()) {
+			$this->markTestSkipped();
+		}
+
+		$this->assertEquals('file', GitPHP_Util::BaseName('some\\path\\to\\file'));
+		$this->assertEquals('file', GitPHP_Util::BaseName('some\\path\\to\\file\\'));
+		$this->assertEquals('file', GitPHP_Util::BaseName('some\\path\\to\\file.ext', '.ext'));
+		$this->assertEquals('.extfile', GitPHP_Util::BaseName('some\\path\\to\\.extfile.ext', '.ext'));
+	}
+
+	public function testGeshiFilename()
+	{
+		$this->assertNull(GitPHP_Util::GeshiFilenameToLanguage('unknownfile'));
+		$this->assertEquals('make', GitPHP_Util::GeshiFilenameToLanguage('Makefile'));
+		$this->assertEquals('make', GitPHP_Util::GeshiFilenameToLanguage('makefile'));
+	}
+
+	public function testListDir()
+	{
+		// TODO: look into vfsStream to test this
+		$this->markTestIncomplete();
+	}
+}
+

comments