123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- <?php
- /**
- * @copyright Copyright (c) 2017 EITA Cooperative (eita.org.br)
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Vinicius Cubas Brand <vinicius@eita.org.br>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * 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
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
- namespace OCA\User_LDAP\Tests;
- use OCA\User_LDAP\GroupPluginManager;
- use OCP\GroupInterface;
- class GroupLDAPPluginTest extends \Test\TestCase {
- /**
- * @return GroupPluginManager
- */
- private function getGroupPluginManager() {
- return new GroupPluginManager();
- }
- public function testImplementsActions() {
- $pluginManager = $this->getGroupPluginManager();
- $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
- ->setMethods(['respondToActions'])
- ->getMock();
- $plugin->expects($this->any())
- ->method('respondToActions')
- ->willReturn(GroupInterface::CREATE_GROUP);
- $plugin2 = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
- ->setMethods(['respondToActions'])
- ->getMock();
- $plugin2->expects($this->any())
- ->method('respondToActions')
- ->willReturn(GroupInterface::ADD_TO_GROUP);
- $pluginManager->register($plugin);
- $pluginManager->register($plugin2);
- $this->assertEquals($pluginManager->getImplementedActions(), GroupInterface::CREATE_GROUP | GroupInterface::ADD_TO_GROUP);
- $this->assertTrue($pluginManager->implementsActions(GroupInterface::CREATE_GROUP));
- $this->assertTrue($pluginManager->implementsActions(GroupInterface::ADD_TO_GROUP));
- }
- public function testCreateGroup() {
- $pluginManager = $this->getGroupPluginManager();
- $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
- ->setMethods(['respondToActions', 'createGroup'])
- ->getMock();
- $plugin->expects($this->any())
- ->method('respondToActions')
- ->willReturn(GroupInterface::CREATE_GROUP);
- $plugin->expects($this->once())
- ->method('createGroup')
- ->with(
- $this->equalTo('group')
- );
- $pluginManager->register($plugin);
- $pluginManager->createGroup('group');
- }
- public function testCreateGroupNotRegistered() {
- $this->expectException(\Exception::class);
- $this->expectExceptionMessage('No plugin implements createGroup in this LDAP Backend.');
- $pluginManager = $this->getGroupPluginManager();
- $pluginManager->createGroup('foo');
- }
- public function testDeleteGroup() {
- $pluginManager = $this->getGroupPluginManager();
- $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
- ->setMethods(['respondToActions', 'deleteGroup'])
- ->getMock();
- $plugin->expects($this->any())
- ->method('respondToActions')
- ->willReturn(GroupInterface::DELETE_GROUP);
- $plugin->expects($this->once())
- ->method('deleteGroup')
- ->with(
- $this->equalTo('group')
- )->willReturn(true);
- $pluginManager->register($plugin);
- $this->assertTrue($pluginManager->deleteGroup('group'));
- }
- public function testDeleteGroupNotRegistered() {
- $this->expectException(\Exception::class);
- $this->expectExceptionMessage('No plugin implements deleteGroup in this LDAP Backend.');
- $pluginManager = $this->getGroupPluginManager();
- $pluginManager->deleteGroup('foo');
- }
- public function testAddToGroup() {
- $pluginManager = $this->getGroupPluginManager();
- $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
- ->setMethods(['respondToActions', 'addToGroup'])
- ->getMock();
- $plugin->expects($this->any())
- ->method('respondToActions')
- ->willReturn(GroupInterface::ADD_TO_GROUP);
- $plugin->expects($this->once())
- ->method('addToGroup')
- ->with(
- $this->equalTo('uid'),
- $this->equalTo('gid')
- );
- $pluginManager->register($plugin);
- $pluginManager->addToGroup('uid', 'gid');
- }
- public function testAddToGroupNotRegistered() {
- $this->expectException(\Exception::class);
- $this->expectExceptionMessage('No plugin implements addToGroup in this LDAP Backend.');
- $pluginManager = $this->getGroupPluginManager();
- $pluginManager->addToGroup('foo', 'bar');
- }
- public function testRemoveFromGroup() {
- $pluginManager = $this->getGroupPluginManager();
- $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
- ->setMethods(['respondToActions', 'removeFromGroup'])
- ->getMock();
- $plugin->expects($this->any())
- ->method('respondToActions')
- ->willReturn(GroupInterface::REMOVE_FROM_GROUP);
- $plugin->expects($this->once())
- ->method('removeFromGroup')
- ->with(
- $this->equalTo('uid'),
- $this->equalTo('gid')
- );
- $pluginManager->register($plugin);
- $pluginManager->removeFromGroup('uid', 'gid');
- }
- public function testRemoveFromGroupNotRegistered() {
- $this->expectException(\Exception::class);
- $this->expectExceptionMessage('No plugin implements removeFromGroup in this LDAP Backend.');
- $pluginManager = $this->getGroupPluginManager();
- $pluginManager->removeFromGroup('foo', 'bar');
- }
- public function testCountUsersInGroup() {
- $pluginManager = $this->getGroupPluginManager();
- $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
- ->setMethods(['respondToActions', 'countUsersInGroup'])
- ->getMock();
- $plugin->expects($this->any())
- ->method('respondToActions')
- ->willReturn(GroupInterface::COUNT_USERS);
- $plugin->expects($this->once())
- ->method('countUsersInGroup')
- ->with(
- $this->equalTo('gid'),
- $this->equalTo('search')
- );
- $pluginManager->register($plugin);
- $pluginManager->countUsersInGroup('gid', 'search');
- }
- public function testCountUsersInGroupNotRegistered() {
- $this->expectException(\Exception::class);
- $this->expectExceptionMessage('No plugin implements countUsersInGroup in this LDAP Backend.');
- $pluginManager = $this->getGroupPluginManager();
- $pluginManager->countUsersInGroup('foo', 'bar');
- }
- public function testgetGroupDetails() {
- $pluginManager = $this->getGroupPluginManager();
- $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
- ->setMethods(['respondToActions', 'getGroupDetails'])
- ->getMock();
- $plugin->expects($this->any())
- ->method('respondToActions')
- ->willReturn(GroupInterface::GROUP_DETAILS);
- $plugin->expects($this->once())
- ->method('getGroupDetails')
- ->with(
- $this->equalTo('gid')
- );
- $pluginManager->register($plugin);
- $pluginManager->getGroupDetails('gid');
- }
- public function testgetGroupDetailsNotRegistered() {
- $this->expectException(\Exception::class);
- $this->expectExceptionMessage('No plugin implements getGroupDetails in this LDAP Backend.');
- $pluginManager = $this->getGroupPluginManager();
- $pluginManager->getGroupDetails('foo');
- }
- }
|