@@ -391,9 +391,65 @@ static function ( $response, $parsed_args ) use ( &$actual ) {
391
391
}
392
392
393
393
/**
394
- * Test that a WP_Error object is returned for non-200 HTTP responses.
394
+ * Test that a WP_Error object is not returned for some response codes.
395
+ *
396
+ * @dataProvider data_response_codes_that_should_not_error
397
+ *
398
+ * @param int $response_code The response code.
395
399
*/
396
- public function test_should_return_wp_error_for_non_200_responses () {
400
+ public function test_should_not_return_wp_error_for_some_response_codes ( $ response_code ) {
401
+ add_filter (
402
+ 'pre_http_request ' ,
403
+ static function () use ( $ response_code ) {
404
+ return [
405
+ 'response ' => [
406
+ 'code ' => $ response_code ,
407
+ 'message ' => 'Test response code ' ,
408
+ ],
409
+ ];
410
+ },
411
+ 10 ,
412
+ 2
413
+ );
414
+
415
+ $ api_rewrite = new AspireUpdate \API_Rewrite ( 'my.api.org ' , true , '' );
416
+ $ actual = $ api_rewrite ->pre_http_request (
417
+ [],
418
+ [],
419
+ $ this ->get_default_host () . '/file.php '
420
+ );
421
+
422
+ $ this ->assertNotInstanceOf (
423
+ 'WP_Error ' ,
424
+ $ actual ,
425
+ 'A WP_Error object was returned. '
426
+ );
427
+ }
428
+
429
+ /**
430
+ * Data provider.
431
+ *
432
+ * @return array[]
433
+ */
434
+ public function data_response_codes_that_should_not_error () {
435
+ return [
436
+ '200 ' => [
437
+ 'response_code ' => 200 ,
438
+ ],
439
+ '404 ' => [
440
+ 'response_code ' => 404 ,
441
+ ],
442
+ ];
443
+ }
444
+
445
+ /**
446
+ * Test that a WP_Error object is returned for other HTTP response codes.
447
+ *
448
+ * @dataProvider data_response_codes_that_should_error
449
+ *
450
+ * @param int $response_code The response code.
451
+ */
452
+ public function test_should_return_wp_error_for_other_response_codes ( $ response_code ) {
397
453
add_filter (
398
454
'pre_http_request ' ,
399
455
static function () {
@@ -428,6 +484,24 @@ static function () {
428
484
);
429
485
}
430
486
487
+ /**
488
+ * Data provider.
489
+ *
490
+ * @return array[]
491
+ */
492
+ public function data_response_codes_that_should_error () {
493
+ $ datasets = [];
494
+
495
+ $ exceptions = [ 200 , 404 ];
496
+ for ( $ i = 0 ; $ i < 599 ; ++$ i ) {
497
+ if ( ! in_array ( $ i , $ exceptions , true ) ) {
498
+ $ datasets [ $ i ] = [ 'response_code ' => $ i ];
499
+ }
500
+ }
501
+
502
+ return $ datasets ;
503
+ }
504
+
431
505
/**
432
506
* Gets the default host.
433
507
*
0 commit comments