1<?php 2 3namespace Sabre\DAV; 4 5class BasicNodeTest extends \PHPUnit_Framework_TestCase { 6 7 /** 8 * @expectedException Sabre\DAV\Exception\Forbidden 9 */ 10 public function testPut() { 11 12 $file = new FileMock(); 13 $file->put('hi'); 14 15 } 16 17 /** 18 * @expectedException Sabre\DAV\Exception\Forbidden 19 */ 20 public function testGet() { 21 22 $file = new FileMock(); 23 $file->get(); 24 25 } 26 27 public function testGetSize() { 28 29 $file = new FileMock(); 30 $this->assertEquals(0,$file->getSize()); 31 32 } 33 34 35 public function testGetETag() { 36 37 $file = new FileMock(); 38 $this->assertNull($file->getETag()); 39 40 } 41 42 public function testGetContentType() { 43 44 $file = new FileMock(); 45 $this->assertNull($file->getContentType()); 46 47 } 48 49 /** 50 * @expectedException Sabre\DAV\Exception\Forbidden 51 */ 52 public function testDelete() { 53 54 $file = new FileMock(); 55 $file->delete(); 56 57 } 58 59 /** 60 * @expectedException Sabre\DAV\Exception\Forbidden 61 */ 62 public function testSetName() { 63 64 $file = new FileMock(); 65 $file->setName('hi'); 66 67 } 68 69 public function testGetLastModified() { 70 71 $file = new FileMock(); 72 // checking if lastmod is within the range of a few seconds 73 $lastMod = $file->getLastModified(); 74 $compareTime = ($lastMod + 1)-time(); 75 $this->assertTrue($compareTime < 3); 76 77 } 78 79 public function testGetChild() { 80 81 $dir = new DirectoryMock(); 82 $file = $dir->getChild('mockfile'); 83 $this->assertTrue($file instanceof FileMock); 84 85 } 86 87 public function testChildExists() { 88 89 $dir = new DirectoryMock(); 90 $this->assertTrue($dir->childExists('mockfile')); 91 92 } 93 94 public function testChildExistsFalse() { 95 96 $dir = new DirectoryMock(); 97 $this->assertFalse($dir->childExists('mockfile2')); 98 99 } 100 101 /** 102 * @expectedException Sabre\DAV\Exception\NotFound 103 */ 104 public function testGetChild404() { 105 106 $dir = new DirectoryMock(); 107 $file = $dir->getChild('blabla'); 108 109 } 110 111 /** 112 * @expectedException Sabre\DAV\Exception\Forbidden 113 */ 114 public function testCreateFile() { 115 116 $dir = new DirectoryMock(); 117 $dir->createFile('hello','data'); 118 119 } 120 121 /** 122 * @expectedException Sabre\DAV\Exception\Forbidden 123 */ 124 public function testCreateDirectory() { 125 126 $dir = new DirectoryMock(); 127 $dir->createDirectory('hello'); 128 129 } 130 131 public function testSimpleDirectoryConstruct() { 132 133 $dir = new SimpleCollection('simpledir',array()); 134 $this->assertInstanceOf('Sabre\DAV\SimpleCollection', $dir); 135 136 } 137 138 /** 139 * @depends testSimpleDirectoryConstruct 140 */ 141 public function testSimpleDirectoryConstructChild() { 142 143 $file = new FileMock(); 144 $dir = new SimpleCollection('simpledir',array($file)); 145 $file2 = $dir->getChild('mockfile'); 146 147 $this->assertEquals($file,$file2); 148 149 } 150 151 /** 152 * @expectedException Sabre\DAV\Exception 153 * @depends testSimpleDirectoryConstruct 154 */ 155 public function testSimpleDirectoryBadParam() { 156 157 $dir = new SimpleCollection('simpledir',array('string shouldn\'t be here')); 158 159 } 160 161 /** 162 * @depends testSimpleDirectoryConstruct 163 */ 164 public function testSimpleDirectoryAddChild() { 165 166 $file = new FileMock(); 167 $dir = new SimpleCollection('simpledir'); 168 $dir->addChild($file); 169 $file2 = $dir->getChild('mockfile'); 170 171 $this->assertEquals($file,$file2); 172 173 } 174 175 /** 176 * @depends testSimpleDirectoryConstruct 177 * @depends testSimpleDirectoryAddChild 178 */ 179 public function testSimpleDirectoryGetChildren() { 180 181 $file = new FileMock(); 182 $dir = new SimpleCollection('simpledir'); 183 $dir->addChild($file); 184 185 $this->assertEquals(array($file),$dir->getChildren()); 186 187 } 188 189 /* 190 * @depends testSimpleDirectoryConstruct 191 */ 192 public function testSimpleDirectoryGetName() { 193 194 $dir = new SimpleCollection('simpledir'); 195 $this->assertEquals('simpledir',$dir->getName()); 196 197 } 198 199 /** 200 * @depends testSimpleDirectoryConstruct 201 * @expectedException Sabre\DAV\Exception\NotFound 202 */ 203 public function testSimpleDirectoryGetChild404() { 204 205 $dir = new SimpleCollection('simpledir'); 206 $dir->getChild('blabla'); 207 208 } 209} 210 211class DirectoryMock extends Collection { 212 213 function getName() { 214 215 return 'mockdir'; 216 217 } 218 219 function getChildren() { 220 221 return array(new FileMock()); 222 223 } 224 225} 226 227class FileMock extends File { 228 229 function getName() { 230 231 return 'mockfile'; 232 233 } 234 235} 236