Skip to content

Commit

Permalink
Fix broken admin theme option (#4194)
Browse files Browse the repository at this point in the history
* Fix broken admin theme option

* Update comment

* Finish fix.

* Add Mink test.

* Better fix.

---------

Co-authored-by: Demian Katz <[email protected]>
  • Loading branch information
aleksip and demiankatz authored Jan 23, 2025
1 parent b70ee00 commit 66854cc
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

/**
* Admin module test class.
*
* PHP version 8
*
* Copyright (C) Villanova University 2025.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package Tests
* @author Demian Katz <[email protected]>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org Main Page
*/

namespace VuFindTest\Mink;

/**
* Admin module test class.
*
* @category VuFind
* @package Tests
* @author Demian Katz <[email protected]>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org Main Page
*/
class AdminTest extends \VuFindTest\Integration\MinkTestCase
{
use \VuFindTest\Feature\HttpRequestTrait;

/**
* Test that the admin module is disabled by default.
*
* @return void
*/
public function testDisabledByDefault(): void
{
$session = $this->getMinkSession();
$session->visit($this->getVuFindUrl() . '/Admin');
$page = $session->getPage();
$this->assertEquals('The Admin module is currently disabled.', $this->findCssAndGetText($page, 'p.error b'));
}

/**
* Data provider for testAdminTheme()
*
* @return array[]
*/
public static function adminThemeProvider(): array
{
return [
'no admin theme' => [false],
'custom admin theme' => [true],
];
}

/**
* Test that admin themes are applied correctly.
*
* @param bool $enabled Should we enable the admin theme?
*
* @return void
*
* @dataProvider adminThemeProvider
*/
public function testAdminTheme(bool $enabled): void
{
$config = [
'Site' => [
'admin_enabled' => true,
],
];
if ($enabled) {
$config['Site']['admin_theme'] = 'local_theme_example';
}
$this->changeConfigs(compact('config'));
$html = $this->httpGet($this->getVuFindUrl() . '/Admin')->getBody();
$assertion = $enabled ? 'assertStringContainsString' : 'assertStringNotContainsString';
$this->$assertion('local_theme_example', $html);
}
}
9 changes: 6 additions & 3 deletions module/VuFindTheme/src/VuFindTheme/Initializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,14 @@ public function init()
protected function getThemeAliasMap(): array
{
if ($this->themeMap === null) {
// Set up special-case 'standard' and 'mobile' aliases:
// Set up special-case 'standard', 'mobile' and 'admin' aliases:
$this->themeMap = ['standard' => $this->config->theme];
if (isset($this->config->mobile_theme)) {
$this->themeMap['mobile'] = $this->config->mobile_theme;
}
if (isset($this->config->admin_theme)) {
$this->themeMap['admin'] = $this->config->admin_theme;
}

// Parse the alternate theme settings for additional options:
$parts = explode(',', $this->config->alternate_themes ?? '');
Expand Down Expand Up @@ -248,9 +251,9 @@ protected function getSelectedUI(array $themes, ?Request $request): string
&& ($routeMatch = $this->event->getRouteMatch())
&& $routeMatch->getParam('admin_route')
&& ($this->config->admin_enabled ?? false)
&& ($adminTheme = ($this->config->admin_theme ?? false))
&& isset($themes['admin'])
) {
return $adminTheme;
return 'admin';
}

// Load standard configuration options:
Expand Down

0 comments on commit 66854cc

Please sign in to comment.