diff options
| author | Andrew Dolgov <fox@fakecake.org> | 2026-05-27 20:32:03 +0300 |
|---|---|---|
| committer | Andrew Dolgov <fox@fakecake.org> | 2026-05-27 20:32:03 +0300 |
| commit | bac87949cb64ce8fffb4cd2d4e7440e943c7b314 (patch) | |
| tree | 53d359c6549325741cb86cf4a74ad15f71ae2ffb /tests | |
| parent | c2ce4528c4b671466291f7947c682b4adffa007f (diff) | |
| download | the-epube-bac87949cb64ce8fffb4cd2d4e7440e943c7b314.tar.gz the-epube-bac87949cb64ce8fffb4cd2d4e7440e943c7b314.tar.xz | |
remove skipped tests, simplify config tests
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ConfigTest.php | 86 | ||||
| -rw-r--r-- | tests/SanitizerTest.php | 20 | ||||
| -rw-r--r-- | tests/bootstrap.php | 2 |
3 files changed, 41 insertions, 67 deletions
diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 1ff5625..74503bc 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -5,18 +5,14 @@ final class ConfigTest extends TestCase { protected function setUp(): void { - // Reset the Config singleton so environment variables are re-read - $ref = new ReflectionClass(Config::class); - $prop = $ref->getProperty('instance'); - $prop->setValue(null, null); + // Get a fresh instance and reload from env + Config::get_instance()->reload(); } protected function tearDown(): void { - // Clean up any environment variables we set - $ref = new ReflectionClass(Config::class); - $prop = $ref->getProperty('instance'); - $prop->setValue(null, null); + // Clean up any test-set config values + Config::get_instance()->reload(); } // ── Singleton behavior ─────────────────────────────────────────────────── @@ -40,11 +36,6 @@ final class ConfigTest extends TestCase $this->assertEquals(42, Config::cast_to('42', Config::T_INT)); } - public function test_cast_to_int_from_numeric_string(): void - { - $this->assertEquals(0, Config::cast_to('0', Config::T_INT)); - } - public function test_cast_to_int_from_float_string(): void { $this->assertEquals(3, Config::cast_to('3.14', Config::T_INT)); @@ -54,7 +45,6 @@ final class ConfigTest extends TestCase { $this->assertTrue(Config::cast_to('1', Config::T_BOOL)); $this->assertTrue(Config::cast_to('true', Config::T_BOOL)); - $this->assertTrue(Config::cast_to('yes', Config::T_BOOL)); } public function test_cast_to_bool_false(): void @@ -62,80 +52,92 @@ final class ConfigTest extends TestCase $this->assertFalse(Config::cast_to('0', Config::T_BOOL)); $this->assertFalse(Config::cast_to('', Config::T_BOOL)); $this->assertFalse(Config::cast_to('false', Config::T_BOOL)); - // "no" is treated as truthy by sql_bool_to_bool - $this->assertTrue(Config::cast_to('no', Config::T_BOOL)); } // ── get() with defaults ────────────────────────────────────────────────── public function test_get_db_type_default(): void { - putenv('EPUBE_DB_TYPE'); + Config::set(Config::DB_TYPE, 'sqlite'); $this->assertEquals('sqlite', Config::get(Config::DB_TYPE)); } public function test_get_db_host_default(): void { - putenv('EPUBE_DB_HOST'); + Config::set(Config::DB_HOST, 'db'); $this->assertEquals('db', Config::get(Config::DB_HOST)); } public function test_get_db_port_default(): void { - putenv('EPUBE_DB_PORT'); + Config::set(Config::DB_PORT, '5432'); $this->assertEquals('5432', Config::get(Config::DB_PORT)); } public function test_get_scratch_db_default(): void { - putenv('EPUBE_SCRATCH_DB'); + Config::set(Config::SCRATCH_DB, 'db/scratch.db'); $this->assertEquals('db/scratch.db', Config::get(Config::SCRATCH_DB)); } public function test_get_session_name_default(): void { - putenv('EPUBE_SESSION_NAME'); + Config::set(Config::SESSION_NAME, 'epube_sid'); $this->assertEquals('epube_sid', Config::get(Config::SESSION_NAME)); } - // ── Env var overrides ──────────────────────────────────────────────────── + // ── set() overrides ────────────────────────────────────────────────────── - public function test_env_override_db_type(): void + public function test_set_db_type(): void { - putenv('EPUBE_DB_TYPE=pgsql'); + Config::set(Config::DB_TYPE, 'pgsql'); $this->assertEquals('pgsql', Config::get(Config::DB_TYPE)); } - public function test_env_override_db_host(): void + public function test_set_db_host(): void { - putenv('EPUBE_DB_HOST=myhost'); + Config::set(Config::DB_HOST, 'myhost'); $this->assertEquals('myhost', Config::get(Config::DB_HOST)); } - public function test_env_override_db_port(): void + public function test_set_db_port(): void { - putenv('EPUBE_DB_PORT=55432'); + Config::set(Config::DB_PORT, '55432'); $this->assertEquals('55432', Config::get(Config::DB_PORT)); } - public function test_env_override_session_name(): void + public function test_set_session_name(): void { - putenv('EPUBE_SESSION_NAME=custom_sid'); + Config::set(Config::SESSION_NAME, 'custom_sid'); $this->assertEquals('custom_sid', Config::get(Config::SESSION_NAME)); } - // ── Config::add() ──────────────────────────────────────────────────────── + public function test_set_session_lifetime(): void + { + Config::set(Config::SESSION_LIFETIME, 3600); + $this->assertEquals(3600, Config::get(Config::SESSION_LIFETIME)); + } + + // ── set() returns bool ─────────────────────────────────────────────────── - public function test_add_custom_config(): void + public function test_set_returns_true_for_known_key(): void { - Config::add('CUSTOM_KEY', 'custom_value', Config::T_STRING); - $this->assertEquals('custom_value', Config::get('CUSTOM_KEY')); + $this->assertTrue(Config::set(Config::DB_TYPE, 'pgsql')); } - public function test_add_custom_config_int(): void + public function test_set_returns_false_for_unknown_key(): void { - Config::add('CUSTOM_INT', '42', Config::T_INT); - $this->assertEquals(42, Config::get('CUSTOM_INT')); + $this->assertFalse(@Config::set('NONEXISTENT_KEY', 'value')); + } + + // ── reload() resets to env ─────────────────────────────────────────────── + + public function test_reload_resets_to_env(): void + { + Config::set(Config::DB_TYPE, 'pgsql'); + putenv('EPUBE_DB_TYPE=sqlite'); + Config::get_instance()->reload(); + $this->assertEquals('sqlite', Config::get(Config::DB_TYPE)); } // ── get_self_url() ─────────────────────────────────────────────────────── @@ -144,7 +146,6 @@ final class ConfigTest extends TestCase { $_SERVER['HTTP_HOST'] = 'example.com'; $_SERVER['REQUEST_URI'] = '/backend.php?op=list'; - // get_self_url strips the .php filename, leaving just the base path $url = Config::get_self_url(); $this->assertStringContainsString('http://', $url); $this->assertEquals('http://example.com', $url); @@ -178,15 +179,6 @@ final class ConfigTest extends TestCase $this->assertStringNotContainsString('///', $url); } - // ── sanity_check() ─────────────────────────────────────────────────────── - - public function test_sanity_check_cli_as_root_fails(): void - { - $this->expectException(Exception::class); - // Mock posix_getuid to return 0 (root) - $this->markTestSkipped('Cannot easily mock posix_getuid in PHP'); - } - // ── get_version() ──────────────────────────────────────────────────────── public function test_get_version_returns_string(): void diff --git a/tests/SanitizerTest.php b/tests/SanitizerTest.php index ea7441c..2560970 100644 --- a/tests/SanitizerTest.php +++ b/tests/SanitizerTest.php @@ -151,13 +151,6 @@ final class SanitizerTest extends TestCase { $this->assertStringNotContainsString('src="relative.png"', $result); } - public function test_sanitize_sanitizes_source_src(): void { - // source is an allowed tag with src attribute, src gets sanitized - // DOMDocument::loadHTML() is very picky about <source> - it requires <video> parent - // which itself is not recognized. Skip this test in offline mode. - $this->markTestSkipped('DOMDocument does not support <source> tag in isolation'); - } - public function test_sanitize_allows_allowed_tags(): void { // Note: not all HTML5 tags are valid in plain HTML context // DOMDocument::loadHTML() does not recognize some HTML5 tags (footer, header, nav, section, @@ -428,10 +421,6 @@ final class SanitizerTest extends TestCase { $this->assertFalse($result); } - public function test_validate_idn_to_ascii(): void { - $this->markTestSkipped('idn_to_ascii() not available in this environment'); - } - public function test_validate_url_with_encoded_path(): void { $result = Sanitizer::validate('http://example.com/path%20with%20spaces'); $this->assertNotFalse($result); @@ -488,13 +477,4 @@ final class SanitizerTest extends TestCase { $result = Sanitizer::build_url($parts); $this->assertEquals('http://example.com', $result); } - - public function test_resolve_redirects_no_redirect(): void { - $this->markTestSkipped('Network access not available in test environment'); - } - - public function test_resolve_redirects_too_many_redirects(): void { - $this->markTestSkipped('Network access not available in test environment'); - } - } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index ba1d61c..8cae8e1 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,4 +2,6 @@ set_include_path(dirname(__DIR__) ."/include" . PATH_SEPARATOR . get_include_path()); + putenv("IS_TESTING=true"); + require_once "common.php"; |
