From 7ffe80cf259945ca85a3dde396b2fb7ef0df2af8 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Wed, 15 Oct 2014 13:43:04 +0200 Subject: [PATCH] Add unit tests for convertToRelativePath --- lib/private/request.php | 2 +- tests/lib/templatelayout.php | 44 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 tests/lib/templatelayout.php diff --git a/lib/private/request.php b/lib/private/request.php index 5fd5b3a7197..221a21a258f 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 00000000000..f87db4fa54b --- /dev/null +++ b/tests/lib/templatelayout.php @@ -0,0 +1,44 @@ + + * 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')); + } +} -- 2.39.5