d36bb954d1
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
113 lines
4.9 KiB
PHP
113 lines
4.9 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* Tests for WPDO_Feature_Flags — 7-state lifecycle state machine.
|
|
*/
|
|
class FeatureFlagsTest extends TestCase {
|
|
|
|
protected function setUp(): void {
|
|
$GLOBALS['_wp_options'] = [];
|
|
}
|
|
|
|
// ── State retrieval ──────────────────────────────────────────────────────
|
|
|
|
public function test_unregistered_module_returns_idle(): void {
|
|
$this->assertSame( 'idle', WPDO_Feature_Flags::get( 'hot_unknown' ) );
|
|
}
|
|
|
|
public function test_get_returns_stored_state(): void {
|
|
WPDO_Feature_Flags::set( 'hot_hp_listing', 'backfill' );
|
|
$this->assertSame( 'backfill', WPDO_Feature_Flags::get( 'hot_hp_listing' ) );
|
|
}
|
|
|
|
// ── set() ─────────────────────────────────────────────────────────────────
|
|
|
|
public function test_set_valid_state_returns_true(): void {
|
|
$result = WPDO_Feature_Flags::set( 'mod', 'cutover' );
|
|
$this->assertTrue( $result );
|
|
$this->assertSame( 'cutover', WPDO_Feature_Flags::get( 'mod' ) );
|
|
}
|
|
|
|
public function test_set_invalid_state_returns_false(): void {
|
|
$result = WPDO_Feature_Flags::set( 'mod', 'invalid_state_xyz' );
|
|
$this->assertFalse( $result );
|
|
}
|
|
|
|
// ── Query-active check ──────────────────────────────────────────────────
|
|
|
|
public function test_is_query_active_true_when_cutover(): void {
|
|
WPDO_Feature_Flags::set( 'hot_hp_listing', 'cutover' );
|
|
$this->assertTrue( WPDO_Feature_Flags::is_query_active( 'hot_hp_listing' ) );
|
|
}
|
|
|
|
public function test_is_query_active_true_when_complete(): void {
|
|
WPDO_Feature_Flags::set( 'hot_hp_listing', 'complete' );
|
|
$this->assertTrue( WPDO_Feature_Flags::is_query_active( 'hot_hp_listing' ) );
|
|
}
|
|
|
|
public function test_is_query_active_false_when_backfill(): void {
|
|
WPDO_Feature_Flags::set( 'hot_hp_listing', 'backfill' );
|
|
$this->assertFalse( WPDO_Feature_Flags::is_query_active( 'hot_hp_listing' ) );
|
|
}
|
|
|
|
// ── is_write_active ──────────────────────────────────────────────────────
|
|
|
|
public function test_is_write_active_true_when_dual_write(): void {
|
|
WPDO_Feature_Flags::set( 'hot_hp_listing', 'dual_write' );
|
|
$this->assertTrue( WPDO_Feature_Flags::is_write_active( 'hot_hp_listing' ) );
|
|
}
|
|
|
|
public function test_is_write_active_false_when_idle(): void {
|
|
WPDO_Feature_Flags::set( 'hot_hp_listing', 'idle' );
|
|
$this->assertFalse( WPDO_Feature_Flags::is_write_active( 'hot_hp_listing' ) );
|
|
}
|
|
|
|
// ── is_read_custom ───────────────────────────────────────────────────────
|
|
|
|
public function test_is_read_custom_true_when_cutover(): void {
|
|
WPDO_Feature_Flags::set( 'hot_hp_listing', 'cutover' );
|
|
$this->assertTrue( WPDO_Feature_Flags::is_read_custom( 'hot_hp_listing' ) );
|
|
}
|
|
|
|
public function test_is_read_custom_false_when_backfill(): void {
|
|
WPDO_Feature_Flags::set( 'hot_hp_listing', 'backfill' );
|
|
$this->assertFalse( WPDO_Feature_Flags::is_read_custom( 'hot_hp_listing' ) );
|
|
}
|
|
|
|
// ── all() ────────────────────────────────────────────────────────────────
|
|
|
|
public function test_all_returns_array_of_states(): void {
|
|
WPDO_Feature_Flags::set( 'hot_hp_listing', 'cutover' );
|
|
WPDO_Feature_Flags::set( 'hot_hp_vendor', 'idle' );
|
|
|
|
$all = WPDO_Feature_Flags::all();
|
|
|
|
$this->assertIsArray( $all );
|
|
$this->assertSame( 'cutover', $all['hot_hp_listing'] );
|
|
$this->assertSame( 'idle', $all['hot_hp_vendor'] );
|
|
}
|
|
|
|
// ── reset() ─────────────────────────────────────────────────────────────
|
|
|
|
public function test_reset_returns_module_to_idle(): void {
|
|
WPDO_Feature_Flags::set( 'hot_hp_listing', 'complete' );
|
|
WPDO_Feature_Flags::reset( 'hot_hp_listing' );
|
|
$this->assertSame( 'idle', WPDO_Feature_Flags::get( 'hot_hp_listing' ) );
|
|
}
|
|
|
|
// ── is_complete ──────────────────────────────────────────────────────────
|
|
|
|
public function test_is_complete_true_when_complete(): void {
|
|
WPDO_Feature_Flags::set( 'hot_hp_listing', 'complete' );
|
|
$this->assertTrue( WPDO_Feature_Flags::is_complete( 'hot_hp_listing' ) );
|
|
}
|
|
|
|
public function test_is_complete_false_when_cutover(): void {
|
|
WPDO_Feature_Flags::set( 'hot_hp_listing', 'cutover' );
|
|
$this->assertFalse( WPDO_Feature_Flags::is_complete( 'hot_hp_listing' ) );
|
|
}
|
|
}
|