Updater: keep custom theme preference with the new theme setting
This commit is contained in:
parent
a0df06517b
commit
04a0e8ea34
8 changed files with 163 additions and 69 deletions
|
@ -331,48 +331,4 @@ 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'));
|
||||
}
|
||||
}
|
||||
|
|
55
tests/ThemeUtilsTest.php
Normal file
55
tests/ThemeUtilsTest.php
Normal 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'));
|
||||
}
|
||||
}
|
|
@ -422,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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue