use OC\User\User;
class GroupTest extends \Test\TestCase {
+
+ /**
+ * @param string $uid
+ * @param $backend
+ * @return User
+ */
+ private function newUser($uid, $backend) {
+ $config = $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $urlgenerator = $this->getMockBuilder('\OCP\IURLGenerator')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ return new User($uid, $backend, null, $config, $urlgenerator);
+ }
+
/**
- * @return \OC\User\Manager | \OC\User\Manager
+ * @return \OC\User\Manager
*/
protected function getUserManager() {
- $userManager = $this->getMock('\OC\User\Manager');
- $backend = $this->getMock('\OC_User_Backend');
- $user1 = new User('user1', $backend);
- $user2 = new User('user2', $backend);
- $user3 = new User('user3', $backend);
+ $userManager = $this->getMockBuilder('\OC\User\Manager')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $backend = $this->getMockBuilder('\OC\User\Backend')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $user1 = $this->newUser('user1', $backend);
+ $user2 = $this->newUser('user2', $backend);
+ $user3 = $this->newUser('user3', $backend);
$userManager->expects($this->any())
->method('get')
->will($this->returnValueMap(array(
}
public function testGetUsersSingleBackend() {
- $backend = $this->getMock('OC\Group\Database');
+ $backend = $this->getMockBuilder('OC\Group\Database')
+ ->disableOriginalConstructor()
+ ->getMock();
$userManager = $this->getUserManager();
$group = new \OC\Group\Group('group1', array($backend), $userManager);
}
public function testGetUsersMultipleBackends() {
- $backend1 = $this->getMock('OC\Group\Database');
- $backend2 = $this->getMock('OC\Group\Database');
+ $backend1 = $this->getMockBuilder('OC\Group\Database')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $backend2 = $this->getMockBuilder('OC\Group\Database')
+ ->disableOriginalConstructor()
+ ->getMock();
$userManager = $this->getUserManager();
$group = new \OC\Group\Group('group1', array($backend1, $backend2), $userManager);
}
public function testInGroupSingleBackend() {
- $backend = $this->getMock('OC\Group\Database');
+ $backend = $this->getMockBuilder('OC\Group\Database')
+ ->disableOriginalConstructor()
+ ->getMock();
$userManager = $this->getUserManager();
- $userBackend = $this->getMock('\OC_User_Backend');
+ $userBackend = $this->getMockBuilder('\OC\User\Backend')
+ ->disableOriginalConstructor()
+ ->getMock();
$group = new \OC\Group\Group('group1', array($backend), $userManager);
$backend->expects($this->once())
->with('user1', 'group1')
->will($this->returnValue(true));
- $this->assertTrue($group->inGroup(new User('user1', $userBackend)));
+ $this->assertTrue($group->inGroup($this->newUser('user1', $userBackend)));
}
public function testInGroupMultipleBackends() {
- $backend1 = $this->getMock('OC\Group\Database');
- $backend2 = $this->getMock('OC\Group\Database');
+ $backend1 = $this->getMockBuilder('OC\Group\Database')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $backend2 = $this->getMockBuilder('OC\Group\Database')
+ ->disableOriginalConstructor()
+ ->getMock();
$userManager = $this->getUserManager();
- $userBackend = $this->getMock('\OC_User_Backend');
+ $userBackend = $this->getMockBuilder('\OC_User_Backend')
+ ->disableOriginalConstructor()
+ ->getMock();
$group = new \OC\Group\Group('group1', array($backend1, $backend2), $userManager);
$backend1->expects($this->once())
->with('user1', 'group1')
->will($this->returnValue(true));
- $this->assertTrue($group->inGroup(new User('user1', $userBackend)));
+ $this->assertTrue($group->inGroup($this->newUser('user1', $userBackend)));
}
public function testAddUser() {
- $backend = $this->getMock('OC\Group\Database');
+ $backend = $this->getMockBuilder('OC\Group\Database')
+ ->disableOriginalConstructor()
+ ->getMock();
$userManager = $this->getUserManager();
- $userBackend = $this->getMock('\OC_User_Backend');
+ $userBackend = $this->getMockBuilder('\OC\User\Backend')
+ ->disableOriginalConstructor()
+ ->getMock();
$group = new \OC\Group\Group('group1', array($backend), $userManager);
$backend->expects($this->once())
->method('addToGroup')
->with('user1', 'group1');
- $group->addUser(new User('user1', $userBackend));
+ $group->addUser($this->newUser('user1', $userBackend));
}
public function testAddUserAlreadyInGroup() {
- $backend = $this->getMock('OC\Group\Database');
+ $backend = $this->getMockBuilder('OC\Group\Database')
+ ->disableOriginalConstructor()
+ ->getMock();
$userManager = $this->getUserManager();
- $userBackend = $this->getMock('\OC_User_Backend');
+ $userBackend = $this->getMockBuilder('\OC\User\Backend')
+ ->disableOriginalConstructor()
+ ->getMock();
$group = new \OC\Group\Group('group1', array($backend), $userManager);
$backend->expects($this->once())
$backend->expects($this->never())
->method('addToGroup');
- $group->addUser(new User('user1', $userBackend));
+ $group->addUser($this->newUser('user1', $userBackend));
}
public function testRemoveUser() {
- $backend = $this->getMock('OC\Group\Database');
+ $backend = $this->getMockBuilder('OC\Group\Database')
+ ->disableOriginalConstructor()
+ ->getMock();
$userManager = $this->getUserManager();
- $userBackend = $this->getMock('\OC_User_Backend');
+ $userBackend = $this->getMockBuilder('\OC\User\Backend')
+ ->disableOriginalConstructor()
+ ->getMock();
$group = new \OC\Group\Group('group1', array($backend), $userManager);
$backend->expects($this->once())
->method('removeFromGroup')
->with('user1', 'group1');
- $group->removeUser(new User('user1', $userBackend));
+ $group->removeUser($this->newUser('user1', $userBackend));
}
public function testRemoveUserNotInGroup() {
- $backend = $this->getMock('OC\Group\Database');
+ $backend = $this->getMockBuilder('OC\Group\Database')
+ ->disableOriginalConstructor()
+ ->getMock();
$userManager = $this->getUserManager();
- $userBackend = $this->getMock('\OC_User_Backend');
+ $userBackend = $this->getMockBuilder('\OC_User_Backend')
+ ->disableOriginalConstructor()
+ ->getMock();
$group = new \OC\Group\Group('group1', array($backend), $userManager);
$backend->expects($this->once())
$backend->expects($this->never())
->method('removeFromGroup');
- $group->removeUser(new User('user1', $userBackend));
+ $group->removeUser($this->newUser('user1', $userBackend));
}
public function testRemoveUserMultipleBackends() {
- $backend1 = $this->getMock('OC\Group\Database');
- $backend2 = $this->getMock('OC\Group\Database');
+ $backend1 = $this->getMockBuilder('OC\Group\Database')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $backend2 = $this->getMockBuilder('OC\Group\Database')
+ ->disableOriginalConstructor()
+ ->getMock();
$userManager = $this->getUserManager();
- $userBackend = $this->getMock('\OC_User_Backend');
+ $userBackend = $this->getMockBuilder('\OC\User\Backend')
+ ->disableOriginalConstructor()
+ ->getMock();
$group = new \OC\Group\Group('group1', array($backend1, $backend2), $userManager);
$backend1->expects($this->once())
->method('removeFromGroup')
->with('user1', 'group1');
- $group->removeUser(new User('user1', $userBackend));
+ $group->removeUser($this->newUser('user1', $userBackend));
}
public function testSearchUsers() {
- $backend = $this->getMock('OC\Group\Database');
+ $backend = $this->getMockBuilder('OC\Group\Database')
+ ->disableOriginalConstructor()
+ ->getMock();
$userManager = $this->getUserManager();
$group = new \OC\Group\Group('group1', array($backend), $userManager);
}
public function testSearchUsersMultipleBackends() {
- $backend1 = $this->getMock('OC\Group\Database');
- $backend2 = $this->getMock('OC\Group\Database');
+ $backend1 = $this->getMockBuilder('OC\Group\Database')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $backend2 = $this->getMockBuilder('OC\Group\Database')
+ ->disableOriginalConstructor()
+ ->getMock();
$userManager = $this->getUserManager();
$group = new \OC\Group\Group('group1', array($backend1, $backend2), $userManager);
}
public function testSearchUsersLimitAndOffset() {
- $backend = $this->getMock('OC\Group\Database');
+ $backend = $this->getMockBuilder('OC\Group\Database')
+ ->disableOriginalConstructor()
+ ->getMock();
$userManager = $this->getUserManager();
$group = new \OC\Group\Group('group1', array($backend), $userManager);
}
public function testSearchUsersMultipleBackendsLimitAndOffset() {
- $backend1 = $this->getMock('OC\Group\Database');
- $backend2 = $this->getMock('OC\Group\Database');
+ $backend1 = $this->getMockBuilder('OC\Group\Database')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $backend2 = $this->getMockBuilder('OC\Group\Database')
+ ->disableOriginalConstructor()
+ ->getMock();
$userManager = $this->getUserManager();
$group = new \OC\Group\Group('group1', array($backend1, $backend2), $userManager);
}
public function testCountUsers() {
- $backend1 = $this->getMock('OC\Group\Database');
+ $backend1 = $this->getMockBuilder('OC\Group\Database')
+ ->disableOriginalConstructor()
+ ->getMock();
$userManager = $this->getUserManager();
$group = new \OC\Group\Group('group1', array($backend1), $userManager);
}
public function testCountUsersMultipleBackends() {
- $backend1 = $this->getMock('OC\Group\Database');
- $backend2 = $this->getMock('OC\Group\Database');
+ $backend1 = $this->getMockBuilder('OC\Group\Database')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $backend2 = $this->getMockBuilder('OC\Group\Database')
+ ->disableOriginalConstructor()
+ ->getMock();
$userManager = $this->getUserManager();
$group = new \OC\Group\Group('group1', array($backend1, $backend2), $userManager);
}
public function testCountUsersNoMethod() {
- $backend1 = $this->getMock('OC\Group\Database');
+ $backend1 = $this->getMockBuilder('OC\Group\Database')
+ ->disableOriginalConstructor()
+ ->getMock();
$userManager = $this->getUserManager();
$group = new \OC\Group\Group('group1', array($backend1), $userManager);
}
public function testDelete() {
- $backend = $this->getMock('OC\Group\Database');
+ $backend = $this->getMockBuilder('OC\Group\Database')
+ ->disableOriginalConstructor()
+ ->getMock();
$userManager = $this->getUserManager();
$group = new \OC\Group\Group('group1', array($backend), $userManager);