diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2014-07-09 12:19:50 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@owncloud.com> | 2014-07-15 08:31:43 +0200 |
commit | 334ace90802a224f60e9dfb942e4581739ddd3c2 (patch) | |
tree | 9daad4358aec60e14b5c5ef616456e642e70bfdf /tests | |
parent | 8ec00dcb6604b395620efb7b36ac36a47b90d2c5 (diff) | |
download | nextcloud-server-334ace90802a224f60e9dfb942e4581739ddd3c2.tar.gz nextcloud-server-334ace90802a224f60e9dfb942e4581739ddd3c2.zip |
Backport of #9562
remove dead code
do not filter groups. but update the user count according to the filter
improve phpdoc
improve metadata runtime cache
add metadata tests
fixing PHPDoc
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/group/metadata.php | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/tests/lib/group/metadata.php b/tests/lib/group/metadata.php new file mode 100644 index 00000000000..7ef2d6b35ff --- /dev/null +++ b/tests/lib/group/metadata.php @@ -0,0 +1,101 @@ +<?php + +/** + * Copyright (c) 2014 Arthur Schiwon <blizzz@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\Group; + +class Test_MetaData extends \PHPUnit_Framework_TestCase { + private function getGroupManagerMock() { + return $this->getMockBuilder('\OC\Group\Manager') + ->disableOriginalConstructor() + ->getMock(); + } + + private function getGroupMock() { + $group = $this->getMockBuilder('\OC\Group\Group') + ->disableOriginalConstructor() + ->getMock(); + + $group->expects($this->exactly(9)) + ->method('getGID') + ->will($this->onConsecutiveCalls( + 'admin', 'admin', 'admin', + 'g2', 'g2', 'g2', + 'g3', 'g3', 'g3')); + + $group->expects($this->exactly(3)) + ->method('count') + ->with('') + ->will($this->onConsecutiveCalls(2, 3, 5)); + + return $group; + } + + + public function testGet() { + $groupManager = $this->getGroupManagerMock(); + $groupMetaData = new \OC\Group\MetaData('foo', true, $groupManager); + $group = $this->getGroupMock(); + $groups = array_fill(0, 3, $group); + + $groupManager->expects($this->once()) + ->method('search') + ->with('') + ->will($this->returnValue($groups)); + + list($adminGroups, $ordinaryGroups) = $groupMetaData->get(); + + $this->assertSame(1, count($adminGroups)); + $this->assertSame(2, count($ordinaryGroups)); + + $this->assertSame('g2', $ordinaryGroups[0]['name']); + $this->assertSame(3, $ordinaryGroups[0]['usercount']); + } + + public function testGetWithSorting() { + $groupManager = $this->getGroupManagerMock(); + $groupMetaData = new \OC\Group\MetaData('foo', true, $groupManager); + $groupMetaData->setSorting($groupMetaData::SORT_USERCOUNT); + $group = $this->getGroupMock(); + $groups = array_fill(0, 3, $group); + + $groupManager->expects($this->once()) + ->method('search') + ->with('') + ->will($this->returnValue($groups)); + + list($adminGroups, $ordinaryGroups) = $groupMetaData->get(); + + $this->assertSame(1, count($adminGroups)); + $this->assertSame(2, count($ordinaryGroups)); + + $this->assertSame('g3', $ordinaryGroups[0]['name']); + $this->assertSame(5, $ordinaryGroups[0]['usercount']); + } + + public function testGetWithCache() { + $groupManager = $this->getGroupManagerMock(); + $groupMetaData = new \OC\Group\MetaData('foo', true, $groupManager); + $group = $this->getGroupMock(); + $groups = array_fill(0, 3, $group); + + $groupManager->expects($this->once()) + ->method('search') + ->with('') + ->will($this->returnValue($groups)); + + //two calls, if caching fails call counts for group and groupmanager + //are exceeded + $groupMetaData->get(); + $groupMetaData->get(); + } + + //get() does not need to be tested with search parameters, because they are + //solely and only passed to GroupManager and Group. + +} |