Merge pull request from ArthurHoaro/feature/theme-manager

Theme manager: improvements
This commit is contained in:
Arthur 2017-01-06 11:40:54 +01:00 committed by GitHub
commit 7418f7cb60
52 changed files with 215 additions and 16 deletions

View file

@ -289,6 +289,7 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
$conf->set('resource.page_cache', 'pagecache');
$conf->set('resource.raintpl_tmp', 'tmp');
$conf->set('resource.raintpl_tpl', 'tpl');
$conf->set('resource.theme', 'default');
$conf->set('resource.update_check', 'data/lastupdatecheck.txt');
$this->assertEquals(
@ -312,10 +313,12 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
$conf->set('resource.page_cache', 'null/pagecache');
$conf->set('resource.raintpl_tmp', 'null/tmp');
$conf->set('resource.raintpl_tpl', 'null/tpl');
$conf->set('resource.raintpl_theme', 'null/tpl/default');
$conf->set('resource.update_check', 'null/data/lastupdatecheck.txt');
$this->assertEquals(
array(
'"null/tpl" directory is not readable',
'"null/tpl/default" directory is not readable',
'"null/cache" directory is not readable',
'"null/cache" directory is not writable',
'"null/data" directory is not readable',

55
tests/ThemeUtilsTest.php Normal file
View file

@ -0,0 +1,55 @@
<?php
namespace Shaarli;
/**
* Class ThemeUtilsTest
*
* @package Shaarli
*/
class ThemeUtilsTest extends \PHPUnit_Framework_TestCase
{
/**
* Test getThemes() with existing theme directories.
*/
public function testGetThemes()
{
$themes = ['theme1', 'default', 'Bl1p_- bL0p'];
foreach ($themes as $theme) {
mkdir('sandbox/tpl/'. $theme, 0755, true);
}
// include a file which should be ignored
touch('sandbox/tpl/supertheme');
$res = ThemeUtils::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/', 0755, true);
$this->assertEquals([], ThemeUtils::getThemes('sandbox/tpl/'));
rmdir('sandbox/tpl/');
}
/**
* Test getThemes() with an invalid path.
*/
public function testGetThemesInvalid()
{
$this->assertEquals([], ThemeUtils::getThemes('nope'));
}
}

View file

@ -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.
@ -421,4 +422,48 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
$this->assertTrue($updater->updateMethodDatastoreIds());
$this->assertEquals($checksum, hash_file('sha1', self::$testDatastore));
}
/**
* Test defaultTheme update with default settings: nothing to do.
*/
public function testDefaultThemeWithDefaultSettings()
{
$sandbox = 'sandbox/config';
copy(self::$configFile . '.json.php', $sandbox . '.json.php');
$this->conf = new ConfigManager($sandbox);
$updater = new Updater([], [], $this->conf, true);
$this->assertTrue($updater->updateMethodDefaultTheme());
$this->assertEquals('tpl/', $this->conf->get('resource.raintpl_tpl'));
$this->assertEquals('default', $this->conf->get('resource.theme'));
$this->conf = new ConfigManager($sandbox);
$this->assertEquals('tpl/', $this->conf->get('resource.raintpl_tpl'));
$this->assertEquals('default', $this->conf->get('resource.theme'));
unlink($sandbox . '.json.php');
}
/**
* Test defaultTheme update with a custom theme in a subfolder
*/
public function testDefaultThemeWithCustomTheme()
{
$theme = 'iamanartist';
$sandbox = 'sandbox/config';
copy(self::$configFile . '.json.php', $sandbox . '.json.php');
$this->conf = new ConfigManager($sandbox);
mkdir('sandbox/'. $theme);
touch('sandbox/'. $theme .'/linklist.html');
$this->conf->set('resource.raintpl_tpl', 'sandbox/'. $theme .'/');
$updater = new Updater([], [], $this->conf, true);
$this->assertTrue($updater->updateMethodDefaultTheme());
$this->assertEquals('sandbox', $this->conf->get('resource.raintpl_tpl'));
$this->assertEquals($theme, $this->conf->get('resource.theme'));
$this->conf = new ConfigManager($sandbox);
$this->assertEquals('sandbox', $this->conf->get('resource.raintpl_tpl'));
$this->assertEquals($theme, $this->conf->get('resource.theme'));
unlink($sandbox . '.json.php');
unlink('sandbox/'. $theme .'/linklist.html');
rmdir('sandbox/'. $theme);
}
}

View file

@ -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