2013-10-21 22:46:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Sabre\DAV;
|
|
|
|
|
|
|
|
class BasicNodeTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException Sabre\DAV\Exception\Forbidden
|
|
|
|
*/
|
2016-05-28 15:46:24 +00:00
|
|
|
function testPut() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$file = new FileMock();
|
|
|
|
$file->put('hi');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException Sabre\DAV\Exception\Forbidden
|
|
|
|
*/
|
2016-05-28 15:46:24 +00:00
|
|
|
function testGet() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$file = new FileMock();
|
|
|
|
$file->get();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
function testGetSize() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$file = new FileMock();
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals(0, $file->getSize());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
function testGetETag() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$file = new FileMock();
|
|
|
|
$this->assertNull($file->getETag());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
function testGetContentType() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$file = new FileMock();
|
|
|
|
$this->assertNull($file->getContentType());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException Sabre\DAV\Exception\Forbidden
|
|
|
|
*/
|
2016-05-28 15:46:24 +00:00
|
|
|
function testDelete() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$file = new FileMock();
|
|
|
|
$file->delete();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException Sabre\DAV\Exception\Forbidden
|
|
|
|
*/
|
2016-05-28 15:46:24 +00:00
|
|
|
function testSetName() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$file = new FileMock();
|
|
|
|
$file->setName('hi');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
function testGetLastModified() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$file = new FileMock();
|
|
|
|
// checking if lastmod is within the range of a few seconds
|
|
|
|
$lastMod = $file->getLastModified();
|
2016-05-28 15:46:24 +00:00
|
|
|
$compareTime = ($lastMod + 1) - time();
|
2013-10-21 22:46:31 +00:00
|
|
|
$this->assertTrue($compareTime < 3);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
function testGetChild() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$dir = new DirectoryMock();
|
|
|
|
$file = $dir->getChild('mockfile');
|
|
|
|
$this->assertTrue($file instanceof FileMock);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
function testChildExists() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$dir = new DirectoryMock();
|
|
|
|
$this->assertTrue($dir->childExists('mockfile'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
function testChildExistsFalse() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$dir = new DirectoryMock();
|
|
|
|
$this->assertFalse($dir->childExists('mockfile2'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException Sabre\DAV\Exception\NotFound
|
|
|
|
*/
|
2016-05-28 15:46:24 +00:00
|
|
|
function testGetChild404() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$dir = new DirectoryMock();
|
|
|
|
$file = $dir->getChild('blabla');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException Sabre\DAV\Exception\Forbidden
|
|
|
|
*/
|
2016-05-28 15:46:24 +00:00
|
|
|
function testCreateFile() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$dir = new DirectoryMock();
|
2016-05-28 15:46:24 +00:00
|
|
|
$dir->createFile('hello', 'data');
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException Sabre\DAV\Exception\Forbidden
|
|
|
|
*/
|
2016-05-28 15:46:24 +00:00
|
|
|
function testCreateDirectory() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$dir = new DirectoryMock();
|
|
|
|
$dir->createDirectory('hello');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
function testSimpleDirectoryConstruct() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$dir = new SimpleCollection('simpledir', []);
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertInstanceOf('Sabre\DAV\SimpleCollection', $dir);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testSimpleDirectoryConstruct
|
|
|
|
*/
|
2016-05-28 15:46:24 +00:00
|
|
|
function testSimpleDirectoryConstructChild() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$file = new FileMock();
|
2016-05-28 15:46:24 +00:00
|
|
|
$dir = new SimpleCollection('simpledir', [$file]);
|
2013-10-21 22:46:31 +00:00
|
|
|
$file2 = $dir->getChild('mockfile');
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals($file, $file2);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException Sabre\DAV\Exception
|
|
|
|
* @depends testSimpleDirectoryConstruct
|
|
|
|
*/
|
2016-05-28 15:46:24 +00:00
|
|
|
function testSimpleDirectoryBadParam() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$dir = new SimpleCollection('simpledir', ['string shouldn\'t be here']);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testSimpleDirectoryConstruct
|
|
|
|
*/
|
2016-05-28 15:46:24 +00:00
|
|
|
function testSimpleDirectoryAddChild() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$file = new FileMock();
|
|
|
|
$dir = new SimpleCollection('simpledir');
|
|
|
|
$dir->addChild($file);
|
|
|
|
$file2 = $dir->getChild('mockfile');
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals($file, $file2);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testSimpleDirectoryConstruct
|
|
|
|
* @depends testSimpleDirectoryAddChild
|
|
|
|
*/
|
2016-05-28 15:46:24 +00:00
|
|
|
function testSimpleDirectoryGetChildren() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$file = new FileMock();
|
|
|
|
$dir = new SimpleCollection('simpledir');
|
|
|
|
$dir->addChild($file);
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals([$file], $dir->getChildren());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @depends testSimpleDirectoryConstruct
|
|
|
|
*/
|
2016-05-28 15:46:24 +00:00
|
|
|
function testSimpleDirectoryGetName() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$dir = new SimpleCollection('simpledir');
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals('simpledir', $dir->getName());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testSimpleDirectoryConstruct
|
|
|
|
* @expectedException Sabre\DAV\Exception\NotFound
|
|
|
|
*/
|
2016-05-28 15:46:24 +00:00
|
|
|
function testSimpleDirectoryGetChild404() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$dir = new SimpleCollection('simpledir');
|
|
|
|
$dir->getChild('blabla');
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class DirectoryMock extends Collection {
|
|
|
|
|
|
|
|
function getName() {
|
|
|
|
|
|
|
|
return 'mockdir';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function getChildren() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
return [new FileMock()];
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class FileMock extends File {
|
|
|
|
|
|
|
|
function getName() {
|
|
|
|
|
|
|
|
return 'mockfile';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|