aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorArthur <arthur@hoa.ro>2017-01-06 11:40:54 +0100
committerGitHub <noreply@github.com>2017-01-06 11:40:54 +0100
commit7418f7cb60524c3bfc2f240386b5e3e7eb9b3257 (patch)
tree4b0c89c133ad1679c5db3a4f0f6b94079f776395 /tests
parent93b1fe54fb99efff30eec0d405cc7319fbbc1f95 (diff)
parent01c6e32a02034ab119d83364c4648ce55d75543b (diff)
downloadShaarli-7418f7cb60524c3bfc2f240386b5e3e7eb9b3257.tar.gz
Shaarli-7418f7cb60524c3bfc2f240386b5e3e7eb9b3257.tar.zst
Shaarli-7418f7cb60524c3bfc2f240386b5e3e7eb9b3257.zip
Merge pull request #732 from ArthurHoaro/feature/theme-manager
Theme manager: improvements
Diffstat (limited to 'tests')
-rw-r--r--tests/ApplicationUtilsTest.php3
-rw-r--r--tests/ThemeUtilsTest.php55
-rw-r--r--tests/Updater/UpdaterTest.php45
-rw-r--r--tests/utils/config/configJson.json.php3
4 files changed, 105 insertions, 1 deletions
diff --git a/tests/ApplicationUtilsTest.php b/tests/ApplicationUtilsTest.php
index 861b8d4e..634bd0ed 100644
--- a/tests/ApplicationUtilsTest.php
+++ b/tests/ApplicationUtilsTest.php
@@ -289,6 +289,7 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
289 $conf->set('resource.page_cache', 'pagecache'); 289 $conf->set('resource.page_cache', 'pagecache');
290 $conf->set('resource.raintpl_tmp', 'tmp'); 290 $conf->set('resource.raintpl_tmp', 'tmp');
291 $conf->set('resource.raintpl_tpl', 'tpl'); 291 $conf->set('resource.raintpl_tpl', 'tpl');
292 $conf->set('resource.theme', 'default');
292 $conf->set('resource.update_check', 'data/lastupdatecheck.txt'); 293 $conf->set('resource.update_check', 'data/lastupdatecheck.txt');
293 294
294 $this->assertEquals( 295 $this->assertEquals(
@@ -312,10 +313,12 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
312 $conf->set('resource.page_cache', 'null/pagecache'); 313 $conf->set('resource.page_cache', 'null/pagecache');
313 $conf->set('resource.raintpl_tmp', 'null/tmp'); 314 $conf->set('resource.raintpl_tmp', 'null/tmp');
314 $conf->set('resource.raintpl_tpl', 'null/tpl'); 315 $conf->set('resource.raintpl_tpl', 'null/tpl');
316 $conf->set('resource.raintpl_theme', 'null/tpl/default');
315 $conf->set('resource.update_check', 'null/data/lastupdatecheck.txt'); 317 $conf->set('resource.update_check', 'null/data/lastupdatecheck.txt');
316 $this->assertEquals( 318 $this->assertEquals(
317 array( 319 array(
318 '"null/tpl" directory is not readable', 320 '"null/tpl" directory is not readable',
321 '"null/tpl/default" directory is not readable',
319 '"null/cache" directory is not readable', 322 '"null/cache" directory is not readable',
320 '"null/cache" directory is not writable', 323 '"null/cache" directory is not writable',
321 '"null/data" directory is not readable', 324 '"null/data" directory is not readable',
diff --git a/tests/ThemeUtilsTest.php b/tests/ThemeUtilsTest.php
new file mode 100644
index 00000000..e44564be
--- /dev/null
+++ b/tests/ThemeUtilsTest.php
@@ -0,0 +1,55 @@
1<?php
2
3namespace Shaarli;
4
5/**
6 * Class ThemeUtilsTest
7 *
8 * @package Shaarli
9 */
10class ThemeUtilsTest extends \PHPUnit_Framework_TestCase
11{
12 /**
13 * Test getThemes() with existing theme directories.
14 */
15 public function testGetThemes()
16 {
17 $themes = ['theme1', 'default', 'Bl1p_- bL0p'];
18 foreach ($themes as $theme) {
19 mkdir('sandbox/tpl/'. $theme, 0755, true);
20 }
21
22 // include a file which should be ignored
23 touch('sandbox/tpl/supertheme');
24
25 $res = ThemeUtils::getThemes('sandbox/tpl/');
26 foreach ($res as $theme) {
27 $this->assertTrue(in_array($theme, $themes));
28 }
29 $this->assertFalse(in_array('supertheme', $res));
30
31 foreach ($themes as $theme) {
32 rmdir('sandbox/tpl/'. $theme);
33 }
34 unlink('sandbox/tpl/supertheme');
35 rmdir('sandbox/tpl');
36 }
37
38 /**
39 * Test getThemes() without any theme dir.
40 */
41 public function testGetThemesEmpty()
42 {
43 mkdir('sandbox/tpl/', 0755, true);
44 $this->assertEquals([], ThemeUtils::getThemes('sandbox/tpl/'));
45 rmdir('sandbox/tpl/');
46 }
47
48 /**
49 * Test getThemes() with an invalid path.
50 */
51 public function testGetThemesInvalid()
52 {
53 $this->assertEquals([], ThemeUtils::getThemes('nope'));
54 }
55}
diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php
index 0171daad..1d15cfaa 100644
--- a/tests/Updater/UpdaterTest.php
+++ b/tests/Updater/UpdaterTest.php
@@ -2,6 +2,7 @@
2 2
3require_once 'application/config/ConfigManager.php'; 3require_once 'application/config/ConfigManager.php';
4require_once 'tests/Updater/DummyUpdater.php'; 4require_once 'tests/Updater/DummyUpdater.php';
5require_once 'inc/rain.tpl.class.php';
5 6
6/** 7/**
7 * Class UpdaterTest. 8 * Class UpdaterTest.
@@ -421,4 +422,48 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
421 $this->assertTrue($updater->updateMethodDatastoreIds()); 422 $this->assertTrue($updater->updateMethodDatastoreIds());
422 $this->assertEquals($checksum, hash_file('sha1', self::$testDatastore)); 423 $this->assertEquals($checksum, hash_file('sha1', self::$testDatastore));
423 } 424 }
425
426 /**
427 * Test defaultTheme update with default settings: nothing to do.
428 */
429 public function testDefaultThemeWithDefaultSettings()
430 {
431 $sandbox = 'sandbox/config';
432 copy(self::$configFile . '.json.php', $sandbox . '.json.php');
433 $this->conf = new ConfigManager($sandbox);
434 $updater = new Updater([], [], $this->conf, true);
435 $this->assertTrue($updater->updateMethodDefaultTheme());
436
437 $this->assertEquals('tpl/', $this->conf->get('resource.raintpl_tpl'));
438 $this->assertEquals('default', $this->conf->get('resource.theme'));
439 $this->conf = new ConfigManager($sandbox);
440 $this->assertEquals('tpl/', $this->conf->get('resource.raintpl_tpl'));
441 $this->assertEquals('default', $this->conf->get('resource.theme'));
442 unlink($sandbox . '.json.php');
443 }
444
445 /**
446 * Test defaultTheme update with a custom theme in a subfolder
447 */
448 public function testDefaultThemeWithCustomTheme()
449 {
450 $theme = 'iamanartist';
451 $sandbox = 'sandbox/config';
452 copy(self::$configFile . '.json.php', $sandbox . '.json.php');
453 $this->conf = new ConfigManager($sandbox);
454 mkdir('sandbox/'. $theme);
455 touch('sandbox/'. $theme .'/linklist.html');
456 $this->conf->set('resource.raintpl_tpl', 'sandbox/'. $theme .'/');
457 $updater = new Updater([], [], $this->conf, true);
458 $this->assertTrue($updater->updateMethodDefaultTheme());
459
460 $this->assertEquals('sandbox', $this->conf->get('resource.raintpl_tpl'));
461 $this->assertEquals($theme, $this->conf->get('resource.theme'));
462 $this->conf = new ConfigManager($sandbox);
463 $this->assertEquals('sandbox', $this->conf->get('resource.raintpl_tpl'));
464 $this->assertEquals($theme, $this->conf->get('resource.theme'));
465 unlink($sandbox . '.json.php');
466 unlink('sandbox/'. $theme .'/linklist.html');
467 rmdir('sandbox/'. $theme);
468 }
424} 469}
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 @@
24 }, 24 },
25 "resource": { 25 "resource": {
26 "datastore": "tests\/utils\/config\/datastore.php", 26 "datastore": "tests\/utils\/config\/datastore.php",
27 "data_dir": "tests\/utils\/config" 27 "data_dir": "tests\/utils\/config",
28 "raintpl_tpl": "tpl/"
28 }, 29 },
29 "plugins": { 30 "plugins": {
30 "WALLABAG_VERSION": 1 31 "WALLABAG_VERSION": 1