1
0

StreamResponseTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * ownCloud - App Framework
  4. *
  5. * @author Bernhard Posselt
  6. * @copyright 2015 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 Test\AppFramework\Http;
  23. use OCP\AppFramework\Http\StreamResponse;
  24. use OCP\AppFramework\Http\IOutput;
  25. use OCP\AppFramework\Http;
  26. class StreamResponseTest extends \Test\TestCase {
  27. /** @var IOutput */
  28. private $output;
  29. protected function setUp() {
  30. parent::setUp();
  31. $this->output = $this->getMockBuilder('OCP\\AppFramework\\Http\\IOutput')
  32. ->disableOriginalConstructor()
  33. ->getMock();
  34. }
  35. public function testOutputNotModified(){
  36. $path = __FILE__;
  37. $this->output->expects($this->once())
  38. ->method('getHttpResponseCode')
  39. ->will($this->returnValue(Http::STATUS_NOT_MODIFIED));
  40. $this->output->expects($this->never())
  41. ->method('setReadfile');
  42. $response = new StreamResponse($path);
  43. $response->callback($this->output);
  44. }
  45. public function testOutputOk(){
  46. $path = __FILE__;
  47. $this->output->expects($this->once())
  48. ->method('getHttpResponseCode')
  49. ->will($this->returnValue(Http::STATUS_OK));
  50. $this->output->expects($this->once())
  51. ->method('setReadfile')
  52. ->with($this->equalTo($path))
  53. ->will($this->returnValue(true));
  54. $response = new StreamResponse($path);
  55. $response->callback($this->output);
  56. }
  57. public function testOutputNotFound(){
  58. $path = __FILE__ . 'test';
  59. $this->output->expects($this->once())
  60. ->method('getHttpResponseCode')
  61. ->will($this->returnValue(Http::STATUS_OK));
  62. $this->output->expects($this->never())
  63. ->method('setReadfile');
  64. $this->output->expects($this->once())
  65. ->method('setHttpResponseCode')
  66. ->with($this->equalTo(Http::STATUS_NOT_FOUND));
  67. $response = new StreamResponse($path);
  68. $response->callback($this->output);
  69. }
  70. public function testOutputReadFileError(){
  71. $path = __FILE__;
  72. $this->output->expects($this->once())
  73. ->method('getHttpResponseCode')
  74. ->will($this->returnValue(Http::STATUS_OK));
  75. $this->output->expects($this->once())
  76. ->method('setReadfile')
  77. ->will($this->returnValue(false));
  78. $this->output->expects($this->once())
  79. ->method('setHttpResponseCode')
  80. ->with($this->equalTo(Http::STATUS_BAD_REQUEST));
  81. $response = new StreamResponse($path);
  82. $response->callback($this->output);
  83. }
  84. }