Merge pull request #4227 from owncloud/fixing-testGetById-master

implement a platform independent version of basename
This commit is contained in:
Thomas Müller 2013-07-30 08:39:53 -07:00
commit f35aadb576
3 changed files with 34 additions and 10 deletions

View File

@ -200,7 +200,7 @@ class Cache {
$data['path'] = $file; $data['path'] = $file;
$data['parent'] = $this->getParentId($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; $data['encrypted'] = isset($data['encrypted']) ? ((int)$data['encrypted']) : 0;
list($queryParts, $params) = $this->buildParts($data); list($queryParts, $params) = $this->buildParts($data);

View File

@ -894,4 +894,11 @@ class OC_Util {
return $value; return $value;
} }
public static function basename($file)
{
$file = rtrim($file, '/');
$t = explode('/', $file);
return array_pop($t);
}
} }

View File

@ -8,12 +8,9 @@
class Test_Util extends PHPUnit_Framework_TestCase { class Test_Util extends PHPUnit_Framework_TestCase {
// Constructor
function Test_Util() {
date_default_timezone_set("UTC");
}
function testFormatDate() { function testFormatDate() {
date_default_timezone_set("UTC");
$result = OC_Util::formatDate(1350129205); $result = OC_Util::formatDate(1350129205);
$expected = 'October 13, 2012 11:53'; $expected = 'October 13, 2012 11:53';
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
@ -65,4 +62,24 @@ class Test_Util extends PHPUnit_Framework_TestCase {
OC_Config::deleteKey('instanceid'); OC_Config::deleteKey('instanceid');
$this->assertStringStartsWith('oc', OC_Util::getInstanceId()); $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/')
);
}
} }