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