2015-12-03 13:26:16 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Joas Schilling <nickvergessen@owncloud.com>
|
2016-01-12 17:02:16 +03:00
|
|
|
* @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/>
|
|
|
|
*
|
2015-12-03 13:26:16 +03:00
|
|
|
*/
|
|
|
|
|
2016-05-25 17:04:15 +03:00
|
|
|
namespace OCA\DAV\Tests\unit\SystemTag;
|
2015-12-03 13:26:16 +03:00
|
|
|
|
|
|
|
use Sabre\DAV\Exception\NotFound;
|
|
|
|
use OC\SystemTag\SystemTag;
|
|
|
|
use OCP\SystemTag\TagNotFoundException;
|
2016-05-11 16:39:24 +03:00
|
|
|
use OCP\SystemTag\ISystemTag;
|
2015-12-03 13:26:16 +03:00
|
|
|
|
2016-05-25 17:04:15 +03:00
|
|
|
class SystemTagMappingNodeTest extends \Test\TestCase {
|
2015-12-03 13:26:16 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \OCP\SystemTag\ISystemTagManager
|
|
|
|
*/
|
|
|
|
private $tagManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \OCP\SystemTag\ISystemTagObjectMapper
|
|
|
|
*/
|
|
|
|
private $tagMapper;
|
|
|
|
|
2016-05-11 16:39:24 +03:00
|
|
|
/**
|
|
|
|
* @var \OCP\IUser
|
|
|
|
*/
|
|
|
|
private $user;
|
|
|
|
|
2015-12-03 13:26:16 +03:00
|
|
|
protected function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
2016-07-15 10:52:46 +03:00
|
|
|
$this->tagManager = $this->getMockBuilder('\OCP\SystemTag\ISystemTagManager')
|
|
|
|
->getMock();
|
|
|
|
$this->tagMapper = $this->getMockBuilder('\OCP\SystemTag\ISystemTagObjectMapper')
|
|
|
|
->getMock();
|
|
|
|
$this->user = $this->getMockBuilder('\OCP\IUser')
|
|
|
|
->getMock();
|
2016-01-20 13:47:23 +03:00
|
|
|
}
|
2015-12-03 13:26:16 +03:00
|
|
|
|
2016-05-11 16:39:24 +03:00
|
|
|
public function getMappingNode($tag = null) {
|
2016-01-20 13:47:23 +03:00
|
|
|
if ($tag === null) {
|
|
|
|
$tag = new SystemTag(1, 'Test', true, true);
|
|
|
|
}
|
|
|
|
return new \OCA\DAV\SystemTag\SystemTagMappingNode(
|
|
|
|
$tag,
|
2015-12-03 13:26:16 +03:00
|
|
|
123,
|
|
|
|
'files',
|
2016-05-11 16:39:24 +03:00
|
|
|
$this->user,
|
2015-12-03 13:26:16 +03:00
|
|
|
$this->tagManager,
|
|
|
|
$this->tagMapper
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetters() {
|
2016-01-20 13:47:23 +03:00
|
|
|
$tag = new SystemTag(1, 'Test', true, false);
|
2016-05-11 16:39:24 +03:00
|
|
|
$node = $this->getMappingNode($tag);
|
2016-01-20 13:47:23 +03:00
|
|
|
$this->assertEquals('1', $node->getName());
|
|
|
|
$this->assertEquals($tag, $node->getSystemTag());
|
|
|
|
$this->assertEquals(123, $node->getObjectId());
|
|
|
|
$this->assertEquals('files', $node->getObjectType());
|
|
|
|
}
|
|
|
|
|
2016-05-11 16:39:24 +03:00
|
|
|
public function testDeleteTag() {
|
|
|
|
$node = $this->getMappingNode();
|
|
|
|
$this->tagManager->expects($this->once())
|
|
|
|
->method('canUserSeeTag')
|
|
|
|
->with($node->getSystemTag())
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
$this->tagManager->expects($this->once())
|
|
|
|
->method('canUserAssignTag')
|
|
|
|
->with($node->getSystemTag())
|
|
|
|
->will($this->returnValue(true));
|
2015-12-03 13:26:16 +03:00
|
|
|
$this->tagManager->expects($this->never())
|
|
|
|
->method('deleteTags');
|
|
|
|
$this->tagMapper->expects($this->once())
|
|
|
|
->method('unassignTags')
|
|
|
|
->with(123, 'files', 1);
|
|
|
|
|
2016-05-11 16:39:24 +03:00
|
|
|
$node->delete();
|
2016-01-20 13:47:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function tagNodeDeleteProviderPermissionException() {
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
// cannot unassign invisible tag
|
|
|
|
new SystemTag(1, 'Original', false, true),
|
|
|
|
'Sabre\DAV\Exception\NotFound',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
// cannot unassign non-assignable tag
|
|
|
|
new SystemTag(1, 'Original', true, false),
|
|
|
|
'Sabre\DAV\Exception\Forbidden',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider tagNodeDeleteProviderPermissionException
|
|
|
|
*/
|
2016-05-11 16:39:24 +03:00
|
|
|
public function testDeleteTagExpectedException(ISystemTag $tag, $expectedException) {
|
|
|
|
$this->tagManager->expects($this->any())
|
|
|
|
->method('canUserSeeTag')
|
|
|
|
->with($tag)
|
|
|
|
->will($this->returnValue($tag->isUserVisible()));
|
|
|
|
$this->tagManager->expects($this->any())
|
|
|
|
->method('canUserAssignTag')
|
|
|
|
->with($tag)
|
|
|
|
->will($this->returnValue($tag->isUserAssignable()));
|
2016-01-20 13:47:23 +03:00
|
|
|
$this->tagManager->expects($this->never())
|
|
|
|
->method('deleteTags');
|
|
|
|
$this->tagMapper->expects($this->never())
|
|
|
|
->method('unassignTags');
|
|
|
|
|
|
|
|
$thrown = null;
|
|
|
|
try {
|
2016-05-11 16:39:24 +03:00
|
|
|
$this->getMappingNode($tag)->delete();
|
2016-01-20 13:47:23 +03:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
$thrown = $e;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertInstanceOf($expectedException, $thrown);
|
2015-12-03 13:26:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException Sabre\DAV\Exception\NotFound
|
|
|
|
*/
|
|
|
|
public function testDeleteTagNotFound() {
|
2016-05-11 16:39:24 +03:00
|
|
|
// assuming the tag existed at the time the node was created,
|
|
|
|
// but got deleted concurrently in the database
|
|
|
|
$tag = new SystemTag(1, 'Test', true, true);
|
|
|
|
$this->tagManager->expects($this->once())
|
|
|
|
->method('canUserSeeTag')
|
|
|
|
->with($tag)
|
|
|
|
->will($this->returnValue($tag->isUserVisible()));
|
|
|
|
$this->tagManager->expects($this->once())
|
|
|
|
->method('canUserAssignTag')
|
|
|
|
->with($tag)
|
|
|
|
->will($this->returnValue($tag->isUserAssignable()));
|
2015-12-03 13:26:16 +03:00
|
|
|
$this->tagMapper->expects($this->once())
|
|
|
|
->method('unassignTags')
|
|
|
|
->with(123, 'files', 1)
|
|
|
|
->will($this->throwException(new TagNotFoundException()));
|
|
|
|
|
2016-05-11 16:39:24 +03:00
|
|
|
$this->getMappingNode($tag)->delete();
|
2015-12-03 13:26:16 +03:00
|
|
|
}
|
|
|
|
}
|