Make WordPress Core


Ignore:
Timestamp:
04/08/2019 05:31:35 AM (5 years ago)
Author:
pento
Message:

HTTP: Add support for the host-only flag to Wp_Http_Cookie.

Props soulseekah.
Fixes #43231.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/http/functions.php

    r43571 r45135  
    200200        $this->assertSame( 'foo', $cookie->value );
    201201    }
     202
     203    /**
     204     * @ticket 43231
     205     */
     206    function test_get_cookie_host_only() {
     207        // emulate WP_Http::request() internals
     208        $requests_response = new Requests_Response();
     209
     210        $requests_response->cookies['test'] = Requests_Cookie::parse( 'test=foo; domain=.wordpress.org' );
     211
     212        $requests_response->cookies['test']->flags['host-only'] = false; // https://github.com/rmccue/Requests/issues/306
     213
     214        $http_response = new WP_HTTP_Requests_Response( $requests_response );
     215
     216        $response = $http_response->to_array();
     217
     218        // check the host_only flag in the resulting WP_Http_Cookie
     219        $cookie = wp_remote_retrieve_cookie( $response, 'test' );
     220        $this->assertEquals( $cookie->domain, 'wordpress.org' );
     221        $this->assertFalse( $cookie->host_only, 'host-only flag not set' );
     222
     223        // regurgitate (Requests_Cookie -> WP_Http_Cookie -> Requests_Cookie)
     224        $cookies = WP_Http::normalize_cookies( wp_remote_retrieve_cookies( $response ) );
     225        $this->assertFalse( $cookies['test']->flags['host-only'], 'host-only flag data lost' );
     226    }
    202227}
Note: See TracChangeset for help on using the changeset viewer.