UtilTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * Utility test class
  4. *
  5. * @author Christopher Han <xiphux@gmail.com>
  6. * @copyright Copyright (c) 2012 Christopher Han
  7. * @package GitPHP
  8. * @subpackage Test
  9. */
  10. class GitPHP_UtilTest extends PHPUnit_Framework_TestCase
  11. {
  12. public function testAddSlash()
  13. {
  14. $this->assertEmpty(GitPHP_Util::AddSlash(''));
  15. $this->assertEquals('/url/with/slash/', GitPHP_Util::AddSlash('/url/with/slash/'));
  16. $this->assertEquals('/url/without/slash/', GitPHP_Util::AddSlash('/url/without/slash'));
  17. $this->assertEquals('/url/with/colon:', GitPHP_Util::AddSlash('/url/with/colon:'));
  18. $this->assertEquals('/', GitPHP_Util::AddSlash('/'));
  19. }
  20. public function testAddSlashNix()
  21. {
  22. if (GitPHP_Util::IsWindows()) {
  23. $this->markTestSkipped();
  24. }
  25. $this->assertEquals('/path/with/slash/', GitPHP_Util::AddSlash('/path/with/slash/', true));
  26. $this->assertEquals('/path/without/slash/', GitPHP_Util::AddSlash('/path/without/slash', true));
  27. $this->assertEquals('/path/with/backslash\\/', GitPHP_Util::AddSlash('/path/with/backslash\\', true));
  28. $this->assertEquals('/path/with/colon:', GitPHP_Util::AddSlash('/path/with/colon:', true));
  29. $this->assertEquals('/', GitPHP_Util::AddSlash('/', true));
  30. $this->assertEquals('\\/', GitPHP_Util::AddSlash('\\', true));
  31. }
  32. public function testAddSlashWin()
  33. {
  34. if (!GitPHP_Util::IsWindows()) {
  35. $this->markTestSkipped();
  36. }
  37. $this->assertEquals('path\\with\\backslash\\', GitPHP_Util::AddSlash('path\\with\\backslash\\', true));
  38. $this->assertEquals('path\\without\\backslash\\', GitPHP_Util::AddSlash('path\\without\\backslash', true));
  39. $this->assertEquals('path\\with\\slash/', GitPHP_Util::AddSlash('path\\with\\slash/', true));
  40. $this->assertEquals('/path/with/colon:', GitPHP_Util::AddSlash('/path/with/colon:', true));
  41. $this->assertEquals('\\', GitPHP_Util::AddSlash('\\', true));
  42. $this->assertEquals('/', GitPHP_Util::AddSlash('/', true));
  43. }
  44. public function testMakeSlug()
  45. {
  46. $this->assertEquals('some-path', GitPHP_Util::MakeSlug('some/path'));
  47. $this->assertEquals('somepath', GitPHP_Util::MakeSlug('somepath'));
  48. }
  49. public function testBaseNameNix()
  50. {
  51. if (GitPHP_Util::IsWindows()) {
  52. $this->markTestSkipped();
  53. }
  54. $this->assertEquals('file', GitPHP_Util::BaseName('/some/path/to/file'));
  55. $this->assertEquals('file', GitPHP_Util::BaseName('/some/path/to/file/'));
  56. $this->assertEquals('file', GitPHP_Util::BaseName('/some/path/to/file.ext', '.ext'));
  57. $this->assertEquals('.extfile', GitPHP_Util::BaseName('/some/path/to/.extfile.ext', '.ext'));
  58. }
  59. public function testBaseNameWin()
  60. {
  61. if (!GitPHP_Util::IsWindows()) {
  62. $this->markTestSkipped();
  63. }
  64. $this->assertEquals('file', GitPHP_Util::BaseName('some\\path\\to\\file'));
  65. $this->assertEquals('file', GitPHP_Util::BaseName('some\\path\\to\\file\\'));
  66. $this->assertEquals('file', GitPHP_Util::BaseName('some\\path\\to\\file.ext', '.ext'));
  67. $this->assertEquals('.extfile', GitPHP_Util::BaseName('some\\path\\to\\.extfile.ext', '.ext'));
  68. }
  69. public function testGeshiFilename()
  70. {
  71. $this->assertNull(GitPHP_Util::GeshiFilenameToLanguage('unknownfile'));
  72. $this->assertEquals('make', GitPHP_Util::GeshiFilenameToLanguage('Makefile'));
  73. $this->assertEquals('make', GitPHP_Util::GeshiFilenameToLanguage('makefile'));
  74. }
  75. public function testListDir()
  76. {
  77. $datadir = dirname(__FILE__) . '/resources/testdir';
  78. $listed = GitPHP_Util::ListDir($datadir);
  79. $this->assertCount(5, $listed);
  80. $expected = array(
  81. $datadir . '/.hiddentestfile',
  82. $datadir . '/testfile1.txt',
  83. $datadir . '/testdir2/testfile2.txt',
  84. $datadir . '/testdir2/testdir4/testfile4.txt',
  85. $datadir . '/testdir3/testfile3.txt'
  86. );
  87. $this->assertCount(0, array_diff($listed, $expected));
  88. $this->assertCount(0, array_diff($expected, $listed));
  89. }
  90. }