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:
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Integration tests for WPDO_V2_Upgrader — atomic v1.3.x → v2.0.0 upgrade (PR-7).
|
||||
*
|
||||
* Covers the four upgrade scenarios from Part F.2:
|
||||
* S1: clean install
|
||||
* S2: v1.3.x → v2.0.0 (no UAE) ← dev10 production case
|
||||
* S3: v1.3.x + UAE coexistence
|
||||
* S4: HPCT residue (covered by existing wpdo_hpct_imported flag)
|
||||
*
|
||||
* @covers WPDO_V2_Upgrader
|
||||
*/
|
||||
class UpgradeV2Test extends TestCase {
|
||||
|
||||
public static function setUpBeforeClass(): void {
|
||||
global $wpdb;
|
||||
// Reset state for repeatability.
|
||||
foreach ( array( 'audit', 'shadow_diffs', 'site_metrics', 'uni_options' ) as $t ) {
|
||||
$wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}wpdo_{$t}`" );
|
||||
}
|
||||
// Drop any leftover wp_uae_* probe tables from prior test runs.
|
||||
$wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}uae_probe`" );
|
||||
}
|
||||
|
||||
protected function setUp(): void {
|
||||
// Clean options between tests for clean preconditions.
|
||||
$GLOBALS['_wp_options'] = array();
|
||||
}
|
||||
|
||||
// ── Pre-flight ──────────────────────────────────────────────────────────
|
||||
|
||||
public function test_pre_flight_passes_in_clean_environment(): void {
|
||||
$checks = WPDO_V2_Upgrader::pre_flight_check();
|
||||
$this->assertIsArray( $checks );
|
||||
// PHP / WP / MySQL versions in this CI/dev environment must satisfy minimums.
|
||||
$this->assertTrue( $checks['php_version'] );
|
||||
$this->assertTrue( $checks['mysql_version'] );
|
||||
}
|
||||
|
||||
public function test_pre_flight_detects_old_php(): void {
|
||||
// Simulating an old PHP is impossible from PHP itself, so we only
|
||||
// verify the keys are present + booleans.
|
||||
$checks = WPDO_V2_Upgrader::pre_flight_check();
|
||||
foreach ( array( 'php_version', 'wp_version', 'mysql_version', 'free_disk_mb', 'features_writable', 'no_active_migration' ) as $key ) {
|
||||
$this->assertArrayHasKey( $key, $checks );
|
||||
$this->assertIsBool( $checks[ $key ] );
|
||||
}
|
||||
}
|
||||
|
||||
// ── S1: clean install ─────────────────────────────────────────────────
|
||||
|
||||
public function test_s1_clean_install_creates_v2_schema(): void {
|
||||
WPDO_V2_Upgrader::upgrade_to_v2();
|
||||
$status = WPDO_Installer::v2_tables_status();
|
||||
foreach ( $status as $exists ) {
|
||||
$this->assertTrue( $exists );
|
||||
}
|
||||
}
|
||||
|
||||
// ── S2: v1.3.x → v2.0.0 (no UAE) ───────────────────────────────────────
|
||||
|
||||
public function test_s2_upgrade_marks_db_version(): void {
|
||||
// Simulate v1.3.x state.
|
||||
update_option( 'wpdo_db_version', '1.0.0' );
|
||||
|
||||
$ok = WPDO_V2_Upgrader::upgrade_to_v2();
|
||||
$this->assertTrue( $ok );
|
||||
$this->assertSame( '2.0.0', get_option( 'wpdo_db_version' ) );
|
||||
$this->assertSame( 'complete', get_option( 'wpdo_v2_upgrade_status' ) );
|
||||
}
|
||||
|
||||
public function test_s2_upgrade_seeds_entity_modules_in_features(): void {
|
||||
update_option( 'wpdo_features', array( 'hot_hp_listing' => 'cutover' ) );
|
||||
WPDO_V2_Upgrader::upgrade_to_v2();
|
||||
|
||||
$flags = get_option( 'wpdo_features' );
|
||||
$this->assertSame( 'cutover', $flags['hot_hp_listing'], 'Pre-existing module state must be preserved' );
|
||||
|
||||
foreach ( array( 'entity_user', 'entity_term', 'entity_comment', 'entity_options' ) as $module ) {
|
||||
$this->assertArrayHasKey( $module, $flags );
|
||||
$this->assertSame( 'idle', $flags[ $module ] );
|
||||
}
|
||||
}
|
||||
|
||||
public function test_s2_upgrade_idempotent(): void {
|
||||
WPDO_V2_Upgrader::upgrade_to_v2();
|
||||
$ok = WPDO_V2_Upgrader::upgrade_to_v2(); // Second run must not fail.
|
||||
$this->assertTrue( $ok );
|
||||
}
|
||||
|
||||
// ── S3: UAE coexistence ───────────────────────────────────────────────
|
||||
|
||||
public function test_s3_detects_uae_data_when_table_present(): void {
|
||||
global $wpdb;
|
||||
$wpdb->query( "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}uae_probe` ( id BIGINT PRIMARY KEY ) ENGINE=InnoDB" );
|
||||
$this->assertTrue( WPDO_V2_Upgrader::detect_uae_data() );
|
||||
|
||||
$wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}uae_probe`" );
|
||||
}
|
||||
|
||||
public function test_s3_no_uae_data_in_clean_environment(): void {
|
||||
// dev10 case: no wp_uae_* tables.
|
||||
$this->assertFalse( WPDO_V2_Upgrader::detect_uae_data() );
|
||||
}
|
||||
|
||||
// ── Rollback ───────────────────────────────────────────────────────────
|
||||
|
||||
public function test_rollback_restores_features_backup(): void {
|
||||
$original = array( 'hot_hp_listing' => 'cutover' );
|
||||
update_option( 'wpdo_features', $original );
|
||||
|
||||
WPDO_V2_Upgrader::upgrade_to_v2();
|
||||
// Simulate user wants to roll back.
|
||||
WPDO_V2_Upgrader::rollback_v2( true );
|
||||
|
||||
$this->assertSame( $original, get_option( 'wpdo_features' ) );
|
||||
$this->assertSame( '1.0.0', get_option( 'wpdo_db_version' ) );
|
||||
$this->assertSame( 'rolled_back', get_option( 'wpdo_v2_upgrade_status' ) );
|
||||
}
|
||||
|
||||
public function test_rollback_with_keep_data_preserves_v2_tables(): void {
|
||||
WPDO_V2_Upgrader::upgrade_to_v2();
|
||||
WPDO_V2_Upgrader::rollback_v2( true );
|
||||
|
||||
$status = WPDO_Installer::v2_tables_status();
|
||||
foreach ( $status as $table => $exists ) {
|
||||
$this->assertTrue( $exists, "{$table} must remain after rollback with --keep-data" );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user