From: Lukas Reschke Date: Wed, 15 Oct 2014 11:43:04 +0000 (+0200) Subject: Add unit tests for convertToRelativePath X-Git-Tag: v8.0.0alpha1~474^2~2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8f8abdbaeef7bcaff1f822714a7f227933cc43c1;p=nextcloud-server.git Add unit tests for convertToRelativePath --- diff --git a/lib/private/request.php b/lib/private/request.php index fa446837a97..1cfa4a150c5 100755 --- a/lib/private/request.php +++ b/lib/private/request.php @@ -245,7 +245,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')); + } +}