Commit 6b1a55c5 authored by Liam Morland's avatar Liam Morland
Browse files

ISTWCMS-4591: Create functional test for UWLdap lookup page

parent 3b051f5b
......@@ -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