Commit 953e01e1 authored by Liam Morland's avatar Liam Morland
Browse files

Merge branch 'feature/ISTWCMS-4591-lkmorlan-ldap' into '8.x-3.x'

ISTWCMS-4591: Testing for class UWLdap

See merge request !78
parents 84e2271b 6b1a55c5
Testing for LDAP auto-fill on pages to create and edit uw_ct_contact.
1. Get page: node/add/uw_ct_contact
2. Enter invalid WatIAM ID in WatIAM user ID, see message "LDAP lookup failed".
3. Enter valid WatIAM ID, values are auto-filled for: "Name", "Name for sorting
purposes", "Email", "Phone #", "Location".
4. Save page then edit.
5. Auto-fill works the same way.
......@@ -92,6 +92,7 @@ class UwWcmsBasicTest extends BrowserTestBase {
......@@ -1849,4 +1850,49 @@ class UwWcmsBasicTest extends BrowserTestBase {
* Tests for UWLdap service.
public function uwLdapTest() {
// Test LDAP view page.
$test_path = 'uw-ldap/wcmsadmi';
$this->assertSession()->pageTextContains('LDAP View: wcmsadmi');
// Test that the LDAP page contains the full name of user wcmsadmi.
// This ought to pass, but in UwLdap::openConnection(), configFactory->get()
// returns NULLs for values in testing preventing LDAP bind.
// @code
// $this->assertSession()->pageTextContains('Administrator Wcms');
// @endcode
// Test LDAP view page is not available to anonymous. Cannot do this first
// because drupalLogout() raises an error if called when there is no user
// logged-in.
// The rest of this could be unit tests, except that accessing
// config.factory does not work in unit or kernel tests.
$config_factory = $this->container->get('config.factory');
// Use mock user object.
$current_user = $this->createMock(AccountProxy::class);
$ldap = new UWLdap($config_factory, $current_user);
// Test search() and lookupPerson().
$search = $ldap->search('(sAMAccountName=wcmsadmi)');
$search = $ldap->formatResults($search[0]);
$lookup = $ldap->lookupPerson('wcmsadmi');
$this->assertEquals($search, $lookup, 'LDAP search() and lookupPerson() give matching results.');
$this->assertEquals($lookup['displayname'][0], 'Administrator Wcms', 'Expected name found in LDAP.');
// Test formatResults().
$test_in = ['objectguid' => ['ABCDEFGHIJKLMNOP']];
$test_in = $ldap->formatResults($test_in);
$test_out = ['objectguid' => ['44434241-4645-4847-494A-4B4C4D4E4F50']];
$this->assertEquals($test_in, $test_out, 'formatResults() gives correct results.');
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment