Blame view
sources/tests/lib/group/metadata.php
2.73 KB
|
f7d878ff1
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 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.
}
|