HttpTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * ownCloud - App Framework
  4. *
  5. * @author Bernhard Posselt
  6. * @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. namespace OC\AppFramework\Http;
  23. use OC\AppFramework\Http;
  24. //require_once(__DIR__ . "/../classloader.php");
  25. class HttpTest extends \PHPUnit_Framework_TestCase {
  26. private $server;
  27. private $http;
  28. protected function setUp(){
  29. $this->server = array();
  30. $this->http = new Http($this->server);
  31. }
  32. public function testProtocol() {
  33. $header = $this->http->getStatusHeader(Http::STATUS_TEMPORARY_REDIRECT);
  34. $this->assertEquals('HTTP/1.1 307 Temporary Redirect', $header);
  35. }
  36. public function testProtocol10() {
  37. $this->http = new Http($this->server, 'HTTP/1.0');
  38. $header = $this->http->getStatusHeader(Http::STATUS_OK);
  39. $this->assertEquals('HTTP/1.0 200 OK', $header);
  40. }
  41. public function testEtagMatchReturnsNotModified() {
  42. $http = new Http(array('HTTP_IF_NONE_MATCH' => 'hi'));
  43. $header = $http->getStatusHeader(Http::STATUS_OK, null, 'hi');
  44. $this->assertEquals('HTTP/1.1 304 Not Modified', $header);
  45. }
  46. public function testLastModifiedMatchReturnsNotModified() {
  47. $dateTime = new \DateTime(null, new \DateTimeZone('GMT'));
  48. $dateTime->setTimestamp('12');
  49. $http = new Http(
  50. array(
  51. 'HTTP_IF_MODIFIED_SINCE' => 'Thu, 01 Jan 1970 00:00:12 +0000')
  52. );
  53. $header = $http->getStatusHeader(Http::STATUS_OK, $dateTime);
  54. $this->assertEquals('HTTP/1.1 304 Not Modified', $header);
  55. }
  56. public function testTempRedirectBecomesFoundInHttp10() {
  57. $http = new Http(array(), 'HTTP/1.0');
  58. $header = $http->getStatusHeader(Http::STATUS_TEMPORARY_REDIRECT);
  59. $this->assertEquals('HTTP/1.0 302 Found', $header);
  60. }
  61. // TODO: write unittests for http codes
  62. }