summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2015-03-11 12:52:18 +0100
committerLukas Reschke <lukas@owncloud.com>2015-03-11 12:52:18 +0100
commit8154ed4d2c924e134b4d1d6fa8cdd13b311cc75a (patch)
tree616e1b66ae90755ea00cf88dc00333234bc54eeb /tests
parent0d0f9a52d255aaccc553e3dcb3ab363b111c2b32 (diff)
parent0f3e36fdfd1c57f5212c495d59b0e5964df8a4ac (diff)
downloadnextcloud-server-8154ed4d2c924e134b4d1d6fa8cdd13b311cc75a.tar.gz
nextcloud-server-8154ed4d2c924e134b4d1d6fa8cdd13b311cc75a.zip
Merge pull request #14791 from owncloud/fix-14516
Adding a more meaningful message for sabre dav exception
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/connector/sabre/exceptionloggerplugin.php71
-rw-r--r--tests/lib/connector/sabre/file.php3
2 files changed, 71 insertions, 3 deletions
diff --git a/tests/lib/connector/sabre/exceptionloggerplugin.php b/tests/lib/connector/sabre/exceptionloggerplugin.php
new file mode 100644
index 00000000000..0662ba029d9
--- /dev/null
+++ b/tests/lib/connector/sabre/exceptionloggerplugin.php
@@ -0,0 +1,71 @@
+<?php
+
+/**
+ * Copyright (c) 2015 Thomas Müller <deepdiver@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Connector\Sabre;
+
+use OC\Connector\Sabre\Exception\InvalidPath;
+use OC\Connector\Sabre\ExceptionLoggerPlugin as PluginToTest;
+use OC\Log;
+use OCP\ILogger;
+use PHPUnit_Framework_MockObject_MockObject;
+use Sabre\DAV\Exception\NotFound;
+use Sabre\DAV\Server;
+use Test\TestCase;
+
+class TestLogger extends Log {
+ public $message;
+ public $level;
+
+ public function __construct($logger = null) {
+ //disable original constructor
+ }
+
+ public function log($level, $message, array $context = array()) {
+ $this->level = $level;
+ $this->message = $message;
+ }
+}
+
+class ExceptionLoggerPlugin extends TestCase {
+
+ /** @var Server */
+ private $server;
+
+ /** @var PluginToTest */
+ private $plugin;
+
+ /** @var TestLogger | PHPUnit_Framework_MockObject_MockObject */
+ private $logger;
+
+ private function init() {
+ $this->server = new Server();
+ $this->logger = new TestLogger();
+ $this->plugin = new PluginToTest('unit-test', $this->logger);
+ $this->plugin->initialize($this->server);
+ }
+
+ /**
+ * @dataProvider providesExceptions
+ */
+ public function testLogging($expectedLogLevel, $expectedMessage, $exception) {
+ $this->init();
+ $this->plugin->logException($exception);
+
+ $this->assertEquals($expectedLogLevel, $this->logger->level);
+ $this->assertStringStartsWith('Exception: {"Message":"' . $expectedMessage, $this->logger->message);
+ }
+
+ public function providesExceptions() {
+ return [
+ [0, 'HTTP\/1.1 404 Not Found', new NotFound()],
+ [4, 'HTTP\/1.1 400 This path leads to nowhere', new InvalidPath('This path leads to nowhere')]
+ ];
+ }
+
+}
diff --git a/tests/lib/connector/sabre/file.php b/tests/lib/connector/sabre/file.php
index f2812e390ac..74e289c1751 100644
--- a/tests/lib/connector/sabre/file.php
+++ b/tests/lib/connector/sabre/file.php
@@ -8,9 +8,6 @@
namespace Test\Connector\Sabre;
-
-use OC_Connector_Sabre_File;
-
class File extends \Test\TestCase {
/**