mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
updating File class and tests
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5211 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
f1625a8ae4
commit
aa81a44bb9
2 changed files with 36 additions and 9 deletions
|
@ -163,6 +163,15 @@ class File extends Object{
|
|||
$size = filesize($this->pwd());
|
||||
return $size;
|
||||
}
|
||||
/**
|
||||
* Returns the File extension.
|
||||
*
|
||||
* @return string The File extension
|
||||
* @access public
|
||||
*/
|
||||
function info() {
|
||||
return pathinfo($this->pwd());
|
||||
}
|
||||
/**
|
||||
* Returns the File extension.
|
||||
*
|
||||
|
@ -170,16 +179,25 @@ class File extends Object{
|
|||
* @access public
|
||||
*/
|
||||
function ext() {
|
||||
$ext = '';
|
||||
$parts = explode('.', $this->name);
|
||||
|
||||
if (count($parts) > 1) {
|
||||
$ext = array_pop($parts);
|
||||
} else {
|
||||
$ext = '';
|
||||
$info = $this->info();
|
||||
if(isset($info['extension'])) {
|
||||
return $info['extension'];
|
||||
}
|
||||
return $ext;
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Returns the File name without extension.
|
||||
*
|
||||
* @return string The File name without extension.
|
||||
* @access public
|
||||
*/
|
||||
function filename() {
|
||||
$info = $this->info();
|
||||
if(isset($info['filename'])) {
|
||||
return $info['filename'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Returns the File's owner.
|
||||
*
|
||||
|
|
|
@ -50,10 +50,19 @@ class FileTest extends UnitTestCase {
|
|||
$result = $this->File->name;
|
||||
$expecting = basename(__FILE__);
|
||||
$this->assertEqual($result, $expecting);
|
||||
|
||||
|
||||
$result = $this->File->info();
|
||||
$expecting = array('dirname'=> dirname(__FILE__), 'basename'=> basename(__FILE__),
|
||||
'extension'=> 'php', 'filename'=> 'file.test');
|
||||
$this->assertEqual($result, $expecting);
|
||||
|
||||
$result = $this->File->ext();
|
||||
$expecting = 'php';
|
||||
$this->assertEqual($result, $expecting);
|
||||
|
||||
$result = $this->File->filename();
|
||||
$expecting = 'file.test';
|
||||
$this->assertEqual($result, $expecting);
|
||||
|
||||
$result = $this->File->md5();
|
||||
$expecting = md5_file($file);
|
||||
|
|
Loading…
Add table
Reference in a new issue