Skip to content

Commit 5a69f9b

Browse files
committed
tests: change helper scope
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>
1 parent 06ba1a8 commit 5a69f9b

2 files changed

Lines changed: 41 additions & 38 deletions

File tree

tests/lib/Template/CSSResourceLocatorTest.php

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,6 @@
3232
use OC\Template\SCSSCacher;
3333
use OC\Template\CSSResourceLocator;
3434

35-
function rrmdir($directory) {
36-
$files = array_diff(scandir($directory), array('.','..'));
37-
foreach ($files as $file) {
38-
if (is_dir($directory . '/' . $file)) {
39-
rrmdir($directory . '/' . $file);
40-
} else {
41-
unlink($directory . '/' . $file);
42-
}
43-
}
44-
return rmdir($directory);
45-
}
46-
47-
function randomString() {
48-
return sha1(uniqid(mt_rand(), true));
49-
}
50-
5135
class CSSResourceLocatorTest extends \Test\TestCase {
5236
/** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */
5337
protected $appData;
@@ -95,6 +79,22 @@ private function cssResourceLocator() {
9579
);
9680
}
9781

82+
private function rrmdir($directory) {
83+
$files = array_diff(scandir($directory), array('.','..'));
84+
foreach ($files as $file) {
85+
if (is_dir($directory . '/' . $file)) {
86+
$this->rrmdir($directory . '/' . $file);
87+
} else {
88+
unlink($directory . '/' . $file);
89+
}
90+
}
91+
return rmdir($directory);
92+
}
93+
94+
private function randomString() {
95+
return sha1(uniqid(mt_rand(), true));
96+
}
97+
9898
public function testConstructor() {
9999
$locator = $this->cssResourceLocator();
100100
$this->assertAttributeEquals('theme', 'theme', $locator);
@@ -107,7 +107,7 @@ public function testConstructor() {
107107

108108
public function testFindWithAppPathSymlink() {
109109
// First create new apps path, and a symlink to it
110-
$apps_dirname = randomString();
110+
$apps_dirname = $this->randomString();
111111
$new_apps_path = sys_get_temp_dir() . '/' . $apps_dirname;
112112
$new_apps_path_symlink = $new_apps_path . '_link';
113113
mkdir($new_apps_path);
@@ -135,14 +135,15 @@ public function testFindWithAppPathSymlink() {
135135
$file = $resource[2];
136136

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

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

146-
rrmdir($new_apps_path);
146+
array_pop(\OC::$APPSROOTS);
147+
$this->rrmdir($new_apps_path);
147148
}
148149
}

tests/lib/Template/JSResourceLocatorTest.php

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,6 @@
3131
use OCP\ILogger;
3232
use OC\Template\JSResourceLocator;
3333

34-
function rrmdir($directory) {
35-
$files = array_diff(scandir($directory), array('.','..'));
36-
foreach ($files as $file) {
37-
if (is_dir($directory . '/' . $file)) {
38-
rrmdir($directory . '/' . $file);
39-
} else {
40-
unlink($directory . '/' . $file);
41-
}
42-
}
43-
return rmdir($directory);
44-
}
45-
46-
function randomString() {
47-
return sha1(uniqid(mt_rand(), true));
48-
}
49-
5034
class JSResourceLocatorTest extends \Test\TestCase {
5135
/** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */
5236
protected $appData;
@@ -86,6 +70,23 @@ private function jsResourceLocator() {
8670
);
8771
}
8872

73+
private function rrmdir($directory) {
74+
$files = array_diff(scandir($directory), array('.','..'));
75+
foreach ($files as $file) {
76+
if (is_dir($directory . '/' . $file)) {
77+
$this->rrmdir($directory . '/' . $file);
78+
} else {
79+
unlink($directory . '/' . $file);
80+
}
81+
}
82+
return rmdir($directory);
83+
}
84+
85+
private function randomString() {
86+
return sha1(uniqid(mt_rand(), true));
87+
}
88+
89+
8990
public function testConstructor() {
9091
$locator = $this->jsResourceLocator();
9192
$this->assertAttributeEquals('theme', 'theme', $locator);
@@ -98,7 +99,7 @@ public function testConstructor() {
9899

99100
public function testFindWithAppPathSymlink() {
100101
// First create new apps path, and a symlink to it
101-
$apps_dirname = randomString();
102+
$apps_dirname = $this->randomString();
102103
$new_apps_path = sys_get_temp_dir() . '/' . $apps_dirname;
103104
$new_apps_path_symlink = $new_apps_path . '_link';
104105
mkdir($new_apps_path);
@@ -126,14 +127,15 @@ public function testFindWithAppPathSymlink() {
126127
$file = $resource[2];
127128

128129
$expectedRoot = $new_apps_path . '/test-app';
129-
$expectedWebRoot = '/apps-test/test-app';
130+
$expectedWebRoot = \OC::$WEBROOT . '/apps-test/test-app';
130131
$expectedFile = 'test-file.js';
131132

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

137-
rrmdir($new_apps_path);
138+
array_pop(\OC::$APPSROOTS);
139+
$this->rrmdir($new_apps_path);
138140
}
139141
}

0 commit comments

Comments
 (0)