HttpTest.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace Test\AppFramework\Http;
  8. use OC\AppFramework\Http;
  9. class HttpTest extends \Test\TestCase {
  10. private $server;
  11. /**
  12. * @var Http
  13. */
  14. private $http;
  15. protected function setUp(): void {
  16. parent::setUp();
  17. $this->server = [];
  18. $this->http = new Http($this->server);
  19. }
  20. public function testProtocol(): void {
  21. $header = $this->http->getStatusHeader(Http::STATUS_TEMPORARY_REDIRECT);
  22. $this->assertEquals('HTTP/1.1 307 Temporary Redirect', $header);
  23. }
  24. public function testProtocol10(): void {
  25. $this->http = new Http($this->server, 'HTTP/1.0');
  26. $header = $this->http->getStatusHeader(Http::STATUS_OK);
  27. $this->assertEquals('HTTP/1.0 200 OK', $header);
  28. }
  29. public function testTempRedirectBecomesFoundInHttp10(): void {
  30. $http = new Http([], 'HTTP/1.0');
  31. $header = $http->getStatusHeader(Http::STATUS_TEMPORARY_REDIRECT);
  32. $this->assertEquals('HTTP/1.0 302 Found', $header);
  33. }
  34. // TODO: write unittests for http codes
  35. }