Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
* connect to a database, so anything reachable from here is reachable without a
* running forum.
*
* Code that needs Config::$modSettings, User::$me or Db::$db is out of scope for
* this suite and belongs in an integration suite running against a real install.
* Code that needs User::$me or Db::$db is out of scope for this suite and belongs
* in an integration suite running against a real install.
*/

const TESTS_BOARDDIR = __DIR__ . '/..';
Expand Down Expand Up @@ -67,7 +67,7 @@
/*
* Paths and the default language, which the Unicode and entity helpers need in
* order to locate their data files. These are the only pieces of Config the suite
* sets: no modSettings, no database credentials, nothing read from Settings.php.
* sets: no database credentials and nothing read from Settings.php.
* A test that needs more than this is an integration test.
*/
SMF\Config::$boarddir = (string) realpath(TESTS_BOARDDIR);
Expand All @@ -78,3 +78,31 @@
SMF\Config::$language = 'en_US';
SMF\Config::$boardurl = 'test.local';
SMF\Config::$scripturl = 'test.local/index.php';

// Populate SMF\Config::$modSettings with default values.
SMF\Lang::load('General+Maintenance', SMF\Config::$language);

$replacements = [
'{$db_prefix}' => 'smf_',
'{$attachdir}' => json_encode([1 => addslashes(SMF\Config::$boarddir . '/attachments')]),
'{$boarddir}' => addslashes(SMF\Config::$boarddir),
'{$boardurl}' => SMF\Config::$boardurl,
'{$enableCompressedOutput}' => 0,
'{$databaseSession_enable}' => 0,
'{$smf_version}' => SMF_VERSION,
'{$current_time}' => time(),
'{$sched_task_offset}' => 82800 + mt_rand(0, 86399),
'{$registration_method}' => 0,
];

foreach (SMF\Lang::$txt as $key => $value) {
if (substr($key, 0, 8) == 'default_') {
$replacements['{$' . $key . '}'] = addslashes($value);
}
}

$replacements['{$default_reserved_names}'] = strtr($replacements['{$default_reserved_names}'], ['\\\\n' => "\n", '\\n' => "\n"]);

foreach ((new \ReflectionClass(SMF\Db\Schema\v3_0\Settings::class))->getDefaultProperties()['initial_data'] as $setting) {
SMF\Config::$modSettings[$setting['variable']] = is_numeric($setting['value']) ? $setting['value'] + 0 : strtr($setting['value'], $replacements);
}
Loading