diff options
Diffstat (limited to 'apps/user_ldap/tests/UserLDAPPluginTest.php')
-rw-r--r-- | apps/user_ldap/tests/UserLDAPPluginTest.php | 181 |
1 files changed, 80 insertions, 101 deletions
diff --git a/apps/user_ldap/tests/UserLDAPPluginTest.php b/apps/user_ldap/tests/UserLDAPPluginTest.php index 1d7d2ee7c75..8a065374e61 100644 --- a/apps/user_ldap/tests/UserLDAPPluginTest.php +++ b/apps/user_ldap/tests/UserLDAPPluginTest.php @@ -1,54 +1,33 @@ <?php + +declare(strict_types=1); /** - * @copyright Copyright (c) 2017 EITA Cooperative (eita.org.br) - * - * @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/>. - * + * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ - namespace OCA\User_LDAP\Tests; - use OC\User\Backend; use OCA\User_LDAP\UserPluginManager; class UserLDAPPluginTest extends \Test\TestCase { - - /** - * @return UserPluginManager - */ - private function getUserPluginManager() { + private function getUserPluginManager(): UserPluginManager { return new UserPluginManager(); } - public function testImplementsActions() { + public function testImplementsActions(): void { $pluginManager = $this->getUserPluginManager(); - $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPUserPluginDummy') - ->setMethods(['respondToActions']) + $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class) + ->onlyMethods(['respondToActions']) ->getMock(); $plugin->expects($this->any()) ->method('respondToActions') ->willReturn(Backend::CREATE_USER); - $plugin2 = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPUserPluginDummy') - ->setMethods(['respondToActions']) + $plugin2 = $this->getMockBuilder(LDAPUserPluginDummy::class) + ->onlyMethods(['respondToActions']) ->getMock(); $plugin2->expects($this->any()) @@ -63,11 +42,11 @@ class UserLDAPPluginTest extends \Test\TestCase { $this->assertTrue($pluginManager->implementsActions(Backend::PROVIDE_AVATAR)); } - public function testCreateUser() { + public function testCreateUser(): void { $pluginManager = $this->getUserPluginManager(); - $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPUserPluginDummy') - ->setMethods(['respondToActions', 'createUser']) + $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class) + ->onlyMethods(['respondToActions', 'createUser']) ->getMock(); $plugin->expects($this->any()) @@ -85,20 +64,20 @@ class UserLDAPPluginTest extends \Test\TestCase { $pluginManager->createUser('user', 'password'); } - /** - * @expectedException \Exception - * @expectedExceptionMessage No plugin implements createUser in this LDAP Backend. - */ - public function testCreateUserNotRegistered() { + + public function testCreateUserNotRegistered(): void { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('No plugin implements createUser in this LDAP Backend.'); + $pluginManager = $this->getUserPluginManager(); - $pluginManager->createUser('foo','bar'); + $pluginManager->createUser('foo', 'bar'); } - public function testSetPassword() { + public function testSetPassword(): void { $pluginManager = $this->getUserPluginManager(); - $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPUserPluginDummy') - ->setMethods(['respondToActions', 'setPassword']) + $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class) + ->onlyMethods(['respondToActions', 'setPassword']) ->getMock(); $plugin->expects($this->any()) @@ -116,20 +95,20 @@ class UserLDAPPluginTest extends \Test\TestCase { $pluginManager->setPassword('user', 'password'); } - /** - * @expectedException \Exception - * @expectedExceptionMessage No plugin implements setPassword in this LDAP Backend. - */ - public function testSetPasswordNotRegistered() { + + public function testSetPasswordNotRegistered(): void { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('No plugin implements setPassword in this LDAP Backend.'); + $pluginManager = $this->getUserPluginManager(); - $pluginManager->setPassword('foo','bar'); + $pluginManager->setPassword('foo', 'bar'); } - public function testGetHome() { + public function testGetHome(): void { $pluginManager = $this->getUserPluginManager(); - $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPUserPluginDummy') - ->setMethods(['respondToActions', 'getHome']) + $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class) + ->onlyMethods(['respondToActions', 'getHome']) ->getMock(); $plugin->expects($this->any()) @@ -146,20 +125,20 @@ class UserLDAPPluginTest extends \Test\TestCase { $pluginManager->getHome('uid'); } - /** - * @expectedException \Exception - * @expectedExceptionMessage No plugin implements getHome in this LDAP Backend. - */ - public function testGetHomeNotRegistered() { + + public function testGetHomeNotRegistered(): void { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('No plugin implements getHome in this LDAP Backend.'); + $pluginManager = $this->getUserPluginManager(); $pluginManager->getHome('foo'); - } + } - public function testGetDisplayName() { + public function testGetDisplayName(): void { $pluginManager = $this->getUserPluginManager(); - $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPUserPluginDummy') - ->setMethods(['respondToActions', 'getDisplayName']) + $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class) + ->onlyMethods(['respondToActions', 'getDisplayName']) ->getMock(); $plugin->expects($this->any()) @@ -176,20 +155,20 @@ class UserLDAPPluginTest extends \Test\TestCase { $pluginManager->getDisplayName('uid'); } - /** - * @expectedException \Exception - * @expectedExceptionMessage No plugin implements getDisplayName in this LDAP Backend. - */ - public function testGetDisplayNameNotRegistered() { + + public function testGetDisplayNameNotRegistered(): void { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('No plugin implements getDisplayName in this LDAP Backend.'); + $pluginManager = $this->getUserPluginManager(); $pluginManager->getDisplayName('foo'); } - public function testSetDisplayName() { + public function testSetDisplayName(): void { $pluginManager = $this->getUserPluginManager(); - $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPUserPluginDummy') - ->setMethods(['respondToActions', 'setDisplayName']) + $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class) + ->onlyMethods(['respondToActions', 'setDisplayName']) ->getMock(); $plugin->expects($this->any()) @@ -204,23 +183,23 @@ class UserLDAPPluginTest extends \Test\TestCase { ); $pluginManager->register($plugin); - $pluginManager->setDisplayName('user', 'password'); + $pluginManager->setDisplayName('user', 'password'); } - /** - * @expectedException \Exception - * @expectedExceptionMessage No plugin implements setDisplayName in this LDAP Backend. - */ - public function testSetDisplayNameNotRegistered() { + + public function testSetDisplayNameNotRegistered(): void { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('No plugin implements setDisplayName in this LDAP Backend.'); + $pluginManager = $this->getUserPluginManager(); $pluginManager->setDisplayName('foo', 'bar'); - } + } - public function testCanChangeAvatar() { + public function testCanChangeAvatar(): void { $pluginManager = $this->getUserPluginManager(); - $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPUserPluginDummy') - ->setMethods(['respondToActions', 'canChangeAvatar']) + $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class) + ->onlyMethods(['respondToActions', 'canChangeAvatar']) ->getMock(); $plugin->expects($this->any()) @@ -237,20 +216,20 @@ class UserLDAPPluginTest extends \Test\TestCase { $pluginManager->canChangeAvatar('uid'); } - /** - * @expectedException \Exception - * @expectedExceptionMessage No plugin implements canChangeAvatar in this LDAP Backend. - */ - public function testCanChangeAvatarNotRegistered() { + + public function testCanChangeAvatarNotRegistered(): void { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('No plugin implements canChangeAvatar in this LDAP Backend.'); + $pluginManager = $this->getUserPluginManager(); $pluginManager->canChangeAvatar('foo'); } - public function testCountUsers() { + public function testCountUsers(): void { $pluginManager = $this->getUserPluginManager(); - $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPUserPluginDummy') - ->setMethods(['respondToActions', 'countUsers']) + $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class) + ->onlyMethods(['respondToActions', 'countUsers']) ->getMock(); $plugin->expects($this->any()) @@ -264,20 +243,20 @@ class UserLDAPPluginTest extends \Test\TestCase { $pluginManager->countUsers(); } - /** - * @expectedException \Exception - * @expectedExceptionMessage No plugin implements countUsers in this LDAP Backend. - */ - public function testCountUsersNotRegistered() { + + public function testCountUsersNotRegistered(): void { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('No plugin implements countUsers in this LDAP Backend.'); + $pluginManager = $this->getUserPluginManager(); $pluginManager->countUsers(); - } + } - public function testDeleteUser() { + public function testDeleteUser(): void { $pluginManager = $this->getUserPluginManager(); - $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPUserPluginDummy') - ->setMethods(['respondToActions', 'canDeleteUser','deleteUser']) + $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class) + ->onlyMethods(['respondToActions', 'canDeleteUser','deleteUser']) ->getMock(); $plugin->expects($this->any()) @@ -300,11 +279,11 @@ class UserLDAPPluginTest extends \Test\TestCase { $pluginManager->deleteUser('uid'); } - /** - * @expectedException \Exception - * @expectedExceptionMessage No plugin implements deleteUser in this LDAP Backend. - */ - public function testDeleteUserNotRegistered() { + + public function testDeleteUserNotRegistered(): void { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('No plugin implements deleteUser in this LDAP Backend.'); + $pluginManager = $this->getUserPluginManager(); $pluginManager->deleteUser('foo'); } |