|
8 | 8 | namespace WorkOS\Tests\Wpunit; |
9 | 9 |
|
10 | 10 | use lucatume\WPBrowser\TestCase\WPTestCase; |
| 11 | +use WorkOS\Admin\Settings; |
11 | 12 | use WorkOS\App; |
12 | 13 | use WorkOS\Config; |
13 | 14 | use WorkOS\Database\Schema; |
@@ -117,6 +118,52 @@ public function test_migrate_active_environment_moves_legacy_value_to_standalone |
117 | 118 | $this->assertSame( 3, (int) get_option( 'workos_db_version' ) ); |
118 | 119 | } |
119 | 120 |
|
| 121 | + /** |
| 122 | + * The settings form edits production/staging option rows but does not post |
| 123 | + * workos_active_environment. A normal save must not coerce the missing |
| 124 | + * active-environment field back to staging. |
| 125 | + */ |
| 126 | + public function test_settings_save_preserves_active_environment_when_field_is_missing(): void { |
| 127 | + if ( ! defined( 'WORKOS_BASENAME' ) ) { |
| 128 | + define( 'WORKOS_BASENAME', 'integration-workos/integration-workos.php' ); |
| 129 | + } |
| 130 | + |
| 131 | + update_option( 'workos_active_environment', 'production' ); |
| 132 | + |
| 133 | + $settings = new Settings(); |
| 134 | + $settings->register_settings(); |
| 135 | + |
| 136 | + update_option( 'workos_active_environment', null ); |
| 137 | + |
| 138 | + $this->assertSame( 'production', get_option( 'workos_active_environment' ) ); |
| 139 | + } |
| 140 | + |
| 141 | + /** |
| 142 | + * Legacy installs may still have the active environment only in |
| 143 | + * workos_global. A settings save must preserve that fallback instead of |
| 144 | + * writing the standalone row as staging. |
| 145 | + */ |
| 146 | + public function test_settings_save_preserves_legacy_active_environment_when_field_is_missing(): void { |
| 147 | + if ( ! defined( 'WORKOS_BASENAME' ) ) { |
| 148 | + define( 'WORKOS_BASENAME', 'integration-workos/integration-workos.php' ); |
| 149 | + } |
| 150 | + |
| 151 | + update_option( |
| 152 | + 'workos_global', |
| 153 | + [ |
| 154 | + 'active_environment' => 'production', |
| 155 | + ] |
| 156 | + ); |
| 157 | + App::container()->get( Global_Options::class )->reset(); |
| 158 | + |
| 159 | + $settings = new Settings(); |
| 160 | + $settings->register_settings(); |
| 161 | + |
| 162 | + update_option( 'workos_active_environment', null ); |
| 163 | + |
| 164 | + $this->assertSame( 'production', get_option( 'workos_active_environment' ) ); |
| 165 | + } |
| 166 | + |
120 | 167 | /** |
121 | 168 | * Test mask_secret with a long value. |
122 | 169 | */ |
|
0 commit comments