ThemeUtilsTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Shaarli;
  3. /**
  4. * Class ThemeUtilsTest
  5. *
  6. * @package Shaarli
  7. */
  8. class ThemeUtilsTest extends \PHPUnit_Framework_TestCase
  9. {
  10. /**
  11. * Test getThemes() with existing theme directories.
  12. */
  13. public function testGetThemes()
  14. {
  15. $themes = ['theme1', 'default', 'Bl1p_- bL0p'];
  16. foreach ($themes as $theme) {
  17. mkdir('sandbox/tpl/'. $theme, 0755, true);
  18. }
  19. // include a file which should be ignored
  20. touch('sandbox/tpl/supertheme');
  21. $res = ThemeUtils::getThemes('sandbox/tpl/');
  22. foreach ($res as $theme) {
  23. $this->assertTrue(in_array($theme, $themes));
  24. }
  25. $this->assertFalse(in_array('supertheme', $res));
  26. foreach ($themes as $theme) {
  27. rmdir('sandbox/tpl/'. $theme);
  28. }
  29. unlink('sandbox/tpl/supertheme');
  30. rmdir('sandbox/tpl');
  31. }
  32. /**
  33. * Test getThemes() without any theme dir.
  34. */
  35. public function testGetThemesEmpty()
  36. {
  37. mkdir('sandbox/tpl/', 0755, true);
  38. $this->assertEquals([], ThemeUtils::getThemes('sandbox/tpl/'));
  39. rmdir('sandbox/tpl/');
  40. }
  41. /**
  42. * Test getThemes() with an invalid path.
  43. */
  44. public function testGetThemesInvalid()
  45. {
  46. $this->assertEquals([], ThemeUtils::getThemes('nope'));
  47. }
  48. }