streamwrappers.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Robin Appelman
  6. * @copyright 2012 Robin Appelman icewind@owncloud.com
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. class Test_StreamWrappers extends UnitTestCase {
  23. public function testFakeDir(){
  24. $items=array('foo','bar');
  25. OC_FakeDirStream::$dirs['test']=$items;
  26. $dh=opendir('fakedir://test');
  27. $result=array();
  28. while($file=readdir($dh)){
  29. $result[]=$file;
  30. $this->assertNotIdentical(false,array_search($file,$items));
  31. }
  32. $this->assertEqual(count($items),count($result));
  33. }
  34. public function testStaticStream(){
  35. $sourceFile=OC::$SERVERROOT.'/tests/data/lorem.txt';
  36. $staticFile='static://test';
  37. $this->assertFalse(file_exists($staticFile));
  38. file_put_contents($staticFile,file_get_contents($sourceFile));
  39. $this->assertTrue(file_exists($staticFile));
  40. $this->assertEqual(file_get_contents($sourceFile),file_get_contents($staticFile));
  41. unlink($staticFile);
  42. clearstatcache();
  43. $this->assertFalse(file_exists($staticFile));
  44. }
  45. public function testCloseStream(){
  46. //ensure all basic stream stuff works
  47. $sourceFile=OC::$SERVERROOT.'/tests/data/lorem.txt';
  48. $tmpFile=OC_Helper::TmpFile('.txt');
  49. $file='close://'.$tmpFile;
  50. $this->assertTrue(file_exists($file));
  51. file_put_contents($file,file_get_contents($sourceFile));
  52. $this->assertEqual(file_get_contents($sourceFile),file_get_contents($file));
  53. unlink($file);
  54. clearstatcache();
  55. $this->assertFalse(file_exists($file));
  56. //test callback
  57. $tmpFile=OC_Helper::TmpFile('.txt');
  58. $file='close://'.$tmpFile;
  59. OC_CloseStreamWrapper::$callBacks[$tmpFile]=array('Test_StreamWrappers','closeCallBack');
  60. $fh=fopen($file,'w');
  61. fwrite($fh,'asd');
  62. try{
  63. fclose($fh);
  64. $this->fail('Expected exception');
  65. }catch(Exception $e){
  66. $path=$e->getMessage();
  67. $this->assertEqual($path,$tmpFile);
  68. }
  69. }
  70. public static function closeCallBack($path){
  71. throw new Exception($path);
  72. }
  73. }