1<?php 2 3namespace Sabre\DAV\FSExt; 4 5use Sabre\DAV; 6 7require_once 'Sabre/TestUtil.php'; 8 9class FileTest extends \PHPUnit_Framework_TestCase { 10 11 function setUp() { 12 13 file_put_contents(SABRE_TEMPDIR . '/file.txt', 'Contents'); 14 15 } 16 17 function tearDown() { 18 19 \Sabre\TestUtil::clearTempDir(); 20 21 } 22 23 function testPut() { 24 25 $filename = SABRE_TEMPDIR . '/file.txt'; 26 $file = new File($filename); 27 $result = $file->put('New contents'); 28 29 $this->assertEquals('New contents',file_get_contents(SABRE_TEMPDIR . '/file.txt')); 30 $this->assertEquals( 31 '"' . 32 sha1( 33 fileinode($filename) . 34 filesize($filename ) . 35 filemtime($filename) 36 ) . '"', 37 $result 38 ); 39 40 } 41 42 function testRange() { 43 44 $file = new File(SABRE_TEMPDIR . '/file.txt'); 45 $file->put('0000000'); 46 $file->patch('111', 2, 3); 47 48 $this->assertEquals('0001110',file_get_contents(SABRE_TEMPDIR . '/file.txt')); 49 50 } 51 52 function testRangeStream() { 53 54 $stream = fopen('php://memory','r+'); 55 fwrite($stream, "222"); 56 rewind($stream); 57 58 $file = new File(SABRE_TEMPDIR . '/file.txt'); 59 $file->put('0000000'); 60 $file->patch($stream, 2, 3); 61 62 $this->assertEquals('0002220',file_get_contents(SABRE_TEMPDIR . '/file.txt')); 63 64 } 65 66 67 function testGet() { 68 69 $file = new File(SABRE_TEMPDIR . '/file.txt'); 70 $this->assertEquals('Contents',stream_get_contents($file->get())); 71 72 } 73 74 function testDelete() { 75 76 $file = new File(SABRE_TEMPDIR . '/file.txt'); 77 $file->delete(); 78 79 $this->assertFalse(file_exists(SABRE_TEMPDIR . '/file.txt')); 80 81 } 82 83 function testGetETag() { 84 85 $filename = SABRE_TEMPDIR . '/file.txt'; 86 $file = new File($filename); 87 $this->assertEquals( 88 '"' . 89 sha1( 90 fileinode($filename) . 91 filesize($filename ) . 92 filemtime($filename) 93 ) . '"', 94 $file->getETag() 95 ); 96 } 97 98 function testGetContentType() { 99 100 $file = new File(SABRE_TEMPDIR . '/file.txt'); 101 $this->assertNull($file->getContentType()); 102 103 } 104 105 function testGetSize() { 106 107 $file = new File(SABRE_TEMPDIR . '/file.txt'); 108 $this->assertEquals(8,$file->getSize()); 109 110 } 111 112} 113