Skip to content

Commit 5bb886d

Browse files
Isolate registered settings in connector gate test
1 parent 764cba3 commit 5bb886d

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

tests/phpunit/tests/connectors/wpRegisterDefaultConnectorSettings.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,37 @@
88
*/
99
class Tests_Connectors_WpRegisterDefaultConnectorSettings extends WP_UnitTestCase {
1010

11-
const CONNECTOR_ID = 'wp_test_non_ai_connector';
12-
const SETTING_NAME = 'connectors_test_non_ai_api_key';
11+
const CONNECTOR_ID = 'wp_test_non_ai_connector';
12+
const SETTING_NAME = 'connectors_test_non_ai_api_key';
1313

1414
/**
15-
* Removes the test connector and setting after each test.
15+
* Snapshot of registered settings before each test.
16+
*
17+
* @var array
18+
*/
19+
private array $original_registered_settings = array();
20+
21+
/**
22+
* Snapshots the registered settings before each test.
23+
*/
24+
public function set_up(): void {
25+
parent::set_up();
26+
27+
global $wp_registered_settings;
28+
$this->original_registered_settings = $wp_registered_settings;
29+
}
30+
31+
/**
32+
* Removes the test connector and restores registered settings.
1633
*/
1734
public function tear_down(): void {
1835
$registry = WP_Connector_Registry::get_instance();
1936
if ( null !== $registry && $registry->is_registered( self::CONNECTOR_ID ) ) {
2037
$registry->unregister( self::CONNECTOR_ID );
2138
}
2239

23-
unregister_setting( 'connectors', self::SETTING_NAME );
40+
global $wp_registered_settings;
41+
$wp_registered_settings = $this->original_registered_settings;
2442

2543
parent::tear_down();
2644
}

0 commit comments

Comments
 (0)