Files
2meet-data-optimizer/tests/unit/CliBridgeModeTest.php
T
wpdev 382786cb9d feat(2meet-data-optimizer): set an entity bridge mode from the CLI under the Promotion Guard
- New `wp tmdo bridge-mode <entity> <mode>` goes through TMDO_Mode_Manager::set(): unsafe jumps and aeav_only promotions refused by the Promotion Guard exit with the reason and leave the mode unchanged. Named apart from the Feature Flags `mode-set`.
- member-sso-sync and member-force-logout warn that they are deprecated: the user sso group they work on is no longer registered.
- Verify: CliBridgeModeTest (RED: method missing); dev36 bridge-mode user aeav_only refused (unsafe jump), term dual_write → shadow_read → aeav_only refused by the HivePress guard → back to disabled, wpdo_bridge_modes identical to before.
- PR: PR-069
2026-09-26 23:36:55 +08:00

58 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
/**
* `wp tmdo bridge-mode <entity> <mode>` (2.2 PR-069): the CLI way to change an
* entity's bridge mode. It must go through TMDO_Mode_Manager::set(), so unsafe
* jumps and promotions refused by the Promotion Guard never reach the option.
* (The Guard matrix itself is covered by PromotionGuardTest.)
*/
class CliBridgeModeTest extends TestCase {
protected function setUp(): void {
ini_set( 'error_log', '/dev/null' );
$GLOBALS['_wp_options'] = array();
$GLOBALS['_wp_filter_callbacks'] = array();
$GLOBALS['_wp_current_user_can'] = array( 'manage_options' => true );
TMDO_Mode_Manager::reset_cache();
}
private function modes( array $modes ): void {
$GLOBALS['_wp_options']['wpdo_bridge_modes'] = $modes;
TMDO_Mode_Manager::reset_cache();
}
public function test_sets_the_mode_of_one_entity(): void {
$this->modes( array( 'user' => 'disabled', 'post' => 'dual_write' ) );
( new TMDO_CLI_V2() )->bridge_mode( array( 'user', 'dual_write' ), array() );
$this->assertSame( 'dual_write', TMDO_Mode_Manager::get( 'user' ) );
$this->assertSame( 'dual_write', TMDO_Mode_Manager::get( 'post' ), 'other entities untouched' );
}
public function test_an_unsafe_jump_is_refused(): void {
$this->modes( array( 'user' => 'disabled' ) );
( new TMDO_CLI_V2() )->bridge_mode( array( 'user', 'aeav_only' ), array() );
$this->assertSame( 'disabled', TMDO_Mode_Manager::get( 'user' ) );
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_a_promotion_refused_by_the_guard_leaves_the_mode_unchanged(): void {
eval( 'namespace HivePress; class Core {}' );
$this->modes( array( 'user' => 'shadow_read' ) );
( new TMDO_CLI_V2() )->bridge_mode( array( 'user', 'aeav_only' ), array() );
$this->assertSame( 'shadow_read', TMDO_Mode_Manager::get( 'user' ) );
$this->assertSame( array( 'user' => 'shadow_read' ), $GLOBALS['_wp_options']['wpdo_bridge_modes'] );
}
}