1*a1a3b679SAndreas Boehler<?php 2*a1a3b679SAndreas Boehler 3*a1a3b679SAndreas Boehlernamespace Sabre\DAV; 4*a1a3b679SAndreas Boehler 5*a1a3b679SAndreas Boehlerrequire_once 'Sabre/TestUtil.php'; 6*a1a3b679SAndreas Boehler 7*a1a3b679SAndreas Boehlerclass ObjectTreeTest extends \PHPUnit_Framework_TestCase { 8*a1a3b679SAndreas Boehler 9*a1a3b679SAndreas Boehler protected $tree; 10*a1a3b679SAndreas Boehler 11*a1a3b679SAndreas Boehler function setup() { 12*a1a3b679SAndreas Boehler 13*a1a3b679SAndreas Boehler \Sabre\TestUtil::clearTempDir(); 14*a1a3b679SAndreas Boehler mkdir(SABRE_TEMPDIR . '/root'); 15*a1a3b679SAndreas Boehler mkdir(SABRE_TEMPDIR . '/root/subdir'); 16*a1a3b679SAndreas Boehler file_put_contents(SABRE_TEMPDIR . '/root/file.txt','contents'); 17*a1a3b679SAndreas Boehler file_put_contents(SABRE_TEMPDIR . '/root/subdir/subfile.txt','subcontents'); 18*a1a3b679SAndreas Boehler $rootNode = new FSExt\Directory(SABRE_TEMPDIR . '/root'); 19*a1a3b679SAndreas Boehler $this->tree = new Tree($rootNode); 20*a1a3b679SAndreas Boehler 21*a1a3b679SAndreas Boehler } 22*a1a3b679SAndreas Boehler 23*a1a3b679SAndreas Boehler function teardown() { 24*a1a3b679SAndreas Boehler 25*a1a3b679SAndreas Boehler \Sabre\TestUtil::clearTempDir(); 26*a1a3b679SAndreas Boehler 27*a1a3b679SAndreas Boehler } 28*a1a3b679SAndreas Boehler 29*a1a3b679SAndreas Boehler function testGetRootNode() { 30*a1a3b679SAndreas Boehler 31*a1a3b679SAndreas Boehler $root = $this->tree->getNodeForPath(''); 32*a1a3b679SAndreas Boehler $this->assertInstanceOf('Sabre\\DAV\\FSExt\\Directory',$root); 33*a1a3b679SAndreas Boehler 34*a1a3b679SAndreas Boehler } 35*a1a3b679SAndreas Boehler 36*a1a3b679SAndreas Boehler function testGetSubDir() { 37*a1a3b679SAndreas Boehler 38*a1a3b679SAndreas Boehler $root = $this->tree->getNodeForPath('subdir'); 39*a1a3b679SAndreas Boehler $this->assertInstanceOf('Sabre\\DAV\\FSExt\\Directory',$root); 40*a1a3b679SAndreas Boehler 41*a1a3b679SAndreas Boehler } 42*a1a3b679SAndreas Boehler 43*a1a3b679SAndreas Boehler function testCopyFile() { 44*a1a3b679SAndreas Boehler 45*a1a3b679SAndreas Boehler $this->tree->copy('file.txt','file2.txt'); 46*a1a3b679SAndreas Boehler $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/file2.txt')); 47*a1a3b679SAndreas Boehler $this->assertEquals('contents',file_get_contents(SABRE_TEMPDIR.'/root/file2.txt')); 48*a1a3b679SAndreas Boehler 49*a1a3b679SAndreas Boehler } 50*a1a3b679SAndreas Boehler 51*a1a3b679SAndreas Boehler /** 52*a1a3b679SAndreas Boehler * @depends testCopyFile 53*a1a3b679SAndreas Boehler */ 54*a1a3b679SAndreas Boehler function testCopyDirectory() { 55*a1a3b679SAndreas Boehler 56*a1a3b679SAndreas Boehler $this->tree->copy('subdir','subdir2'); 57*a1a3b679SAndreas Boehler $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir2')); 58*a1a3b679SAndreas Boehler $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir2/subfile.txt')); 59*a1a3b679SAndreas Boehler $this->assertEquals('subcontents',file_get_contents(SABRE_TEMPDIR.'/root/subdir2/subfile.txt')); 60*a1a3b679SAndreas Boehler 61*a1a3b679SAndreas Boehler } 62*a1a3b679SAndreas Boehler 63*a1a3b679SAndreas Boehler /** 64*a1a3b679SAndreas Boehler * @depends testCopyFile 65*a1a3b679SAndreas Boehler */ 66*a1a3b679SAndreas Boehler function testMoveFile() { 67*a1a3b679SAndreas Boehler 68*a1a3b679SAndreas Boehler $this->tree->move('file.txt','file2.txt'); 69*a1a3b679SAndreas Boehler $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/file2.txt')); 70*a1a3b679SAndreas Boehler $this->assertFalse(file_exists(SABRE_TEMPDIR.'/root/file.txt')); 71*a1a3b679SAndreas Boehler $this->assertEquals('contents',file_get_contents(SABRE_TEMPDIR.'/root/file2.txt')); 72*a1a3b679SAndreas Boehler 73*a1a3b679SAndreas Boehler } 74*a1a3b679SAndreas Boehler 75*a1a3b679SAndreas Boehler /** 76*a1a3b679SAndreas Boehler * @depends testMoveFile 77*a1a3b679SAndreas Boehler */ 78*a1a3b679SAndreas Boehler function testMoveFileNewParent() { 79*a1a3b679SAndreas Boehler 80*a1a3b679SAndreas Boehler $this->tree->move('file.txt','subdir/file2.txt'); 81*a1a3b679SAndreas Boehler $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir/file2.txt')); 82*a1a3b679SAndreas Boehler $this->assertFalse(file_exists(SABRE_TEMPDIR.'/root/file.txt')); 83*a1a3b679SAndreas Boehler $this->assertEquals('contents',file_get_contents(SABRE_TEMPDIR.'/root/subdir/file2.txt')); 84*a1a3b679SAndreas Boehler 85*a1a3b679SAndreas Boehler } 86*a1a3b679SAndreas Boehler 87*a1a3b679SAndreas Boehler /** 88*a1a3b679SAndreas Boehler * @depends testCopyDirectory 89*a1a3b679SAndreas Boehler */ 90*a1a3b679SAndreas Boehler function testMoveDirectory() { 91*a1a3b679SAndreas Boehler 92*a1a3b679SAndreas Boehler $this->tree->move('subdir','subdir2'); 93*a1a3b679SAndreas Boehler $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir2')); 94*a1a3b679SAndreas Boehler $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir2/subfile.txt')); 95*a1a3b679SAndreas Boehler $this->assertFalse(file_exists(SABRE_TEMPDIR.'/root/subdir')); 96*a1a3b679SAndreas Boehler $this->assertEquals('subcontents',file_get_contents(SABRE_TEMPDIR.'/root/subdir2/subfile.txt')); 97*a1a3b679SAndreas Boehler 98*a1a3b679SAndreas Boehler } 99*a1a3b679SAndreas Boehler 100*a1a3b679SAndreas Boehler} 101