| 1 |
<?php |
| 2 |
/** |
| 3 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 4 |
* or more contributor license agreements. See the NOTICE file |
| 5 |
* distributed with this work for additional information |
| 6 |
* regarding copyright ownership. The ASF licenses this file |
| 7 |
* to you under the Apache License, Version 2.0 (the |
| 8 |
* "License"); you may not use this file except in compliance |
| 9 |
* with the License. You may obtain a copy of the License at |
| 10 |
* |
| 11 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 12 |
* |
| 13 |
* Unless required by applicable law or agreed to in writing, |
| 14 |
* software distributed under the License is distributed on an |
| 15 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 |
* KIND, either express or implied. See the License for the |
| 17 |
* specific language governing permissions and limitations |
| 18 |
* under the License. |
| 19 |
*/ |
| 20 |
|
| 21 |
class RequestTest extends BaseTest |
| 22 |
{ |
| 23 |
public function testRequestParameters() |
| 24 |
{ |
| 25 |
$url = 'http://localhost:8080/foo/bar?foo=a&foo=b&wowee=oh+my'; |
| 26 |
$url2 = 'http://localhost:8080/foo/bar?foo=a&foo=b&wowee=oh+my&hi=there'; |
| 27 |
$request = new Google_Http_Request($url); |
| 28 |
$request->setExpectedClass("Google_Client"); |
| 29 |
$this->assertEquals(2, count($request->getQueryParams())); |
| 30 |
$request->setQueryParam("hi", "there"); |
| 31 |
$this->assertEquals($url2, $request->getUrl()); |
| 32 |
$this->assertEquals("Google_Client", $request->getExpectedClass()); |
| 33 |
|
| 34 |
$urlPath = "/foo/bar"; |
| 35 |
$request = new Google_Http_Request($urlPath); |
| 36 |
$this->assertEquals($urlPath, $request->getUrl()); |
| 37 |
$request->setBaseComponent("http://example.com"); |
| 38 |
$this->assertEquals("http://example.com" . $urlPath, $request->getUrl()); |
| 39 |
|
| 40 |
$url3a = 'http://localhost:8080/foo/bar'; |
| 41 |
$url3b = 'foo=a&foo=b&wowee=oh+my'; |
| 42 |
$url3c = 'foo=a&foo=b&wowee=oh+my&hi=there'; |
| 43 |
$request = new Google_Http_Request($url3a."?".$url3b, "POST"); |
| 44 |
$request->setQueryParam("hi", "there"); |
| 45 |
$request->maybeMoveParametersToBody(); |
| 46 |
$this->assertEquals($url3a, $request->getUrl()); |
| 47 |
$this->assertEquals($url3c, $request->getPostBody()); |
| 48 |
|
| 49 |
$url4 = 'http://localhost:8080/upload/foo/bar?foo=a&foo=b&wowee=oh+my&hi=there'; |
| 50 |
$request = new Google_Http_Request($url); |
| 51 |
$this->assertEquals(2, count($request->getQueryParams())); |
| 52 |
$request->setQueryParam("hi", "there"); |
| 53 |
$base = $request->getBaseComponent(); |
| 54 |
$request->setBaseComponent($base . '/upload'); |
| 55 |
$this->assertEquals($url4, $request->getUrl()); |
| 56 |
} |
| 57 |
|
| 58 |
public function testGzipSupport() |
| 59 |
{ |
| 60 |
$url = 'http://localhost:8080/foo/bar?foo=a&foo=b&wowee=oh+my'; |
| 61 |
$request = new Google_Http_Request($url); |
| 62 |
$request->enableGzip(); |
| 63 |
$this->assertStringEndsWith(Google_Http_Request::GZIP_UA, $request->getUserAgent()); |
| 64 |
$this->assertArrayHasKey('accept-encoding', $request->getRequestHeaders()); |
| 65 |
$this->assertTrue($request->canGzip()); |
| 66 |
$request->disableGzip(); |
| 67 |
$this->assertStringEndsNotWith(Google_Http_Request::GZIP_UA, $request->getUserAgent()); |
| 68 |
$this->assertArrayNotHasKey('accept-encoding', $request->getRequestHeaders()); |
| 69 |
$this->assertFalse($request->canGzip()); |
| 70 |
} |
| 71 |
} |
| 72 |
|