Skip to content

Commit

Permalink
tests: change helper scope
Browse files Browse the repository at this point in the history
This seems to be the only way to have the same helpers used between
tests in a manner that works for both standalone phpunit and
autotest.sh.

Signed-off-by: Kyle Fazzari <kyrofa@ubuntu.com>
  • Loading branch information
kyrofa committed Nov 8, 2017
1 parent 06ba1a8 commit 5a69f9b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 38 deletions.
39 changes: 20 additions & 19 deletions tests/lib/Template/CSSResourceLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,6 @@
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;
Expand Down Expand Up @@ -95,6 +79,22 @@ private function cssResourceLocator() {
);
}

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);
Expand All @@ -107,7 +107,7 @@ public function testConstructor() {

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);
Expand Down Expand Up @@ -135,14 +135,15 @@ public function testFindWithAppPathSymlink() {
$file = $resource[2];

$expectedRoot = $new_apps_path . '/test-app';
$expectedWebRoot = '/apps-test/test-app';
$expectedWebRoot = \OC::$WEBROOT . '/apps-test/test-app';
$expectedFile = 'test-file.css';

$this->assertEquals($expectedRoot, $root,
'Ensure the app path symlink is resolved into the real path');
$this->assertEquals($expectedWebRoot, $webRoot);
$this->assertEquals($expectedFile, $file);

rrmdir($new_apps_path);
array_pop(\OC::$APPSROOTS);
$this->rrmdir($new_apps_path);
}
}
40 changes: 21 additions & 19 deletions tests/lib/Template/JSResourceLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,6 @@
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;
Expand Down Expand Up @@ -86,6 +70,23 @@ private function jsResourceLocator() {
);
}

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);
Expand All @@ -98,7 +99,7 @@ public function testConstructor() {

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);
Expand Down Expand Up @@ -126,14 +127,15 @@ public function testFindWithAppPathSymlink() {
$file = $resource[2];

$expectedRoot = $new_apps_path . '/test-app';
$expectedWebRoot = '/apps-test/test-app';
$expectedWebRoot = \OC::$WEBROOT . '/apps-test/test-app';
$expectedFile = 'test-file.js';

$this->assertEquals($expectedRoot, $root,
'Ensure the app path symlink is resolved into the real path');
$this->assertEquals($expectedWebRoot, $webRoot);
$this->assertEquals($expectedFile, $file);

rrmdir($new_apps_path);
array_pop(\OC::$APPSROOTS);
$this->rrmdir($new_apps_path);
}
}

0 comments on commit 5a69f9b

Please sign in to comment.