]> source.dussan.org Git - nextcloud-server.git/commitdiff
Added tests for various installations types
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Thu, 28 Dec 2017 12:32:45 +0000 (13:32 +0100)
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Wed, 3 Jan 2018 21:05:02 +0000 (22:05 +0100)
- With root installation
 - Core css
 - App inside server root
 - Secondary apps directory outside server root
- With an installation in a sub directory
 - Core css
 - App inside server root
 - Secondary apps directory outside server root

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
lib/private/Template/SCSSCacher.php
tests/lib/Template/SCSSCacherTest.php

index 2f63b425a1e8208b998ca453ca7cf9c012937cdd..5b904bced65ef98a9552ed45b6309a1c87382f82 100644 (file)
@@ -102,7 +102,7 @@ class SCSSCacher {
                $fileNameCSS = $this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileNameSCSS));
 
                $path = implode('/', $path);
-               $webDir = $this->getWebDir($path, $app);
+               $webDir = $this->getWebDir($path, $app, $this->serverRoot, \OC::$WEBROOT);
 
                try {
                        $folder = $this->appData->getFolder($app);
@@ -187,7 +187,7 @@ class SCSSCacher {
                $scss = new Compiler();
                $scss->setImportPaths([
                        $path,
-                       \OC::$SERVERROOT . '/core/css/',
+                       $this->serverRoot . '/core/css/',
                ]);
                // Continue after throw
                $scss->setIgnoreErrors(true);
@@ -312,17 +312,19 @@ class SCSSCacher {
        /**
         * Get WebDir root
         * @param string $path the css file path
-        * @param string $app the app name
+        * @param string $appName the app name
+        * @param string $serverRoot the server root path
+        * @param string $webRoot the nextcloud installation root path
         * @return string the webDir
         */
-       private function getWebDir($path, $app) {
+       private function getWebDir($path, $appName, $serverRoot, $webRoot) {
                // Detect if path is within server root AND if path is within an app path
-               if ( strpos($path, $this->serverRoot) === -1 && $appWebPath = \OC_App::getAppWebPath($app) ) {
+               if ( !strpos($path, $serverRoot) && $appWebPath = \OC_App::getAppWebPath($appName) ) {
                        // Get the file path within the app directory
-                       $appDirectoryPath = explode($app, $path)[1];
+                       $appDirectoryPath = explode($appName, $path)[1];
                        // Remove the webroot
-                       return str_replace(\OC::$WEBROOT, '', $appWebPath.$appDirectoryPath);
+                       return str_replace($webRoot, '', $appWebPath.$appDirectoryPath);
                }
-               return \OC::$WEBROOT.substr($path, strlen($this->serverRoot));
+               return $webRoot.substr($path, strlen($serverRoot));
        }
 }
index 1df8e86f93ca56d36a93946b65978ec47602eb63..97a2879c94218bc89ac65b3c3135014b6169f54b 100644 (file)
@@ -384,4 +384,41 @@ class SCSSCacherTest extends \Test\TestCase {
                $this->assertEquals(substr($result, 1), $actual);
        }
 
+       public function dataGetWebDir() {
+               return [
+                       ['/http/core/css', 'core', '', '/http', '/core/css'],
+                       ['/http/apps/test/css', 'test', '', '/http', '/apps/test/css'],
+                       ['/http/nextcloud/core/css', 'core', '/nextcloud', '/http/nextcloud', '/nextcloud/core/css'],
+                       ['/http/nextcloud/apps/test/css', 'test', '/nextcloud', '/http/nextcloud', '/nextcloud/apps/test/css'],
+                       ['/srv/apps2/test/css', 'test', '', '/http', '/apps2/test/css'],
+                       ['/srv/apps2/test/css', 'test', '/nextcloud', '/http/nextcloud', '/apps2/test/css']
+               ];
+       }
+
+       private function randomString() {
+               return sha1(uniqid(mt_rand(), true));
+       }
+
+       /**
+        * @param $path
+        * @param $appName
+        * @param $webRoot
+        * @param $serverRoot
+        * @dataProvider dataGetWebDir
+        */
+       public function testgetWebDir($path, $appName, $webRoot, $serverRoot, $correctWebDir) {
+               $tmpDir = sys_get_temp_dir().'/'.$this->randomString();
+               // Adding fake apps folder and create fake app install
+               \OC::$APPSROOTS[] = [
+                       'path' => $tmpDir.'/srv/apps2',
+                       'url' => '/apps2',
+                       'writable' => false
+               ];
+               mkdir($tmpDir.$path, 0777, true);
+               $actual = self::invokePrivate($this->scssCacher, 'getWebDir', [$tmpDir.$path, $appName, $tmpDir.$serverRoot, $webRoot]);
+               $this->assertEquals($correctWebDir, $actual);
+               array_pop(\OC::$APPSROOTS);
+               rmdir($tmpDir.$path);
+       }
+
 }