PageRenderTime 51ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/Sabre/DAV/FSExt/FileTest.php

https://github.com/KOLANICH/SabreDAV
PHP | 95 lines | 54 code | 41 blank | 0 comment | 0 complexity | 65176027558605fcfcb42d017c312964 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. namespace Sabre\DAV\FSExt;
  3. use Sabre\DAV;
  4. require_once 'Sabre/TestUtil.php';
  5. class FileTest extends \PHPUnit_Framework_TestCase {
  6. function setUp() {
  7. file_put_contents(SABRE_TEMPDIR . '/file.txt', 'Contents');
  8. }
  9. function tearDown() {
  10. \Sabre\TestUtil::clearTempDir();
  11. }
  12. function testPut() {
  13. $file = new File(SABRE_TEMPDIR . '/file.txt');
  14. $result = $file->put('New contents');
  15. $this->assertEquals('New contents',file_get_contents(SABRE_TEMPDIR . '/file.txt'));
  16. $this->assertEquals('"' . md5('New contents') . '"', $result);
  17. }
  18. function testRange() {
  19. $file = new File(SABRE_TEMPDIR . '/file.txt');
  20. $file->put('0000000');
  21. $file->putRange('111',3);
  22. $this->assertEquals('0011100',file_get_contents(SABRE_TEMPDIR . '/file.txt'));
  23. }
  24. function testRangeStream() {
  25. $stream = fopen('php://memory','r+');
  26. fwrite($stream, "222");
  27. rewind($stream);
  28. $file = new File(SABRE_TEMPDIR . '/file.txt');
  29. $file->put('0000000');
  30. $file->putRange($stream,3);
  31. $this->assertEquals('0022200',file_get_contents(SABRE_TEMPDIR . '/file.txt'));
  32. }
  33. function testGet() {
  34. $file = new File(SABRE_TEMPDIR . '/file.txt');
  35. $this->assertEquals('Contents',stream_get_contents($file->get()));
  36. }
  37. function testDelete() {
  38. $file = new File(SABRE_TEMPDIR . '/file.txt');
  39. $file->delete();
  40. $this->assertFalse(file_exists(SABRE_TEMPDIR . '/file.txt'));
  41. }
  42. function testGetETag() {
  43. $file = new File(SABRE_TEMPDIR . '/file.txt');
  44. $this->assertEquals('"' . md5('Contents') . '"',$file->getETag());
  45. }
  46. function testGetContentType() {
  47. $file = new File(SABRE_TEMPDIR . '/file.txt');
  48. $this->assertNull($file->getContentType());
  49. }
  50. function testGetSize() {
  51. $file = new File(SABRE_TEMPDIR . '/file.txt');
  52. $this->assertEquals(8,$file->getSize());
  53. }
  54. }