예제 #1
0
 public function setUp()
 {
     parent::setUp();
     $this->connection = \OC::$server->getDatabaseConnection();
     $this->pruneTagsTables();
     $this->tagManager = $this->getMockBuilder('OCP\\SystemTag\\ISystemTagManager')->getMock();
     $this->tagMapper = new SystemTagObjectMapper($this->connection, $this->tagManager);
     $this->tag1 = new SystemTag(1, 'testtag1', false, false);
     $this->tag2 = new SystemTag(2, 'testtag2', true, false);
     $this->tag3 = new SystemTag(3, 'testtag3', false, false);
     $this->tagManager->expects($this->any())->method('getTagsByIds')->will($this->returnCallback(function ($tagIds) {
         $result = [];
         if (in_array(1, $tagIds)) {
             $result[1] = $this->tag1;
         }
         if (in_array(2, $tagIds)) {
             $result[2] = $this->tag2;
         }
         if (in_array(3, $tagIds)) {
             $result[3] = $this->tag3;
         }
         return $result;
     }));
     $this->tagMapper->assignTags(1, 'testtype', $this->tag1->getId());
     $this->tagMapper->assignTags(1, 'testtype', $this->tag2->getId());
     $this->tagMapper->assignTags(2, 'testtype', $this->tag1->getId());
     $this->tagMapper->assignTags(3, 'anothertype', $this->tag1->getId());
 }
예제 #2
0
 /**
  * @dataProvider tagNodeDeleteProviderPermissionException
  */
 public function testDeleteTagExpectedException($tag, $expectedException)
 {
     $this->tagManager->expects($this->never())->method('deleteTags');
     $this->tagMapper->expects($this->never())->method('unassignTags');
     $thrown = null;
     try {
         $this->getMappingNode(false, $tag)->delete();
     } catch (\Exception $e) {
         $thrown = $e;
     }
     $this->assertInstanceOf($expectedException, $thrown);
 }
 public function testChildExistsWithInvisibleTag()
 {
     $tag = new SystemTag(555, 'TagOne', false, false);
     $this->tagMapper->expects($this->once())->method('haveTag')->with([111], 'files', '555')->will($this->returnValue(true));
     $this->tagManager->expects($this->once())->method('getTagsByIds')->with(['555'])->will($this->returnValue([$tag]));
     $this->assertFalse($this->getNode()->childExists('555'));
 }
예제 #4
0
 /**
  * @expectedException Sabre\DAV\Exception\NotFound
  */
 public function testDeleteTagNotFound()
 {
     $tag = new SystemTag(1, 'tag1', true, true);
     $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()));
     $this->tagManager->expects($this->once())->method('deleteTags')->with('1')->will($this->throwException(new TagNotFoundException()));
     $this->getTagNode(false, $tag)->delete();
 }
 /**
  * @expectedException Sabre\DAV\Exception\NotFound
  */
 public function testDeleteTagNotFound()
 {
     // 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()));
     $this->tagMapper->expects($this->once())->method('unassignTags')->with(123, 'files', 1)->will($this->throwException(new TagNotFoundException()));
     $this->getMappingNode($tag)->delete();
 }
예제 #6
0
 /**
  * @dataProvider nodeClassProvider
  * @expectedException Sabre\DAV\Exception\Conflict
  */
 public function testCreateTagConflict($nodeClass)
 {
     $requestData = json_encode(['name' => 'Test', 'userVisible' => true, 'userAssignable' => false]);
     $node = $this->getMockBuilder($nodeClass)->disableOriginalConstructor()->getMock();
     $this->tagManager->expects($this->once())->method('createTag')->with('Test', true, false)->will($this->throwException(new TagAlreadyExistsException('Tag already exists')));
     $this->tree->expects($this->any())->method('getNodeForPath')->with('/systemtags')->will($this->returnValue($node));
     $request = $this->getMockBuilder('Sabre\\HTTP\\RequestInterface')->disableOriginalConstructor()->getMock();
     $response = $this->getMockBuilder('Sabre\\HTTP\\ResponseInterface')->disableOriginalConstructor()->getMock();
     $request->expects($this->once())->method('getPath')->will($this->returnValue('/systemtags'));
     $request->expects($this->once())->method('getBodyAsString')->will($this->returnValue($requestData));
     $request->expects($this->once())->method('getHeader')->with('Content-Type')->will($this->returnValue('application/json'));
     $this->plugin->httpPost($request, $response);
 }
예제 #7
0
 public function testProcessFilterRulesVisibleTagAsUser()
 {
     $this->groupManager->expects($this->any())->method('isAdmin')->will($this->returnValue(false));
     $tag1 = $this->getMock('\\OCP\\SystemTag\\ISystemTag');
     $tag1->expects($this->any())->method('getId')->will($this->returnValue('123'));
     $tag1->expects($this->any())->method('isUserVisible')->will($this->returnValue(true));
     $tag2 = $this->getMock('\\OCP\\SystemTag\\ISystemTag');
     $tag2->expects($this->any())->method('getId')->will($this->returnValue('123'));
     $tag2->expects($this->any())->method('isUserVisible')->will($this->returnValue(true));
     $this->tagManager->expects($this->once())->method('getTagsByIds')->with(['123', '456'])->will($this->returnValue([$tag1, $tag2]));
     $this->tagMapper->expects($this->at(0))->method('getObjectIdsForTags')->with('123')->will($this->returnValue(['111', '222']));
     $this->tagMapper->expects($this->at(1))->method('getObjectIdsForTags')->with('456')->will($this->returnValue(['222', '333']));
     $rules = [['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'], ['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456']];
     $this->assertEquals(['222'], array_values($this->invokePrivate($this->plugin, 'processFilterRules', [$rules])));
 }
 public function testGetChildren()
 {
     $tag1 = new SystemTag(555, 'TagOne', true, false);
     $tag2 = new SystemTag(556, 'TagTwo', true, true);
     $this->tagMapper->expects($this->once())->method('getTagIdsForObjects')->with([111], 'files')->will($this->returnValue(['111' => ['555', '556']]));
     $this->tagManager->expects($this->once())->method('getTagsByIds')->with(['555', '556'])->will($this->returnValue(['555' => $tag1, '666' => $tag2]));
     $children = $this->node->getChildren();
     $this->assertCount(2, $children);
     $this->assertInstanceOf('\\OCA\\DAV\\SystemTag\\SystemTagMappingNode', $children[0]);
     $this->assertInstanceOf('\\OCA\\DAV\\SystemTag\\SystemTagMappingNode', $children[1]);
     $this->assertEquals(111, $children[0]->getObjectId());
     $this->assertEquals('files', $children[0]->getObjectType());
     $this->assertEquals($tag1, $children[0]->getSystemTag());
     $this->assertEquals(111, $children[1]->getObjectId());
     $this->assertEquals('files', $children[1]->getObjectType());
     $this->assertEquals($tag2, $children[1]->getSystemTag());
 }
예제 #9
0
 /**
  * @expectedException Sabre\DAV\Exception\NotFound
  */
 public function testDeleteTagNotFound()
 {
     $this->tagManager->expects($this->once())->method('deleteTags')->with('1')->will($this->throwException(new TagNotFoundException()));
     $this->getTagNode()->delete();
 }
예제 #10
0
 /**
  * @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');
 }
예제 #11
0
 public function testDeleteTag()
 {
     $this->tagManager->expects($this->never())->method('deleteTags');
     $this->tagMapper->expects($this->once())->method('unassignTags')->with(123, 'files', 1);
     $this->node->delete();
 }