Improved test environment sandboxing
This commit is contained in:
parent
2f54ee75b7
commit
04481122ce
6 changed files with 172 additions and 39 deletions
|
@ -1,6 +1,3 @@
|
|||
[chibi]
|
||||
enableCache=1
|
||||
|
||||
[main]
|
||||
dbDriver = "sqlite"
|
||||
dbLocation = "./data/db.sqlite"
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit cf0b4bd2253d0d3240a87ce31f77ee587b306638
|
||||
Subproject commit a7e3dddbaeb6ba5b711ae3c916307a0896aee758
|
33
src/core.php
33
src/core.php
|
@ -31,30 +31,40 @@ function getContext()
|
|||
return $context;
|
||||
}
|
||||
|
||||
function resetEnvironment()
|
||||
function prepareConfig($testEnvironment)
|
||||
{
|
||||
//load config manually
|
||||
global $config;
|
||||
global $rootDir;
|
||||
global $startTime;
|
||||
|
||||
$configPaths =
|
||||
[
|
||||
$rootDir . DS . 'data' . DS . 'config.ini',
|
||||
$rootDir . DS . 'data' . DS . 'local.ini',
|
||||
$rootDir . DS . 'tests' . DS . 'test.ini',
|
||||
];
|
||||
$configPaths = [];
|
||||
if (!$testEnvironment)
|
||||
{
|
||||
$configPaths []= $rootDir . DS . 'data' . DS . 'config.ini';
|
||||
$configPaths []= $rootDir . DS . 'data' . DS . 'local.ini';
|
||||
}
|
||||
else
|
||||
{
|
||||
$configPaths []= $rootDir . DS . 'tests' . DS . 'config.ini';
|
||||
}
|
||||
|
||||
$config = new \Chibi\Config();
|
||||
foreach ($configPaths as $path)
|
||||
if (file_exists($path))
|
||||
$config->loadIni($path);
|
||||
$config->rootDir = $rootDir;
|
||||
}
|
||||
|
||||
function prepareEnvironment($testEnvironment)
|
||||
{
|
||||
//prepare context
|
||||
global $context;
|
||||
global $startTime;
|
||||
$context = new StdClass;
|
||||
$context->startTime = $startTime;
|
||||
|
||||
$config = getConfig();
|
||||
|
||||
//extension sanity checks
|
||||
$requiredExtensions = ['pdo', 'pdo_' . $config->main->dbDriver, 'gd', 'openssl', 'fileinfo'];
|
||||
foreach ($requiredExtensions as $ext)
|
||||
|
@ -71,8 +81,9 @@ function resetEnvironment()
|
|||
\Chibi\Database::connect(
|
||||
$config->main->dbDriver,
|
||||
TextHelper::absolutePath($config->main->dbLocation),
|
||||
$config->main->dbUser,
|
||||
$config->main->dbPass);
|
||||
isset($config->main->dbUser) ? $config->main->dbUser : null,
|
||||
isset($config->main->dbPass) ? $config->main->dbPass : null);
|
||||
}
|
||||
|
||||
resetEnvironment();
|
||||
prepareConfig(false);
|
||||
prepareEnvironment(false);
|
||||
|
|
3
tests/.gitignore
vendored
3
tests/.gitignore
vendored
|
@ -1 +1,4 @@
|
|||
db.sqlite
|
||||
files
|
||||
thumbs
|
||||
logs
|
||||
|
|
130
tests/config.ini
Normal file
130
tests/config.ini
Normal file
|
@ -0,0 +1,130 @@
|
|||
[main]
|
||||
filesPath = "./tests/files/"
|
||||
thumbsPath = "./tests/thumbs/"
|
||||
logsPath = "./tests/logs/{yyyy-mm}.log"
|
||||
mediaPath = "./public_html/media/"
|
||||
title = "szurubooru/tests"
|
||||
salt = "salt..."
|
||||
|
||||
[misc]
|
||||
featuredPostMaxDays=7
|
||||
debugQueries=0
|
||||
logAnonymousUploads=1
|
||||
|
||||
[help]
|
||||
title=Help
|
||||
subTitles[help]=General help
|
||||
subTitles[rules]=Rules
|
||||
subTitles[privacy]=Privacy policy
|
||||
paths[help]=./data/help.md
|
||||
paths[rules]=./data/rules.md
|
||||
paths[privacy]=./data/privacy.md
|
||||
|
||||
[browsing]
|
||||
usersPerPage=8
|
||||
postsPerPage=20
|
||||
logsPerPage=250
|
||||
tagsPerPage=100
|
||||
tagsRelated=15
|
||||
thumbWidth=150
|
||||
thumbHeight=150
|
||||
thumbStyle=outside
|
||||
endlessScrollingDefault=1
|
||||
showPostTagTitlesDefault=0
|
||||
showDislikedPostsDefault=1
|
||||
maxSearchTokens=4
|
||||
maxRelatedPosts=50
|
||||
|
||||
[posts]
|
||||
maxSourceLength = 200
|
||||
|
||||
[comments]
|
||||
minLength = 5
|
||||
maxLength = 2000
|
||||
commentsPerPage = 10
|
||||
maxCommentsInList = 5
|
||||
|
||||
[registration]
|
||||
staffActivation = 0
|
||||
passMinLength = 5
|
||||
passRegex = "/^.+$/"
|
||||
userNameMinLength = 3
|
||||
userNameMaxLength = 20
|
||||
userNameRegex = "/^[\w_-]+$/ui"
|
||||
|
||||
needEmailForRegistering = 0
|
||||
needEmailForCommenting = 0
|
||||
needEmailForUploading = 0
|
||||
confirmationEmailEnabled = 1
|
||||
confirmationEmailSenderName = "{host} mailing system"
|
||||
confirmationEmailSenderEmail = "noreply@{host}"
|
||||
confirmationEmailSubject = "{host} - account activation"
|
||||
confirmationEmailBody = "Hello,{nl}{nl}You received this e-mail because someone registered a user with this e-mail address at {host}. If it's you, visit {link} to finish registration process, otherwise you may ignore and delete this e-mail.{nl}{nl}Kind regards,{nl}{host} mailing system"
|
||||
passwordResetEmailSenderName = "{host} mailing system"
|
||||
passwordResetEmailSenderEmail = "noreply@{host}"
|
||||
passwordResetEmailSubject = "{host} - password reset"
|
||||
passwordResetEmailBody = "Hello,{nl}{nl}You received this e-mail because someone requested a password reset for user with this e-mail address at {host}. If it's you, visit {link} to finish password reset process, otherwise you may ignore and delete this e-mail.{nl}{nl}Kind regards,{nl}{host} mailing system"
|
||||
|
||||
[privileges]
|
||||
registerAccount=anonymous
|
||||
;registerAccount=nobody
|
||||
|
||||
uploadPost=registered
|
||||
listPosts=anonymous
|
||||
listPosts.sketchy=registered
|
||||
listPosts.unsafe=registered
|
||||
listPosts.hidden=moderator
|
||||
viewPost=anonymous
|
||||
viewPost.sketchy=registered
|
||||
viewPost.unsafe=registered
|
||||
viewPost.hidden=moderator
|
||||
retrievePost=anonymous
|
||||
favoritePost=registered
|
||||
editPostSafety.own=registered
|
||||
editPostSafety.all=moderator
|
||||
editPostTags=registered
|
||||
editPostThumb=moderator
|
||||
editPostSource=moderator
|
||||
editPostRelations.own=registered
|
||||
editPostRelations.all=moderator
|
||||
editPostFile=moderator
|
||||
massTag.own=registered
|
||||
massTag.all=power-user
|
||||
hidePost=moderator
|
||||
deletePost=moderator
|
||||
featurePost=moderator
|
||||
scorePost=registered
|
||||
flagPost=registered
|
||||
|
||||
listUsers=registered
|
||||
viewUser=registered
|
||||
viewUserEmail.all=admin
|
||||
viewUserEmail.own=registered
|
||||
changeUserPassword.own=registered
|
||||
changeUserPassword.all=admin
|
||||
changeUserEmail.own=registered
|
||||
changeUserEmail.all=admin
|
||||
changeUserAccessRank=admin
|
||||
changeUserName=moderator
|
||||
changeUserSettings.all=nobody
|
||||
changeUserSettings.own=registered
|
||||
acceptUserRegistration=moderator
|
||||
banUser.own=nobody
|
||||
banUser.all=admin
|
||||
deleteUser.own=registered
|
||||
deleteUser.all=nobody
|
||||
flagUser=registered
|
||||
|
||||
listComments=anonymous
|
||||
addComment=registered
|
||||
deleteComment.own=registered
|
||||
deleteComment.all=moderator
|
||||
editComment.own=registered
|
||||
editComment.all=admin
|
||||
|
||||
listTags=anonymous
|
||||
mergeTags=moderator
|
||||
renameTags=moderator
|
||||
|
||||
listLogs=moderator
|
||||
viewLog=moderator
|
|
@ -3,8 +3,6 @@ require_once __DIR__ . '/../src/core.php';
|
|||
require_once __DIR__ . '/../src/upgrade.php';
|
||||
\Chibi\Autoloader::registerFileSystem(__DIR__);
|
||||
|
||||
$configPath = __DIR__ . '/test.ini';
|
||||
|
||||
$options = getopt('cf:', ['clean', 'filter:']);
|
||||
|
||||
$cleanDatabase = (isset($options['c']) or isset($options['clean']));
|
||||
|
@ -16,36 +14,29 @@ elseif (isset($options['filter']))
|
|||
else
|
||||
$filter = null;
|
||||
|
||||
try
|
||||
{
|
||||
$dbPath = __DIR__ . '/db.sqlite';
|
||||
$dbPath = __DIR__ . '/db.sqlite';
|
||||
|
||||
if (file_exists($dbPath) and $cleanDatabase)
|
||||
if (file_exists($dbPath) and $cleanDatabase)
|
||||
unlink($dbPath);
|
||||
|
||||
$configIni =
|
||||
[
|
||||
'[main]',
|
||||
'dbDriver = "sqlite"',
|
||||
'dbLocation = "' . $dbPath . '"',
|
||||
'filesPath = "' . __DIR__ . 'files',
|
||||
'thumbsPath = "' . __DIR__ . 'thumbs',
|
||||
'logsPath = "/dev/null"',
|
||||
'[registration]',
|
||||
'needEmailForRegistering = 0',
|
||||
'needEmailForCommenting = 0',
|
||||
'needEmailForUploading = 0'
|
||||
];
|
||||
|
||||
file_put_contents($configPath, implode(PHP_EOL, $configIni));
|
||||
|
||||
try
|
||||
{
|
||||
resetEnvironment();
|
||||
upgradeDatabase();
|
||||
|
||||
runAll($filter);
|
||||
}
|
||||
finally
|
||||
{
|
||||
unlink($configPath);
|
||||
}
|
||||
|
||||
function resetEnvironment()
|
||||
{
|
||||
global $dbPath;
|
||||
prepareConfig(true);
|
||||
getConfig()->main->dbDriver = 'sqlite';
|
||||
getConfig()->main->dbLocation = $dbPath;
|
||||
prepareEnvironment(true);
|
||||
}
|
||||
|
||||
function getTestMethods($filter)
|
||||
|
@ -151,6 +142,7 @@ function runAll($filter)
|
|||
function runSingle($callback)
|
||||
{
|
||||
resetEnvironment();
|
||||
resetEnvironment(true);
|
||||
\Chibi\Database::rollback(function() use ($callback)
|
||||
{
|
||||
$callback();
|
||||
|
|
Loading…
Reference in a new issue