diff --git a/lib/chibi-core b/lib/chibi-core index ba4284ea..eba4f6f4 160000 --- a/lib/chibi-core +++ b/lib/chibi-core @@ -1 +1 @@ -Subproject commit ba4284ea7d1a43123e5be23afa62322932467125 +Subproject commit eba4f6f486f540a4301f5b20fb68e14bb9b20466 diff --git a/src/Access.php b/src/Access.php index 67ec50f8..93c2a1da 100644 --- a/src/Access.php +++ b/src/Access.php @@ -6,9 +6,19 @@ class Access public static function init() { - self::$privileges = []; self::$checkPrivileges = true; + self::$privileges = \Chibi\Cache::getCache('privileges', [get_called_class(), 'getPrivilegesFromConfig']); + } + public static function initWithoutCache() + { + self::$checkPrivileges = true; + self::$privileges = self::getPrivilegesFromConfig(); + } + + public static function getPrivilegesFromConfig() + { + $privileges = []; foreach (Core::getConfig()->privileges as $key => $minAccessRankName) { if (strpos($key, '.') === false) @@ -19,14 +29,15 @@ class Access if (!in_array($privilegeName, Privilege::getAllConstants())) throw new Exception('Invalid privilege name in config: ' . $privilegeName); - if (!isset(self::$privileges[$privilegeName])) + if (!isset($privileges[$privilegeName])) { - self::$privileges[$privilegeName] = []; - self::$privileges[$privilegeName][null] = $minAccessRank; + $privileges[$privilegeName] = []; + $privileges[$privilegeName][null] = $minAccessRank; } - self::$privileges[$privilegeName][$subPrivilegeName] = $minAccessRank; + $privileges[$privilegeName][$subPrivilegeName] = $minAccessRank; } + return $privileges; } public static function check(Privilege $privilege, $user = null) diff --git a/src/Helpers/Assets.php b/src/Helpers/Assets.php index 03540af6..e85b4489 100644 --- a/src/Helpers/Assets.php +++ b/src/Helpers/Assets.php @@ -3,6 +3,12 @@ class Assets extends \Chibi\Util\Assets { private $pageThumbnail = null; private $subTitle = null; + private $engineVersion = null; + + public function __construct() + { + $this->engineVersion = PropertyModel::get(PropertyModel::EngineVersion); + } public function setSubTitle($text) { @@ -16,7 +22,7 @@ class Assets extends \Chibi\Util\Assets public function addStylesheet($path) { - return $this->addStylesheetFullPath($this->decorateUrl('/media/css/' . $path)); + return parent::addStylesheet('/media/css/' . $path . '?' . $this->engineVersion); } public function addStylesheetFullPath($path) @@ -26,7 +32,7 @@ class Assets extends \Chibi\Util\Assets public function addScript($path) { - return $this->addScriptFullPath($this->decorateUrl('/media/js/' . $path)); + return $this->addScriptFullPath('/media/js/' . $path . '?' . $this->engineVersion); } public function addScriptFullPath($path) @@ -57,10 +63,4 @@ class Assets extends \Chibi\Util\Assets $html = str_replace('', $bodySnippet . '', $html); return $html; } - - - private function decorateUrl($url) - { - return $url . '?' . PropertyModel::get(PropertyModel::EngineVersion); - } } diff --git a/src/Helpers/TextHelper.php b/src/Helpers/TextHelper.php index c3b123b9..54e10093 100644 --- a/src/Helpers/TextHelper.php +++ b/src/Helpers/TextHelper.php @@ -199,9 +199,19 @@ class TextHelper public static function reprTags($tags) { + if (empty($tags)) + return ''; $x = []; - foreach ($tags as $tag) - $x []= self::reprTag($tag); + if (is_object($tags[0])) + { + foreach ($tags as $tag) + $x []= '#' . $tag->getName(); + } + else + { + foreach ($tags as $tag) + $x []= '#' . $tag; + } natcasesort($x); return join(', ', $x); } diff --git a/src/Views/layout-normal.phtml b/src/Views/layout-normal.phtml index 8bd675fd..d5313398 100644 --- a/src/Views/layout-normal.phtml +++ b/src/Views/layout-normal.phtml @@ -11,9 +11,6 @@ if (!empty(Core::getConfig()->appearance->extraScripts)) if (!empty(Core::getConfig()->appearance->extraStylesheets)) foreach (Core::getConfig()->appearance->extraStylesheets as $path) $this->assets->addStylesheetFullPath($path); -$lastSearchQuery = isset($this->context->transport->lastSearchQuery) - ? $this->context->transport->lastSearchQuery - : ''; ?> @@ -29,6 +26,11 @@ $lastSearchQuery = isset($this->context->transport->lastSearchQuery) + context->transport->lastSearchQuery) + ? $this->context->transport->lastSearchQuery + : ''; + ?>
getTestFixtures($this->filter); - $success = $this->runAll($testFixtures); - exit($success ? 0 : 1); + return $this->runAll($testFixtures); } public function setFilter($filter) diff --git a/tests/SzurubooruTestRunner.php b/tests/SzurubooruTestRunner.php index b30457b7..98135390 100644 --- a/tests/SzurubooruTestRunner.php +++ b/tests/SzurubooruTestRunner.php @@ -1,4 +1,7 @@ run(); + $success = $testRunner->run(); + $this->removeCache(); + return $success; + } + + private function removeCache() + { + $cachePath = __DIR__ + . DIRECTORY_SEPARATOR . '..' + . DIRECTORY_SEPARATOR . 'lib' + . DIRECTORY_SEPARATOR . 'chibi-core' + . DIRECTORY_SEPARATOR . 'cache'; + + foreach (glob($cachePath . DIRECTORY_SEPARATOR . '*.dat') as $fn) + unlink($fn); } private function printHelp() @@ -157,7 +174,7 @@ class SzurubooruTestRunner implements ITestRunner private function prepareTestConfig($options) { $config = new \Chibi\Config(); - $config->loadIni(Core::getConfig()->rootDir . DS . 'tests' . DS . 'config.ini'); + $config->loadIni(Core::getConfig()->rootDir . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'config.ini'); $config->isForTests = true; $config->main->dbDriver = $options->dbDriver; @@ -180,6 +197,7 @@ class SzurubooruTestRunner implements ITestRunner $_SESSION = []; Auth::setCurrentUser(null); + $this->removeCache(); $this->removeTestFolders(); $this->prepareTestConfig($options); Core::prepareEnvironment(); diff --git a/tests/Tests/AbstractTest.php b/tests/Tests/AbstractTest.php index e2e65dbd..00f4a2e8 100644 --- a/tests/Tests/AbstractTest.php +++ b/tests/Tests/AbstractTest.php @@ -34,12 +34,12 @@ class AbstractTest protected function grantAccess($privilege) { Core::getConfig()->privileges->$privilege = 'anonymous'; - Access::init(); + Access::initWithoutCache(); } protected function revokeAccess($privilege) { Core::getConfig()->privileges->$privilege = 'nobody'; - Access::init(); + Access::initWithoutCache(); } } diff --git a/tests/Tests/MiscTests/AccessTest.php b/tests/Tests/MiscTests/AccessTest.php index e708353e..1a98efdc 100644 --- a/tests/Tests/MiscTests/AccessTest.php +++ b/tests/Tests/MiscTests/AccessTest.php @@ -29,7 +29,7 @@ class AccessTest extends AbstractTest public function testAccessRanks2() { Core::getConfig()->privileges->listPosts = 'power-user'; - Access::init(); + Access::initWithoutCache(); $user = $this->userMocker->mockSingle(); $user->setAccessRank(new AccessRank(AccessRank::Admin)); @@ -51,7 +51,7 @@ class AccessTest extends AbstractTest public function testSubPrivilegesOnlySub() { Core::getConfig()->privileges->{'listPosts.own'} = 'power-user'; - Access::init(); + Access::initWithoutCache(); $user = $this->userMocker->mockSingle(); $user->setAccessRank(new AccessRank(AccessRank::PowerUser)); @@ -64,7 +64,7 @@ class AccessTest extends AbstractTest { Core::getConfig()->privileges->{'listPosts.own'} = 'power-user'; Core::getConfig()->privileges->{'listPosts'} = 'admin'; - Access::init(); + Access::initWithoutCache(); $this->testSubPrivilegesSubAndGeneral(); } @@ -72,7 +72,7 @@ class AccessTest extends AbstractTest { Core::getConfig()->privileges->{'listPosts'} = 'admin'; Core::getConfig()->privileges->{'listPosts.own'} = 'power-user'; - Access::init(); + Access::initWithoutCache(); $this->testSubPrivilegesSubAndGeneral(); } @@ -95,7 +95,7 @@ class AccessTest extends AbstractTest Core::getConfig()->privileges->{'listPosts.own'} = 'power-user'; Core::getConfig()->privileges->{'listPosts.all'} = 'admin'; Core::getConfig()->privileges->{'listPosts'} = 'nobody'; - Access::init(); + Access::initWithoutCache(); $this->testSubPrivilegesMultipleSubAndGeneral(); } @@ -104,7 +104,7 @@ class AccessTest extends AbstractTest Core::getConfig()->privileges->{'listPosts'} = 'nobody'; Core::getConfig()->privileges->{'listPosts.own'} = 'power-user'; Core::getConfig()->privileges->{'listPosts.all'} = 'admin'; - Access::init(); + Access::initWithoutCache(); $this->testSubPrivilegesMultipleSubAndGeneral(); } diff --git a/tests/run-all.php b/tests/run-all.php index fdfdf9ff..0e0ce87c 100644 --- a/tests/run-all.php +++ b/tests/run-all.php @@ -1,6 +1,5 @@ run(); +$success = $runner->run(); +exit($success ? 0 : 1);