summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-07-30 08:39:53 -0700
committerThomas Müller <thomas.mueller@tmit.eu>2013-07-30 08:39:53 -0700
commitf35aadb5760923a42c8c4395a1dd381faef5251d (patch)
tree4a1c12df0c44e4260ee9c4d059606dc049361f09
parent91318f7b061a39cbb520fdb38ae1156f466738b5 (diff)
parent409268f3227854dab73233a88a114f26b0fed478 (diff)
downloadnextcloud-server-f35aadb5760923a42c8c4395a1dd381faef5251d.tar.gz
nextcloud-server-f35aadb5760923a42c8c4395a1dd381faef5251d.zip
Merge pull request #4227 from owncloud/fixing-testGetById-master
implement a platform independent version of basename
-rw-r--r--lib/files/cache/cache.php2
-rwxr-xr-xlib/util.php7
-rw-r--r--tests/lib/util.php33
3 files changed, 33 insertions, 9 deletions
diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php
index 3818fdbd840..5b8dc46b771 100644
--- a/lib/files/cache/cache.php
+++ b/lib/files/cache/cache.php
@@ -200,7 +200,7 @@ class Cache {
$data['path'] = $file;
$data['parent'] = $this->getParentId($file);
- $data['name'] = basename($file);
+ $data['name'] = \OC_Util::basename($file);
$data['encrypted'] = isset($data['encrypted']) ? ((int)$data['encrypted']) : 0;
list($queryParts, $params) = $this->buildParts($data);
diff --git a/lib/util.php b/lib/util.php
index 1f666a5e37f..b7dc2207e6c 100755
--- a/lib/util.php
+++ b/lib/util.php
@@ -894,4 +894,11 @@ class OC_Util {
return $value;
}
+
+ public static function basename($file)
+ {
+ $file = rtrim($file, '/');
+ $t = explode('/', $file);
+ return array_pop($t);
+ }
}
diff --git a/tests/lib/util.php b/tests/lib/util.php
index 9742d57ac7a..a038538d7ea 100644
--- a/tests/lib/util.php
+++ b/tests/lib/util.php
@@ -8,12 +8,9 @@
class Test_Util extends PHPUnit_Framework_TestCase {
- // Constructor
- function Test_Util() {
+ function testFormatDate() {
date_default_timezone_set("UTC");
- }
- function testFormatDate() {
$result = OC_Util::formatDate(1350129205);
$expected = 'October 13, 2012 11:53';
$this->assertEquals($expected, $result);
@@ -61,8 +58,28 @@ class Test_Util extends PHPUnit_Framework_TestCase {
OC_Config::deleteKey('mail_domain');
}
- function testGetInstanceIdGeneratesValidId() {
- OC_Config::deleteKey('instanceid');
- $this->assertStringStartsWith('oc', OC_Util::getInstanceId());
- }
+ function testGetInstanceIdGeneratesValidId() {
+ OC_Config::deleteKey('instanceid');
+ $this->assertStringStartsWith('oc', OC_Util::getInstanceId());
+ }
+
+ /**
+ * @dataProvider baseNameProvider
+ */
+ public function testBaseName($expected, $file)
+ {
+ $base = \OC_Util::basename($file);
+ $this->assertEquals($expected, $base);
+ }
+
+ public function baseNameProvider()
+ {
+ return array(
+ array('public_html', '/home/user/public_html/'),
+ array('public_html', '/home/user/public_html'),
+ array('', '/'),
+ array('public_html', 'public_html'),
+ array('442aa682de2a64db1e010f50e60fd9c9', 'local::C:\Users\ADMINI~1\AppData\Local\Temp\2/442aa682de2a64db1e010f50e60fd9c9/')
+ );
+ }
}