MiddlewareTest.php 2.5 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 OC\AppFramework;
  23. use OC\AppFramework\Http\Request;
  24. use OCP\AppFramework\Middleware;
  25. use OCP\AppFramework\Http\Response;
  26. class ChildMiddleware extends Middleware {};
  27. class MiddlewareTest extends \Test\TestCase {
  28. /**
  29. * @var Middleware
  30. */
  31. private $middleware;
  32. private $controller;
  33. private $exception;
  34. private $api;
  35. /** @var Response */
  36. private $response;
  37. protected function setUp(){
  38. parent::setUp();
  39. $this->middleware = new ChildMiddleware();
  40. $this->api = $this->getMockBuilder(
  41. 'OC\AppFramework\DependencyInjection\DIContainer')
  42. ->disableOriginalConstructor()
  43. ->getMock();
  44. $this->controller = $this->getMock(
  45. 'OCP\AppFramework\Controller',
  46. [],
  47. [
  48. $this->api,
  49. new Request(
  50. [],
  51. $this->getMock('\OCP\Security\ISecureRandom'),
  52. $this->getMock('\OCP\IConfig')
  53. )
  54. ]
  55. );
  56. $this->exception = new \Exception();
  57. $this->response = $this->getMock('OCP\AppFramework\Http\Response');
  58. }
  59. public function testBeforeController() {
  60. $this->middleware->beforeController($this->controller, null);
  61. $this->assertNull(null);
  62. }
  63. public function testAfterExceptionRaiseAgainWhenUnhandled() {
  64. $this->setExpectedException('Exception');
  65. $afterEx = $this->middleware->afterException($this->controller, null, $this->exception);
  66. }
  67. public function testAfterControllerReturnResponseWhenUnhandled() {
  68. $response = $this->middleware->afterController($this->controller, null, $this->response);
  69. $this->assertEquals($this->response, $response);
  70. }
  71. public function testBeforeOutputReturnOutputhenUnhandled() {
  72. $output = $this->middleware->beforeOutput($this->controller, null, 'test');
  73. $this->assertEquals('test', $output);
  74. }
  75. }