Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Dec 30, 2017
1 parent b71c920 commit c0c4443
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/private/Template/SCSSCacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ private function prependBaseurlPrefix($cssFile) {
*/
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, $serverRoot) && $appWebPath = \OC_App::getAppWebPath($appName) ) {
if ( strpos($path, $serverRoot) === false && $appWebPath = \OC_App::getAppWebPath($appName)) {
// Get the file path within the app directory
$appDirectoryPath = explode($appName, $path)[1];
// Remove the webroot
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/LegacyHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
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
Expand Down
24 changes: 13 additions & 11 deletions tests/lib/Template/SCSSCacherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,17 +384,6 @@ public function testGetCachedSCSS($appName, $fileName, $result) {
$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));
}
Expand All @@ -411,6 +400,19 @@ private function rrmdir($directory) {
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
Expand Down
10 changes: 8 additions & 2 deletions tests/lib/UrlGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class UrlGeneratorTest extends \Test\TestCase {
private $request;
/** @var IURLGenerator */
private $urlGenerator;
/** @var string */
private $originalWebRoot;

public function setUp() {
parent::setUp();
Expand All @@ -38,6 +40,12 @@ public function setUp() {
$this->cacheFactory,
$this->request
);
$this->originalWebRoot = \OC::$WEBROOT;
}

public function tearDown() {
// Reset webRoot
\OC::$WEBROOT = $this->originalWebRoot;
}

private function mockBaseUrl() {
Expand All @@ -47,7 +55,6 @@ private function mockBaseUrl() {
$this->request->expects($this->once())
->method('getServerHost')
->willReturn('localhost');

}

/**
Expand Down Expand Up @@ -156,4 +163,3 @@ public function testGetBaseUrl() {
}

}

0 comments on commit c0c4443

Please sign in to comment.