fix(2meet-data-optimizer): default misc bucket and garbage filter to off

- Both term/comment filters now default to disabled for new installs, so
  activating the plugin no longer reroutes or drops other plugins' meta
- One-time maybe_upgrade() migration keeps the misc bucket on for sites
  that already hold misc rows and never set the toggle (data stays readable)
- Admin toggles show the same defaults as the filters

Verify: phpunit-integration --filter 'defaults_false|preserve_default';
  unit 600 OK, integration 420 OK
PR: PR-006
This commit is contained in:
2026-09-25 21:39:38 +08:00
parent d3b72bd1af
commit 151aadd661
6 changed files with 89 additions and 9 deletions
@@ -189,11 +189,59 @@ class TermCommentMiscBucketTest extends TestCase {
// ── is_enabled toggle ───────────────────────────────────────────────────
public function test_is_enabled_defaults_true(): void {
public function test_is_enabled_defaults_false(): void {
delete_option( WPDO_Term_Comment_Misc_Bucket::OPT_ENABLED );
$this->assertFalse( WPDO_Term_Comment_Misc_Bucket::is_enabled() );
}
// ── one-time default migration for sites that already use the bucket ─────
public function test_preserve_default_keeps_bucket_on_when_misc_has_rows(): void {
$this->reset_preserve_state();
WPDO_Term_Comment_Misc_Bucket::on_term_update( null, 1, 'a', 'x', '' );
TMDO_Installer::maybe_preserve_misc_bucket_default();
$this->assertSame( '1', get_option( WPDO_Term_Comment_Misc_Bucket::OPT_ENABLED ) );
$this->assertTrue( WPDO_Term_Comment_Misc_Bucket::is_enabled() );
}
public function test_preserve_default_leaves_bucket_off_when_misc_empty(): void {
$this->reset_preserve_state();
TMDO_Installer::maybe_preserve_misc_bucket_default();
$this->assertFalse( get_option( WPDO_Term_Comment_Misc_Bucket::OPT_ENABLED ) );
$this->assertFalse( WPDO_Term_Comment_Misc_Bucket::is_enabled() );
$this->assertNotEmpty( get_option( TMDO_Installer::MISC_BUCKET_DEFAULT_FLAG ) );
}
public function test_preserve_default_respects_explicit_off(): void {
$this->reset_preserve_state();
update_option( WPDO_Term_Comment_Misc_Bucket::OPT_ENABLED, '0' );
WPDO_Term_Comment_Misc_Bucket::on_term_update( null, 1, 'a', 'x', '' );
TMDO_Installer::maybe_preserve_misc_bucket_default();
$this->assertSame( '0', get_option( WPDO_Term_Comment_Misc_Bucket::OPT_ENABLED ) );
delete_option( WPDO_Term_Comment_Misc_Bucket::OPT_ENABLED );
}
public function test_preserve_default_runs_only_once(): void {
$this->reset_preserve_state();
TMDO_Installer::maybe_preserve_misc_bucket_default(); // Empty tables: stays off, flag set.
WPDO_Term_Comment_Misc_Bucket::on_term_update( null, 1, 'a', 'x', '' );
TMDO_Installer::maybe_preserve_misc_bucket_default();
$this->assertFalse( get_option( WPDO_Term_Comment_Misc_Bucket::OPT_ENABLED ) );
}
private function reset_preserve_state(): void {
delete_option( WPDO_Term_Comment_Misc_Bucket::OPT_ENABLED );
delete_option( TMDO_Installer::MISC_BUCKET_DEFAULT_FLAG );
}
public function test_is_enabled_respects_zero_value(): void {
update_option( WPDO_Term_Comment_Misc_Bucket::OPT_ENABLED, '0' );
$this->assertFalse( WPDO_Term_Comment_Misc_Bucket::is_enabled() );