[Pkg-owncloud-commits] [owncloud] 29/46: Add unit tests for convertToRelativePath

David Prévot taffit at moszumanska.debian.org
Fri Oct 24 15:11:43 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit 7ffe80cf259945ca85a3dde396b2fb7ef0df2af8
Author: Lukas Reschke <lukas at owncloud.com>
Date:   Wed Oct 15 13:43:04 2014 +0200

    Add unit tests for convertToRelativePath
---
 lib/private/request.php      |  2 +-
 tests/lib/templatelayout.php | 44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/lib/private/request.php b/lib/private/request.php
index 5fd5b3a..221a21a 100755
--- a/lib/private/request.php
+++ b/lib/private/request.php
@@ -205,7 +205,7 @@ class OC_Request {
 	 * @return string Path info or false when not found
 	 */
 	public static function getRawPathInfo() {
-		$requestUri = $_SERVER['REQUEST_URI'];
+		$requestUri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
 		// remove too many leading slashes - can be caused by reverse proxy configuration
 		if (strpos($requestUri, '/') === 0) {
 			$requestUri = '/' . ltrim($requestUri, '/');
diff --git a/tests/lib/templatelayout.php b/tests/lib/templatelayout.php
new file mode 100644
index 0000000..f87db4f
--- /dev/null
+++ b/tests/lib/templatelayout.php
@@ -0,0 +1,44 @@
+<?php
+/**
+ * Copyright (c) 2014 Lukas Reschke <lukas at owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Test;
+
+/**
+ * @package OC\Test
+ */
+class OC_TemplateLayout extends \PHPUnit_Framework_TestCase {
+
+	/**
+	 * Contains valid file paths in the scheme array($absolutePath, $expectedPath)
+	 * @return array
+	 */
+	public function validFilePathProvider() {
+		return array(
+			array(\OC::$SERVERROOT . '/apps/files/js/fancyJS.js', '/apps/files/js/fancyJS.js'),
+			array(\OC::$SERVERROOT. '/test.js', '/test.js'),
+			array(\OC::$SERVERROOT . '/core/test.js', '/core/test.js'),
+			array(\OC::$SERVERROOT, ''),
+		);
+	}
+
+	/**
+	 * @dataProvider validFilePathProvider
+	 */
+	public function testConvertToRelativePath($absolutePath, $expected) {
+		$relativePath = \Test_Helper::invokePrivate(new \OC_TemplateLayout('user'), 'convertToRelativePath', array($absolutePath));
+		$this->assertEquals($expected, $relativePath);
+	}
+
+	/**
+	 * @expectedException \Exception
+	 * @expectedExceptionMessage $filePath is not under the \OC::$SERVERROOT
+	 */
+	public function testInvalidConvertToRelativePath() {
+		\Test_Helper::invokePrivate(new \OC_TemplateLayout('user'), 'convertToRelativePath', array('/this/file/is/invalid'));
+	}
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list