staticstream.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test\Files\Stream;
  9. class StaticStream extends \PHPUnit_Framework_TestCase {
  10. private $sourceFile;
  11. private $sourceText;
  12. public function __construct() {
  13. $this->sourceFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
  14. $this->sourceText = file_get_contents($this->sourceFile);
  15. }
  16. public function tearDown() {
  17. \OC\Files\Stream\StaticStream::clear();
  18. }
  19. public function testContent() {
  20. file_put_contents('static://foo', $this->sourceText);
  21. $this->assertEquals($this->sourceText, file_get_contents('static://foo'));
  22. }
  23. public function testMultipleFiles() {
  24. file_put_contents('static://foo', $this->sourceText);
  25. file_put_contents('static://bar', strrev($this->sourceText));
  26. $this->assertEquals($this->sourceText, file_get_contents('static://foo'));
  27. $this->assertEquals(strrev($this->sourceText), file_get_contents('static://bar'));
  28. }
  29. public function testOverwrite() {
  30. file_put_contents('static://foo', $this->sourceText);
  31. file_put_contents('static://foo', 'qwerty');
  32. $this->assertEquals('qwerty', file_get_contents('static://foo'));
  33. }
  34. public function testIsFile() {
  35. $this->assertFalse(is_file('static://foo'));
  36. file_put_contents('static://foo', $this->sourceText);
  37. $this->assertTrue(is_file('static://foo'));
  38. }
  39. public function testIsDir() {
  40. $this->assertFalse(is_dir('static://foo'));
  41. file_put_contents('static://foo', $this->sourceText);
  42. $this->assertFalse(is_dir('static://foo'));
  43. }
  44. public function testFileType() {
  45. file_put_contents('static://foo', $this->sourceText);
  46. $this->assertEquals('file', filetype('static://foo'));
  47. }
  48. public function testUnlink() {
  49. $this->assertFalse(file_exists('static://foo'));
  50. file_put_contents('static://foo', $this->sourceText);
  51. $this->assertTrue(file_exists('static://foo'));
  52. unlink('static://foo');
  53. clearstatcache();
  54. $this->assertFalse(file_exists('static://foo'));
  55. }
  56. }