request.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. class requestTest extends PHPUnit_Framework_TestCase
  3. {
  4. private $_request;
  5. public function setUp()
  6. {
  7. /* Setup Routine */
  8. }
  9. public function tearDown()
  10. {
  11. /* Tear Down Routine */
  12. }
  13. public function reset()
  14. {
  15. $_SERVER = array();
  16. $_GET = array();
  17. $_POST = array();
  18. }
  19. public function testView()
  20. {
  21. $this->reset();
  22. $_SERVER['REQUEST_METHOD'] = 'GET';
  23. $request = new request;
  24. $this->assertFalse($request->isJsonApiCall(), 'is HTML call');
  25. $this->assertEquals('view', $request->getOperation());
  26. }
  27. public function testRead()
  28. {
  29. $this->reset();
  30. $_SERVER['REQUEST_METHOD'] = 'GET';
  31. $_SERVER['QUERY_STRING'] = 'foo';
  32. $request = new request;
  33. $this->assertFalse($request->isJsonApiCall(), 'is HTML call');
  34. $this->assertEquals('foo', $request->getParam('pasteid'));
  35. $this->assertEquals('read', $request->getOperation());
  36. }
  37. public function testDelete()
  38. {
  39. $this->reset();
  40. $_SERVER['REQUEST_METHOD'] = 'GET';
  41. $_GET['pasteid'] = 'foo';
  42. $_GET['deletetoken'] = 'bar';
  43. $request = new request;
  44. $this->assertFalse($request->isJsonApiCall(), 'is HTML call');
  45. $this->assertEquals('delete', $request->getOperation());
  46. $this->assertEquals('foo', $request->getParam('pasteid'));
  47. $this->assertEquals('bar', $request->getParam('deletetoken'));
  48. }
  49. public function testApiCreate()
  50. {
  51. $this->reset();
  52. $_SERVER['REQUEST_METHOD'] = 'PUT';
  53. $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
  54. $_POST['data'] = 'foo';
  55. $request = new request;
  56. $this->assertTrue($request->isJsonApiCall(), 'is JSON Api call');
  57. $this->assertEquals('create', $request->getOperation());
  58. $this->assertEquals('foo', $request->getParam('data'));
  59. }
  60. public function testApiCreateAlternative()
  61. {
  62. $this->reset();
  63. $_SERVER['REQUEST_METHOD'] = 'POST';
  64. $_SERVER['HTTP_ACCEPT'] = 'application/json, text/javascript, */*; q=0.01';
  65. $_POST['attachment'] = 'foo';
  66. $request = new request;
  67. $this->assertTrue($request->isJsonApiCall(), 'is JSON Api call');
  68. $this->assertEquals('create', $request->getOperation());
  69. $this->assertEquals('foo', $request->getParam('attachment'));
  70. }
  71. public function testApiRead()
  72. {
  73. $this->reset();
  74. $_SERVER['REQUEST_METHOD'] = 'GET';
  75. $_SERVER['HTTP_ACCEPT'] = 'application/json, text/javascript, */*; q=0.01';
  76. $_SERVER['QUERY_STRING'] = 'foo';
  77. $request = new request;
  78. $this->assertTrue($request->isJsonApiCall(), 'is JSON Api call');
  79. $this->assertEquals('foo', $request->getParam('pasteid'));
  80. $this->assertEquals('read', $request->getOperation());
  81. }
  82. public function testApiDelete()
  83. {
  84. $this->reset();
  85. $_SERVER['REQUEST_METHOD'] = 'DELETE';
  86. $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
  87. $_GET['pasteid'] = 'foo';
  88. $_GET['deletetoken'] = 'bar';
  89. $request = new request;
  90. $this->assertTrue($request->isJsonApiCall(), 'is JSON Api call');
  91. $this->assertEquals('delete', $request->getOperation());
  92. $this->assertEquals('foo', $request->getParam('pasteid'));
  93. $this->assertEquals('bar', $request->getParam('deletetoken'));
  94. }
  95. }