2014-07-09 10:19:50 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2015-10-27 13:09:45 +00:00
|
|
|
* @author Arthur Schiwon <blizzz@owncloud.com>
|
|
|
|
* @author Lukas Reschke <lukas@owncloud.com>
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
2014-07-09 10:19:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Test\Group;
|
|
|
|
|
2016-09-07 18:02:11 +00:00
|
|
|
use OCP\IUserSession;
|
|
|
|
|
2016-05-19 06:44:41 +00:00
|
|
|
class MetaDataTest extends \Test\TestCase {
|
2015-10-27 13:09:45 +00:00
|
|
|
/** @var \OC\Group\Manager */
|
|
|
|
private $groupManager;
|
|
|
|
/** @var \OCP\IUserSession */
|
|
|
|
private $userSession;
|
|
|
|
/** @var \OC\Group\MetaData */
|
|
|
|
private $groupMetadata;
|
|
|
|
/** @var bool */
|
|
|
|
private $isAdmin = true;
|
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
$this->groupManager = $this->getMockBuilder('\OC\Group\Manager')
|
2014-07-09 10:19:50 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2016-09-07 18:02:11 +00:00
|
|
|
$this->userSession = $this->createMock(IUserSession::class);
|
2015-10-27 13:09:45 +00:00
|
|
|
$this->groupMetadata = new \OC\Group\MetaData(
|
|
|
|
'foo',
|
|
|
|
$this->isAdmin,
|
|
|
|
$this->groupManager,
|
|
|
|
$this->userSession
|
|
|
|
);
|
2014-07-09 10:19:50 +00:00
|
|
|
}
|
|
|
|
|
2015-05-18 10:23:12 +00:00
|
|
|
private function getGroupMock($countCallCount = 0) {
|
2014-07-09 10:19:50 +00:00
|
|
|
$group = $this->getMockBuilder('\OC\Group\Group')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
2018-03-03 11:22:27 +00:00
|
|
|
$group->expects($this->exactly(6))
|
2014-07-09 10:19:50 +00:00
|
|
|
->method('getGID')
|
|
|
|
->will($this->onConsecutiveCalls(
|
2018-03-05 09:10:05 +00:00
|
|
|
'admin', 'admin',
|
|
|
|
'g2', 'g2',
|
|
|
|
'g3', 'g3'));
|
2014-07-09 10:19:50 +00:00
|
|
|
|
2018-03-03 11:22:27 +00:00
|
|
|
$group->expects($this->exactly(3))
|
|
|
|
->method('getDisplayName')
|
|
|
|
->will($this->onConsecutiveCalls(
|
|
|
|
'admin',
|
|
|
|
'g2',
|
|
|
|
'g3'));
|
|
|
|
|
2015-05-18 10:23:12 +00:00
|
|
|
$group->expects($this->exactly($countCallCount))
|
2014-07-09 10:19:50 +00:00
|
|
|
->method('count')
|
|
|
|
->with('')
|
|
|
|
->will($this->onConsecutiveCalls(2, 3, 5));
|
|
|
|
|
|
|
|
return $group;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testGet() {
|
|
|
|
$group = $this->getGroupMock();
|
|
|
|
$groups = array_fill(0, 3, $group);
|
|
|
|
|
2015-10-27 13:09:45 +00:00
|
|
|
$this->groupManager->expects($this->once())
|
2014-07-09 10:19:50 +00:00
|
|
|
->method('search')
|
|
|
|
->with('')
|
|
|
|
->will($this->returnValue($groups));
|
|
|
|
|
2015-10-27 13:09:45 +00:00
|
|
|
list($adminGroups, $ordinaryGroups) = $this->groupMetadata->get();
|
2014-07-09 10:19:50 +00:00
|
|
|
|
|
|
|
$this->assertSame(1, count($adminGroups));
|
|
|
|
$this->assertSame(2, count($ordinaryGroups));
|
|
|
|
|
|
|
|
$this->assertSame('g2', $ordinaryGroups[0]['name']);
|
2015-05-18 10:23:12 +00:00
|
|
|
// user count is not loaded
|
|
|
|
$this->assertSame(0, $ordinaryGroups[0]['usercount']);
|
2014-07-09 10:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetWithSorting() {
|
2015-10-27 13:09:45 +00:00
|
|
|
$this->groupMetadata->setSorting(1);
|
2015-05-18 10:23:12 +00:00
|
|
|
$group = $this->getGroupMock(3);
|
2014-07-09 10:19:50 +00:00
|
|
|
$groups = array_fill(0, 3, $group);
|
|
|
|
|
2015-10-27 13:09:45 +00:00
|
|
|
$this->groupManager->expects($this->once())
|
2014-07-09 10:19:50 +00:00
|
|
|
->method('search')
|
|
|
|
->with('')
|
|
|
|
->will($this->returnValue($groups));
|
|
|
|
|
2015-10-27 13:09:45 +00:00
|
|
|
list($adminGroups, $ordinaryGroups) = $this->groupMetadata->get();
|
2014-07-09 10:19:50 +00:00
|
|
|
|
|
|
|
$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() {
|
|
|
|
$group = $this->getGroupMock();
|
|
|
|
$groups = array_fill(0, 3, $group);
|
|
|
|
|
2015-10-27 13:09:45 +00:00
|
|
|
$this->groupManager->expects($this->once())
|
2014-07-09 10:19:50 +00:00
|
|
|
->method('search')
|
|
|
|
->with('')
|
|
|
|
->will($this->returnValue($groups));
|
|
|
|
|
|
|
|
//two calls, if caching fails call counts for group and groupmanager
|
|
|
|
//are exceeded
|
2015-10-27 13:09:45 +00:00
|
|
|
$this->groupMetadata->get();
|
|
|
|
$this->groupMetadata->get();
|
2014-07-09 10:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//get() does not need to be tested with search parameters, because they are
|
|
|
|
//solely and only passed to GroupManager and Group.
|
|
|
|
|
2015-10-27 13:09:45 +00:00
|
|
|
public function testGetGroupsAsAdmin() {
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('search')
|
|
|
|
->with('Foo')
|
|
|
|
->will($this->returnValue(['DummyValue']));
|
|
|
|
|
|
|
|
$expected = ['DummyValue'];
|
|
|
|
$this->assertSame($expected, $this->invokePrivate($this->groupMetadata, 'getGroups', ['Foo']));
|
|
|
|
}
|
2014-07-09 10:19:50 +00:00
|
|
|
}
|