summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2014-07-09 12:19:50 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2014-07-14 21:26:37 +0200
commitab2c7e06a4ea3c751058b6b72dc9b8832836669a (patch)
tree709a7a31a74be44d08dc038b3169f1cb4144a4d5 /tests
parent9ee1c7ff7143c9d75a5f5a9f9477cc73f5d97717 (diff)
downloadnextcloud-server-ab2c7e06a4ea3c751058b6b72dc9b8832836669a.tar.gz
nextcloud-server-ab2c7e06a4ea3c751058b6b72dc9b8832836669a.zip
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
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/group/metadata.php101
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.
+
+}