streams/vendor/sabre/dav/tests/Sabre/DAV/BasicNodeTest.php

236 lines
4.4 KiB
PHP
Raw Normal View History

<?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() {
$file = new FileMock();
$file->put('hi');
}
/**
* @expectedException Sabre\DAV\Exception\Forbidden
*/
2016-05-28 15:46:24 +00:00
function testGet() {
$file = new FileMock();
$file->get();
}
2016-05-28 15:46:24 +00:00
function testGetSize() {
$file = new FileMock();
2016-05-28 15:46:24 +00:00
$this->assertEquals(0, $file->getSize());
}
2016-05-28 15:46:24 +00:00
function testGetETag() {
$file = new FileMock();
$this->assertNull($file->getETag());
}
2016-05-28 15:46:24 +00:00
function testGetContentType() {
$file = new FileMock();
$this->assertNull($file->getContentType());
}
/**
* @expectedException Sabre\DAV\Exception\Forbidden
*/
2016-05-28 15:46:24 +00:00
function testDelete() {
$file = new FileMock();
$file->delete();
}
/**
* @expectedException Sabre\DAV\Exception\Forbidden
*/
2016-05-28 15:46:24 +00:00
function testSetName() {
$file = new FileMock();
$file->setName('hi');
}
2016-05-28 15:46:24 +00:00
function testGetLastModified() {
$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();
$this->assertTrue($compareTime < 3);
}
2016-05-28 15:46:24 +00:00
function testGetChild() {
$dir = new DirectoryMock();
$file = $dir->getChild('mockfile');
$this->assertTrue($file instanceof FileMock);
}
2016-05-28 15:46:24 +00:00
function testChildExists() {
$dir = new DirectoryMock();
$this->assertTrue($dir->childExists('mockfile'));
}
2016-05-28 15:46:24 +00:00
function testChildExistsFalse() {
$dir = new DirectoryMock();
$this->assertFalse($dir->childExists('mockfile2'));
}
/**
* @expectedException Sabre\DAV\Exception\NotFound
*/
2016-05-28 15:46:24 +00:00
function testGetChild404() {
$dir = new DirectoryMock();
$file = $dir->getChild('blabla');
}
/**
* @expectedException Sabre\DAV\Exception\Forbidden
*/
2016-05-28 15:46:24 +00:00
function testCreateFile() {
$dir = new DirectoryMock();
2016-05-28 15:46:24 +00:00
$dir->createFile('hello', 'data');
}
/**
* @expectedException Sabre\DAV\Exception\Forbidden
*/
2016-05-28 15:46:24 +00:00
function testCreateDirectory() {
$dir = new DirectoryMock();
$dir->createDirectory('hello');
}
2016-05-28 15:46:24 +00:00
function testSimpleDirectoryConstruct() {
2016-05-28 15:46:24 +00:00
$dir = new SimpleCollection('simpledir', []);
$this->assertInstanceOf('Sabre\DAV\SimpleCollection', $dir);
}
/**
* @depends testSimpleDirectoryConstruct
*/
2016-05-28 15:46:24 +00:00
function testSimpleDirectoryConstructChild() {
$file = new FileMock();
2016-05-28 15:46:24 +00:00
$dir = new SimpleCollection('simpledir', [$file]);
$file2 = $dir->getChild('mockfile');
2016-05-28 15:46:24 +00:00
$this->assertEquals($file, $file2);
}
/**
* @expectedException Sabre\DAV\Exception
* @depends testSimpleDirectoryConstruct
*/
2016-05-28 15:46:24 +00:00
function testSimpleDirectoryBadParam() {
2016-05-28 15:46:24 +00:00
$dir = new SimpleCollection('simpledir', ['string shouldn\'t be here']);
}
/**
* @depends testSimpleDirectoryConstruct
*/
2016-05-28 15:46:24 +00:00
function testSimpleDirectoryAddChild() {
$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);
}
/**
* @depends testSimpleDirectoryConstruct
* @depends testSimpleDirectoryAddChild
*/
2016-05-28 15:46:24 +00:00
function testSimpleDirectoryGetChildren() {
$file = new FileMock();
$dir = new SimpleCollection('simpledir');
$dir->addChild($file);
2016-05-28 15:46:24 +00:00
$this->assertEquals([$file], $dir->getChildren());
}
/*
* @depends testSimpleDirectoryConstruct
*/
2016-05-28 15:46:24 +00:00
function testSimpleDirectoryGetName() {
$dir = new SimpleCollection('simpledir');
2016-05-28 15:46:24 +00:00
$this->assertEquals('simpledir', $dir->getName());
}
/**
* @depends testSimpleDirectoryConstruct
* @expectedException Sabre\DAV\Exception\NotFound
*/
2016-05-28 15:46:24 +00:00
function testSimpleDirectoryGetChild404() {
$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()];
}
}
class FileMock extends File {
function getName() {
return 'mockfile';
}
}