summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <Raydiation@users.noreply.github.com>2015-02-27 15:43:01 +0100
committerBernhard Posselt <Raydiation@users.noreply.github.com>2015-02-27 15:43:01 +0100
commit970b14d2979cb03d1e9ba96cbce3e43a52835333 (patch)
treefcfc92e273dbd8ab04663e5484a63194a22b43ed /tests
parent0c058490f4d6eeb7bfb066aa36cac635f5f9b175 (diff)
parent95239ad21e113d7d25d5844b0ac5f15a606f2140 (diff)
downloadnextcloud-server-970b14d2979cb03d1e9ba96cbce3e43a52835333.tar.gz
nextcloud-server-970b14d2979cb03d1e9ba96cbce3e43a52835333.zip
Merge pull request #13616 from owncloud/streamresponse
AppFramework StreamResponse
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/appframework/AppTest.php42
-rw-r--r--tests/lib/appframework/http/StreamResponseTest.php99
2 files changed, 128 insertions, 13 deletions
diff --git a/tests/lib/appframework/AppTest.php b/tests/lib/appframework/AppTest.php
index e60f3439f23..05190ca09b5 100644
--- a/tests/lib/appframework/AppTest.php
+++ b/tests/lib/appframework/AppTest.php
@@ -24,6 +24,9 @@
namespace OC\AppFramework;
+use OCP\AppFramework\Http\Response;
+
+
function rrmdir($directory) {
$files = array_diff(scandir($directory), array('.','..'));
foreach ($files as $file) {
@@ -36,9 +39,11 @@ function rrmdir($directory) {
return rmdir($directory);
}
+
class AppTest extends \Test\TestCase {
private $container;
+ private $io;
private $api;
private $controller;
private $dispatcher;
@@ -62,6 +67,7 @@ class AppTest extends \Test\TestCase {
->disableOriginalConstructor()
->getMock();
+ $this->io = $this->getMockBuilder('OCP\\AppFramework\\Http\\IOutput')->getMock();
$this->headers = array('key' => 'value');
$this->output = 'hi';
@@ -70,6 +76,7 @@ class AppTest extends \Test\TestCase {
$this->container[$this->controllerName] = $this->controller;
$this->container['Dispatcher'] = $this->dispatcher;
+ $this->container['OCP\\AppFramework\\Http\\IOutput'] = $this->io;
$this->container['urlParams'] = array();
$this->appPath = __DIR__ . '/../../../apps/namespacetestapp/appinfo';
@@ -86,14 +93,15 @@ class AppTest extends \Test\TestCase {
public function testControllerNameAndMethodAreBeingPassed(){
- $return = array(null, array(), array(), null);
+ $return = array(null, array(), array(), null, new Response());
$this->dispatcher->expects($this->once())
->method('dispatch')
->with($this->equalTo($this->controller),
$this->equalTo($this->controllerMethod))
->will($this->returnValue($return));
- $this->expectOutputString('');
+ $this->io->expects($this->never())
+ ->method('setOutput');
App::main($this->controllerName, $this->controllerMethod,
$this->container);
@@ -122,26 +130,34 @@ class AppTest extends \Test\TestCase {
rrmdir($this->appPath);
}
- /*
- FIXME: this complains about shit headers which are already sent because
- of the content length. Would be cool if someone could fix this
public function testOutputIsPrinted(){
- $return = array(null, array(), $this->output);
+ $return = [null, [], [], $this->output, new Response()];
$this->dispatcher->expects($this->once())
->method('dispatch')
->with($this->equalTo($this->controller),
$this->equalTo($this->controllerMethod))
->will($this->returnValue($return));
-
- $this->expectOutputString($this->output);
-
- App::main($this->controllerName, $this->controllerMethod, array(),
- $this->container);
+ $this->io->expects($this->once())
+ ->method('setOutput')
+ ->with($this->equalTo($this->output));
+ App::main($this->controllerName, $this->controllerMethod, $this->container, []);
}
- */
- // FIXME: if someone manages to test the headers output, I'd be grateful
+ public function testCallbackIsCalled(){
+ $mock = $this->getMockBuilder('OCP\AppFramework\Http\ICallbackResponse')
+ ->getMock();
+
+ $return = [null, [], [], $this->output, $mock];
+ $this->dispatcher->expects($this->once())
+ ->method('dispatch')
+ ->with($this->equalTo($this->controller),
+ $this->equalTo($this->controllerMethod))
+ ->will($this->returnValue($return));
+ $mock->expects($this->once())
+ ->method('callback');
+ App::main($this->controllerName, $this->controllerMethod, $this->container, []);
+ }
}
diff --git a/tests/lib/appframework/http/StreamResponseTest.php b/tests/lib/appframework/http/StreamResponseTest.php
new file mode 100644
index 00000000000..4c47ecfbd6c
--- /dev/null
+++ b/tests/lib/appframework/http/StreamResponseTest.php
@@ -0,0 +1,99 @@
+<?php
+
+/**
+ * ownCloud - App Framework
+ *
+ * @author Bernhard Posselt
+ * @copyright 2015 Bernhard Posselt <dev@bernhard-posselt.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+namespace OC\AppFramework\Http;
+
+
+use OCP\AppFramework\Http\StreamResponse;
+use OCP\AppFramework\Http;
+
+
+class StreamResponseTest extends \Test\TestCase {
+
+ /** @var IOutput */
+ private $output;
+
+ protected function setUp() {
+ parent::setUp();
+ $this->output = $this->getMock('OCP\\AppFramework\\Http\\IOutput');
+ }
+
+ public function testOutputNotModified(){
+ $path = __FILE__;
+ $this->output->expects($this->once())
+ ->method('getHttpResponseCode')
+ ->will($this->returnValue(Http::STATUS_NOT_MODIFIED));
+ $this->output->expects($this->never())
+ ->method('setReadfile');
+ $response = new StreamResponse($path);
+
+ $response->callback($this->output);
+ }
+
+ public function testOutputOk(){
+ $path = __FILE__;
+ $this->output->expects($this->once())
+ ->method('getHttpResponseCode')
+ ->will($this->returnValue(Http::STATUS_OK));
+ $this->output->expects($this->once())
+ ->method('setReadfile')
+ ->with($this->equalTo($path))
+ ->will($this->returnValue(true));
+ $response = new StreamResponse($path);
+
+ $response->callback($this->output);
+ }
+
+ public function testOutputNotFound(){
+ $path = __FILE__ . 'test';
+ $this->output->expects($this->once())
+ ->method('getHttpResponseCode')
+ ->will($this->returnValue(Http::STATUS_OK));
+ $this->output->expects($this->never())
+ ->method('setReadfile');
+ $this->output->expects($this->once())
+ ->method('setHttpResponseCode')
+ ->with($this->equalTo(Http::STATUS_NOT_FOUND));
+ $response = new StreamResponse($path);
+
+ $response->callback($this->output);
+ }
+
+ public function testOutputReadFileError(){
+ $path = __FILE__;
+ $this->output->expects($this->once())
+ ->method('getHttpResponseCode')
+ ->will($this->returnValue(Http::STATUS_OK));
+ $this->output->expects($this->once())
+ ->method('setReadfile')
+ ->will($this->returnValue(false));
+ $this->output->expects($this->once())
+ ->method('setHttpResponseCode')
+ ->with($this->equalTo(Http::STATUS_BAD_REQUEST));
+ $response = new StreamResponse($path);
+
+ $response->callback($this->output);
+ }
+
+}