public function testCreateDeleteUsers1() { $ldap = TestsHelper::getLdapConfig(216); // Loop 50 times to test random users for ($i = 0; $i < 50; $i++) { $user = TestsHelper::getUserCreds(null, 101); // Create the new user $adapter = new SHUserAdaptersLdap($user, $ldap, array('isNew' => 1)); $adapter->setAttributes($user); $commit = $adapter->commitChanges(); $this->assertTrue($commit->status); // Test the new user $testAdapter = new SHUserAdaptersLdap($user, $ldap); $this->assertEquals($user['dn'], $testAdapter->getId(true)); $phone = JArrayHelper::getValue($testAdapter->getAttributes('telephoneNumber'), 'telephoneNumber'); $this->assertEquals($user['telephoneNumber'], $phone); // Delete the new user $this->assertTrue($adapter->delete()); } }
/** * Commits the changes to the LDAP user adapter and parses the result. * If any errors occurred then optionally log them and throw an exception. * * @param SHUserAdaptersLdap $adapter LDAP user adapter. * @param boolean $log Log any errors directly to SHLog. * @param boolean $throw Throws an exception on error OR return array on error. * * @return true|SHAdapterResponseCommits * * @exception */ public static function commitChanges($adapter, $log = false, $throw = true) { $results = $adapter->commitChanges(); if ($log) { // Lets log all the commits foreach ($results->getCommits() as $commit) { if ($commit->status === JLog::INFO) { SHLog::add($commit->message, 10634, JLog::INFO, 'ldap'); } else { SHLog::add($commit->message, 10636, JLog::ERROR, 'ldap'); SHLog::add($commit->exception, 10637, JLog::ERROR, 'ldap'); } } } // Check if any of the commits failed if (!$results->status) { if ($throw) { throw new RuntimeException(JText::_('LIB_SHLDAPHELPER_ERR_10638'), 10638); } else { return $results; } } return true; }