chore: initial snapshot of 2meet-data-optimizer v0.1.0

Baseline before backporting wp-data-optimizer v3.0.1-v3.4.6.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TbG1keQQ7XBa7qMQY16KCY
This commit is contained in:
2026-07-31 05:06:36 +08:00
commit d36bb954d1
206 changed files with 66538 additions and 0 deletions
+80
View File
@@ -0,0 +1,80 @@
<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
/**
* Unit tests for the shadow_read_only sub-flag added by PR-4.
*
* Orthogonal to the main 7-state FSM. Only takes effect when a module is in
* the `verify` state.
*
* @covers WPDO_Feature_Flags::enable_shadow_read
* @covers WPDO_Feature_Flags::disable_shadow_read
* @covers WPDO_Feature_Flags::is_shadow_read_active
* @covers WPDO_Feature_Flags::all_shadow
*/
class ShadowReadFlagTest extends TestCase {
protected function setUp(): void {
$GLOBALS['_wp_options'] = array();
// Reset both caches via reflection.
$ref = new ReflectionClass( WPDO_Feature_Flags::class );
foreach ( array( 'cache', 'shadow_cache' ) as $prop ) {
$p = $ref->getProperty( $prop );
$p->setAccessible( true );
$p->setValue( null, null );
}
}
public function test_default_is_inactive(): void {
$this->assertFalse( WPDO_Feature_Flags::is_shadow_read_active( 'hot_hp_listing' ) );
}
public function test_enable_then_active_only_in_verify_state(): void {
WPDO_Feature_Flags::enable_shadow_read( 'hot_hp_listing' );
// idle → not active even though flag is on.
$this->assertFalse( WPDO_Feature_Flags::is_shadow_read_active( 'hot_hp_listing' ) );
// dual_write → still not active.
WPDO_Feature_Flags::set( 'hot_hp_listing', 'dual_write' );
$this->assertFalse( WPDO_Feature_Flags::is_shadow_read_active( 'hot_hp_listing' ) );
// verify → active.
WPDO_Feature_Flags::set( 'hot_hp_listing', 'verify' );
$this->assertTrue( WPDO_Feature_Flags::is_shadow_read_active( 'hot_hp_listing' ) );
// cutover → no longer active (verify-only sub-flag).
WPDO_Feature_Flags::set( 'hot_hp_listing', 'cutover' );
$this->assertFalse( WPDO_Feature_Flags::is_shadow_read_active( 'hot_hp_listing' ) );
}
public function test_disable_clears_active(): void {
WPDO_Feature_Flags::enable_shadow_read( 'hot_hp_vendor' );
WPDO_Feature_Flags::set( 'hot_hp_vendor', 'verify' );
$this->assertTrue( WPDO_Feature_Flags::is_shadow_read_active( 'hot_hp_vendor' ) );
WPDO_Feature_Flags::disable_shadow_read( 'hot_hp_vendor' );
$this->assertFalse( WPDO_Feature_Flags::is_shadow_read_active( 'hot_hp_vendor' ) );
}
public function test_all_shadow_returns_only_enabled_modules(): void {
WPDO_Feature_Flags::enable_shadow_read( 'mod_a' );
WPDO_Feature_Flags::enable_shadow_read( 'mod_b' );
WPDO_Feature_Flags::disable_shadow_read( 'mod_b' );
$flags = WPDO_Feature_Flags::all_shadow();
$this->assertArrayHasKey( 'mod_a', $flags );
$this->assertArrayNotHasKey( 'mod_b', $flags );
}
public function test_shadow_flag_independent_per_module(): void {
WPDO_Feature_Flags::enable_shadow_read( 'hot_hp_listing' );
WPDO_Feature_Flags::set( 'hot_hp_listing', 'verify' );
WPDO_Feature_Flags::set( 'hot_hp_vendor', 'verify' );
$this->assertTrue( WPDO_Feature_Flags::is_shadow_read_active( 'hot_hp_listing' ) );
$this->assertFalse( WPDO_Feature_Flags::is_shadow_read_active( 'hot_hp_vendor' ) );
}
}