Skip to content

Commit b2c233e

Browse files
committed
Tests: Check cURL hook references without a live request.
Move the `http_api_curl` reference check into tests for `WP_HTTP_Requests_Hooks`. Dispatch `curl.before_send` with a local cURL handle and verify that changing the callback parameter changes the original handle variable. Remove the live-request version from `Tests_HTTP_curl`, retaining its other external HTTP tests. Developed in: #14057 Props shailu25. See #63914. git-svn-id: https://develop.svn.wordpress.org/trunk@64265 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 40c0b8a commit b2c233e

2 files changed

Lines changed: 63 additions & 23 deletions

File tree

‎tests/phpunit/tests/http/curl.php‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,4 @@
88
*/
99
class Tests_HTTP_curl extends WP_HTTP_UnitTestCase {
1010
public $transport = 'curl';
11-
12-
/**
13-
* @ticket 39783
14-
*
15-
* @covers ::wp_remote_request
16-
*/
17-
public function test_http_api_curl_stream_parameter_is_a_reference() {
18-
add_action( 'http_api_curl', array( $this, '_action_test_http_api_curl_stream_parameter_is_a_reference' ), 10, 3 );
19-
wp_remote_request(
20-
$this->file_stream_url,
21-
array(
22-
'stream' => true,
23-
'timeout' => 30,
24-
)
25-
);
26-
remove_action( 'http_api_curl', array( $this, '_action_test_http_api_curl_stream_parameter_is_a_reference' ), 10 );
27-
}
28-
29-
public function _action_test_http_api_curl_stream_parameter_is_a_reference( &$stream, $r, $url ) {
30-
// $stream not being a reference will cause a PHP warning.
31-
// For counting tests purposes, let's do a fake assert.
32-
$this->assertTrue( true );
33-
}
3411
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* Tests for WP_HTTP_Requests_Hooks.
4+
*
5+
* @group http
6+
*
7+
* @covers WP_HTTP_Requests_Hooks
8+
* @covers WP_HTTP_Requests_Hooks::dispatch
9+
*/
10+
class Tests_HTTP_wpHttpRequestsHooks extends WP_UnitTestCase {
11+
12+
/**
13+
* cURL handle passed into the http_api_curl action.
14+
*
15+
* @var mixed
16+
*/
17+
private $action_handle;
18+
19+
/**
20+
* @ticket 39783
21+
* @ticket 63914
22+
*/
23+
public function test_http_api_curl_stream_parameter_is_a_reference() {
24+
if ( ! function_exists( 'curl_init' ) ) {
25+
$this->markTestSkipped( 'The cURL extension is not available.' );
26+
}
27+
28+
$handle = curl_init();
29+
$this->action_handle = null;
30+
31+
$hooks = new WP_HTTP_Requests_Hooks(
32+
'https://example.com/',
33+
array(
34+
'method' => 'GET',
35+
)
36+
);
37+
38+
add_action( 'http_api_curl', array( $this, 'capture_http_api_curl_handle' ), 10, 3 );
39+
40+
$hooks->dispatch( 'curl.before_send', array( &$handle ) );
41+
42+
remove_action( 'http_api_curl', array( $this, 'capture_http_api_curl_handle' ), 10 );
43+
44+
$this->assertNotNull( $this->action_handle, 'The http_api_curl action should run for curl.before_send.' );
45+
$this->assertNull( $handle, 'The cURL handle should be passed to http_api_curl by reference.' );
46+
}
47+
48+
/**
49+
* Captures the http_api_curl handle and clears it by reference.
50+
*
51+
* @param mixed $handle cURL handle (passed by reference).
52+
* @param array $args Request arguments.
53+
* @param string $url Request URL.
54+
*/
55+
public function capture_http_api_curl_handle( &$handle, $args, $url ) {
56+
unset( $args, $url );
57+
58+
$this->action_handle = $handle;
59+
60+
// Mutating the parameter must change the original handle variable.
61+
$handle = null;
62+
}
63+
}

0 commit comments

Comments
 (0)