Changeset 7820
- Timestamp:
- 10/04/2026 05:56:10 PM (3 weeks ago)
- Location:
- trunk/tests/phpunit
- Files:
-
- 1 added
- 1 edited
-
includes/anonymous-cookie-runner.php (added)
-
testcases/users/functions/functions.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/testcases/users/functions/functions.php
r7818 r7820 112 112 /** 113 113 * @covers ::bbp_set_current_anonymous_user_data 114 * @todo Test the Set-Cookie headers from an HTTP request.115 114 */ 116 115 public function test_bbp_set_current_anonymous_user_data() { 117 $this->markTestIncomplete( 'The successful cookie path requires an HTTP test harness.' ); 116 $listener = stream_socket_server( 'tcp://127.0.0.1:0', $error_number, $error_string ); 117 $this->assertIsResource( $listener, $error_string ); 118 $address = stream_socket_get_name( $listener, false ); 119 $port = (int) substr( strrchr( $address, ':' ), 1 ); 120 fclose( $listener ); 121 122 $runner = dirname( __DIR__, 3 ) . '/includes/anonymous-cookie-runner.php'; 123 $command = array( PHP_BINARY, '-d', 'output_buffering=1048576', '-S', '127.0.0.1:' . $port, $runner ); 124 $pipes = array(); 125 $env = array_merge( getenv(), array( 'BBP_TEST_MULTISITE' => is_multisite() ? '1' : '0' ) ); 126 $server = proc_open( $command, array( 127 0 => array( 'pipe', 'r' ), 128 1 => array( 'pipe', 'w' ), 129 2 => array( 'pipe', 'w' ), 130 ), $pipes, dirname( __DIR__, 4 ), $env ); 131 $this->assertIsResource( $server ); 132 fclose( $pipes[0] ); 133 134 try { 135 $ready = false; 136 for ( $attempt = 0; $attempt < 100; ++$attempt ) { 137 $socket = @fsockopen( '127.0.0.1', $port, $error_number, $error_string, 0.1 ); 138 if ( is_resource( $socket ) ) { 139 fclose( $socket ); 140 $ready = true; 141 break; 142 } 143 usleep( 50000 ); 144 } 145 $this->assertTrue( $ready, 'The cookie test server did not start.' ); 146 147 $response = wp_remote_get( 'http://127.0.0.1:' . $port . '/', array( 'timeout' => 15 ) ); 148 $this->assertFalse( is_wp_error( $response ), is_wp_error( $response ) ? $response->get_error_message() : '' ); 149 $this->assertSame( 200, wp_remote_retrieve_response_code( $response ) ); 150 151 $cookies = array(); 152 foreach ( wp_remote_retrieve_cookies( $response ) as $cookie ) { 153 $cookies[ $cookie->name ] = $cookie->value; 154 } 155 $this->assertSame( 'Guest User', $cookies[ 'comment_author_' . COOKIEHASH ] ); 156 $this->assertSame( 'guest@example.org', $cookies[ 'comment_author_email_' . COOKIEHASH ] ); 157 $this->assertSame( 'https://example.org/', $cookies[ 'comment_author_url_' . COOKIEHASH ] ); 158 } finally { 159 proc_terminate( $server ); 160 fclose( $pipes[1] ); 161 fclose( $pipes[2] ); 162 proc_close( $server ); 163 } 118 164 } 119 165
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)