]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - tests/ApplicationUtilsTest.php
Minor improvements regarding #705 (coding style, unit tests, etc.)
[github/shaarli/Shaarli.git] / tests / ApplicationUtilsTest.php
index 634bd0eda01a76848ef80058aadcfc4db71e6d1c..c39649e81876ca51d518be966f4df639a79d26d0 100644 (file)
@@ -331,4 +331,48 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
             ApplicationUtils::checkResourcePermissions($conf)
         );
     }
+
+    /**
+     * Test getThemes() with existing theme directories.
+     */
+    public function testGetThemes()
+    {
+        $themes = ['theme1', 'default', 'Bl1p_- bL0p'];
+        foreach ($themes as $theme) {
+            mkdir('sandbox/tpl/'. $theme, 0777, true);
+        }
+
+        // include a file which should be ignored
+        touch('sandbox/tpl/supertheme');
+
+        $res = ApplicationUtils::getThemes('sandbox/tpl/');
+        foreach ($res as $theme) {
+            $this->assertTrue(in_array($theme, $themes));
+        }
+        $this->assertFalse(in_array('supertheme', $res));
+
+        foreach ($themes as $theme) {
+            rmdir('sandbox/tpl/'. $theme);
+        }
+        unlink('sandbox/tpl/supertheme');
+        rmdir('sandbox/tpl');
+    }
+
+    /**
+     * Test getThemes() without any theme dir.
+     */
+    public function testGetThemesEmpty()
+    {
+        mkdir('sandbox/tpl/', 0777, true);
+        $this->assertEquals([], ApplicationUtils::getThemes('sandbox/tpl/'));
+        rmdir('sandbox/tpl/');
+    }
+
+    /**
+     * Test getThemes() with an invalid path.
+     */
+    public function testGetThemesInvalid()
+    {
+        $this->assertEquals([], ApplicationUtils::getThemes('nope'));
+    }
 }