public function testDeleteSingleShareLazy()
 {
     $qb = $this->dbConn->getQueryBuilder();
     $qb->insert('share')->values(['share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER), 'share_with' => $qb->expr()->literal('sharedWith'), 'uid_owner' => $qb->expr()->literal('shareOwner'), 'uid_initiator' => $qb->expr()->literal('sharedBy'), 'item_type' => $qb->expr()->literal('file'), 'file_source' => $qb->expr()->literal(42), 'file_target' => $qb->expr()->literal('myTarget'), 'permissions' => $qb->expr()->literal(13)]);
     $this->assertEquals(1, $qb->execute());
     $id = $qb->getLastInsertId();
     $this->rootFolder->expects($this->never())->method($this->anything());
     $share = $this->provider->getShareById($id);
     $this->provider->delete($share);
     $qb = $this->dbConn->getQueryBuilder();
     $qb->select('*')->from('share');
     $cursor = $qb->execute();
     $result = $cursor->fetchAll();
     $cursor->closeCursor();
     $this->assertEmpty($result);
 }
 public function testDeleteNestedShares()
 {
     $qb = $this->dbConn->getQueryBuilder();
     $qb->insert('share')->values(['share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER), 'share_with' => $qb->expr()->literal('sharedWith'), 'uid_owner' => $qb->expr()->literal('sharedBy'), 'item_type' => $qb->expr()->literal('file'), 'file_source' => $qb->expr()->literal(42), 'file_target' => $qb->expr()->literal('myTarget'), 'permissions' => $qb->expr()->literal(13)]);
     $this->assertEquals(1, $qb->execute());
     // Get the id
     $qb = $this->dbConn->getQueryBuilder();
     $cursor = $qb->select('id')->from('share')->setMaxResults(1)->orderBy('id', 'DESC')->execute();
     $id1 = $cursor->fetch();
     $id1 = $id1['id'];
     $cursor->closeCursor();
     $qb = $this->dbConn->getQueryBuilder();
     $qb->insert('share')->values(['share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER), 'share_with' => $qb->expr()->literal('sharedWith'), 'uid_owner' => $qb->expr()->literal('sharedBy'), 'item_type' => $qb->expr()->literal('file'), 'file_source' => $qb->expr()->literal(42), 'file_target' => $qb->expr()->literal('myTarget'), 'permissions' => $qb->expr()->literal(13), 'parent' => $qb->expr()->literal($id1)]);
     $this->assertEquals(1, $qb->execute());
     // Get the id
     $qb = $this->dbConn->getQueryBuilder();
     $cursor = $qb->select('id')->from('share')->setMaxResults(1)->orderBy('id', 'DESC')->execute();
     $id2 = $cursor->fetch();
     $id2 = $id2['id'];
     $cursor->closeCursor();
     $qb = $this->dbConn->getQueryBuilder();
     $qb->insert('share')->values(['share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER), 'share_with' => $qb->expr()->literal('sharedWith'), 'uid_owner' => $qb->expr()->literal('sharedBy'), 'item_type' => $qb->expr()->literal('file'), 'file_source' => $qb->expr()->literal(42), 'file_target' => $qb->expr()->literal('myTarget'), 'permissions' => $qb->expr()->literal(13), 'parent' => $qb->expr()->literal($id2)]);
     $this->assertEquals(1, $qb->execute());
     $storage = $this->getMock('OC\\Files\\Storage\\Storage');
     $storage->method('getOwner')->willReturn('shareOwner');
     $path = $this->getMock('OCP\\Files\\Node');
     $path->method('getStorage')->wilLReturn($storage);
     $this->userFolder->method('getById')->with(42)->willReturn([$path]);
     $sharedWith = $this->getMock('OCP\\IUser');
     $sharedWith->method('getUID')->willReturn('sharedWith');
     $sharedBy = $this->getMock('OCP\\IUser');
     $sharedBy->method('getUID')->willReturn('sharedBy');
     $shareOwner = $this->getMock('OCP\\IUser');
     $this->userManager->method('get')->will($this->returnValueMap([['sharedWith', $sharedWith], ['sharedBy', $sharedBy], ['shareOwner', $shareOwner]]));
     $share = $this->provider->getShareById($id1);
     $this->provider->delete($share);
     $qb = $this->dbConn->getQueryBuilder();
     $qb->select('*')->from('share');
     $cursor = $qb->execute();
     $result = $cursor->fetchAll();
     $cursor->closeCursor();
     $this->assertEmpty($result);
 }