mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-03-31 18:54:29 +00:00
Tests: Use assertSame() in some newly introduced tests.
This ensures that not only the return values match the expected results, but also that their type is the same. Going forward, stricter type checking by using `assertSame()` should generally be preferred to `assertEquals()` where appropriate, to make the tests more reliable. Follow-up to [49904], [49925], [49992], [50012], [50013], [50065], [50075], [50131], [50150], [50157]. See #38266, #52482. git-svn-id: https://develop.svn.wordpress.org/trunk@50284 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -65,14 +65,14 @@ class Tests_HTTPS_Detection extends WP_UnitTestCase {
|
||||
// If initial request succeeds, all good.
|
||||
add_filter( 'pre_http_request', array( $this, 'mock_success_with_sslverify' ), 10, 2 );
|
||||
wp_update_https_detection_errors();
|
||||
$this->assertEquals( array(), get_option( 'https_detection_errors' ) );
|
||||
$this->assertSame( array(), get_option( 'https_detection_errors' ) );
|
||||
|
||||
// If initial request fails and request without SSL verification succeeds,
|
||||
// return error with 'ssl_verification_failed' error code.
|
||||
add_filter( 'pre_http_request', array( $this, 'mock_error_with_sslverify' ), 10, 2 );
|
||||
add_filter( 'pre_http_request', array( $this, 'mock_success_without_sslverify' ), 10, 2 );
|
||||
wp_update_https_detection_errors();
|
||||
$this->assertEquals(
|
||||
$this->assertSame(
|
||||
array( 'ssl_verification_failed' => array( 'Bad SSL certificate.' ) ),
|
||||
get_option( 'https_detection_errors' )
|
||||
);
|
||||
@@ -82,7 +82,7 @@ class Tests_HTTPS_Detection extends WP_UnitTestCase {
|
||||
add_filter( 'pre_http_request', array( $this, 'mock_error_with_sslverify' ), 10, 2 );
|
||||
add_filter( 'pre_http_request', array( $this, 'mock_error_without_sslverify' ), 10, 2 );
|
||||
wp_update_https_detection_errors();
|
||||
$this->assertEquals(
|
||||
$this->assertSame(
|
||||
array( 'bad_ssl_certificate' => array( 'Bad SSL certificate.' ) ),
|
||||
get_option( 'https_detection_errors' )
|
||||
);
|
||||
@@ -91,7 +91,7 @@ class Tests_HTTPS_Detection extends WP_UnitTestCase {
|
||||
// 'bad_response_code' error code.
|
||||
add_filter( 'pre_http_request', array( $this, 'mock_not_found' ), 10, 2 );
|
||||
wp_update_https_detection_errors();
|
||||
$this->assertEquals(
|
||||
$this->assertSame(
|
||||
array( 'bad_response_code' => array( 'Not Found' ) ),
|
||||
get_option( 'https_detection_errors' )
|
||||
);
|
||||
@@ -100,13 +100,13 @@ class Tests_HTTPS_Detection extends WP_UnitTestCase {
|
||||
// WordPress site, return error with 'bad_response_source' error code.
|
||||
add_filter( 'pre_http_request', array( $this, 'mock_bad_source' ), 10, 2 );
|
||||
wp_update_https_detection_errors();
|
||||
$this->assertEquals(
|
||||
$this->assertSame(
|
||||
array( 'bad_response_source' => array( 'It looks like the response did not come from this site.' ) ),
|
||||
get_option( 'https_detection_errors' )
|
||||
);
|
||||
|
||||
// Check that the requests are made to the correct URL.
|
||||
$this->assertEquals( 'https://example.com/', $this->last_request_url );
|
||||
$this->assertSame( 'https://example.com/', $this->last_request_url );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,7 +121,7 @@ class Tests_HTTPS_Detection extends WP_UnitTestCase {
|
||||
}
|
||||
);
|
||||
wp_update_https_detection_errors();
|
||||
$this->assertEquals( array(), get_option( 'https_detection_errors' ) );
|
||||
$this->assertSame( array(), get_option( 'https_detection_errors' ) );
|
||||
|
||||
// Override to enforce an error being detected.
|
||||
add_filter(
|
||||
@@ -134,7 +134,7 @@ class Tests_HTTPS_Detection extends WP_UnitTestCase {
|
||||
}
|
||||
);
|
||||
wp_update_https_detection_errors();
|
||||
$this->assertEquals(
|
||||
$this->assertSame(
|
||||
array( 'ssl_verification_failed' => array( 'Bad SSL certificate.' ) ),
|
||||
get_option( 'https_detection_errors' )
|
||||
);
|
||||
@@ -145,7 +145,7 @@ class Tests_HTTPS_Detection extends WP_UnitTestCase {
|
||||
*/
|
||||
public function test_wp_schedule_https_detection() {
|
||||
wp_schedule_https_detection();
|
||||
$this->assertEquals( 'twicedaily', wp_get_schedule( 'wp_https_detection' ) );
|
||||
$this->assertSame( 'twicedaily', wp_get_schedule( 'wp_https_detection' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,7 +157,7 @@ class Tests_HTTPS_Detection extends WP_UnitTestCase {
|
||||
'url' => 'http://example.com/',
|
||||
'args' => array( 'sslverify' => true ),
|
||||
);
|
||||
$this->assertEquals( $request, wp_cron_conditionally_prevent_sslverify( $request ) );
|
||||
$this->assertSame( $request, wp_cron_conditionally_prevent_sslverify( $request ) );
|
||||
|
||||
// If URL is using HTTPS, set 'sslverify' to false.
|
||||
$request = array(
|
||||
@@ -166,7 +166,7 @@ class Tests_HTTPS_Detection extends WP_UnitTestCase {
|
||||
);
|
||||
$expected = $request;
|
||||
$expected['args']['sslverify'] = false;
|
||||
$this->assertEquals( $expected, wp_cron_conditionally_prevent_sslverify( $request ) );
|
||||
$this->assertSame( $expected, wp_cron_conditionally_prevent_sslverify( $request ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user