diff --git a/tests/lib/Template/CSSResourceLocatorTest.php b/tests/lib/Template/CSSResourceLocatorTest.php index bd13487282..a16cc18cb0 100644 --- a/tests/lib/Template/CSSResourceLocatorTest.php +++ b/tests/lib/Template/CSSResourceLocatorTest.php @@ -32,22 +32,6 @@ use OCP\ICache; use OC\Template\SCSSCacher; use OC\Template\CSSResourceLocator; -function rrmdir($directory) { - $files = array_diff(scandir($directory), array('.','..')); - foreach ($files as $file) { - if (is_dir($directory . '/' . $file)) { - rrmdir($directory . '/' . $file); - } else { - unlink($directory . '/' . $file); - } - } - return rmdir($directory); -} - -function randomString() { - return sha1(uniqid(mt_rand(), true)); -} - class CSSResourceLocatorTest extends \Test\TestCase { /** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */ protected $appData; @@ -95,6 +79,22 @@ class CSSResourceLocatorTest extends \Test\TestCase { ); } + 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); + } + + private function randomString() { + return sha1(uniqid(mt_rand(), true)); + } + public function testConstructor() { $locator = $this->cssResourceLocator(); $this->assertAttributeEquals('theme', 'theme', $locator); @@ -107,24 +107,24 @@ class CSSResourceLocatorTest extends \Test\TestCase { public function testFindWithAppPathSymlink() { // First create new apps path, and a symlink to it - $apps_dirname = randomString(); + $apps_dirname = $this->randomString(); $new_apps_path = sys_get_temp_dir() . '/' . $apps_dirname; $new_apps_path_symlink = $new_apps_path . '_link'; mkdir($new_apps_path); symlink($apps_dirname, $new_apps_path_symlink); // Create an app within that path - mkdir($new_apps_path . '/' . 'test-app'); + mkdir($new_apps_path . '/' . 'test-css-app'); // Use the symlink as the app path \OC::$APPSROOTS[] = [ 'path' => $new_apps_path_symlink, - 'url' => '/apps-test', + 'url' => '/css-apps-test', 'writable' => false, ]; $locator = $this->cssResourceLocator(); - $locator->find(array('test-app/test-file')); + $locator->find(array('test-css-app/test-file')); $resources = $locator->getResources(); $this->assertCount(1, $resources); @@ -134,8 +134,8 @@ class CSSResourceLocatorTest extends \Test\TestCase { $webRoot = $resource[1]; $file = $resource[2]; - $expectedRoot = $new_apps_path . '/test-app'; - $expectedWebRoot = '/apps-test/test-app'; + $expectedRoot = $new_apps_path . '/test-css-app'; + $expectedWebRoot = \OC::$WEBROOT . '/css-apps-test/test-css-app'; $expectedFile = 'test-file.css'; $this->assertEquals($expectedRoot, $root, @@ -143,6 +143,8 @@ class CSSResourceLocatorTest extends \Test\TestCase { $this->assertEquals($expectedWebRoot, $webRoot); $this->assertEquals($expectedFile, $file); - rrmdir($new_apps_path); + array_pop(\OC::$APPSROOTS); + unlink($new_apps_path_symlink); + $this->rrmdir($new_apps_path); } } diff --git a/tests/lib/Template/JSResourceLocatorTest.php b/tests/lib/Template/JSResourceLocatorTest.php index 49f0fb67f4..6841ee2fee 100644 --- a/tests/lib/Template/JSResourceLocatorTest.php +++ b/tests/lib/Template/JSResourceLocatorTest.php @@ -31,22 +31,6 @@ use OC\SystemConfig; use OCP\ILogger; use OC\Template\JSResourceLocator; -function rrmdir($directory) { - $files = array_diff(scandir($directory), array('.','..')); - foreach ($files as $file) { - if (is_dir($directory . '/' . $file)) { - rrmdir($directory . '/' . $file); - } else { - unlink($directory . '/' . $file); - } - } - return rmdir($directory); -} - -function randomString() { - return sha1(uniqid(mt_rand(), true)); -} - class JSResourceLocatorTest extends \Test\TestCase { /** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */ protected $appData; @@ -86,6 +70,23 @@ class JSResourceLocatorTest extends \Test\TestCase { ); } + 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); + } + + private function randomString() { + return sha1(uniqid(mt_rand(), true)); + } + + public function testConstructor() { $locator = $this->jsResourceLocator(); $this->assertAttributeEquals('theme', 'theme', $locator); @@ -98,24 +99,24 @@ class JSResourceLocatorTest extends \Test\TestCase { public function testFindWithAppPathSymlink() { // First create new apps path, and a symlink to it - $apps_dirname = randomString(); + $apps_dirname = $this->randomString(); $new_apps_path = sys_get_temp_dir() . '/' . $apps_dirname; $new_apps_path_symlink = $new_apps_path . '_link'; mkdir($new_apps_path); symlink($apps_dirname, $new_apps_path_symlink); // Create an app within that path - mkdir($new_apps_path . '/' . 'test-app'); + mkdir($new_apps_path . '/' . 'test-js-app'); // Use the symlink as the app path \OC::$APPSROOTS[] = [ 'path' => $new_apps_path_symlink, - 'url' => '/apps-test', + 'url' => '/js-apps-test', 'writable' => false, ]; $locator = $this->jsResourceLocator(); - $locator->find(array('test-app/test-file')); + $locator->find(array('test-js-app/test-file')); $resources = $locator->getResources(); $this->assertCount(1, $resources); @@ -125,8 +126,8 @@ class JSResourceLocatorTest extends \Test\TestCase { $webRoot = $resource[1]; $file = $resource[2]; - $expectedRoot = $new_apps_path . '/test-app'; - $expectedWebRoot = '/apps-test/test-app'; + $expectedRoot = $new_apps_path . '/test-js-app'; + $expectedWebRoot = \OC::$WEBROOT . '/js-apps-test/test-js-app'; $expectedFile = 'test-file.js'; $this->assertEquals($expectedRoot, $root, @@ -134,6 +135,8 @@ class JSResourceLocatorTest extends \Test\TestCase { $this->assertEquals($expectedWebRoot, $webRoot); $this->assertEquals($expectedFile, $file); - rrmdir($new_apps_path); + array_pop(\OC::$APPSROOTS); + unlink($new_apps_path_symlink); + $this->rrmdir($new_apps_path); } }