86ac84e07c
- The settings form and the AJAX section save both went through TMDO_Mode_Manager::set() and dropped its WP_Error: an unsafe jump or a Promotion Guard refusal still said "saved" while the mode stayed put - TMDO_Admin::apply_bridge_modes() returns the refusals; the full form keeps them in a per-user transient and shows them after the redirect, the AJAX save returns them as the error message (the settings JS shows it) - Verify: AdminBridgeModeSaveTest (5 new); unit 709, integration 606, phpcs 0, stan OK - PR: PR-135 (manual F-2)
79 lines
2.7 KiB
PHP
79 lines
2.7 KiB
PHP
<?php
|
||
declare(strict_types=1);
|
||
|
||
use PHPUnit\Framework\TestCase;
|
||
|
||
/**
|
||
* The admin settings form saves bridge modes through TMDO_Mode_Manager::set().
|
||
* A refused change (unsafe jump, Promotion Guard) used to be dropped silently:
|
||
* the page said "saved" while the mode stayed put (2.4.2 PR-135, manual F-2).
|
||
*/
|
||
class AdminBridgeModeSaveTest extends TestCase {
|
||
|
||
public static function setUpBeforeClass(): void {
|
||
require_once TMDO_PATH . 'admin/class-tmdo-admin.php';
|
||
}
|
||
|
||
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 );
|
||
$GLOBALS['_wp_current_user_id'] = 7;
|
||
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_an_accepted_change_is_applied_without_refusals(): void {
|
||
$this->modes( array( 'user' => 'disabled' ) );
|
||
|
||
$refused = TMDO_Admin::apply_bridge_modes( array( 'user' => 'dual_write' ) );
|
||
|
||
$this->assertSame( array(), $refused );
|
||
$this->assertSame( 'dual_write', TMDO_Mode_Manager::get( 'user' ) );
|
||
}
|
||
|
||
public function test_an_unsafe_jump_is_reported_and_the_mode_kept(): void {
|
||
$this->modes( array( 'post' => 'disabled' ) );
|
||
|
||
$refused = TMDO_Admin::apply_bridge_modes( array( 'post' => 'shadow_read' ) );
|
||
|
||
$this->assertCount( 1, $refused );
|
||
$this->assertStringStartsWith( 'post', $refused[0] );
|
||
$this->assertSame( 'disabled', TMDO_Mode_Manager::get( 'post' ) );
|
||
}
|
||
|
||
public function test_empty_or_unknown_modes_are_ignored(): void {
|
||
$this->modes( array( 'term' => 'disabled' ) );
|
||
|
||
$this->assertSame( array(), TMDO_Admin::apply_bridge_modes( array( 'post' => '', 'term' => 'bogus' ) ) );
|
||
$this->assertSame( 'disabled', TMDO_Mode_Manager::get( 'term' ) );
|
||
}
|
||
|
||
/**
|
||
* @runInSeparateProcess
|
||
* @preserveGlobalState disabled
|
||
*/
|
||
public function test_a_promotion_refused_by_the_guard_is_reported(): void {
|
||
eval( 'namespace HivePress; class Core {}' );
|
||
$this->modes( array( 'user' => 'shadow_read' ) );
|
||
|
||
$refused = TMDO_Admin::apply_bridge_modes( array( 'user' => 'aeav_only' ) );
|
||
|
||
$this->assertCount( 1, $refused );
|
||
$this->assertSame( 'shadow_read', TMDO_Mode_Manager::get( 'user' ) );
|
||
}
|
||
|
||
/** The full-page form redirects after saving: refusals wait in a per-user transient, shown once. */
|
||
public function test_refusals_are_kept_for_the_next_page_view_only(): void {
|
||
TMDO_Admin::remember_bridge_mode_refusals( array( 'post:refused' ) );
|
||
|
||
$this->assertSame( array( 'post:refused' ), TMDO_Admin::pull_bridge_mode_refusals() );
|
||
$this->assertSame( array(), TMDO_Admin::pull_bridge_mode_refusals() );
|
||
}
|
||
}
|