diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/comments/fakemanager.php | 10 | ||||
-rw-r--r-- | tests/lib/comments/manager.php | 69 | ||||
-rw-r--r-- | tests/lib/contacts/localadressbook.php | 114 | ||||
-rw-r--r-- | tests/lib/share20/defaultshareprovidertest.php | 107 | ||||
-rw-r--r-- | tests/lib/share20/managertest.php | 94 | ||||
-rw-r--r-- | tests/lib/systemtag/systemtagmanagertest.php | 17 | ||||
-rw-r--r-- | tests/lib/systemtag/systemtagobjectmappertest.php | 27 |
7 files changed, 314 insertions, 124 deletions
diff --git a/tests/lib/comments/fakemanager.php b/tests/lib/comments/fakemanager.php index e5cf58dda4f..7186529e718 100644 --- a/tests/lib/comments/fakemanager.php +++ b/tests/lib/comments/fakemanager.php @@ -19,7 +19,7 @@ class FakeManager implements \OCP\Comments\ICommentsManager { \DateTime $notOlderThan = null ) {} - public function getNumberOfCommentsForObject($objectType, $objectId) {} + public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null) {} public function create($actorType, $actorId, $objectType, $objectId) {} @@ -30,4 +30,12 @@ class FakeManager implements \OCP\Comments\ICommentsManager { public function deleteReferencesOfActor($actorType, $actorId) {} public function deleteCommentsAtObject($objectType, $objectId) {} + + public function setReadMark($objectType, $objectId, \DateTime $dateTime, \OCP\IUser $user) {} + + public function getReadMark($objectType, $objectId, \OCP\IUser $user) {} + + public function deleteReadMarksFromUser(\OCP\IUser $user) {} + + public function deleteReadMarksOnObject($objectType, $objectId) {} } diff --git a/tests/lib/comments/manager.php b/tests/lib/comments/manager.php index cc2eebb64d1..a71f78f2818 100644 --- a/tests/lib/comments/manager.php +++ b/tests/lib/comments/manager.php @@ -561,4 +561,73 @@ class Test_Comments_Manager extends TestCase $this->assertTrue($wasSuccessful); } + public function testSetMarkRead() { + $user = $this->getMock('\OCP\IUser'); + $user->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('alice')); + + $dateTimeSet = new \DateTime(); + + $manager = $this->getManager(); + $manager->setReadMark('robot', '36', $dateTimeSet, $user); + + $dateTimeGet = $manager->getReadMark('robot', '36', $user); + + $this->assertEquals($dateTimeGet, $dateTimeSet); + } + + public function testSetMarkReadUpdate() { + $user = $this->getMock('\OCP\IUser'); + $user->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('alice')); + + $dateTimeSet = new \DateTime('yesterday'); + + $manager = $this->getManager(); + $manager->setReadMark('robot', '36', $dateTimeSet, $user); + + $dateTimeSet = new \DateTime('today'); + $manager->setReadMark('robot', '36', $dateTimeSet, $user); + + $dateTimeGet = $manager->getReadMark('robot', '36', $user); + + $this->assertEquals($dateTimeGet, $dateTimeSet); + } + + public function testReadMarkDeleteUser() { + $user = $this->getMock('\OCP\IUser'); + $user->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('alice')); + + $dateTimeSet = new \DateTime(); + + $manager = $this->getManager(); + $manager->setReadMark('robot', '36', $dateTimeSet, $user); + + $manager->deleteReadMarksFromUser($user); + $dateTimeGet = $manager->getReadMark('robot', '36', $user); + + $this->assertNull($dateTimeGet); + } + + public function testReadMarkDeleteObject() { + $user = $this->getMock('\OCP\IUser'); + $user->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('alice')); + + $dateTimeSet = new \DateTime(); + + $manager = $this->getManager(); + $manager->setReadMark('robot', '36', $dateTimeSet, $user); + + $manager->deleteReadMarksOnObject('robot', '36'); + $dateTimeGet = $manager->getReadMark('robot', '36', $user); + + $this->assertNull($dateTimeGet); + } + } diff --git a/tests/lib/contacts/localadressbook.php b/tests/lib/contacts/localadressbook.php deleted file mode 100644 index ad3c088e3cd..00000000000 --- a/tests/lib/contacts/localadressbook.php +++ /dev/null @@ -1,114 +0,0 @@ -<?php -use OC\Contacts\LocalAddressBook; -use OCP\IUser; - -/** - * ownCloud - * - * @author Thomas Müller - * @copyright 2014 Thomas Müller thomas.mueller@tmit.eu - * - * You should have received a copy of the GNU Affero General Public - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - */ - -class Test_LocalAddressBook extends \Test\TestCase -{ - - public function testSearchFN() { - $stub = $this->getMockForAbstractClass('\OCP\IUserManager', array('searchDisplayName')); - - $stub->expects($this->any())->method('searchDisplayName')->will($this->returnValue(array( - new SimpleUserForTesting('tom', 'Thomas'), - new SimpleUserForTesting('tomtom', 'Thomas T.'), - ))); - - $localAddressBook = new LocalAddressBook($stub); - - $result = $localAddressBook->search('tom', array('FN'), array()); - $this->assertEquals(2, count($result)); - } - - public function testSearchId() { - $stub = $this->getMockForAbstractClass('\OCP\IUserManager', array('searchDisplayName')); - - $stub->expects($this->any())->method('search')->will($this->returnValue(array( - new SimpleUserForTesting('tom', 'Thomas'), - new SimpleUserForTesting('tomtom', 'Thomas T.'), - ))); - - $localAddressBook = new LocalAddressBook($stub); - - $result = $localAddressBook->search('tom', array('id'), array()); - $this->assertEquals(2, count($result)); - } -} - - -class SimpleUserForTesting implements IUser { - - private $uid; - private $displayName; - - public function __construct($uid, $displayName) { - - $this->uid = $uid; - $this->displayName = $displayName; - } - - public function getUID() { - return $this->uid; - } - - public function getDisplayName() { - return $this->displayName; - } - - public function setDisplayName($displayName) { - } - - public function getLastLogin() { - } - - public function updateLastLoginTimestamp() { - } - - public function delete() { - } - - public function setPassword($password, $recoveryPassword = null) { - } - - public function getHome() { - } - - public function getBackendClassName() { - } - - public function canChangeAvatar() { - } - - public function canChangePassword() { - } - - public function canChangeDisplayName() { - } - - public function isEnabled() { - } - - public function setEnabled($enabled) { - } - - public function getEMailAddress() { - } - - public function getAvatarImage($size) { - } - - public function getCloudId() { - } - - public function setEMailAddress($mailAddress) { - } -} diff --git a/tests/lib/share20/defaultshareprovidertest.php b/tests/lib/share20/defaultshareprovidertest.php index 28b57435e1d..504bd776036 100644 --- a/tests/lib/share20/defaultshareprovidertest.php +++ b/tests/lib/share20/defaultshareprovidertest.php @@ -247,6 +247,44 @@ class DefaultShareProviderTest extends \Test\TestCase { $this->assertEquals('myTarget', $share->getTarget()); } + public function testGetShareByIdUserGroupShare() { + $id = $this->addShareToDB(\OCP\Share::SHARE_TYPE_GROUP, 'group0', 'user0', 'user0', 'file', 42, 'myTarget', 31, null, null); + $this->addShareToDB(2, 'user1', 'user0', 'user0', 'file', 42, 'userTarget', 0, null, null, $id); + + $user0 = $this->getMock('OCP\IUser'); + $user0->method('getUID')->willReturn('user0'); + $user1 = $this->getMock('OCP\IUser'); + $user1->method('getUID')->willReturn('user1'); + + $group0 = $this->getMock('OCP\IGroup'); + $group0->method('inGroup')->with($user1)->willReturn(true); + + $node = $this->getMock('\OCP\Files\Folder'); + $node->method('getId')->willReturn(42); + + $this->rootFolder->method('getUserFolder')->with('user0')->will($this->returnSelf()); + $this->rootFolder->method('getById')->willReturn([$node]); + + $this->userManager->method('get')->will($this->returnValueMap([ + ['user0', $user0], + ['user1', $user1], + ])); + $this->groupManager->method('get')->with('group0')->willReturn($group0); + + $share = $this->provider->getShareById($id, $user1); + + $this->assertEquals($id, $share->getId()); + $this->assertEquals(\OCP\Share::SHARE_TYPE_GROUP, $share->getShareType()); + $this->assertSame($group0, $share->getSharedWith()); + $this->assertSame($user0, $share->getSharedBy()); + $this->assertSame($user0, $share->getShareOwner()); + $this->assertSame($node, $share->getNode()); + $this->assertEquals(0, $share->getPermissions()); + $this->assertEquals(null, $share->getToken()); + $this->assertEquals(null, $share->getExpirationDate()); + $this->assertEquals('userTarget', $share->getTarget()); + } + public function testGetShareByIdLinkShare() { $qb = $this->dbConn->getQueryBuilder(); @@ -1854,6 +1892,75 @@ class DefaultShareProviderTest extends \Test\TestCase { $stmt->closeCursor(); + } + + public function testMoveUserShare() { + $id = $this->addShareToDB(\OCP\Share::SHARE_TYPE_USER, 'user0', 'user1', 'user1', 'file', + 42, 'mytaret', 31, null, null); + + $user0 = $this->getMock('\OCP\IUser'); + $user0->method('getUID')->willReturn('user0'); + $user1 = $this->getMock('\OCP\IUser'); + $user1->method('getUID')->willReturn('user1'); + + $this->userManager->method('get')->will($this->returnValueMap([ + ['user0', $user0], + ['user1', $user1], + ])); + + $file = $this->getMock('\OCP\Files\File'); + $file->method('getId')->willReturn(42); + + $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf()); + $this->rootFolder->method('getById')->willReturn([$file]); + + $share = $this->provider->getShareById($id, null); + + $share->setTarget('/newTarget'); + $this->provider->move($share, $user0); + + $share = $this->provider->getShareById($id, null); + $this->assertSame('/newTarget', $share->getTarget()); + } + + public function testMoveGroupShare() { + $id = $this->addShareToDB(\OCP\Share::SHARE_TYPE_GROUP, 'group0', 'user1', 'user1', 'file', + 42, 'mytaret', 31, null, null); + + $user0 = $this->getMock('\OCP\IUser'); + $user0->method('getUID')->willReturn('user0'); + $user1 = $this->getMock('\OCP\IUser'); + $user1->method('getUID')->willReturn('user1'); + + $group0 = $this->getMock('\OCP\IGroup'); + $group0->method('getGID')->willReturn('group0'); + $group0->method('inGroup')->with($user0)->willReturn(true); + + $this->groupManager->method('get')->with('group0')->willReturn($group0); + + $this->userManager->method('get')->will($this->returnValueMap([ + ['user0', $user0], + ['user1', $user1], + ])); + + $folder = $this->getMock('\OCP\Files\Folder'); + $folder->method('getId')->willReturn(42); + + $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf()); + $this->rootFolder->method('getById')->willReturn([$folder]); + + $share = $this->provider->getShareById($id, $user0); + + $share->setTarget('/newTarget'); + $this->provider->move($share, $user0); + + $share = $this->provider->getShareById($id, $user0); + $this->assertSame('/newTarget', $share->getTarget()); + + $share->setTarget('/ultraNewTarget'); + $this->provider->move($share, $user0); + $share = $this->provider->getShareById($id, $user0); + $this->assertSame('/ultraNewTarget', $share->getTarget()); } } diff --git a/tests/lib/share20/managertest.php b/tests/lib/share20/managertest.php index b5559bb5172..6043d30a0bb 100644 --- a/tests/lib/share20/managertest.php +++ b/tests/lib/share20/managertest.php @@ -1645,6 +1645,27 @@ class ManagerTest extends \Test\TestCase { $this->assertTrue($this->manager->checkPassword($share, 'password')); } + public function testCheckPasswordUpdateShare() { + $share = $this->manager->newShare(); + $share->setShareType(\OCP\Share::SHARE_TYPE_LINK) + ->setPassword('passwordHash'); + + $this->hasher->method('verify')->with('password', 'passwordHash', '') + ->will($this->returnCallback(function($pass, $hash, &$newHash) { + $newHash = 'newHash'; + + return true; + })); + + $this->defaultProvider->expects($this->once()) + ->method('update') + ->with($this->callback(function (\OCP\Share\IShare $share) { + return $share->getPassword() === 'newHash'; + })); + + $this->assertTrue($this->manager->checkPassword($share, 'password')); + } + /** * @expectedException Exception * @expectedExceptionMessage The Share API is disabled @@ -1887,6 +1908,79 @@ class ManagerTest extends \Test\TestCase { $manager->updateShare($share); } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Can't change target of link share + */ + public function testMoveShareLink() { + $share = $this->manager->newShare(); + $share->setShareType(\OCP\Share::SHARE_TYPE_LINK); + + $recipient = $this->getMock('\OCP\IUser'); + + $this->manager->moveShare($share, $recipient); + } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Invalid recipient + */ + public function testMoveShareUserNotRecipient() { + $share = $this->manager->newShare(); + $share->setShareType(\OCP\Share::SHARE_TYPE_USER); + + $sharedWith = $this->getMock('\OCP\IUser'); + $share->setSharedWith($sharedWith); + + $recipient = $this->getMock('\OCP\IUser'); + + $this->manager->moveShare($share, $recipient); + } + + public function testMoveShareUser() { + $share = $this->manager->newShare(); + $share->setShareType(\OCP\Share::SHARE_TYPE_USER); + + $recipient = $this->getMock('\OCP\IUser'); + $share->setSharedWith($recipient); + + $this->defaultProvider->method('move')->with($share, $recipient)->will($this->returnArgument(0)); + + $this->manager->moveShare($share, $recipient); + } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Invalid recipient + */ + public function testMoveShareGroupNotRecipient() { + $share = $this->manager->newShare(); + $share->setShareType(\OCP\Share::SHARE_TYPE_GROUP); + + $sharedWith = $this->getMock('\OCP\IGroup'); + $share->setSharedWith($sharedWith); + + $recipient = $this->getMock('\OCP\IUser'); + $sharedWith->method('inGroup')->with($recipient)->willReturn(false); + + $this->manager->moveShare($share, $recipient); + } + + public function testMoveShareGroup() { + $share = $this->manager->newShare(); + $share->setShareType(\OCP\Share::SHARE_TYPE_GROUP); + + $sharedWith = $this->getMock('\OCP\IGroup'); + $share->setSharedWith($sharedWith); + + $recipient = $this->getMock('\OCP\IUser'); + $sharedWith->method('inGroup')->with($recipient)->willReturn(true); + + $this->defaultProvider->method('move')->with($share, $recipient)->will($this->returnArgument(0)); + + $this->manager->moveShare($share, $recipient); + } } class DummyPassword { diff --git a/tests/lib/systemtag/systemtagmanagertest.php b/tests/lib/systemtag/systemtagmanagertest.php index 97c072f33f6..64220205ade 100644 --- a/tests/lib/systemtag/systemtagmanagertest.php +++ b/tests/lib/systemtag/systemtagmanagertest.php @@ -15,6 +15,7 @@ use OC\SystemTag\SystemTagObjectMapper; use OCP\IDBConnection; use OCP\SystemTag\ISystemTag; use OCP\SystemTag\ISystemTagManager; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Test\TestCase; /** @@ -35,11 +36,23 @@ class SystemTagManagerTest extends TestCase { */ private $connection; + /** + * @var EventDispatcherInterface + */ + private $dispatcher; + public function setUp() { parent::setUp(); $this->connection = \OC::$server->getDatabaseConnection(); - $this->tagManager = new SystemTagManager($this->connection); + + $this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface') + ->getMock(); + + $this->tagManager = new SystemTagManager( + $this->connection, + $this->dispatcher + ); $this->pruneTagsTables(); } @@ -378,7 +391,7 @@ class SystemTagManagerTest extends TestCase { $tag1 = $this->tagManager->createTag('one', true, false); $tag2 = $this->tagManager->createTag('two', true, true); - $tagMapper = new SystemTagObjectMapper($this->connection, $this->tagManager); + $tagMapper = new SystemTagObjectMapper($this->connection, $this->tagManager, $this->dispatcher); $tagMapper->assignTags(1, 'testtype', $tag1->getId()); $tagMapper->assignTags(1, 'testtype', $tag2->getId()); diff --git a/tests/lib/systemtag/systemtagobjectmappertest.php b/tests/lib/systemtag/systemtagobjectmappertest.php index 4ea80c216ed..5c8204f6a87 100644 --- a/tests/lib/systemtag/systemtagobjectmappertest.php +++ b/tests/lib/systemtag/systemtagobjectmappertest.php @@ -10,14 +10,15 @@ namespace Test\SystemTag; +use OC\SystemTag\SystemTag; use OC\SystemTag\SystemTagManager; use OC\SystemTag\SystemTagObjectMapper; -use \OCP\SystemTag\ISystemTag; -use \OCP\SystemTag\ISystemTagManager; -use \OCP\SystemTag\ISystemTagObjectMapper; -use \OCP\SystemTag\TagNotFoundException; -use \OCP\IDBConnection; -use \OC\SystemTag\SystemTag; +use OCP\IDBConnection; +use OCP\SystemTag\ISystemTag; +use OCP\SystemTag\ISystemTagManager; +use OCP\SystemTag\ISystemTagObjectMapper; +use OCP\SystemTag\TagNotFoundException; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Test\TestCase; /** @@ -44,6 +45,11 @@ class SystemTagObjectMapperTest extends TestCase { private $connection; /** + * @var EventDispatcherInterface + */ + private $dispatcher; + + /** * @var ISystemTag */ private $tag1; @@ -67,7 +73,14 @@ class SystemTagObjectMapperTest extends TestCase { $this->tagManager = $this->getMockBuilder('OCP\SystemTag\ISystemTagManager') ->getMock(); - $this->tagMapper = new SystemTagObjectMapper($this->connection, $this->tagManager); + $this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface') + ->getMock(); + + $this->tagMapper = new SystemTagObjectMapper( + $this->connection, + $this->tagManager, + $this->dispatcher + ); $this->tag1 = new SystemTag(1, 'testtag1', false, false); $this->tag2 = new SystemTag(2, 'testtag2', true, false); |