BrowserErrorPagePluginTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCA\DAV\Tests\unit\DAV;
  25. use OCA\DAV\Files\BrowserErrorPagePlugin;
  26. use PHPUnit_Framework_MockObject_MockObject;
  27. use Sabre\DAV\Exception\NotFound;
  28. use Sabre\HTTP\Response;
  29. class BrowserErrorPagePluginTest extends \Test\TestCase {
  30. /**
  31. * @dataProvider providesExceptions
  32. * @param $expectedCode
  33. * @param $exception
  34. */
  35. public function test($expectedCode, $exception) {
  36. /** @var BrowserErrorPagePlugin | PHPUnit_Framework_MockObject_MockObject $plugin */
  37. $plugin = $this->getMockBuilder(BrowserErrorPagePlugin::class)->setMethods(['sendResponse', 'generateBody'])->getMock();
  38. $plugin->expects($this->once())->method('generateBody')->willReturn(':boom:');
  39. $plugin->expects($this->once())->method('sendResponse');
  40. /** @var \Sabre\DAV\Server | PHPUnit_Framework_MockObject_MockObject $server */
  41. $server = $this->getMockBuilder('Sabre\DAV\Server')->disableOriginalConstructor()->getMock();
  42. $server->expects($this->once())->method('on');
  43. $httpResponse = $this->getMockBuilder(Response::class)->disableOriginalConstructor()->getMock();
  44. $httpResponse->expects($this->once())->method('addHeaders');
  45. $httpResponse->expects($this->once())->method('setStatus')->with($expectedCode);
  46. $httpResponse->expects($this->once())->method('setBody')->with(':boom:');
  47. $server->httpResponse = $httpResponse;
  48. $plugin->initialize($server);
  49. $plugin->logException($exception);
  50. }
  51. public function providesExceptions() {
  52. return [
  53. [ 404, new NotFound()],
  54. [ 500, new \RuntimeException()],
  55. ];
  56. }
  57. }