160 lines
4.2 KiB
PHP
160 lines
4.2 KiB
PHP
<?php
|
|
/**
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
|
*
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
* @license AGPL-3.0
|
|
*
|
|
* This code is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
* as published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
*
|
|
*/
|
|
|
|
namespace OCA\DAV\Tests\Unit\SystemTag;
|
|
|
|
|
|
use OC\SystemTag\SystemTag;
|
|
use OCP\SystemTag\TagNotFoundException;
|
|
|
|
class SystemTagsByIdCollection extends \Test\TestCase {
|
|
|
|
/**
|
|
* @var \OCA\DAV\SystemTag\SystemTagsByIdCollection
|
|
*/
|
|
private $node;
|
|
|
|
/**
|
|
* @var \OCP\SystemTag\ISystemTagManager
|
|
*/
|
|
private $tagManager;
|
|
|
|
protected function setUp() {
|
|
parent::setUp();
|
|
|
|
$this->tagManager = $this->getMock('\OCP\SystemTag\ISystemTagManager');
|
|
|
|
$this->node = new \OCA\DAV\SystemTag\SystemTagsByIdCollection($this->tagManager);
|
|
}
|
|
|
|
/**
|
|
* @expectedException Sabre\DAV\Exception\Forbidden
|
|
*/
|
|
public function testForbiddenCreateFile() {
|
|
$this->node->createFile('555');
|
|
}
|
|
|
|
/**
|
|
* @expectedException Sabre\DAV\Exception\Forbidden
|
|
*/
|
|
public function testForbiddenCreateDirectory() {
|
|
$this->node->createDirectory('789');
|
|
}
|
|
|
|
public function testGetChild() {
|
|
$tag = new SystemTag(123, 'Test', true, false);
|
|
|
|
$this->tagManager->expects($this->once())
|
|
->method('getTagsByIds')
|
|
->with(['123'])
|
|
->will($this->returnValue([$tag]));
|
|
|
|
$childNode = $this->node->getChild('123');
|
|
|
|
$this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $childNode);
|
|
$this->assertEquals('123', $childNode->getName());
|
|
$this->assertEquals($tag, $childNode->getSystemTag());
|
|
}
|
|
|
|
/**
|
|
* @expectedException Sabre\DAV\Exception\BadRequest
|
|
*/
|
|
public function testGetChildInvalidName() {
|
|
$this->tagManager->expects($this->once())
|
|
->method('getTagsByIds')
|
|
->with(['invalid'])
|
|
->will($this->throwException(new \InvalidArgumentException()));
|
|
|
|
$this->node->getChild('invalid');
|
|
}
|
|
|
|
/**
|
|
* @expectedException Sabre\DAV\Exception\NotFound
|
|
*/
|
|
public function testGetChildNotFound() {
|
|
$this->tagManager->expects($this->once())
|
|
->method('getTagsByIds')
|
|
->with(['444'])
|
|
->will($this->throwException(new TagNotFoundException()));
|
|
|
|
$this->node->getChild('444');
|
|
}
|
|
|
|
public function testGetChildren() {
|
|
$tag1 = new SystemTag(123, 'One', true, false);
|
|
$tag2 = new SystemTag(456, 'Two', true, true);
|
|
|
|
$this->tagManager->expects($this->once())
|
|
->method('getAllTags')
|
|
->with(true)
|
|
->will($this->returnValue([$tag1, $tag2]));
|
|
|
|
$children = $this->node->getChildren();
|
|
|
|
$this->assertCount(2, $children);
|
|
|
|
$this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $children[0]);
|
|
$this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $children[1]);
|
|
$this->assertEquals($tag1, $children[0]->getSystemTag());
|
|
$this->assertEquals($tag2, $children[1]->getSystemTag());
|
|
}
|
|
|
|
public function testGetChildrenEmpty() {
|
|
$this->tagManager->expects($this->once())
|
|
->method('getAllTags')
|
|
->with(true)
|
|
->will($this->returnValue([]));
|
|
$this->assertCount(0, $this->node->getChildren());
|
|
}
|
|
|
|
public function testChildExists() {
|
|
$tag = new SystemTag(123, 'One', true, false);
|
|
|
|
$this->tagManager->expects($this->once())
|
|
->method('getTagsByIds')
|
|
->with(['123'])
|
|
->will($this->returnValue([$tag]));
|
|
|
|
$this->assertTrue($this->node->childExists('123'));
|
|
}
|
|
|
|
public function testChildExistsNotFound() {
|
|
$this->tagManager->expects($this->once())
|
|
->method('getTagsByIds')
|
|
->with(['123'])
|
|
->will($this->throwException(new TagNotFoundException()));
|
|
|
|
$this->assertFalse($this->node->childExists('123'));
|
|
}
|
|
|
|
/**
|
|
* @expectedException Sabre\DAV\Exception\BadRequest
|
|
*/
|
|
public function testChildExistsBadRequest() {
|
|
$this->tagManager->expects($this->once())
|
|
->method('getTagsByIds')
|
|
->with(['invalid'])
|
|
->will($this->throwException(new \InvalidArgumentException()));
|
|
|
|
$this->node->childExists('invalid');
|
|
}
|
|
}
|