@@ -117,158 +117,140 @@ public function test_includes_registered_provider_from_registry() {
117117 }
118118
119119 /**
120- * @ticket 64730
120+ * @ticket 64791
121121 */
122122 public function test_filter_can_add_new_connector () {
123- add_filter (
124- 'wp_connectors_settings ' ,
125- static function ( $ connectors ) {
126- $ connectors ['my_email_service ' ] = array (
127- 'name ' => 'My Email Service ' ,
128- 'description ' => 'Send transactional emails. ' ,
129- 'type ' => 'email_service ' ,
130- 'authentication ' => array ( 'method ' => 'none ' ),
131- );
132- return $ connectors ;
133- }
134- );
123+ $ callback = static function ( $ connectors ) {
124+ $ connectors ['my_email_service ' ] = array (
125+ 'name ' => 'My Email Service ' ,
126+ 'description ' => 'Send transactional emails. ' ,
127+ 'type ' => 'email_service ' ,
128+ 'authentication ' => array ( 'method ' => 'none ' ),
129+ );
130+ return $ connectors ;
131+ };
132+ add_filter ( 'wp_connectors_settings ' , $ callback );
135133
136134 $ connectors = _wp_connectors_get_connector_settings ();
135+ remove_filter ( 'wp_connectors_settings ' , $ callback );
137136
138137 $ this ->assertArrayHasKey ( 'my_email_service ' , $ connectors );
139138 $ this ->assertSame ( 'My Email Service ' , $ connectors ['my_email_service ' ]['name ' ] );
140139 $ this ->assertSame ( 'email_service ' , $ connectors ['my_email_service ' ]['type ' ] );
141140 $ this ->assertSame ( 'none ' , $ connectors ['my_email_service ' ]['authentication ' ]['method ' ] );
142-
143- remove_all_filters ( 'wp_connectors_settings ' );
144141 }
145142
146143 /**
147- * @ticket 64730
144+ * @ticket 64791
148145 */
149146 public function test_filter_can_modify_existing_connector () {
150- add_filter (
151- 'wp_connectors_settings ' ,
152- static function ( $ connectors ) {
153- $ connectors ['google ' ]['description ' ] = 'Custom description for Google. ' ;
154- return $ connectors ;
155- }
156- );
147+ $ callback = static function ( $ connectors ) {
148+ $ connectors ['google ' ]['description ' ] = 'Custom description for Google. ' ;
149+ return $ connectors ;
150+ };
151+ add_filter ( 'wp_connectors_settings ' , $ callback );
157152
158153 $ connectors = _wp_connectors_get_connector_settings ();
154+ remove_filter ( 'wp_connectors_settings ' , $ callback );
159155
160156 $ this ->assertSame ( 'Custom description for Google. ' , $ connectors ['google ' ]['description ' ] );
161-
162- remove_all_filters ( 'wp_connectors_settings ' );
163157 }
164158
165159 /**
166- * @ticket 64730
160+ * @ticket 64791
167161 */
168162 public function test_filter_can_remove_connector () {
169- add_filter (
170- 'wp_connectors_settings ' ,
171- static function ( $ connectors ) {
172- unset( $ connectors ['openai ' ] );
173- return $ connectors ;
174- }
175- );
163+ $ callback = static function ( $ connectors ) {
164+ unset( $ connectors ['openai ' ] );
165+ return $ connectors ;
166+ };
167+ add_filter ( 'wp_connectors_settings ' , $ callback );
176168
177169 $ connectors = _wp_connectors_get_connector_settings ();
170+ remove_filter ( 'wp_connectors_settings ' , $ callback );
178171
179172 $ this ->assertArrayNotHasKey ( 'openai ' , $ connectors );
180173 // Other connectors remain.
181174 $ this ->assertArrayHasKey ( 'google ' , $ connectors );
182175 $ this ->assertArrayHasKey ( 'anthropic ' , $ connectors );
183-
184- remove_all_filters ( 'wp_connectors_settings ' );
185176 }
186177
187178 /**
188- * @ticket 64730
179+ * @ticket 64791
189180 */
190181 public function test_filter_added_api_key_connector_gets_setting_name () {
191- add_filter (
192- 'wp_connectors_settings ' ,
193- static function ( $ connectors ) {
194- $ connectors ['custom_ai ' ] = array (
195- 'name ' => 'Custom AI ' ,
196- 'description ' => 'A custom AI provider. ' ,
197- 'type ' => 'ai_provider ' ,
198- 'authentication ' => array (
199- 'method ' => 'api_key ' ,
200- 'credentials_url ' => 'https://example.com/keys ' ,
201- ),
202- );
203- return $ connectors ;
204- }
205- );
182+ $ callback = static function ( $ connectors ) {
183+ $ connectors ['custom_ai ' ] = array (
184+ 'name ' => 'Custom AI ' ,
185+ 'description ' => 'A custom AI provider. ' ,
186+ 'type ' => 'ai_provider ' ,
187+ 'authentication ' => array (
188+ 'method ' => 'api_key ' ,
189+ 'credentials_url ' => 'https://example.com/keys ' ,
190+ ),
191+ );
192+ return $ connectors ;
193+ };
194+ add_filter ( 'wp_connectors_settings ' , $ callback );
206195
207196 $ connectors = _wp_connectors_get_connector_settings ();
197+ remove_filter ( 'wp_connectors_settings ' , $ callback );
208198
209199 $ this ->assertArrayHasKey ( 'custom_ai ' , $ connectors );
210200 $ this ->assertSame (
211201 'connectors_ai_custom_ai_api_key ' ,
212202 $ connectors ['custom_ai ' ]['authentication ' ]['setting_name ' ],
213203 'Connectors added via the filter with api_key auth should receive a setting_name automatically. '
214204 );
215-
216- remove_all_filters ( 'wp_connectors_settings ' );
217205 }
218206
219207 /**
220- * @ticket 64730
208+ * @ticket 64791
221209 */
222210 public function test_filter_added_non_ai_api_key_connector_does_not_get_setting_name () {
223- add_filter (
224- 'wp_connectors_settings ' ,
225- static function ( $ connectors ) {
226- $ connectors ['my_crm ' ] = array (
227- 'name ' => 'My CRM ' ,
228- 'description ' => 'CRM integration. ' ,
229- 'type ' => 'crm ' ,
230- 'authentication ' => array (
231- 'method ' => 'api_key ' ,
232- 'credentials_url ' => 'https://example.com/crm-keys ' ,
233- ),
234- );
235- return $ connectors ;
236- }
237- );
211+ $ callback = static function ( $ connectors ) {
212+ $ connectors ['my_crm ' ] = array (
213+ 'name ' => 'My CRM ' ,
214+ 'description ' => 'CRM integration. ' ,
215+ 'type ' => 'crm ' ,
216+ 'authentication ' => array (
217+ 'method ' => 'api_key ' ,
218+ 'credentials_url ' => 'https://example.com/crm-keys ' ,
219+ ),
220+ );
221+ return $ connectors ;
222+ };
223+ add_filter ( 'wp_connectors_settings ' , $ callback );
238224
239225 $ connectors = _wp_connectors_get_connector_settings ();
226+ remove_filter ( 'wp_connectors_settings ' , $ callback );
240227
241228 $ this ->assertArrayHasKey ( 'my_crm ' , $ connectors );
242229 $ this ->assertArrayNotHasKey (
243230 'setting_name ' ,
244231 $ connectors ['my_crm ' ]['authentication ' ],
245232 'Non-AI connectors should not receive an auto-generated setting_name. '
246233 );
247-
248- remove_all_filters ( 'wp_connectors_settings ' );
249234 }
250235
251236 /**
252- * @ticket 64730
237+ * @ticket 64791
253238 */
254239 public function test_filter_receives_all_default_connectors () {
255240 $ received = null ;
256241
257- add_filter (
258- 'wp_connectors_settings ' ,
259- static function ( $ connectors ) use ( &$ received ) {
260- $ received = $ connectors ;
261- return $ connectors ;
262- }
263- );
242+ $ callback = static function ( $ connectors ) use ( &$ received ) {
243+ $ received = $ connectors ;
244+ return $ connectors ;
245+ };
246+ add_filter ( 'wp_connectors_settings ' , $ callback );
264247
265248 _wp_connectors_get_connector_settings ();
249+ remove_filter ( 'wp_connectors_settings ' , $ callback );
266250
267251 $ this ->assertArrayHasKey ( 'google ' , $ received );
268252 $ this ->assertArrayHasKey ( 'openai ' , $ received );
269253 $ this ->assertArrayHasKey ( 'anthropic ' , $ received );
270254 $ this ->assertArrayHasKey ( 'mock_connectors_test ' , $ received );
271-
272- remove_all_filters ( 'wp_connectors_settings ' );
273255 }
274256}
0 commit comments