RequestTest.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. class RequestTest extends BaseTest
  21. {
  22. public function testRequestParameters()
  23. {
  24. $url = 'http://localhost:8080/foo/bar?foo=a&foo=b&wowee=oh+my';
  25. $url2 = 'http://localhost:8080/foo/bar?foo=a&foo=b&wowee=oh+my&hi=there';
  26. $request = new Google_Http_Request($url);
  27. $request->setExpectedClass("Google_Client");
  28. $this->assertEquals(2, count($request->getQueryParams()));
  29. $request->setQueryParam("hi", "there");
  30. $this->assertEquals($url2, $request->getUrl());
  31. $this->assertEquals("Google_Client", $request->getExpectedClass());
  32. $urlPath = "/foo/bar";
  33. $request = new Google_Http_Request($urlPath);
  34. $this->assertEquals($urlPath, $request->getUrl());
  35. $request->setBaseComponent("http://example.com");
  36. $this->assertEquals("http://example.com" . $urlPath, $request->getUrl());
  37. $url3a = 'http://localhost:8080/foo/bar';
  38. $url3b = 'foo=a&foo=b&wowee=oh+my';
  39. $url3c = 'foo=a&foo=b&wowee=oh+my&hi=there';
  40. $request = new Google_Http_Request($url3a."?".$url3b, "POST");
  41. $request->setQueryParam("hi", "there");
  42. $request->maybeMoveParametersToBody();
  43. $this->assertEquals($url3a, $request->getUrl());
  44. $this->assertEquals($url3c, $request->getPostBody());
  45. $url4 = 'http://localhost:8080/upload/foo/bar?foo=a&foo=b&wowee=oh+my&hi=there';
  46. $request = new Google_Http_Request($url);
  47. $this->assertEquals(2, count($request->getQueryParams()));
  48. $request->setQueryParam("hi", "there");
  49. $base = $request->getBaseComponent();
  50. $request->setBaseComponent($base . '/upload');
  51. $this->assertEquals($url4, $request->getUrl());
  52. }
  53. public function testGzipSupport()
  54. {
  55. $url = 'http://localhost:8080/foo/bar?foo=a&foo=b&wowee=oh+my';
  56. $request = new Google_Http_Request($url);
  57. $request->enableGzip();
  58. $this->assertStringEndsWith(Google_Http_Request::GZIP_UA, $request->getUserAgent());
  59. $this->assertArrayHasKey('accept-encoding', $request->getRequestHeaders());
  60. $this->assertTrue($request->canGzip());
  61. $request->disableGzip();
  62. $this->assertStringEndsNotWith(Google_Http_Request::GZIP_UA, $request->getUserAgent());
  63. $this->assertArrayNotHasKey('accept-encoding', $request->getRequestHeaders());
  64. $this->assertFalse($request->canGzip());
  65. }
  66. }