From a0df06517bada0f811b464017ce385290e02c2bf Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 3 Jan 2017 11:42:21 +0100 Subject: Minor improvements regarding #705 (coding style, unit tests, etc.) --- tests/ApplicationUtilsTest.php | 44 ++++++++++++++++++++++++++++++++++ tests/Updater/UpdaterTest.php | 1 + tests/utils/config/configJson.json.php | 3 ++- 3 files changed, 47 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/ApplicationUtilsTest.php b/tests/ApplicationUtilsTest.php index 634bd0ed..c39649e8 100644 --- a/tests/ApplicationUtilsTest.php +++ b/tests/ApplicationUtilsTest.php @@ -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')); + } } diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index 0171daad..a1530996 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php @@ -2,6 +2,7 @@ require_once 'application/config/ConfigManager.php'; require_once 'tests/Updater/DummyUpdater.php'; +require_once 'inc/rain.tpl.class.php'; /** * Class UpdaterTest. diff --git a/tests/utils/config/configJson.json.php b/tests/utils/config/configJson.json.php index 06a302e8..13d38c66 100644 --- a/tests/utils/config/configJson.json.php +++ b/tests/utils/config/configJson.json.php @@ -24,7 +24,8 @@ }, "resource": { "datastore": "tests\/utils\/config\/datastore.php", - "data_dir": "tests\/utils\/config" + "data_dir": "tests\/utils\/config", + "raintpl_tpl": "tpl/" }, "plugins": { "WALLABAG_VERSION": 1 -- cgit v1.2.3