예제 #1
0
 /**
  * @ticket 33711
  */
 function test_get_response_cookies()
 {
     $url = 'https://login.wordpress.org/wp-login.php';
     $response = wp_remote_head($url);
     $cookies = wp_remote_retrieve_cookies($response);
     $this->assertNotEmpty($cookies);
     $cookie = wp_remote_retrieve_cookie($response, 'wordpress_test_cookie');
     $this->assertInstanceOf('WP_Http_Cookie', $cookie);
     $this->assertSame('wordpress_test_cookie', $cookie->name);
     $this->assertSame('WP Cookie check', $cookie->value);
     $value = wp_remote_retrieve_cookie_value($response, 'wordpress_test_cookie');
     $this->assertSame('WP Cookie check', $value);
     $no_value = wp_remote_retrieve_cookie_value($response, 'not_a_cookie');
     $this->assertSame('', $no_value);
     $no_cookie = wp_remote_retrieve_cookie($response, 'not_a_cookie');
     $this->assertSame('', $no_cookie);
 }
예제 #2
0
/**
 * Retrieve a single cookie's value by name from the raw response.
 *
 * @since 4.4.0
 *
 * @param array  $response HTTP response.
 * @param string $name     The name of the cookie to retrieve.
 * @return string The value of the cookie. Empty string if the cookie isn't present in the response.
 */
function wp_remote_retrieve_cookie_value($response, $name)
{
    $cookie = wp_remote_retrieve_cookie($response, $name);
    if (!is_a($cookie, 'WP_Http_Cookie')) {
        return '';
    }
    return $cookie->value;
}
 /**
  * @ticket 37437
  */
 function test_get_response_cookies_with_name_value_array()
 {
     $url = 'http://example.org';
     $response = wp_remote_get($url, array('cookies' => array('test' => 'foo')));
     $cookies = wp_remote_retrieve_cookies($response);
     $this->assertNotEmpty($cookies);
     $cookie = wp_remote_retrieve_cookie($response, 'test');
     $this->assertInstanceOf('WP_Http_Cookie', $cookie);
     $this->assertSame('test', $cookie->name);
     $this->assertSame('foo', $cookie->value);
 }