mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 00:48:25 +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());
|
$size = filesize($this->pwd());
|
||||||
return $size;
|
return $size;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Returns the File extension.
|
||||||
|
*
|
||||||
|
* @return string The File extension
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function info() {
|
||||||
|
return pathinfo($this->pwd());
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Returns the File extension.
|
* Returns the File extension.
|
||||||
*
|
*
|
||||||
|
@ -170,16 +179,25 @@ class File extends Object{
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function ext() {
|
function ext() {
|
||||||
$ext = '';
|
$info = $this->info();
|
||||||
$parts = explode('.', $this->name);
|
if(isset($info['extension'])) {
|
||||||
|
return $info['extension'];
|
||||||
if (count($parts) > 1) {
|
|
||||||
$ext = array_pop($parts);
|
|
||||||
} else {
|
|
||||||
$ext = '';
|
|
||||||
}
|
}
|
||||||
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.
|
* Returns the File's owner.
|
||||||
*
|
*
|
||||||
|
|
|
@ -50,10 +50,19 @@ class FileTest extends UnitTestCase {
|
||||||
$result = $this->File->name;
|
$result = $this->File->name;
|
||||||
$expecting = basename(__FILE__);
|
$expecting = basename(__FILE__);
|
||||||
$this->assertEqual($result, $expecting);
|
$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();
|
$result = $this->File->ext();
|
||||||
$expecting = 'php';
|
$expecting = 'php';
|
||||||
$this->assertEqual($result, $expecting);
|
$this->assertEqual($result, $expecting);
|
||||||
|
|
||||||
|
$result = $this->File->filename();
|
||||||
|
$expecting = 'file.test';
|
||||||
|
$this->assertEqual($result, $expecting);
|
||||||
|
|
||||||
$result = $this->File->md5();
|
$result = $this->File->md5();
|
||||||
$expecting = md5_file($file);
|
$expecting = md5_file($file);
|
||||||
|
|
Loading…
Add table
Reference in a new issue