Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2018-10-31 00:42:24 +0300
committerArthur Schiwon <blizzz@arthur-schiwon.de>2018-10-31 00:44:50 +0300
commit0c5d9127e87549b84bf4edd7df34de2412d9ebfe (patch)
tree9e5a62f97a5f502bc1de77ecb1ad1e40a09354c3 /apps/user_ldap/tests
parent1293affc84db2e9e2ea127bb1dd44faaa85f9797 (diff)
remove app specific IUserTools and consolidate test
Just some house keeping. IUserTools with used in even older days for easier creation of Access instances… Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/user_ldap/tests')
-rw-r--r--apps/user_ldap/tests/User/ManagerTest.php224
1 files changed, 100 insertions, 124 deletions
diff --git a/apps/user_ldap/tests/User/ManagerTest.php b/apps/user_ldap/tests/User/ManagerTest.php
index 104a70ff700..5c111abdc4e 100644
--- a/apps/user_ldap/tests/User/ManagerTest.php
+++ b/apps/user_ldap/tests/User/ManagerTest.php
@@ -28,11 +28,13 @@
namespace OCA\User_LDAP\Tests\User;
+use OCA\User_LDAP\Access;
+use OCA\User_LDAP\Connection;
use OCA\User_LDAP\FilesystemHelper;
use OCA\User_LDAP\ILDAPWrapper;
use OCA\User_LDAP\LogWrapper;
-use OCA\User_LDAP\User\IUserTools;
use OCA\User_LDAP\User\Manager;
+use OCA\User_LDAP\User\User;
use OCP\IAvatarManager;
use OCP\IConfig;
use OCP\IDBConnection;
@@ -48,200 +50,181 @@ use OCP\Notification\IManager as INotificationManager;
* @package OCA\User_LDAP\Tests\User
*/
class ManagerTest extends \Test\TestCase {
+ /** @var Access|\PHPUnit_Framework_MockObject_MockObject */
+ protected $access;
- private function getTestInstances() {
- $access = $this->createMock(IUserTools::class);
- $config = $this->createMock(IConfig::class);
- $filesys = $this->createMock(FilesystemHelper::class);
- $log = $this->createMock(LogWrapper::class);
- $avaMgr = $this->createMock(IAvatarManager::class);
- $image = $this->createMock(Image::class);
- $dbc = $this->createMock(IDBConnection::class);
- $userMgr = $this->createMock(IUserManager::class);
- $notiMgr = $this->createMock(INotificationManager::class);
-
- $connection = new \OCA\User_LDAP\Connection(
- $lw = $this->createMock(ILDAPWrapper::class),
- '',
- null
- );
+ /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
+ protected $config;
- $access->expects($this->any())
- ->method('getConnection')
- ->will($this->returnValue($connection));
+ /** @var FilesystemHelper|\PHPUnit_Framework_MockObject_MockObject */
+ protected $fileSystemHelper;
- return array($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr);
- }
+ /** @var LogWrapper|\PHPUnit_Framework_MockObject_MockObject */
+ protected $log;
- public function testGetByDNExisting() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
- $this->getTestInstances();
+ /** @var IAvatarManager|\PHPUnit_Framework_MockObject_MockObject */
+ protected $avatarManager;
- $inputDN = 'cn=foo,dc=foobar,dc=bar';
- $uid = '563418fc-423b-1033-8d1c-ad5f418ee02e';
+ /** @var Image|\PHPUnit_Framework_MockObject_MockObject */
+ protected $image;
- $access->expects($this->once())
- ->method('stringResemblesDN')
- ->with($this->equalTo($inputDN))
- ->will($this->returnValue(true));
+ /** @var IDBConnection|\PHPUnit_Framework_MockObject_MockObject */
+ protected $dbc;
- $access->expects($this->once())
- ->method('dn2username')
- ->with($this->equalTo($inputDN))
- ->will($this->returnValue($uid));
+ /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
+ protected $ncUserManager;
- $access->expects($this->never())
- ->method('username2dn');
+ /** @var INotificationManager|\PHPUnit_Framework_MockObject_MockObject */
+ protected $notificationManager;
- $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr, $notiMgr);
- $manager->setLdapAccess($access);
- $user = $manager->get($inputDN);
+ /** @var ILDAPWrapper|\PHPUnit_Framework_MockObject_MockObject */
+ protected $ldapWrapper;
- // Now we fetch the user again. If this leads to a failing test,
- // runtime caching the manager is broken.
- $user = $manager->get($inputDN);
-
- $this->assertInstanceOf('\OCA\User_LDAP\User\User', $user);
- }
+ /** @var Connection */
+ protected $connection;
- public function testGetByEDirectoryDN() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
- $this->getTestInstances();
+ /** @var Manager */
+ protected $manager;
- $inputDN = 'uid=foo,o=foobar,c=bar';
- $uid = '563418fc-423b-1033-8d1c-ad5f418ee02e';
+ public function setUp() {
+ parent::setUp();
- $access->expects($this->once())
- ->method('stringResemblesDN')
- ->with($this->equalTo($inputDN))
- ->will($this->returnValue(true));
-
- $access->expects($this->once())
- ->method('dn2username')
- ->with($this->equalTo($inputDN))
- ->will($this->returnValue($uid));
+ $this->access = $this->createMock(Access::class);
+ $this->config = $this->createMock(IConfig::class);
+ $this->fileSystemHelper = $this->createMock(FilesystemHelper::class);
+ $this->log = $this->createMock(LogWrapper::class);
+ $this->avatarManager = $this->createMock(IAvatarManager::class);
+ $this->image = $this->createMock(Image::class);
+ $this->dbc = $this->createMock(IDBConnection::class);
+ $this->ncUserManager = $this->createMock(IUserManager::class);
+ $this->notificationManager = $this->createMock(INotificationManager::class);
- $access->expects($this->never())
- ->method('username2dn');
+ $this->ldapWrapper = $this->createMock(ILDAPWrapper::class);
+ $this->connection = new Connection($this->ldapWrapper, '', null);
- $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr, $notiMgr);
- $manager->setLdapAccess($access);
- $user = $manager->get($inputDN);
+ $this->access->expects($this->any())
+ ->method('getConnection')
+ ->will($this->returnValue($this->connection));
+
+ /** @noinspection PhpUnhandledExceptionInspection */
+ $this->manager = new Manager(
+ $this->config,
+ $this->fileSystemHelper,
+ $this->log,
+ $this->avatarManager,
+ $this->image,
+ $this->dbc,
+ $this->ncUserManager,
+ $this->notificationManager
+ );
- $this->assertInstanceOf('\OCA\User_LDAP\User\User', $user);
+ $this->manager->setLdapAccess($this->access);
}
- public function testGetByExoticDN() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
- $this->getTestInstances();
+ public function dnProvider() {
+ return [
+ ['cn=foo,dc=foobar,dc=bar'],
+ ['uid=foo,o=foobar,c=bar'],
+ ['ab=cde,f=ghei,mno=pq'],
+ ];
+ }
- $inputDN = 'ab=cde,f=ghei,mno=pq';
+ /**
+ * @dataProvider dnProvider
+ */
+ public function testGetByDNExisting(string $inputDN) {
$uid = '563418fc-423b-1033-8d1c-ad5f418ee02e';
- $access->expects($this->once())
+ $this->access->expects($this->once())
->method('stringResemblesDN')
->with($this->equalTo($inputDN))
->will($this->returnValue(true));
-
- $access->expects($this->once())
+ $this->access->expects($this->once())
->method('dn2username')
->with($this->equalTo($inputDN))
->will($this->returnValue($uid));
-
- $access->expects($this->never())
+ $this->access->expects($this->never())
->method('username2dn');
- $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr, $notiMgr);
- $manager->setLdapAccess($access);
- $user = $manager->get($inputDN);
+ /** @noinspection PhpUnhandledExceptionInspection */
+ $this->manager->get($inputDN);
- $this->assertInstanceOf('\OCA\User_LDAP\User\User', $user);
+ // Now we fetch the user again. If this leads to a failing test,
+ // runtime caching the manager is broken.
+ /** @noinspection PhpUnhandledExceptionInspection */
+ $user = $this->manager->get($inputDN);
+
+ $this->assertInstanceOf(User::class, $user);
}
public function testGetByDNNotExisting() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
- $this->getTestInstances();
-
$inputDN = 'cn=gone,dc=foobar,dc=bar';
- $access->expects($this->once())
+ $this->access->expects($this->once())
->method('stringResemblesDN')
->with($this->equalTo($inputDN))
->will($this->returnValue(true));
-
- $access->expects($this->once())
+ $this->access->expects($this->once())
->method('dn2username')
->with($this->equalTo($inputDN))
->will($this->returnValue(false));
-
- $access->expects($this->once())
+ $this->access->expects($this->once())
->method('username2dn')
->with($this->equalTo($inputDN))
->will($this->returnValue(false));
- $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr, $notiMgr);
- $manager->setLdapAccess($access);
- $user = $manager->get($inputDN);
+ /** @noinspection PhpUnhandledExceptionInspection */
+ $user = $this->manager->get($inputDN);
$this->assertNull($user);
}
public function testGetByUidExisting() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
- $this->getTestInstances();
-
$dn = 'cn=foo,dc=foobar,dc=bar';
$uid = '563418fc-423b-1033-8d1c-ad5f418ee02e';
- $access->expects($this->never())
+ $this->access->expects($this->never())
->method('dn2username');
-
- $access->expects($this->once())
+ $this->access->expects($this->once())
->method('username2dn')
->with($this->equalTo($uid))
->will($this->returnValue($dn));
-
- $access->expects($this->once())
+ $this->access->expects($this->once())
->method('stringResemblesDN')
->with($this->equalTo($uid))
->will($this->returnValue(false));
- $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr, $notiMgr);
- $manager->setLdapAccess($access);
- $user = $manager->get($uid);
+ /** @noinspection PhpUnhandledExceptionInspection */
+ $this->manager->get($uid);
// Now we fetch the user again. If this leads to a failing test,
// runtime caching the manager is broken.
- $user = $manager->get($uid);
+ /** @noinspection PhpUnhandledExceptionInspection */
+ $user = $this->manager->get($uid);
- $this->assertInstanceOf('\OCA\User_LDAP\User\User', $user);
+ $this->assertInstanceOf(User::class, $user);
}
public function testGetByUidNotExisting() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
- $this->getTestInstances();
-
$uid = 'gone';
- $access->expects($this->never())
+ $this->access->expects($this->never())
->method('dn2username');
-
- $access->expects($this->exactly(1))
+ $this->access->expects($this->exactly(1))
->method('username2dn')
->with($this->equalTo($uid))
->will($this->returnValue(false));
- $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr, $notiMgr);
- $manager->setLdapAccess($access);
- $user = $manager->get($uid);
+ /** @noinspection PhpUnhandledExceptionInspection */
+ $user = $this->manager->get($uid);
$this->assertNull($user);
}
public function attributeRequestProvider() {
return [
- [ false ],
- [ true ],
+ [false],
+ [true],
];
}
@@ -249,23 +232,16 @@ class ManagerTest extends \Test\TestCase {
* @dataProvider attributeRequestProvider
*/
public function testGetAttributes($minimal) {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
- $this->getTestInstances();
-
- $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr, $notiMgr);
- $manager->setLdapAccess($access);
-
- $connection = $access->getConnection();
- $connection->setConfiguration([
+ $this->connection->setConfiguration([
'ldapEmailAttribute' => 'mail',
'ldapUserAvatarRule' => 'default',
'ldapQuotaAttribute' => '',
]);
- $attributes = $manager->getAttributes($minimal);
+ $attributes = $this->manager->getAttributes($minimal);
$this->assertTrue(in_array('dn', $attributes));
- $this->assertTrue(in_array($access->getConnection()->ldapEmailAttribute, $attributes));
+ $this->assertTrue(in_array($this->access->getConnection()->ldapEmailAttribute, $attributes));
$this->assertFalse(in_array('', $attributes));
$this->assertSame(!$minimal, in_array('jpegphoto', $attributes));
$this->assertSame(!$minimal, in_array('thumbnailphoto', $attributes));