Boilerplate to use a Directus Instance to Build a Custom Website, Content will be Manage by Directus
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
2.9 KiB

5 years ago
  1. <?php
  2. /**
  3. * Flight: An extensible micro-framework.
  4. *
  5. * @copyright Copyright (c) 2012, Mike Cao <mike@mikecao.com>
  6. * @license MIT, http://flightphp.com/license
  7. */
  8. require_once 'vendor/autoload.php';
  9. require_once __DIR__.'/../flight/autoload.php';
  10. class RequestTest extends PHPUnit_Framework_TestCase
  11. {
  12. /**
  13. * @var \flight\net\Request
  14. */
  15. private $request;
  16. function setUp() {
  17. $_SERVER['REQUEST_URI'] = '/';
  18. $_SERVER['SCRIPT_NAME'] = '/index.php';
  19. $_SERVER['REQUEST_METHOD'] = 'GET';
  20. $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
  21. $_SERVER['REMOTE_ADDR'] = '8.8.8.8';
  22. $_SERVER['HTTPS'] = 'on';
  23. $_SERVER['HTTP_X_FORWARDED_FOR'] = '32.32.32.32';
  24. $this->request = new \flight\net\Request();
  25. }
  26. function testDefaults() {
  27. $this->assertEquals('/', $this->request->url);
  28. $this->assertEquals('/', $this->request->base);
  29. $this->assertEquals('GET', $this->request->method);
  30. $this->assertEquals('', $this->request->referrer);
  31. $this->assertEquals(true, $this->request->ajax);
  32. $this->assertEquals('HTTP/1.1', $this->request->scheme);
  33. $this->assertEquals('', $this->request->type);
  34. $this->assertEquals(0, $this->request->length);
  35. $this->assertEquals(true, $this->request->secure);
  36. $this->assertEquals('', $this->request->accept);
  37. }
  38. function testIpAddress() {
  39. $this->assertEquals('8.8.8.8', $this->request->ip);
  40. $this->assertEquals('32.32.32.32', $this->request->proxy_ip);
  41. }
  42. function testSubdirectory() {
  43. $_SERVER['SCRIPT_NAME'] = '/subdir/index.php';
  44. $request = new \flight\net\Request();
  45. $this->assertEquals('/subdir', $request->base);
  46. }
  47. function testQueryParameters() {
  48. $_SERVER['REQUEST_URI'] = '/page?id=1&name=bob';
  49. $request = new \flight\net\Request();
  50. $this->assertEquals('/page?id=1&name=bob', $request->url);
  51. $this->assertEquals(1, $request->query->id);
  52. $this->assertEquals('bob', $request->query->name);
  53. }
  54. function testCollections() {
  55. $_SERVER['REQUEST_URI'] = '/page?id=1';
  56. $_GET['q'] = 1;
  57. $_POST['q'] = 1;
  58. $_COOKIE['q'] = 1;
  59. $_FILES['q'] = 1;
  60. $request = new \flight\net\Request();
  61. $this->assertEquals(1, $request->query->q);
  62. $this->assertEquals(1, $request->query->id);
  63. $this->assertEquals(1, $request->data->q);
  64. $this->assertEquals(1, $request->cookies->q);
  65. $this->assertEquals(1, $request->files->q);
  66. }
  67. function testMethodOverrideWithHeader() {
  68. $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'PUT';
  69. $request = new \flight\net\Request();
  70. $this->assertEquals('PUT', $request->method);
  71. }
  72. function testMethodOverrideWithPost() {
  73. $_REQUEST['_method'] = 'PUT';
  74. $request = new \flight\net\Request();
  75. $this->assertEquals('PUT', $request->method);
  76. }
  77. }