mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2025-03-02 11:19:28 -05:00
Use the traditional "template" config key, update unit-tests
This commit is contained in:
parent
bce449de10
commit
5b54f2cdb0
@ -53,7 +53,7 @@ templateselection = false
|
||||
; which can be combined with "-dark" and "-compact" for "bootstrap-dark-page",
|
||||
; "bootstrap-compact-page" and finally "bootstrap5" (tpl/bootstrap5.php) - previews at:
|
||||
; https://privatebin.info/screenshots.html
|
||||
; templatedefault = "bootstrap"
|
||||
; template = "bootstrap"
|
||||
|
||||
; (optional) info text to display
|
||||
; use single, instead of double quotes for HTML attributes
|
||||
|
@ -46,7 +46,7 @@ class Configuration
|
||||
'syntaxhighlightingtheme' => '',
|
||||
'sizelimit' => 10485760,
|
||||
'templateselection' => false,
|
||||
'templatedefault' => '',
|
||||
'template' => 'bootstrap',
|
||||
'info' => 'More information on the <a href=\'https://privatebin.info/\'>project page</a>.',
|
||||
'notice' => '',
|
||||
'languageselection' => false,
|
||||
@ -79,13 +79,13 @@ class Configuration
|
||||
'markdown' => 'Markdown',
|
||||
),
|
||||
'available_templates' => array(
|
||||
'bootstrap5',
|
||||
'bootstrap',
|
||||
'bootstrap-page',
|
||||
'bootstrap-dark',
|
||||
'bootstrap-dark-page',
|
||||
'bootstrap-compact',
|
||||
'bootstrap-compact-page',
|
||||
'bootstrap5',
|
||||
'page',
|
||||
),
|
||||
'traffic' => array(
|
||||
|
@ -213,9 +213,10 @@ class Controller
|
||||
$this->_conf = new Configuration;
|
||||
|
||||
$templates = $this->_conf->getSection('available_templates');
|
||||
$template = $this->_conf->getKey('templatedefault');
|
||||
$template = $this->_conf->getKey('template');
|
||||
TemplateSwitcher::setAvailableTemplates($templates);
|
||||
TemplateSwitcher::setTemplateFallback($template);
|
||||
|
||||
// force default template, if template selection is disabled and a default is set
|
||||
if (!$this->_conf->getKey('templateselection') && !empty($template)) {
|
||||
$_COOKIE['template'] = $template;
|
||||
|
@ -26,7 +26,7 @@ class TemplateSwitcher {
|
||||
* @static
|
||||
* @var string
|
||||
*/
|
||||
protected static $_templateFallback = "bootstrap";
|
||||
protected static $_templateFallback;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PrivateBin\Configuration;
|
||||
use PrivateBin\TemplateSwitcher;
|
||||
|
||||
|
||||
@ -9,17 +10,27 @@ class TemplateSwitcherTest extends TestCase
|
||||
|
||||
public function testSetTemplateFallback()
|
||||
{
|
||||
$defaultTemplateFallback = "bootstrap";
|
||||
$customTemplateFallback = "bootstrap-dark";
|
||||
$conf = new Configuration;
|
||||
|
||||
$existingTemplateFallback = "bootstrap-dark";
|
||||
$wrongTemplateFallback = "bootstrap-wrong";
|
||||
|
||||
$this->assertEquals($defaultTemplateFallback, TemplateSwitcher::getTemplate(), "Default template fallback");
|
||||
TemplateSwitcher::setAvailableTemplates($conf->getSection('available_templates'));
|
||||
TemplateSwitcher::setTemplateFallback($existingTemplateFallback);
|
||||
$this->assertEquals($existingTemplateFallback, TemplateSwitcher::getTemplate(), "Correct template fallback");
|
||||
|
||||
TemplateSwitcher::setTemplateFallback($wrongTemplateFallback);
|
||||
$this->assertEquals($defaultTemplateFallback, TemplateSwitcher::getTemplate(), "Wrong template fallback");
|
||||
$this->assertEquals($existingTemplateFallback, TemplateSwitcher::getTemplate(), "Wrong template fallback");
|
||||
}
|
||||
|
||||
TemplateSwitcher::setTemplateFallback($customTemplateFallback);
|
||||
$this->assertEquals($customTemplateFallback, TemplateSwitcher::getTemplate(), "Custom template fallback");
|
||||
|
||||
public function testSetAvailableTemplates()
|
||||
{
|
||||
$conf = new Configuration;
|
||||
$availableTemplates = $conf->getSection('available_templates');
|
||||
|
||||
TemplateSwitcher::setAvailableTemplates($availableTemplates);
|
||||
$this->assertEquals($availableTemplates, TemplateSwitcher::getAvailableTemplates(), "Set available templates");
|
||||
}
|
||||
|
||||
|
||||
@ -41,15 +52,19 @@ class TemplateSwitcherTest extends TestCase
|
||||
|
||||
public function testGetAvailableTemplates()
|
||||
{
|
||||
$this->assertNotEmpty(TemplateSwitcher::getAvailableTemplates(), "Available templates");
|
||||
$this->assertNotEmpty(TemplateSwitcher::getAvailableTemplates(), "Get available templates");
|
||||
}
|
||||
|
||||
|
||||
public function testIsTemplateAvailable()
|
||||
{
|
||||
$conf = new Configuration;
|
||||
|
||||
$existingTemplate = "bootstrap";
|
||||
$nonExistentTemplate = "bootstrap-wrong";
|
||||
|
||||
TemplateSwitcher::setAvailableTemplates($conf->getSection('available_templates'));
|
||||
|
||||
$this->assertTrue(TemplateSwitcher::isTemplateAvailable($existingTemplate), "Existing template");
|
||||
$this->assertFalse(TemplateSwitcher::isTemplateAvailable($nonExistentTemplate), "Non-existent template");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user