1
0

HttpTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * ownCloud - App Framework
  4. *
  5. * @author Bernhard Posselt
  6. * @copyright 2012 Bernhard Posselt <dev@bernhard-posselt.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 Test\AppFramework\Http;
  23. use OC\AppFramework\Http;
  24. class HttpTest extends \Test\TestCase {
  25. private $server;
  26. /**
  27. * @var Http
  28. */
  29. private $http;
  30. protected function setUp(){
  31. parent::setUp();
  32. $this->server = array();
  33. $this->http = new Http($this->server);
  34. }
  35. public function testProtocol() {
  36. $header = $this->http->getStatusHeader(Http::STATUS_TEMPORARY_REDIRECT);
  37. $this->assertEquals('HTTP/1.1 307 Temporary Redirect', $header);
  38. }
  39. public function testProtocol10() {
  40. $this->http = new Http($this->server, 'HTTP/1.0');
  41. $header = $this->http->getStatusHeader(Http::STATUS_OK);
  42. $this->assertEquals('HTTP/1.0 200 OK', $header);
  43. }
  44. public function testEtagMatchReturnsNotModified() {
  45. $http = new Http(array('HTTP_IF_NONE_MATCH' => 'hi'));
  46. $header = $http->getStatusHeader(Http::STATUS_OK, null, 'hi');
  47. $this->assertEquals('HTTP/1.1 304 Not Modified', $header);
  48. }
  49. public function testQuotedEtagMatchReturnsNotModified() {
  50. $http = new Http(array('HTTP_IF_NONE_MATCH' => '"hi"'));
  51. $header = $http->getStatusHeader(Http::STATUS_OK, null, 'hi');
  52. $this->assertEquals('HTTP/1.1 304 Not Modified', $header);
  53. }
  54. public function testLastModifiedMatchReturnsNotModified() {
  55. $dateTime = new \DateTime(null, new \DateTimeZone('GMT'));
  56. $dateTime->setTimestamp('12');
  57. $http = new Http(
  58. array(
  59. 'HTTP_IF_MODIFIED_SINCE' => 'Thu, 01 Jan 1970 00:00:12 +0000')
  60. );
  61. $header = $http->getStatusHeader(Http::STATUS_OK, $dateTime);
  62. $this->assertEquals('HTTP/1.1 304 Not Modified', $header);
  63. }
  64. public function testTempRedirectBecomesFoundInHttp10() {
  65. $http = new Http(array(), 'HTTP/1.0');
  66. $header = $http->getStatusHeader(Http::STATUS_TEMPORARY_REDIRECT);
  67. $this->assertEquals('HTTP/1.0 302 Found', $header);
  68. }
  69. // TODO: write unittests for http codes
  70. }