Skip to content

Commit

Permalink
fix Integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
David Coutadeur committed Apr 24, 2024
1 parent 65c7c80 commit b9e97e8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Ltb/AttributeValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static function ldap_get_first_available_value($ldap, $entry, $attributes
return false;
}

/** function \Ltb\AttributeValue::ldap_get_mail_for_notification($ldap, $entry) {
/** function \Ltb\AttributeValue::ldap_get_mail_for_notification($ldap, $entry, $mail_attributes) {
* Get from ldap entry first value corresponding to $mail_attributes (globally configured)
* @param $ldap php_ldap connection object
* @param $entry ldap entry to parse
Expand Down
43 changes: 30 additions & 13 deletions tests/IntegrationTests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ public function test_ldap_get_first_available_value(): void

# Test ldap_get_first_available_value
$ent = Ltb\AttributeValue::ldap_get_first_available_value($ldap, $entry, $this->attributes);
$this->assertEquals($ent->attribute, "cn", "not getting attribute cn");
$this->assertEquals($ent->value, "test1", "not getting value test1 as cn first value");
$this->assertEquals("cn", $ent->attribute, "not getting attribute cn");
$this->assertEquals("test1", $ent->value, "not getting value test1 as cn first value");
}

public function test_ldap_get_mail_for_notification(): void
{

$mail_attributes = array("mail");

$ldap = ldap_connect($this->host);
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
Expand All @@ -119,15 +119,25 @@ public function test_ldap_get_mail_for_notification(): void
$entry = ldap_first_entry($ldap, $sr);

# Test ldap_get_first_available_value
$mail = Ltb\AttributeValue::ldap_get_mail_for_notification($ldap, $entry);
$this->assertEquals($mail, '[email protected]', "not getting [email protected] as mail for notification");
$mail = Ltb\AttributeValue::ldap_get_mail_for_notification($ldap, $entry, $mail_attributes);
$this->assertEquals('[email protected]', $mail, "not getting [email protected] as mail for notification");

}

public function test_connect(): void
{

list($ldap, $msg) = Ltb\Ldap::connect($this->host, false, $this->managerDN, $this->managerPW, 10, null);
$ldapInstance = new \Ltb\Ldap(
$this->host,
false,
$this->managerDN,
$this->managerPW,
10,
null,
null,
null
);
list($ldap, $msg) = $ldapInstance->connect();

$this->assertNotFalse($ldap, "Error while connecting to LDAP server");
$this->assertFalse($msg, "Error message returned while connecting to LDAP server");
Expand All @@ -136,17 +146,24 @@ public function test_connect(): void
public function test_get_list(): void
{

$ldap = ldap_connect($this->host);
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
$ldapInstance = new \Ltb\Ldap(
$this->host,
false,
$this->managerDN,
$this->managerPW,
10,
$this->user_branch,
0,
null
);

// binding to ldap server
$ldapbind = ldap_bind($ldap, $this->managerDN, $this->managerPW);
list($ldap, $msg) = $ldapInstance->connect();

// return hashmap: [ cn_value => sn_value ]
$result = Ltb\Ldap::get_list($ldap, $this->user_branch, "(uid=test)", "cn","sn");
$result = $ldapInstance->get_list($this->user_branch, "(uid=test)", "cn","sn");

$this->assertEquals(array_keys($result)[0], 'test1', "not getting test1 as key in get_list function");
$this->assertEquals($result["test1"], 'test', "not getting test as value in get_list function");
$this->assertEquals('test1', array_keys($result)[0], "not getting test1 as key in get_list function");
$this->assertEquals('test', $result["test1"], "not getting test as value in get_list function");

}

Expand Down

0 comments on commit b9e97e8

Please sign in to comment.