$this->assertEquals(true,abs($time-$stat['atime'])<1,'Unexpected access time');//there can be small difference between those values due to running time
$this->assertEquals('file',OC_FILESYSTEM::filetype('/dummyFile'),'Unexpected filetype of file');
$this->assertEquals('dir',OC_FILESYSTEM::filetype('/dummyFolder'),'Unexpected filetype of folder');
}
publicfunctionreadfile(){
OC_FILESYSTEM::file_put_contents('/dummy','foo');
ob_start();
OC_FILESYSTEM::readfile('/dummy');
$this->assertEquals('foo',ob_get_contents(),'Unexpected output of readfile');
ob_end_clean();
}
publicfunctionisReadable(){
OC_FILESYSTEM::file_put_contents('/dummy','foo');
$this->assertEquals(true,OC_FILESYSTEM::is_readable('/dummy'),'Can\'t read created file');
}
publicfunctionisWritable(){
OC_FILESYSTEM::file_put_contents('/dummy','foo');
$this->assertEquals(true,OC_FILESYSTEM::is_writeable('/dummy'),'Can\'t write created file');
}
publicfunctionfileatime(){
OC_FILESYSTEM::file_put_contents('/dummy','foo');
$time=time();
$this->assertEquals(true,abs($time-OC_FILESYSTEM::fileatime('/dummy'))<1,'Unexpected access time');//there can be small difference between those values due to running time
}
publicfunctionfilectime(){
OC_FILESYSTEM::file_put_contents('/dummy','foo');
$time=time();
$this->assertEquals(true,abs($time-OC_FILESYSTEM::filectime('/dummy'))<1,'Unexpected creation time');//there can be small difference between those values due to running time
}
publicfunctionfilemtime(){
OC_FILESYSTEM::file_put_contents('/dummy','foo');
$time=time();
$this->assertEquals(true,abs($time-OC_FILESYSTEM::filemtime('/dummy'))<1,'Unexpected modified time');//there can be small difference between those values due to running time
}
publicfunctionfileGetContents(){
OC_FILESYSTEM::file_put_contents('/dummy','foo');
$this->assertEquals('foo',OC_FILESYSTEM::file_get_contents('/dummy'),'Unexpected content of file');
}
publicfunctionunlink(){
OC_FILESYSTEM::file_put_contents('/dummy','foo');
OC_FILESYSTEM::unlink('/dummy');
$this->assertEquals(false,OC_FILESYSTEM::file_exists('/dummy'),'File still exists after deletion');
}
publicfunctionrename(){
OC_FILESYSTEM::file_put_contents('/dummy','foo');
OC_FILESYSTEM::rename('/dummy','/bar');
$this->assertEquals(true,OC_FILESYSTEM::file_exists('/bar'),'New file doesnt exists after moving');
$this->assertEquals(false,OC_FILESYSTEM::file_exists('/dummy'),'Old file still exists after moving');
$this->assertEquals('foo',OC_FILESYSTEM::file_get_contents('/bar'),'Unexpected content of file after moving');
}
publicfunctioncopy(){
OC_FILESYSTEM::file_put_contents('/dummy','foo');
OC_FILESYSTEM::copy('/dummy','/bar');
$this->assertEquals(true,OC_FILESYSTEM::file_exists('/bar'),'New file doesnt exists after copying');
$this->assertEquals(true,OC_FILESYSTEM::file_exists('/dummy'),'Old file doesnt exists after copying');
$this->assertEquals('foo',OC_FILESYSTEM::file_get_contents('/bar'),'Unexpected content of file after copying');
}
publicfunctionfopen(){
OC_FILESYSTEM::file_put_contents('/dummy','foo');
$fh=OC_FILESYSTEM::fopen('/dummy','r');
if(!$fh){
$this->fail('Cant open file for reading');
}
$content=fread($fh,3);
$this->assertEquals('foo',$content,'Unexpected content of file');
fclose($fh);
$fh=OC_FILESYSTEM::fopen('/dummy','a');
fwrite($fh,'bar',3);
fclose($fh);
$this->assertEquals('foobar',OC_FILESYSTEM::file_get_contents('/dummy'),'Unexpected content of file after appending');
$fh=OC_FILESYSTEM::fopen('/dummy','w');
fwrite($fh,'bar',3);
fclose($fh);
$this->assertEquals('bar',OC_FILESYSTEM::file_get_contents('/dummy'),'Unexpected content of file after writing');
}
publicfunctiontoTmpFile(){
OC_FILESYSTEM::file_put_contents('/dummy','foo');
$tmp=OC_FILESYSTEM::toTmpFile('/dummy');
$this->assertEquals('foo',file_get_contents($tmp),'Unexpected content of temporary file');
unlink($tmp);
}
publicfunctionfromTmpFile(){
OC_FILESYSTEM::file_put_contents('/dummy','foo');
$tmp=OC_FILESYSTEM::toTmpFile('/dummy');
OC_FILESYSTEM::fromTmpFile($tmp,'/bar');
$this->assertEquals('foo',OC_FILESYSTEM::file_get_contents('/bar'),'Unexpected content of new file');
$this->assertEquals(false,file_exists($tmp),'Temporary file still exists');