From 1564098591d01d948580f6ee3f931421e3bdd259 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 10 Feb 2025 13:50:43 +0000 Subject: [PATCH] do a global config rollback at the end of every test --- core/testcase.php | 8 ++++++-- ext/approval/test.php | 7 ------- ext/comment/test.php | 7 ------- ext/downtime/test.php | 7 ------- ext/rating/test.php | 4 +--- ext/ratings_blur/test.php | 3 +-- ext/res_limit/test.php | 14 -------------- 7 files changed, 8 insertions(+), 42 deletions(-) diff --git a/core/testcase.php b/core/testcase.php index d3c2f35f6..62cc203f9 100644 --- a/core/testcase.php +++ b/core/testcase.php @@ -24,6 +24,8 @@ abstract class ShimmiePHPUnitTestCase extends TestBase protected static string $admin_name = "demo"; protected static string $user_name = "test"; protected string $wipe_time = "test"; + /** @var array */ + private array $config_snapshot = []; /** * Start a DB transaction for each test class @@ -41,7 +43,7 @@ public static function setUpBeforeClass(): void */ public function setUp(): void { - global $database, $_tracer, $page; + global $database, $_tracer, $page, $config; $_tracer->begin($this->name()); $_tracer->begin("setUp"); $class = str_replace("Test", "", get_class($this)); @@ -60,6 +62,7 @@ public function setUp(): void send_event(new ImageDeletionEvent(Image::by_id_ex((int)$image_id), true)); } $page = new Page(); + $this->config_snapshot = $config->values; $_tracer->end(); # setUp $_tracer->begin("test"); @@ -67,8 +70,9 @@ public function setUp(): void public function tearDown(): void { - global $_tracer, $database; + global $_tracer, $config, $database; $database->execute("ROLLBACK TO test_start"); + $config->values = $this->config_snapshot; $_tracer->end(); # test $_tracer->end(); # $this->getName() } diff --git a/ext/approval/test.php b/ext/approval/test.php index 348d295d3..ee813e51b 100644 --- a/ext/approval/test.php +++ b/ext/approval/test.php @@ -33,11 +33,4 @@ public function testApprovalNeeded(): void $this->log_in_as_user(); $this->assert_search_results(["some_tag"], [$image_id]); } - - public function tearDown(): void - { - global $config; - $config->set_bool(ApprovalConfig::IMAGES, false); - parent::tearDown(); - } } diff --git a/ext/comment/test.php b/ext/comment/test.php index 5d30675b9..aa35f3508 100644 --- a/ext/comment/test.php +++ b/ext/comment/test.php @@ -14,13 +14,6 @@ public function setUp(): void $this->log_out(); } - public function tearDown(): void - { - global $config; - $config->set_int(CommentConfig::LIMIT, 10); - parent::tearDown(); - } - public function testCommentsPage(): void { global $user; diff --git a/ext/downtime/test.php b/ext/downtime/test.php index 77dfa2610..40eeb1ec9 100644 --- a/ext/downtime/test.php +++ b/ext/downtime/test.php @@ -6,13 +6,6 @@ class DowntimeTest extends ShimmiePHPUnitTestCase { - public function tearDown(): void - { - global $config; - $config->set_bool("downtime", false); - parent::tearDown(); - } - public function testDowntime(): void { global $config; diff --git a/ext/rating/test.php b/ext/rating/test.php index c25bad5d0..0f5e24ea4 100644 --- a/ext/rating/test.php +++ b/ext/rating/test.php @@ -107,9 +107,7 @@ public function testCountImages(): void // that it doesn't mess with other unrelated tests public function tearDown(): void { - global $config, $user_config; - $config->set_array("ext_rating_user_privs", ["?", "s", "q", "e"]); - $config->set_array("ext_rating_anonymous_privs", ["?", "s", "q", "e"]); + global $user_config; $this->log_in_as_user(); $user_config->set_array(RatingsConfig::USER_DEFAULTS, ["?", "s", "q", "e"]); diff --git a/ext/ratings_blur/test.php b/ext/ratings_blur/test.php index 46db667dc..801502551 100644 --- a/ext/ratings_blur/test.php +++ b/ext/ratings_blur/test.php @@ -122,8 +122,7 @@ private function delete_test_user(string $username): void // that it doesn't mess with other unrelated tests public function tearDown(): void { - global $config, $user_config; - $config->set_array(RatingsBlurConfig::GLOBAL_DEFAULTS, RatingsBlurConfig::DEFAULT_OPTIONS); + global $user_config; $this->log_in_as_user(); $user_config->set_array(RatingsBlurConfig::USER_DEFAULTS, RatingsBlurConfig::DEFAULT_OPTIONS); diff --git a/ext/res_limit/test.php b/ext/res_limit/test.php index d87d3de0c..0251671c5 100644 --- a/ext/res_limit/test.php +++ b/ext/res_limit/test.php @@ -66,18 +66,4 @@ public function testResLimitRatio(): void }); $this->assertEquals("Post needs to be in one of these ratios: 16:9", $e->getMessage()); } - - # reset to defaults, otherwise this can interfere with - # other extensions' test suites - public function tearDown(): void - { - global $config; - $config->delete("upload_min_height"); - $config->delete("upload_min_width"); - $config->delete("upload_max_height"); - $config->delete("upload_max_width"); - $config->delete("upload_ratios"); - - parent::tearDown(); - } }