diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-01-02 15:03:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-02 15:03:07 +0100 |
commit | aac9a1c41adda69e8a1e4e2610b2a1f34b3284db (patch) | |
tree | 8018b98e0f5322c07b1b24f9b71f86fbea01192d /tests | |
parent | 99175c32e5305538e3ded6e80fbaa77cd8f7ebfb (diff) | |
parent | c0c4443ffc6608ea2917a9c5bec1c0150a94b404 (diff) | |
download | nextcloud-server-aac9a1c41adda69e8a1e4e2610b2a1f34b3284db.tar.gz nextcloud-server-aac9a1c41adda69e8a1e4e2610b2a1f34b3284db.zip |
Merge pull request #7631 from nextcloud/fix-scss-webroot-and-url-rewrite
Fix scss webroot and url rewrite
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/LegacyHelperTest.php | 11 | ||||
-rw-r--r-- | tests/lib/Template/SCSSCacherTest.php | 64 | ||||
-rw-r--r-- | tests/lib/UrlGeneratorTest.php | 10 |
3 files changed, 72 insertions, 13 deletions
diff --git a/tests/lib/LegacyHelperTest.php b/tests/lib/LegacyHelperTest.php index f1e22ea600e..736c5bf7fad 100644 --- a/tests/lib/LegacyHelperTest.php +++ b/tests/lib/LegacyHelperTest.php @@ -12,6 +12,17 @@ use OC\Files\View; use OC_Helper; class LegacyHelperTest extends \Test\TestCase { + /** @var string */ + private $originalWebRoot; + + public function setUp() { + $this->originalWebRoot = \OC::$WEBROOT; + } + + public function tearDown() { + // Reset webRoot + \OC::$WEBROOT = $this->originalWebRoot; + } /** * @dataProvider humanFileSizeProvider diff --git a/tests/lib/Template/SCSSCacherTest.php b/tests/lib/Template/SCSSCacherTest.php index 3825bc44c59..fca9500810e 100644 --- a/tests/lib/Template/SCSSCacherTest.php +++ b/tests/lib/Template/SCSSCacherTest.php @@ -352,19 +352,10 @@ class SCSSCacherTest extends \Test\TestCase { } public function testRebaseUrls() { - $webDir = 'apps/files/css'; + $webDir = '/apps/files/css'; $css = '#id { background-image: url(\'../img/image.jpg\'); }'; $actual = self::invokePrivate($this->scssCacher, 'rebaseUrls', [$css, $webDir]); - $expected = '#id { background-image: url(\'../../../apps/files/css/../img/image.jpg\'); }'; - $this->assertEquals($expected, $actual); - } - - public function testRebaseUrlsIgnoreFrontendController() { - $this->config->expects($this->once())->method('getSystemValue')->with('htaccess.IgnoreFrontController', false)->willReturn(true); - $webDir = 'apps/files/css'; - $css = '#id { background-image: url(\'../img/image.jpg\'); }'; - $actual = self::invokePrivate($this->scssCacher, 'rebaseUrls', [$css, $webDir]); - $expected = '#id { background-image: url(\'../../apps/files/css/../img/image.jpg\'); }'; + $expected = '#id { background-image: url(\'/apps/files/css/../img/image.jpg\'); }'; $this->assertEquals($expected, $actual); } @@ -393,4 +384,55 @@ class SCSSCacherTest extends \Test\TestCase { $this->assertEquals(substr($result, 1), $actual); } + private function randomString() { + return sha1(uniqid(mt_rand(), true)); + } + + private function rrmdir($directory) { + $files = array_diff(scandir($directory), array('.','..')); + foreach ($files as $file) { + if (is_dir($directory . '/' . $file)) { + $this->rrmdir($directory . '/' . $file); + } else { + unlink($directory . '/' . $file); + } + } + return rmdir($directory); + } + + public function dataGetWebDir() { + return [ + // Root installation + ['/http/core/css', 'core', '', '/http', '/core/css'], + ['/http/apps/scss/css', 'scss', '', '/http', '/apps/scss/css'], + ['/srv/apps2/scss/css', 'scss', '', '/http', '/apps2/scss/css'], + // Sub directory install + ['/http/nextcloud/core/css', 'core', '/nextcloud', '/http/nextcloud', '/nextcloud/core/css'], + ['/http/nextcloud/apps/scss/css', 'scss', '/nextcloud', '/http/nextcloud', '/nextcloud/apps/scss/css'], + ['/srv/apps2/scss/css', 'scss', '/nextcloud', '/http/nextcloud', '/apps2/scss/css'] + ]; + } + + /** + * @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); + $this->rrmdir($tmpDir.$path); + } + } diff --git a/tests/lib/UrlGeneratorTest.php b/tests/lib/UrlGeneratorTest.php index 69067f51e08..340c9c7082d 100644 --- a/tests/lib/UrlGeneratorTest.php +++ b/tests/lib/UrlGeneratorTest.php @@ -27,6 +27,8 @@ class UrlGeneratorTest extends \Test\TestCase { private $request; /** @var IURLGenerator */ private $urlGenerator; + /** @var string */ + private $originalWebRoot; public function setUp() { parent::setUp(); @@ -38,6 +40,12 @@ class UrlGeneratorTest extends \Test\TestCase { $this->cacheFactory, $this->request ); + $this->originalWebRoot = \OC::$WEBROOT; + } + + public function tearDown() { + // Reset webRoot + \OC::$WEBROOT = $this->originalWebRoot; } private function mockBaseUrl() { @@ -47,7 +55,6 @@ class UrlGeneratorTest extends \Test\TestCase { $this->request->expects($this->once()) ->method('getServerHost') ->willReturn('localhost'); - } /** @@ -156,4 +163,3 @@ class UrlGeneratorTest extends \Test\TestCase { } } - |