Completed
Push — stable8.2 ( b4bbd4...3350d6 )
by
unknown
59:02
created

IntegrationTestUserDisplayName::initConnection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2
Metric Value
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * @author Arthur Schiwon <[email protected]>
4
 * @author Morris Jobke <[email protected]>
5
 *
6
 * @copyright Copyright (c) 2016, ownCloud, Inc.
7
 * @license AGPL-3.0
8
 *
9
 * This code is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License, version 3,
11
 * as published by the Free Software Foundation.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License, version 3,
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
20
 *
21
 */
22
use OCA\user_ldap\lib\user\User;
23
use OCA\User_LDAP\Mapping\UserMapping;
24
use OCA\user_ldap\tests\integration\AbstractIntegrationTest;
25
26
require_once __DIR__  . '/../../../../../../lib/base.php';
27
28
class IntegrationTestUserDisplayName extends AbstractIntegrationTest {
29
	/** @var  UserMapping */
30
	protected $mapping;
31
32
	/**
33
	 * prepares the LDAP environment and sets up a test configuration for
34
	 * the LDAP backend.
35
	 */
36
	public function init() {
37
		require(__DIR__ . '/../../setup-scripts/createExplicitUsers.php');
38
		parent::init();
39
		$this->mapping = new UserMapping(\OC::$server->getDatabaseConnection());
40
		$this->mapping->clear();
41
		$this->access->setUserMapper($this->mapping);
42
		$userBackend  = new OCA\user_ldap\USER_LDAP($this->access, \OC::$server->getConfig());
43
		\OC_User::useBackend($userBackend);
44
	}
45
46
	/**
47
	 * adds a map entry for the user, so we know the username
48
	 *
49
	 * @param $dn
50
	 * @param $username
51
	 */
52
	private function prepareUser($dn, $username) {
53
		// assigns our self-picked oc username to the dn
54
		$this->mapping->map($dn, $username, 'fakeUUID-' . $username);
55
	}
56
57
	/**
58
	 * tests whether a display name consisting of two parts is created correctly
59
	 *
60
	 * @return bool
61
	 */
62
	protected function case1() {
63
		$username = 'alice1337';
64
		$dn = 'uid=alice,ou=Users,' . $this->base;
65
		$this->prepareUser($dn, $username);
66
		$displayName = \OC::$server->getUserManager()->get($username)->getDisplayName();
67
68
		return strpos($displayName, '([email protected])') !== false;
69
	}
70
71
	/**
72
	 * tests whether a display name consisting of one part is created correctly
73
	 *
74
	 * @return bool
75
	 */
76
	protected function case2() {
77
		$this->connection->setConfiguration([
78
			'ldapUserDisplayName2' => '',
79
		]);
80
		$username = 'boris23421';
81
		$dn = 'uid=boris,ou=Users,' . $this->base;
82
		$this->prepareUser($dn, $username);
83
		$displayName = \OC::$server->getUserManager()->get($username)->getDisplayName();
84
85
		return strpos($displayName, '([email protected])') === false;
86
	}
87
88
	/**
89
	 * sets up the LDAP configuration to be used for the test
90
	 */
91
	protected function initConnection() {
92
		parent::initConnection();
93
		$this->connection->setConfiguration([
94
			'ldapUserDisplayName' => 'displayName',
95
			'ldapUserDisplayName2' => 'mail',
96
		]);
97
	}
98
}
99
100
require_once(__DIR__ . '/../../setup-scripts/config.php');
101
$test = new IntegrationTestUserDisplayName($host, $port, $adn, $apwd, $bdn);
102
$test->init();
103
$test->run();
104