2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
2024-01-15 23:04:19 +00:00
|
|
|
/**
|
|
|
|
* Sets up a base test environment:
|
|
|
|
* - Loads the code
|
|
|
|
* - Runs the installer
|
|
|
|
* - Runs the database upgrade
|
|
|
|
* - Creates test users
|
|
|
|
* - Commits the database transaction
|
|
|
|
*/
|
2021-12-14 18:32:47 +00:00
|
|
|
declare(strict_types=1);
|
2020-03-13 09:23:54 +00:00
|
|
|
|
2023-01-10 22:44:09 +00:00
|
|
|
namespace Shimmie2;
|
|
|
|
|
2020-01-27 19:28:58 +00:00
|
|
|
chdir(dirname(dirname(__FILE__)));
|
2020-06-24 13:53:36 +00:00
|
|
|
require_once "core/sanitize_php.php";
|
2020-01-27 19:28:58 +00:00
|
|
|
require_once "vendor/autoload.php";
|
|
|
|
require_once "tests/defines.php";
|
|
|
|
require_once "core/sys_config.php";
|
|
|
|
require_once "core/polyfills.php";
|
|
|
|
require_once "core/util.php";
|
2015-08-09 11:14:28 +00:00
|
|
|
|
2024-02-07 22:47:12 +00:00
|
|
|
$_SERVER['SCRIPT_FILENAME'] = '/var/www/html/test/index.php';
|
|
|
|
$_SERVER['DOCUMENT_ROOT'] = '/var/www/html';
|
2015-08-09 11:14:28 +00:00
|
|
|
$_SERVER['QUERY_STRING'] = '/';
|
2024-02-07 22:47:12 +00:00
|
|
|
|
2023-12-31 18:41:08 +00:00
|
|
|
if (file_exists("data/test-trace.json")) {
|
|
|
|
unlink("data/test-trace.json");
|
2020-01-29 00:49:21 +00:00
|
|
|
}
|
2015-08-09 11:14:28 +00:00
|
|
|
|
2020-01-27 19:28:58 +00:00
|
|
|
global $cache, $config, $database, $user, $page, $_tracer;
|
2020-06-24 13:53:36 +00:00
|
|
|
_set_up_shimmie_environment();
|
2020-01-28 23:57:43 +00:00
|
|
|
$tracer_enabled = true;
|
2023-01-10 22:44:09 +00:00
|
|
|
$_tracer = new \EventTracer();
|
2020-01-28 23:57:43 +00:00
|
|
|
$_tracer->begin("bootstrap");
|
2020-01-27 19:28:58 +00:00
|
|
|
_load_core_files();
|
2023-02-02 16:04:35 +00:00
|
|
|
$cache = loadCache(CACHE_DSN);
|
2023-12-16 00:37:40 +00:00
|
|
|
$database = new Database(getenv("TEST_DSN") ?: "sqlite::memory:");
|
2020-01-27 19:28:58 +00:00
|
|
|
create_dirs();
|
|
|
|
create_tables($database);
|
|
|
|
$config = new DatabaseConfig($database);
|
2023-12-16 00:37:40 +00:00
|
|
|
_load_extension_files();
|
2020-01-27 19:28:58 +00:00
|
|
|
_load_theme_files();
|
|
|
|
$page = new Page();
|
|
|
|
_load_event_listeners();
|
2023-12-16 00:37:40 +00:00
|
|
|
$config->set_string("thumb_engine", "static");
|
2020-02-09 16:26:57 +00:00
|
|
|
$config->set_bool("nice_urls", true);
|
2020-01-27 19:52:54 +00:00
|
|
|
send_event(new DatabaseUpgradeEvent());
|
2020-01-27 19:05:43 +00:00
|
|
|
send_event(new InitExtEvent());
|
2023-02-24 21:08:05 +00:00
|
|
|
$user = User::by_id($config->get_int("anon_id", 0));
|
2024-01-15 22:50:43 +00:00
|
|
|
$userPage = new UserPage();
|
|
|
|
$userPage->onUserCreation(new UserCreationEvent("demo", "demo", "demo", "demo@demo.com", false));
|
|
|
|
$userPage->onUserCreation(new UserCreationEvent("test", "test", "test", "test@test.com", false));
|
2024-01-15 22:59:45 +00:00
|
|
|
// in mysql, CREATE TABLE commits transactions, so after the database
|
|
|
|
// upgrade we may or may not be inside a transaction depending on if
|
|
|
|
// any tables were created.
|
2024-08-31 16:05:18 +00:00
|
|
|
if ($database->is_transaction_open()) {
|
2024-01-15 22:59:45 +00:00
|
|
|
$database->commit();
|
|
|
|
}
|
2020-01-28 23:57:43 +00:00
|
|
|
$_tracer->end();
|