From: Gunnar Wrobel Date: Fri, 30 Oct 2009 23:01:13 +0000 (+0100) Subject: Continued search implementation. Extended testing. Ensured that test requiring Net_LD... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=31dca96ddfd1a050c24b04cc619413944902316d;p=horde.git Continued search implementation. Extended testing. Ensured that test requiring Net_LDAP2 are skipped. --- diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server.php b/framework/Kolab_Server/lib/Horde/Kolab/Server.php index 32cdbff9d..d80da8db1 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server.php @@ -93,34 +93,27 @@ interface Horde_Kolab_Server /** * Finds object data matching a given set of criteria. * - * @param Horde_Kolab_Server_Query_Element $criteria The criteria for the search. - * @param array $params Additional search parameters. + * @param string $query The LDAP search query + * @param array $params Additional search parameters. * * @return Horde_Kolab_Server_Result The result object. * * @throws Horde_Kolab_Server_Exception */ - public function find( - Horde_Kolab_Server_Query_Element $criteria, - array $params = array() - ); + public function find($query, array $params = array()); /** * Finds all object data below a parent matching a given set of criteria. * - * @param Horde_Kolab_Server_Query_Element $criteria The criteria for the search. - * @param string $parent The parent to search below. - * @param array $params Additional search parameters. + * @param string $query The LDAP search query + * @param string $parent The parent to search below. + * @param array $params Additional search parameters. * * @return Horde_Kolab_Server_Result The result object. * * @throws Horde_Kolab_Server_Exception */ - public function findBelow( - Horde_Kolab_Server_Query_Element $criteria, - $parent, - array $params = array() - ); + public function findBelow($query, $parent, array $params = array()); /** * Modify existing object data. diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Cleaner.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Cleaner.php index adb685fd5..5c1026683 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Cleaner.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Cleaner.php @@ -124,36 +124,31 @@ class Horde_Kolab_Server_Cleaner implements Horde_Kolab_Server /** * Finds object data matching a given set of criteria. * - * @param Horde_Kolab_Server_Query_Element $criteria The criteria for the search. - * @param array $params Additional search parameters. + * @param string $query The LDAP search query + * @param array $params Additional search parameters. * * @return Horde_Kolab_Server_Result The result object. * * @throws Horde_Kolab_Server_Exception */ - public function find( - Horde_Kolab_Server_Query_Element $criteria, - array $params = array() - ) { + public function find($query, array $params = array()) + { return $this->_server->find($criteria, $params); } /** * Finds all object data below a parent matching a given set of criteria. * - * @param Horde_Kolab_Server_Query_Element $criteria The criteria for the search. - * @param string $parent The parent to search below. - * @param array $params Additional search parameters. + * @param string $query The LDAP search query + * @param string $parent The parent to search below. + * @param array $params Additional search parameters. * * @return Horde_Kolab_Server_Result The result object. * * @throws Horde_Kolab_Server_Exception */ - public function findBelow( - Horde_Kolab_Server_Query_Element $criteria, - $parent, - array $params = array() - ) { + public function findBelow($query, $parent, array $params = array()) + { return $this->_server->findBelow($criteria, $parent, $params); } diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Composite.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Composite.php index 252aaeac1..7f03c37c1 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Composite.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Composite.php @@ -123,7 +123,7 @@ class Horde_Kolab_Server_Composite { /** Bind anonymously first. */ $this->server->connectGuid(); - $guid = $this->search->getGuidForUser($user); + $guid = $this->search->searchGuidForUidOrMail($user); $this->server->connectGuid($guid, $pass); } } diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap.php index cf5d7862a..c40f9646f 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap.php @@ -167,18 +167,16 @@ abstract class Horde_Kolab_Server_Ldap implements Horde_Kolab_Server /** * Finds object data matching a given set of criteria. * - * @param Horde_Kolab_Server_Query_Element $criteria The criteria for the search. - * @param array $params Additional search parameters. + * @param string $query The LDAP search query + * @param array $params Additional search parameters. * * @return Horde_Kolab_Server_Result The result object. * * @throws Horde_Kolab_Server_Exception */ - public function find( - Horde_Kolab_Server_Query_Element $criteria, - array $params = array() - ) { - return $this->findBelow($criteria, $this->_base_dn, $params); + public function find($query, array $params = array()) + { + return $this->findBelow($query, $this->_base_dn, $params); } /** diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap/Changes.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap/Changes.php index 8664f1f85..259977582 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap/Changes.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap/Changes.php @@ -27,7 +27,6 @@ */ class Horde_Kolab_Server_Ldap_Changes { - /** * The object to be modified. * @@ -69,7 +68,7 @@ class Horde_Kolab_Server_Ldap_Changes $attributes = array_merge(array_keys($old), array_keys($new)); foreach ($attributes as $attribute) { if (!isset($old[$attribute])) { - $cs['add'][] = array($attribute => $new[$attribute]); + $cs['add'][$attribute] = $new[$attribute]; continue; } if (!isset($new[$attribute])) { @@ -77,7 +76,8 @@ class Horde_Kolab_Server_Ldap_Changes continue; } if (count($new[$attribute]) == 1 - && count($old[$attribute]) == 1) { + && count($old[$attribute]) == 1 + ) { if ($new[$attribute][0] == $old[$attribute][0]) { continue; } else { diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap/Filtered.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap/Filtered.php index 2858c9f82..e172f6f6b 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap/Filtered.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap/Filtered.php @@ -55,22 +55,17 @@ class Horde_Kolab_Server_Ldap_Filtered extends Horde_Kolab_Server_Ldap /** * Finds all object data below a parent matching a given set of criteria. * - * @param Horde_Kolab_Server_Query_Element $criteria The criteria for the search. - * @param string $parent The parent to search below. - * @param array $params Additional search parameters. + * @param string $query The LDAP search query + * @param string $parent The parent to search below. + * @param array $params Additional search parameters. * * @return Horde_Kolab_Server_Result The result object. * * @throws Horde_Kolab_Server_Exception */ - public function findBelow( - Horde_Kolab_Server_Query_Element $criteria, - $parent, - array $params = array() - ) { - $query = new Horde_Kolab_Server_Query_Ldap($criteria); - $query_string = (string) $query; - $query_string = '(&(' . $this->_filter . ')' . $query_string . ')'; - return $this->_search($query_string, $params, $parent); + public function findBelow($query, $parent, array $params = array()) + { + $query = '(&(' . $this->_filter . ')' . $query . ')'; + return $this->_search($query, $params, $parent); } } diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap/Standard.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap/Standard.php index dd448dbf0..cc740a34b 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap/Standard.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap/Standard.php @@ -31,20 +31,16 @@ class Horde_Kolab_Server_Ldap_Standard extends Horde_Kolab_Server_Ldap /** * Finds all object data below a parent matching a given set of criteria. * - * @param Horde_Kolab_Server_Query_Element $criteria The criteria for the search. - * @param string $parent The parent to search below. - * @param array $params Additional search parameters. + * @param string $query The LDAP search query + * @param string $parent The parent to search below. + * @param array $params Additional search parameters. * * @return Horde_Kolab_Server_Result The result object. * * @throws Horde_Kolab_Server_Exception */ - public function findBelow( - Horde_Kolab_Server_Query_Element $criteria, - $parent, - array $params = array() - ) { - $query = new Horde_Kolab_Server_Query_Ldap($criteria); + public function findBelow($query, $parent, array $params = array()) + { return $this->_search((string) $query, $params, $parent); } } diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Logged.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Logged.php index 1644b88e6..c71e5f56e 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Logged.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Logged.php @@ -91,7 +91,7 @@ class Horde_Kolab_Server_Logged implements Horde_Kolab_Server */ public function getGuid() { - $this->_server->getGuid(); + return $this->_server->getGuid(); } /** @@ -101,7 +101,7 @@ class Horde_Kolab_Server_Logged implements Horde_Kolab_Server */ public function getBaseGuid() { - $this->_server->getBaseGuid(); + return $this->_server->getBaseGuid(); } /** @@ -140,37 +140,32 @@ class Horde_Kolab_Server_Logged implements Horde_Kolab_Server /** * Finds object data matching a given set of criteria. * - * @param Horde_Kolab_Server_Query_Element $criteria The criteria for the search. - * @param array $params Additional search parameters. + * @param string $query The LDAP search query + * @param array $params Additional search parameters. * * @return Horde_Kolab_Server_Result The result object. * * @throws Horde_Kolab_Server_Exception */ - public function find( - Horde_Kolab_Server_Query_Element $criteria, - array $params = array() - ) { - return $this->_server->find($criteria, $params); + public function find($query, array $params = array()) + { + return $this->_server->find($query, $params); } /** * Finds all object data below a parent matching a given set of criteria. * - * @param Horde_Kolab_Server_Query_Element $criteria The criteria for the search. - * @param string $parent The parent to search below. - * @param array $params Additional search parameters. + * @param string $query The LDAP search query + * @param string $parent The parent to search below. + * @param array $params Additional search parameters. * * @return Horde_Kolab_Server_Result The result object. * * @throws Horde_Kolab_Server_Exception */ - public function findBelow( - Horde_Kolab_Server_Query_Element $criteria, - $parent, - array $params = array() - ) { - return $this->_server->findBelow($criteria, $parent, $params); + public function findBelow($query, $parent, array $params = array()) + { + return $this->_server->findBelow($query, $parent, $params); } /** diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Mapped.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Mapped.php index 0f549c147..f911d748b 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Mapped.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Mapped.php @@ -146,17 +146,15 @@ class Horde_Kolab_Server_Mapped implements Horde_Kolab_Server /** * Finds object data matching a given set of criteria. * - * @param array $criteria The criteria for the search. - * @param array $params Additional search parameters. + * @param string $query The LDAP search query + * @param array $params Additional search parameters. * * @return array The result array. * * @throws Horde_Kolab_Server_Exception */ - public function find( - Horde_Kolab_Server_Query_Element $criteria, - array $params = array() - ) { + public function find($query, array $params = array()) + { $criteria = new Horde_Kolab_Server_Query_Element_Mapped($criteria, $this); $data = $this->_server->find($criteria, $params); $this->unmapAttributes($data); @@ -166,19 +164,16 @@ class Horde_Kolab_Server_Mapped implements Horde_Kolab_Server /** * Finds all object data below a parent matching a given set of criteria. * - * @param array $criteria The criteria for the search. - * @param string $parent The parent to search below. - * @param array $params Additional search parameters. + * @param string $query The LDAP search query + * @param string $parent The parent to search below. + * @param array $params Additional search parameters. * * @return array The result array. * * @throws Horde_Kolab_Server_Exception */ - public function findBelow( - Horde_Kolab_Server_Query_Element $criteria, - $parent, - array $params = array() - ) { + public function findBelow($query, $parent, array $params = array()) + { $criteria = new Horde_Kolab_Server_Query_Element_Mapped($criteria, $this); $data = $this->_server->findBelow($criteria, $parent, $params); $this->unmapAttributes($data); diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Base.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Base.php index f579dffec..c3e63b253 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Base.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Base.php @@ -67,13 +67,15 @@ implements Horde_Kolab_Server_Object_Attribute public function __construct( Horde_Kolab_Server_Object $object, Horde_Kolab_Server_Composite $composite, - $internal, - $external = null + $external ) { - $this->_internal = $internal; $this->_object = $object; $this->_composite = $composite; $this->_external = $external; + + $this->_internal = $this->_composite->structure->getInternalAttribute( + $this->_external + ); } /** diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Objectclass.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Objectclass.php index effb2d1d1..eed3ebd29 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Objectclass.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Objectclass.php @@ -28,9 +28,6 @@ class Horde_Kolab_Server_Object_Attribute_Objectclass extends Horde_Kolab_Server_Object_Attribute_Decorator { - /** The internal attribute name */ - const INTERNAL = 'objectClass'; - /** * Constructor * @@ -45,7 +42,7 @@ extends Horde_Kolab_Server_Object_Attribute_Decorator $this->_attribute = new Horde_Kolab_Server_Object_Attribute_Required( new Horde_Kolab_Server_Object_Attribute_Locked( new Horde_Kolab_Server_Object_Attribute_Value( - $object, $composite, self::INTERNAL, 'Objectclass' + $object, $composite, 'Objectclass' ) ) ); diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Groupofnames.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Groupofnames.php index ad68cdeb6..874979925 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Groupofnames.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Groupofnames.php @@ -168,8 +168,8 @@ class Horde_Kolab_Server_Object_Groupofnames extends Horde_Kolab_Server_Object_T static public function getSearchOperations() { $searches = array( - 'gidForSearch', - 'getGroups', +/* 'gidForSearch', */ +/* 'getGroups', */ ); return $searches; } diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabgermanbankarrangement.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabgermanbankarrangement.php index 036574f64..4907a82c0 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabgermanbankarrangement.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabgermanbankarrangement.php @@ -166,7 +166,7 @@ class Horde_Kolab_Server_Object_Kolabgermanbankarrangement extends Horde_Kolab_S static public function getSearchOperations() { $searches = array( - 'accountsForMail', +/* 'accountsForMail', */ ); return $searches; } diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabgroupofnames.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabgroupofnames.php index d32071765..4419a125f 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabgroupofnames.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabgroupofnames.php @@ -162,9 +162,9 @@ class Horde_Kolab_Server_Object_Kolabgroupofnames extends Horde_Kolab_Server_Obj static public function getSearchOperations() { $searches = array( - 'gidForMail', - 'memberOfGroupAddress', - 'getGroupAddresses', +/* 'gidForMail', */ +/* 'memberOfGroupAddress', */ +/* 'getGroupAddresses', */ ); return $searches; } diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabinetorgperson.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabinetorgperson.php index b3d03e357..08eacba14 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabinetorgperson.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabinetorgperson.php @@ -27,133 +27,32 @@ */ class Horde_Kolab_Server_Object_Kolabinetorgperson extends Horde_Kolab_Server_Object_Inetorgperson { - /** Define attributes specific to this object type */ - - /** Alias mail addresses */ - const ATTRIBUTE_ALIAS = 'alias'; - - /** Delegates for this person */ - const ATTRIBUTE_DELEGATE = 'kolabDelegate'; - - /** Marker for a deleted object */ - const ATTRIBUTE_DELETED = 'kolabDeleteFlag'; + /** The specific object class of this object type */ + const OBJECTCLASS_KOLABINETORGPERSON = 'kolabInetOrgPerson'; - /** How many days of the free/busy future should be calculated in advance? */ - const ATTRIBUTE_FBFUTURE = 'kolabFreeBusyFuture'; + /** Define attributes specific to this object type */ /** - * The home server of this person. It identifies the correct machine in a - * master/slave setup. + * The attributes defined for this class. + * + * @var array */ - const ATTRIBUTE_HOMESERVER = 'kolabHomeServer'; - - /** The free/busy server of this person */ - const ATTRIBUTE_FREEBUSYHOST = 'kolabFreeBusyServer'; - - /** The host that keeps the IMAP mail store of this person */ - const ATTRIBUTE_IMAPHOST = 'kolabImapServer'; - - /** The invitation policy for this person */ - const ATTRIBUTE_IPOLICY = 'kolabInvitationPolicy'; - - /** The salutation of this person. */ - const ATTRIBUTE_SALUTATION = 'kolabSalutation'; - - /** Persons gender */ - const ATTRIBUTE_GENDER = 'gender'; - - /** The marital status */ - const ATTRIBUTE_MARITALSTATUS = 'kolabMaritalStatus'; - - /** The home fax number */ - const ATTRIBUTE_HOMEFAX = 'homeFacsimileTelephoneNumber'; - - /** The german tax ID */ - const ATTRIBUTE_GERMANTAXID = 'germanTaxId'; - - /** The country of residence */ - const ATTRIBUTE_COUNTRY = 'c'; - - /** The IMAP quota */ - const ATTRIBUTE_QUOTA = 'cyrus-userquota'; - - /** Allowed recipients for this person */ - const ATTRIBUTE_ALLOWEDRECIPIENTS = 'kolabAllowSMTPRecipient'; - - /** Allowed senders for this person */ - const ATTRIBUTE_ALLOWEDFROM = 'kolabAllowSMTPFrom'; - - /** The date of birth */ - const ATTRIBUTE_DATEOFBIRTH = 'apple-birthday'; - - /** The date of birth as Horde_Date */ - const ATTRDATE_DATEOFBIRTH = 'apple-birthdayDate'; - - /** The place of birth */ - const ATTRIBUTE_PLACEOFBIRTH = 'birthPlace'; - - /** Birth name */ - const ATTRIBUTE_BIRTHNAME = 'birthName'; - - /** Pseudonym */ - const ATTRIBUTE_PSEUDONYM = 'pseudonym'; - - /** Country of citizenship */ - const ATTRIBUTE_COUNTRYCITIZENSHIP = 'countryOfCitizenship'; - - /** Legal form (if the person is a legal entity) */ - const ATTRIBUTE_LEGALFORM = 'legalForm'; - - /** Registered capital (if the person is a legal entity) */ - const ATTRIBUTE_REGISTEREDCAPITAL = 'tradeRegisterRegisteredCapital'; - - /** URI for bylaw (if the person is a legal entity) */ - const ATTRIBUTE_BYLAWURI = 'bylawURI'; - - /** Date of incorporation (if the person is a legal entity) */ - const ATTRIBUTE_DATEOFINCORPORATION = 'dateOfIncorporation'; - - /** Legal representative (if the person is a legal entity) */ - const ATTRIBUTE_LEGALREPRESENTATIVE = 'legalRepresentative'; - - /** Commercial procuration (if the person is a legal entity) */ - const ATTRIBUTE_COMMERCIALPROCURATION = 'commercialProcuration'; - - /** Legal representation policy (if the person is a legal entity) */ - const ATTRIBUTE_LEGALREPRESENTATIONPOLICY = 'legalRepresentationPolicy'; - - /** Acting deputy (if the person is a legal entity) */ - const ATTRIBUTE_ACTINGDEPUTY = 'actingDeputy'; - - /** VAT number (if the person is a legal entity) */ - const ATTRIBUTE_VATNUMBER = 'VATNumber'; - - /** Additional legal relationships (if the person is a legal entity) */ - const ATTRIBUTE_OTHERLEGAL = 'otherLegalRelationship'; - - /** Is this entity in liquidation? (if the person is a legal entity) */ - const ATTRIBUTE_INLIQUIDATION = 'inLiquidation'; - - /** Type of entity as given by the trade register (if the person is a legal entity) */ - const ATTRIBUTE_TRTYPE = 'tradeRegisterType'; - - /** Location of entity as given by the trade register (if the person is a legal entity) */ - const ATTRIBUTE_TRLOCATION = 'tradeRegisterLocation'; - - /** Identifier of entity as given by the trade register (if the person is a legal entity) */ - const ATTRIBUTE_TRIDENTIFIER = 'tradeRegisterIdentifier'; - - /** URI of entity as given by the trade register (if the person is a legal entity) */ - const ATTRIBUTE_TRURI = 'tradeRegisterURI'; - - /** Date of last change in the trade register (if the person is a legal entity) */ - const ATTRIBUTE_TRLASTCHANGED = 'tradeRegisterLastChangedDate'; - - /** Subdomain for this person */ - const ATTRIBUTE_DC = 'domainComponent'; + static public $attributes = array( + 'alias', 'kolabDelegate', 'kolabDeleteFlag', 'kolabFreeBusyFuture', + 'kolabHomeServer', 'kolabFreeBusyServer', 'kolabImapServer', + 'kolabInvitationPolicy', 'kolabSalutation', 'gender', + 'kolabMaritalStatus', 'homeFacsimileTelephoneNumber', 'germanTaxId', + 'c', 'cyrus-userquota', 'kolabAllowSMTPRecipient', 'kolabAllowSMTPFrom', + 'apple-birthday', 'apple-birthdayDate', 'birthPlace', 'birthName', + 'pseudonym', 'countryOfCitizenship', 'legalForm', + 'tradeRegisterRegisteredCapital', 'bylawURI', 'dateOfIncorporation', + 'legalRepresentative', 'commercialProcuration', + 'legalRepresentationPolicy', 'actingDeputy', 'VATNumber', + 'otherLegalRelationship', 'inLiquidation', 'tradeRegisterType', + 'tradeRegisterLocation', 'tradeRegisterIdentifier', 'tradeRegisterURI', + 'tradeRegisterLastChangedDate', 'domainComponent', + ); - /** The specific object class of this object type */ - const OBJECTCLASS_KOLABINETORGPERSON = 'kolabInetOrgPerson'; /** * A structure to initialize the attribute structure for this class. @@ -313,12 +212,11 @@ class Horde_Kolab_Server_Object_Kolabinetorgperson extends Horde_Kolab_Server_Ob */ public static function getFilter() { - $criteria = array('AND' => array(array('field' => self::ATTRIBUTE_OC, - 'op' => '=', - 'test' => self::OBJECTCLASS_KOLABINETORGPERSON), - ), + $filter = new Horde_Kolab_Server_Query_Element_Equals( + 'Objectclass', + self::OBJECTCLASS_KOLABINETORGPERSON ); - return $criteria; + return $filter; } /** @@ -378,309 +276,20 @@ class Horde_Kolab_Server_Object_Kolabinetorgperson extends Horde_Kolab_Server_Ob static public function getSearchOperations() { $searches = array( - 'uidForSearch', - 'uidForId', - 'uidForMail', - 'uidForIdOrMail', - 'uidForAlias', - 'uidForMailOrAlias', - 'uidForIdOrMailOrAlias', - 'mailForIdOrMail', - 'addrsForIdOrMail', + 'Horde_Kolab_Server_Object_Search_Guidforkolabusers', + 'Horde_Kolab_Server_Object_Search_Guidforuid', + 'Horde_Kolab_Server_Object_Search_Guidformail', + 'Horde_Kolab_Server_Object_Search_Guidforuidormail', + 'Horde_Kolab_Server_Object_Search_Guidforalias', + 'Horde_Kolab_Server_Object_Search_Guidformailoralias', + 'Horde_Kolab_Server_Object_Search_Guidforuidormailoralias', + 'Horde_Kolab_Server_Object_Search_Mailforuidormail', + 'Horde_Kolab_Server_Object_Search_Addressesforuidormail', ); return $searches; } /** - * Identify the kolab UID for the first object found using the specified - * search criteria. - * - * @param Horde_Kolab_Server $server The server to query. - * @param array $criteria The search parameters as array. - * @param int $restrict A Horde_Kolab_Server::RESULT_* result restriction. - * - * @return boolean|string|array The UID(s) or false if there was no result. - * - * @throws Horde_Kolab_Server_Exception - */ - static public function uidForSearch($server, $criteria, - $restrict = 0) - { - $users = array('field' => self::ATTRIBUTE_OC, - 'op' => '=', - 'test' => self::OBJECTCLASS_KOLABINETORGPERSON); - if (!empty($criteria)) { - $criteria = array('AND' => array($users, $criteria)); - } else { - $criteria = array('AND' => array($users)); - } - return self::basicUidForSearch($server, $criteria, $restrict); - } - - /** - * Identify the UID for the first object found with the given ID. - * - * @param Horde_Kolab_Server $server The server to query. - * @param string $id Search for objects with this ID. - * @param int $restrict A Horde_Kolab_Server::RESULT_* result restriction. - * - * @return mixed The UID or false if there was no result. - * - * @throws Horde_Kolab_Server_Exception - */ - static public function uidForId($server, $id, - $restrict = 0) - { - $criteria = array('AND' => array(array('field' => self::ATTRIBUTE_SID, - 'op' => '=', - 'test' => $id), - ), - ); - return self::uidForSearch($server, $criteria, $restrict); - } - - /** - * Identify the UID for the first user found with the given mail. - * - * @param Horde_Kolab_Server $server The server to query. - * @param string $mail Search for users with this mail address. - * @param int $restrict A Horde_Kolab_Server::RESULT_* result restriction. - * - * @return mixed The UID or false if there was no result. - * - * @throws Horde_Kolab_Server_Exception - */ - static public function uidForMail($server, $mail, - $restrict = 0) - { - $criteria = array('AND' => array(array('field' => self::ATTRIBUTE_MAIL, - 'op' => '=', - 'test' => $mail), - ), - ); - return self::uidForSearch($server, $criteria, $restrict); - } - - /** - * Identify the UID for the first object found with the given ID or mail. - * - * @param Horde_Kolab_Server $server The server to query. - * @param string $id Search for objects with this uid/mail. - * - * @return string|boolean The UID or false if there was no result. - * - * @throws Horde_Kolab_Server_Exception - */ - static public function uidForIdOrMail($server, $id) - { - $criteria = array('OR' => - array( - array('field' => self::ATTRIBUTE_SID, - 'op' => '=', - 'test' => $id), - array('field' => self::ATTRIBUTE_MAIL, - 'op' => '=', - 'test' => $id), - ), - ); - return self::uidForSearch($server, $criteria); - } - - /** - * Identify the UID for the first object found with the given alias. - * - * @param Horde_Kolab_Server $server The server to query. - * @param string $mail Search for objects with this mail alias. - * @param int $restrict A Horde_Kolab_Server::RESULT_* result restriction. - * - * @return mixed The UID or false if there was no result. - * - * @throws Horde_Kolab_Server_Exception - */ - static public function uidForAlias($server, $mail, - $restrict = 0) - { - $criteria = array('AND' => array(array('field' => self::ATTRIBUTE_ALIAS, - 'op' => '=', - 'test' => $mail), - ), - ); - return self::uidForSearch($server, $criteria, $restrict); - } - - - /** - * Identify the UID for the first object found with the given mail - * address or alias. - * - * @param Horde_Kolab_Server $server The server to query. - * @param string $mail Search for objects with this mail address - * or alias. - * - * @return string|boolean The UID or false if there was no result. - * - * @throws Horde_Kolab_Server_Exception - */ - static public function uidForMailOrAlias($server, $mail) - { - $criteria = array('OR' => - array( - array('field' => self::ATTRIBUTE_ALIAS, - 'op' => '=', - 'test' => $mail), - array('field' => self::ATTRIBUTE_MAIL, - 'op' => '=', - 'test' => $mail), - ) - ); - return self::uidForSearch($server, $criteria); - } - - /** - * Identify the UID for the first object found with the given ID, - * mail or alias. - * - * @param Horde_Kolab_Server $server The server to query. - * @param string $id Search for objects with this ID/mail/alias. - * - * @return string|boolean The UID or false if there was no result. - * - * @throws Horde_Kolab_Server_Exception - */ - static public function uidForIdOrMailOrAlias($server, $id) - { - $criteria = array('OR' => - array( - array('field' => self::ATTRIBUTE_ALIAS, - 'op' => '=', - 'test' => $id), - array('field' => self::ATTRIBUTE_MAIL, - 'op' => '=', - 'test' => $id), - array('field' => self::ATTRIBUTE_SID, - 'op' => '=', - 'test' => $id), - ), - ); - return self::uidForSearch($server, $criteria); - } - - /** - * Identify the primary mail attribute for the first object found - * with the given ID or mail. - * - * @param Horde_Kolab_Server $server The server to query. - * @param string $id Search for objects with this ID/mail. - * - * @return mixed The mail address or false if there was no result. - * - * @throws Horde_Kolab_Server_Exception - */ - static public function mailForIdOrMail($server, $id) - { - $criteria = array('AND' => - array( - array('field' => self::ATTRIBUTE_OC, - 'op' => '=', - 'test' => self::OBJECTCLASS_KOLABINETORGPERSON), - array('OR' => - array( - array('field' => self::ATTRIBUTE_SID, - 'op' => '=', - 'test' => $id), - array('field' => self::ATTRIBUTE_MAIL, - 'op' => '=', - 'test' => $id), - ), - ), - ), - ); - - $data = self::attrsForSearch($server, $criteria, array(self::ATTRIBUTE_MAIL), - self::RESULT_STRICT); - if (!empty($data)) { - return $data[self::ATTRIBUTE_MAIL][0]; - } else { - return false; - } - } - - /** - * Returns a list of allowed email addresses for the given user. - * - * @param Horde_Kolab_Server $server The server to query. - * @param string $id Search for objects with this ID/mail. - * - * @return array An array of allowed mail addresses. - * - * @throws Horde_Kolab_Server_Exception - */ - static public function addrsForIdOrMail($server, $id) - { - $criteria = array('AND' => - array( - array('field' => self::ATTRIBUTE_OC, - 'op' => '=', - 'test' => self::OBJECTCLASS_KOLABINETORGPERSON), - array('OR' => - array( - array('field' => self::ATTRIBUTE_SID, - 'op' => '=', - 'test' => $id), - array('field' => self::ATTRIBUTE_MAIL, - 'op' => '=', - 'test' => $id), - ), - ), - ), - ); - - $result = self::attrsForSearch($server, $criteria, - array(self::ATTRIBUTE_MAIL, - self::ATTRIBUTE_ALIAS), - self::RESULT_STRICT); - if (isset($result[self::ATTRIBUTE_ALIAS])) { - $addrs = array_merge((array) $result[self::ATTRIBUTE_MAIL], - (array) $result[self::ATTRIBUTE_ALIAS]); - } else { - $addrs = $result[self::ATTRIBUTE_MAIL]; - } - - if (empty($result)) { - return array(); - } - $criteria = array('AND' => - array( - array('field' => self::ATTRIBUTE_OC, - 'op' => '=', - 'test' => self::OBJECTCLASS_KOLABINETORGPERSON), - array('field' => self::ATTRIBUTE_DELEGATE, - 'op' => '=', - 'test' => $result[self::ATTRIBUTE_MAIL][0]), - ), - ); - - $result = self::attrsForSearch($server, $criteria, - array(self::ATTRIBUTE_MAIL, - self::ATTRIBUTE_ALIAS), - self::RESULT_MANY); - if (!empty($result)) { - foreach ($result as $adr) { - if (isset($adr[self::ATTRIBUTE_MAIL])) { - $addrs = array_merge((array) $addrs, (array) $adr[self::ATTRIBUTE_MAIL]); - } - if (isset($adr[self::ATTRIBUTE_ALIAS])) { - $addrs = array_merge((array) $addrs, (array) $adr[self::ATTRIBUTE_ALIAS]); - } - } - } - - $addrs = array_map('strtolower', $addrs); - - return $addrs; - } - - /** * Returns the server url of the given type for this user. * * This method is used to encapsulate multidomain support. diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabpop3account.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabpop3account.php index 00c615e9e..7f0385e2d 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabpop3account.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabpop3account.php @@ -170,7 +170,7 @@ class Horde_Kolab_Server_Object_Kolabpop3account extends Horde_Kolab_Server_Obje static public function getSearchOperations() { $searches = array( - 'pop3AccountsForMail', +/* 'pop3AccountsForMail', */ ); return $searches; } diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Person.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Person.php index 469347b00..e0c72f000 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Person.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Person.php @@ -224,32 +224,7 @@ class Horde_Kolab_Server_Object_Person extends Horde_Kolab_Server_Object_Top static public function getSearchOperations() { return array( - 'uidForCn', + 'Horde_Kolab_Server_Object_Search_Guidforcn', ); } - - /** - * Identify the UID for the first object found with the given common name. - * - * @param Horde_Kolab_Server $server The server to search. - * @param string $cn Search for objects with this - * common name. - * @param int $restrict A Horde_Kolab_Server::RESULT_* - * result restriction. - * - * @return mixed The UID or false if there was no result. - * - * @throws Horde_Kolab_Server_Exception - */ - static public function uidForCn($server, $cn, - $restrict = 0) - { - $criteria = array('AND' => array(array('field' => self::ATTRIBUTE_CN, - 'op' => '=', - 'test' => $cn), - ), - ); - return self::basicUidForSearch($server, $criteria, $restrict); - } - } \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search.php index b59386fab..445989b33 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search.php @@ -28,9 +28,9 @@ interface Horde_Kolab_Server_Object_Search { /** - * Perform the search. + * Return the refernce to the composite server. * - * @return mixed The search result. + * @return Horde_Kolab_Server_Composite */ - public function search(); + public function getComposite(); } \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Addressesforuidormail.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Addressesforuidormail.php new file mode 100644 index 000000000..21a24bdcb --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Addressesforuidormail.php @@ -0,0 +1,136 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Return the mail addresses of the KolabInetOrgPersons with the given uid or + * mail address and include all alias and delegate addresses. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Object_Search_Addressesforuidormail +extends Horde_Kolab_Server_Object_Search_Base +{ + + /** + * The basic attribute search. + * + * @var Horde_Kolab_Server_Object_Search + */ + private $_search; + + /** + * Constructor + * + * @param Horde_Kolab_Server_Composite $composite A link to the composite + * server handler. + */ + public function __construct(Horde_Kolab_Server_Composite $composite) + { + $this->_composite = $composite; + $this->_search = new Horde_Kolab_Server_Object_Search_Attributes( + $this->getComposite() + ); + } + + /** + * Return the mail addresses of the KolabInetOrgPersons with the given uid + * or mail address and include all alias and delegate addresses. + * + * @param string $uid The uid to search for. + * @param string $mail The mail address to search for. + * + * @return array The GUID(s). + * + * @throws Horde_Kolab_Server_Exception + */ + public function searchAddressesForUidOrMail($uid, $mail) + { + $criteria = new Horde_Kolab_Server_Query_Element_And( + new Horde_Kolab_Server_Query_Element_Equals( + 'Objectclass', + Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON + ), + new Horde_Kolab_Server_Query_Element_Or( + new Horde_Kolab_Server_Query_Element_Equals( + 'Uid', $uid + ), + new Horde_Kolab_Server_Query_Element_Equals( + 'Mail', $mail + ) + ) + ); + $search = new Horde_Kolab_Server_Object_Search_Constraint_Strict( + $this->_search + ); + + $data = $search->searchAttributes( + $criteria, array('Mail', 'Alias') + ); + + if (empty($data)) { + return array(); + } + + $mail = $this->getComposite()->structure->getAttributeInternal( + 'Mail' + ); + $alias = $this->getComposite()->structure->getAttributeInternal( + 'Alias' + ); + + if (isset($result[$alias])) { + $addrs = array_merge($data[$mail], $data[$alias]); + } else { + $addrs = $data[$mail]; + } + + $criteria = new Horde_Kolab_Server_Query_Element_And( + new Horde_Kolab_Server_Query_Element_Equals( + 'Objectclass', + Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON + ), + new Horde_Kolab_Server_Query_Element_Equals( + 'Delegate', $data[$mail][0] + ) + ); + + $data = $this->_search->searchAttributes( + $criteria, array('Mail', 'Alias') + ); + + if (!empty($data)) { + foreach ($data as $adr) { + if (isset($adr[$mail])) { + $addrs = array_merge($addrs, $adr[$mail]); + } + if (isset($adr[$alias])) { + $addrs = array_merge($addrs, $adr[$alias]); + } + } + } + + $addrs = array_map('strtolower', $addrs); + + return $addrs; + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Attributes.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Attributes.php index 6e9a0d376..058023552 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Attributes.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Attributes.php @@ -37,12 +37,11 @@ extends Horde_Kolab_Server_Object_Search_Base * * @return mixed The search result. */ - public function search() - { - $criteria = func_get_arg(0); - $attributes = func_get_arg(1); - + public function searchAttributes( + Horde_Kolab_Server_Query_Element $criteria, + array $attributes + ) { $params = array('attributes' => $attributes); - return $this->_composite->server->find($criteria, $params); + return $this->getComposite()->structure->find($criteria, $params); } } \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Base.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Base.php index 11dfefdff..b14446e3e 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Base.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Base.php @@ -45,6 +45,16 @@ implements Horde_Kolab_Server_Object_Search { $this->_composite = $composite; } + + /** + * Return the refernce to the composite server. + * + * @return Horde_Kolab_Server_Composite + */ + public function getComposite() + { + return $this->_composite; + } /** * Identify the GUID(s) of the result entry(s). diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Children.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Children.php index 3deb3b8bd..8d18c8abf 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Children.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Children.php @@ -26,31 +26,27 @@ * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Search_Children -extends Horde_Kolab_Server_Object_Search_Guid +extends Horde_Kolab_Server_Object_Search_Base { /** * Perform the search. * - * @param Horde_Kolab_Server_Query_Element $criteria The search criteria. - * @param string $objectclass The type of children - * to return. + * @param string $parent_guid The guid of the parent. + * @param string $objectclass The type of children to return. * * @return mixed The search result. */ - public function search() + public function searchChildren($parent_guid, $objectclass) { - $criteria = func_get_arg(0); - $objectclass = func_get_arg(1); - - $criteria = new Horde_Kolab_Server_Query_Element_And( - array( - new Horde_Kolab_Server_Query_Element_Equals( - Horde_Kolab_Server_Object_Top::ATTRIBUTE_OC, - $objectclass - ), - $criteria - ) + $criteria = new Horde_Kolab_Server_Query_Element_Equals( + 'Objectclass', $objectclass + ); + $params = array( + 'attributes' => Horde_Kolab_Server_Object_Top::ATTRIBUTE_GUID + ); + $data = $this->_composite->server->findBelow( + $criteria, $parent, $params ); - return parent::search($criteria); + return self::guidFromResult($data); } } \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Constraint/Single.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Constraint/Single.php index 82e2ed37c..c935a5dd9 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Constraint/Single.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Constraint/Single.php @@ -31,7 +31,7 @@ implements Horde_Kolab_Server_Object_Search /** * A link to the search. * - * @var Horde_Kolab_Server_Search + * @var Horde_Kolab_Server_Object_Search */ private $_search; @@ -40,20 +40,33 @@ implements Horde_Kolab_Server_Object_Search * * @param Horde_Kolab_Server_Search $search The search being restricted. */ - public function __construct(Horde_Kolab_Server_Search $search) + public function __construct(Horde_Kolab_Server_Object_Search $search) { $this->_search = $search; } /** - * Perform the search. + * Return the refernce to the composite server. * - * @return mixed The search result. + * @return Horde_Kolab_Server_Composite */ - public function search() + public function getComposite() + { + return $this->_search->getComposite(); + } + + /** + * Delegate to the actual search operation. + * + * @param string $method The name of the called method. + * @param array $args Arguments of the call. + * + * @return array The search result. + */ + public function __call($method, $args) { $args = func_get_args(); - $result = call_user_func_array(array($this->_search, 'search'), $args); + $result = call_user_func_array(array($this->_search, $method), $args); return array_pop($result); } } \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Constraint/Strict.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Constraint/Strict.php index 65f9e3c12..b1e740d73 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Constraint/Strict.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Constraint/Strict.php @@ -46,13 +46,27 @@ implements Horde_Kolab_Server_Object_Search } /** - * Perform the search. + * Return the refernce to the composite server. * - * @return mixed The search result. + * @return Horde_Kolab_Server_Composite */ - public function search() + public function getComposite() + { + return $this->_search->getComposite(); + } + + /** + * Delegate to the actual search operation. + * + * @param string $method The name of the called method. + * @param array $args Arguments of the call. + * + * @return array The search result. + */ + public function __call($method, $args) { $args = func_get_args(); + $result = call_user_func_array(array($this->_search, $method), $args); $result = call_user_func_array(array($this->_search, 'search'), $args); if (count($result) > 1) { throw new Horde_Kolab_Server_Exception( diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guid.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guid.php index 0a105495f..45dc17e6b 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guid.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guid.php @@ -33,16 +33,14 @@ extends Horde_Kolab_Server_Object_Search_Base * * @param Horde_Kolab_Server_Query_Element $criteria The search criteria. * - * @return mixed The search result. + * @return array The search result. */ - public function search() + public function searchGuid(Horde_Kolab_Server_Query_Element $criteria) { - $criteria = func_get_arg(0); - $params = array( - 'attributes' => Horde_Kolab_Server_Object_Top::ATTRIBUTE_GUID + 'attributes' => 'Guid' ); - $data = $this->_composite->server->find($criteria, $params); + $data = $this->getComposite()->structure->find($criteria, $params); return self::guidFromResult($data); } } \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforalias.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforalias.php new file mode 100644 index 000000000..9592bca39 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforalias.php @@ -0,0 +1,47 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Return all KolabInetOrgPersons with the given alias address. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Object_Search_Guidforalias +extends Horde_Kolab_Server_Object_Search_Restrictkolab +{ + /** + * Return all KolabInetOrgPersons with the given alias. + * + * @param string $alias The alias address to search for. + * + * @return array The GUID(s). + * + * @throws Horde_Kolab_Server_Exception + */ + public function searchGuidForAlias($alias) + { + $criteria = new Horde_Kolab_Server_Query_Element_Equals( + 'Alias', $alias + ); + return parent::searchRestrictKolab($criteria); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforcn.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforcn.php new file mode 100644 index 000000000..5b31bd31d --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforcn.php @@ -0,0 +1,47 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Identify the GUID for the objects found with the given common name. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Object_Search_Guidforcn +extends Horde_Kolab_Server_Object_Search_Guid +{ + /** + * Identify the GUID for the objects found with the given common name. + * + * @param string $cn Search for objects with this common name. + * + * @return array The GUID(s). + * + * @throws Horde_Kolab_Server_Exception + */ + public function searchGuidForCn($cn) + { + $criteria = new Horde_Kolab_Server_Query_Element_Equals( + 'Cn', $cn + ); + return parent::searchGuid($criteria); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforkolabusers.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforkolabusers.php new file mode 100644 index 000000000..3266c6320 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforkolabusers.php @@ -0,0 +1,46 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Return the GUIDs of all KolabInetOrgPersons. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Object_Search_Guidforkolabusers +extends Horde_Kolab_Server_Object_Search_Guid +{ + /** + * Return the GUIDs of all KolabInetOrgPersons. + * + * @return array The GUID(s). + * + * @throws Horde_Kolab_Server_Exception + */ + public function searchGuidForKolabUsers() + { + $criteria = new Horde_Kolab_Server_Query_Element_Equals( + 'Objectclass', + Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON + ); + return parent::searchGuid($criteria); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidformail.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidformail.php new file mode 100644 index 000000000..3974c7124 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidformail.php @@ -0,0 +1,47 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Return all KolabInetOrgPersons with the given mail address. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Object_Search_Guidformail +extends Horde_Kolab_Server_Object_Search_Restrictkolab +{ + /** + * Return all KolabInetOrgPersons with the given mail. + * + * @param string $mail The mail to search for. + * + * @return array The GUID(s). + * + * @throws Horde_Kolab_Server_Exception + */ + public function searchGuidForMail($mail) + { + $criteria = new Horde_Kolab_Server_Query_Element_Equals( + 'Mail', $mail + ); + return parent::searchRestrictKolab($criteria); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidformailoralias.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidformailoralias.php new file mode 100644 index 000000000..6ca3fe585 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidformailoralias.php @@ -0,0 +1,53 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Return all KolabInetOrgPersons with the given mail or alias address. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Object_Search_Guidformailoralias +extends Horde_Kolab_Server_Object_Search_Restrictkolab +{ + /** + * Return all KolabInetOrgPersons with the given mail or alias address. + * + * @param string $mail The mail address to search for. + * @param string $alias The alias address to search for. + * + * @return array The GUID(s). + * + * @throws Horde_Kolab_Server_Exception + */ + public function searchGuidForMailOrAlias($mail, $alias) + { + $criteria = new Horde_Kolab_Server_Query_Element_Or( + new Horde_Kolab_Server_Query_Element_Equals( + 'Mail', $mail + ), + new Horde_Kolab_Server_Query_Element_Equals( + 'Alias', $alias + ) + ); + return parent::searchRestrictKolab($criteria); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuid.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuid.php new file mode 100644 index 000000000..0c62c859d --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuid.php @@ -0,0 +1,47 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Return all KolabInetOrgPersons with the given uid. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Object_Search_Guidforuid +extends Horde_Kolab_Server_Object_Search_Restrictkolab +{ + /** + * Return all KolabInetOrgPersons with the given uid. + * + * @param string $uid The uid to search for. + * + * @return array The GUID(s). + * + * @throws Horde_Kolab_Server_Exception + */ + public function searchGuidForUid($uid) + { + $criteria = new Horde_Kolab_Server_Query_Element_Equals( + 'Uid', $uid + ); + return parent::searchRestrictKolab($criteria); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuidormail.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuidormail.php new file mode 100644 index 000000000..3d5eb60d6 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuidormail.php @@ -0,0 +1,54 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Return all KolabInetOrgPersons with the given uid or mail address. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Object_Search_Guidforuidormail +extends Horde_Kolab_Server_Object_Search_Restrictkolab +{ + /** + * Return all KolabInetOrgPersons with the given uid or mail address. + * + * @param string $id The uid or mail address to search for. + * + * @return array The GUID(s). + * + * @throws Horde_Kolab_Server_Exception + */ + public function searchGuidForUidOrMail($id) + { + $criteria = new Horde_Kolab_Server_Query_Element_Or( + array( + new Horde_Kolab_Server_Query_Element_Equals( + 'Uid', $id + ), + new Horde_Kolab_Server_Query_Element_Equals( + 'Mail', $id + ) + ) + ); + return parent::searchRestrictKolab($criteria); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuidormailoralias.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuidormailoralias.php new file mode 100644 index 000000000..177ef9669 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuidormailoralias.php @@ -0,0 +1,57 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Return all KolabInetOrgPersons with the given uid, mail or alias address. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Object_Search_Guidforuidormailoralias +extends Horde_Kolab_Server_Object_Search_Restrictkolab +{ + /** + * Return all KolabInetOrgPersons with the given uid, mail or alias address. + * + * @param string $id The uid or mail address or alias address to search for. + * + * @return array The GUID(s). + * + * @throws Horde_Kolab_Server_Exception + */ + public function searchGuidForUidOrMailOrAlias($id) + { + $criteria = new Horde_Kolab_Server_Query_Element_Or( + array( + new Horde_Kolab_Server_Query_Element_Equals( + 'Uid', $id + ), + new Horde_Kolab_Server_Query_Element_Equals( + 'Mail', $id + ), + new Horde_Kolab_Server_Query_Element_Equals( + 'Alias', $id + ) + ) + ); + return parent::searchRestrictKolab($criteria); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Mailforuidormail.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Mailforuidormail.php new file mode 100644 index 000000000..3006cf1e0 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Mailforuidormail.php @@ -0,0 +1,95 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Return the mail address of the KolabInetOrgPersons with the given uid or mail + * address. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Object_Search_Mailforuidormail +extends Horde_Kolab_Server_Object_Search_Base +{ + + /** + * The base attribute search. + * + * @var Horde_Kolab_Server_Object_Search + */ + private $_search; + + /** + * Constructor + * + * @param Horde_Kolab_Server_Composite $composite A link to the composite + * server handler. + */ + public function __construct(Horde_Kolab_Server_Composite $composite) + { + $this->_composite = $composite; + $this->_search = new Horde_Kolab_Server_Object_Search_Constraint_Strict( + new Horde_Kolab_Server_Object_Search_Attributes( + $this->getComposite() + ) + ); + } + + /** + * Return the mail address of the KolabInetOrgPersons with the given uid or + * mail address. + * + * @param string $uid The uid to search for. + * @param string $mail The mail address to search for. + * + * @return array The GUID(s). + * + * @throws Horde_Kolab_Server_Exception + */ + public function searchMailForUidOrMail($uid, $mail) + { + $criteria = new Horde_Kolab_Server_Query_Element_And( + new Horde_Kolab_Server_Query_Element_Equals( + 'Objectclass', + Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON + ), + new Horde_Kolab_Server_Query_Element_Or( + new Horde_Kolab_Server_Query_Element_Equals( + 'Uid', $uid + ), + new Horde_Kolab_Server_Query_Element_Equals( + 'Mail', $mail + ) + ) + ); + $data = $this->_search->searchAttributes($criteria, array('Mail')); + + $internal = $this->getComposite()->structure->getAttributeInternal( + 'Mail' + ); + if (!empty($data)) { + return $data[$internal][0]; + } else { + return false; + } + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Restrictkolab.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Restrictkolab.php new file mode 100644 index 000000000..c7c7e2517 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Restrictkolab.php @@ -0,0 +1,54 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Restrict a search to KolabInetOrgPersons. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Object_Search_Restrictkolab +extends Horde_Kolab_Server_Object_Search_Guid +{ + /** + * Restrict a search to KolabInetOrgPersons. + * + * @param Horde_Kolab_Server_Query_Element $criteria The search criteria. + * + * @return array The GUID(s). + * + * @throws Horde_Kolab_Server_Exception + */ + public function searchRestrictKolab( + Horde_Kolab_Server_Query_Element $criteria + ) { + $criteria = new Horde_Kolab_Server_Query_Element_And( + array( + new Horde_Kolab_Server_Query_Element_Equals( + 'Objectclass', + Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON + ), + $criteria + ) + ); + return parent::searchGuid($criteria); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Top.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Top.php index 21cabf950..5b50743b5 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Top.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Top.php @@ -93,9 +93,9 @@ implements Horde_Kolab_Server_Object_Searches static public function getSearchOperations() { $searches = array( - 'Guid', - 'Attributes', - 'Children', + 'Horde_Kolab_Server_Object_Search_Guid', + 'Horde_Kolab_Server_Object_Search_Attributes', + 'Horde_Kolab_Server_Object_Search_Children', ); return $searches; } diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Query/Ldap.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Query/Ldap.php index f6c6fb6ee..ddb05bb2b 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Query/Ldap.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Query/Ldap.php @@ -35,13 +35,23 @@ class Horde_Kolab_Server_Query_Ldap implements Horde_Kolab_Server_Query private $_criteria; /** + * The db structure. + * + * @var Horde_Kolab_Server_Structure + */ + private $_structure; + + /** * Constructor. * * @param array $criteria The query criteria. */ - public function __construct(Horde_Kolab_Server_Query_Element $criteria) - { - $this->_criteria = $criteria; + public function __construct( + Horde_Kolab_Server_Query_Element $criteria, + Horde_Kolab_Server_Structure $structure + ) { + $this->_criteria = $criteria; + $this->_structure = $structure; } /** @@ -53,8 +63,13 @@ class Horde_Kolab_Server_Query_Ldap implements Horde_Kolab_Server_Query */ public function __toString() { - $filter = $this->_criteria->convert($this); - return $filter->asString(); + try { + $filter = $this->_criteria->convert($this); + $result = $filter->asString(); + return $result; + } catch (Horde_Kolab_Server_Exception $e) { + return ''; + } } /** @@ -170,7 +185,9 @@ class Horde_Kolab_Server_Query_Ldap implements Horde_Kolab_Server_Query $operator ) { $result = Net_LDAP2_Filter::create( - $single->getName(), $operator, $single->getValue() + $this->_structure->getInternalAttribute($single->getName()), + $operator, + $single->getValue() ); $this->_handleError($result); return $result; diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Base.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Base.php index 0d4a70661..18f4604cc 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Base.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Base.php @@ -67,18 +67,25 @@ class Horde_Kolab_Server_Search_Base implements Horde_Kolab_Server_Search $server_searches = array(); foreach ($this->_composite->structure->getSupportedObjects() as $sobj) { $methods = get_class_methods($sobj); - if (in_array('getSearchOperations', $methods)) { - $searches = call_user_func(array($sobj, 'getSearchOperations')); - foreach ($searches as $search) { - if (in_array($search, $methods)) { - $server_searches[$search] = array('class' => $sobj); - } else { + if (!in_array('getSearchOperations', $methods)) { + continue; + } + $search_classes = call_user_func(array($sobj, 'getSearchOperations')); + foreach ($search_classes as $search_class) { + if (!class_exists($search_class)) { + throw new Horde_Kolab_Server_Exception( sprintf( - "Class \"%s\" does not support method \"%s\"!", + "%s::getSearchOperations specified non-existing class \"%s\"!", $sobj, - $search - ); - } + $search_class + ) + ); + } + $methods = get_class_methods($search_class); + unset($methods['getComposite']); + unset($methods['__construct']); + foreach ($methods as $method) { + $server_searches[$method] = array('class' => $search_class); } } } @@ -108,13 +115,9 @@ class Horde_Kolab_Server_Search_Base implements Horde_Kolab_Server_Search public function __call($method, $args) { if (in_array($method, array_keys($this->_searches))) { - array_unshift($args, $this->_composite); - return call_user_func_array( - array( - $this->_searches[$method]['class'], $method - ), - $args - ); + $class = $this->_searches[$method]['class']; + $search = new $class($this->_composite); + return call_user_func_array(array($search, $method), $args); } throw new Horde_Kolab_Server_Exception( sprintf( diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure.php index 17ccd6a51..9b38e8040 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure.php @@ -29,6 +29,38 @@ interface Horde_Kolab_Server_Structure { /** + * Finds object data matching a given set of criteria. + * + * @param Horde_Kolab_Server_Query_Element $criteria The criteria for the search. + * @param array $params Additional search parameters. + * + * @return Horde_Kolab_Server_Result The result object. + * + * @throws Horde_Kolab_Server_Exception + */ + public function find( + Horde_Kolab_Server_Query_Element $criteria, + array $params = array() + ); + + /** + * Finds all object data below a parent matching a given set of criteria. + * + * @param Horde_Kolab_Server_Query_Element $criteria The criteria for the search. + * @param string $parent The parent to search below. + * @param array $params Additional search parameters. + * + * @return Horde_Kolab_Server_Result The result object. + * + * @throws Horde_Kolab_Server_Exception + */ + public function findBelow( + Horde_Kolab_Server_Query_Element $criteria, + $parent, + array $params = array() + ); + + /** * Set the composite server reference for this object. * * @param Horde_Kolab_Server_Composite $composite A link to the composite @@ -46,6 +78,15 @@ interface Horde_Kolab_Server_Structure public function getSupportedObjects(); /** + * Maps the external attribute name to its internal counterpart. + * + * @param string $external The external attribute name. + * + * @return string The internal attribute name. + */ + public function getInternalAttribute($external); + + /** * Determine the type of an object by its tree position and other * parameters. * diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Base.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Base.php index 0c18a4ea6..d840ef3d2 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Base.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Base.php @@ -32,7 +32,49 @@ abstract class Horde_Kolab_Server_Structure_Base implements Horde_Kolab_Server_S * * @var Horde_Kolab_Server_Composite */ - protected $composite; + private $_composite; + + /** + * Finds object data matching a given set of criteria. + * + * @param Horde_Kolab_Server_Query_Element $criteria The criteria for the search. + * @param array $params Additional search parameters. + * + * @return Horde_Kolab_Server_Result The result object. + * + * @throws Horde_Kolab_Server_Exception + */ + public function find( + Horde_Kolab_Server_Query_Element $criteria, + array $params = array() + ) { + $query = new Horde_Kolab_Server_Query_Ldap($criteria, $this); + return $this->_composite->server->find( + (string) $query, $params + ); + } + + /** + * Finds all object data below a parent matching a given set of criteria. + * + * @param Horde_Kolab_Server_Query_Element $criteria The criteria for the search. + * @param string $parent The parent to search below. + * @param array $params Additional search parameters. + * + * @return Horde_Kolab_Server_Result The result object. + * + * @throws Horde_Kolab_Server_Exception + */ + public function findBelow( + Horde_Kolab_Server_Query_Element $criteria, + $parent, + array $params = array() + ) { + $query = new Horde_Kolab_Server_Query_Ldap($criteria, $this); + return $this->_composite->server->findBelow( + (string) $query, $parent, $params + ); + } /** * Set the composite server reference for this object. @@ -44,6 +86,17 @@ abstract class Horde_Kolab_Server_Structure_Base implements Horde_Kolab_Server_S */ public function setComposite(Horde_Kolab_Server_Composite $composite) { - $this->composite = $composite; + $this->_composite = $composite; + } + + /** + * Get the composite server reference for this object. + * + * @return Horde_Kolab_Server_Composite A link to the composite server + * handler. + */ + public function getComposite() + { + return $this->_composite; } } diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Kolab.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Kolab.php index 263b1a940..28c9a5616 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Kolab.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Kolab.php @@ -86,9 +86,9 @@ class Horde_Kolab_Server_Structure_Kolab extends Horde_Kolab_Server_Structure_Ld return parent::_determineType($guid, $ocs); } - $groups = $this->composite->search->getGroups($guid); + $groups = $this->getComposite()->search->getGroups($guid); if (!empty($groups)) { - $base = $this->composite->server->getBaseGuid(); + $base = $this->getComposite()->server->getBaseGuid(); if (in_array('cn=admin,cn=internal,' . $base, $groups)) { return 'Horde_Kolab_Server_Object_Kolab_Administrator'; } diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Ldap.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Ldap.php index 3e1639eb4..8518d0b2c 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Ldap.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Ldap.php @@ -77,9 +77,6 @@ class Horde_Kolab_Server_Structure_Ldap extends Horde_Kolab_Server_Structure_Bas } catch (Horde_Kolab_Server_Exception $e) { } } - if ($oc == 'top') { - return 'Horde_Kolab_Server_Object'; - } throw new Horde_Kolab_Server_Exception( sprintf("Unknown object type for GUID %s.", $guid), Horde_Kolab_Server_Exception::SYSTEM @@ -97,7 +94,7 @@ class Horde_Kolab_Server_Structure_Ldap extends Horde_Kolab_Server_Structure_Bas */ public function generateServerGuid($type, $id, array $info) { - return sprintf('%s,%s', $id, $this->composite->server->getBaseGuid()); + return sprintf('%s,%s', $id, $this->getComposite()->server->getBaseGuid()); } /** @@ -115,7 +112,7 @@ class Horde_Kolab_Server_Structure_Ldap extends Horde_Kolab_Server_Structure_Bas */ protected function getObjectClasses($guid) { - $object = $this->composite->server->read( + $object = $this->getComposite()->server->read( $guid, array('objectClass') ); if (!isset($object['objectClass'])) { @@ -133,4 +130,29 @@ class Horde_Kolab_Server_Structure_Ldap extends Horde_Kolab_Server_Structure_Bas ); return $result; } + + /** + * Maps the external attribute name to its internal counterpart. + * + * @param string $external The external attribute name. + * + * @return string The internal attribute name. + */ + public function getInternalAttribute($external) + { + switch ($external) { + case 'Objectclass': + return 'objectClass'; + case 'Guid': + return 'dn'; + case 'Uid': + return 'uid'; + case 'Mail': + return 'mail'; + default: + throw new Horde_Kolab_Server_Exception( + sprintf('Undefined internal attribute "%s"', $external) + ); + } + } } diff --git a/framework/Kolab_Server/package.xml b/framework/Kolab_Server/package.xml index 0891eea69..58265c3fc 100644 --- a/framework/Kolab_Server/package.xml +++ b/framework/Kolab_Server/package.xml @@ -141,6 +141,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + @@ -149,6 +150,16 @@ http://pear.php.net/dtd/package-2.0.xsd"> + + + + + + + + + + @@ -218,6 +229,41 @@ http://pear.php.net/dtd/package-2.0.xsd"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -241,7 +287,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> - + @@ -252,23 +298,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - - - - - - - - - - - - - - - - - @@ -376,12 +405,23 @@ http://pear.php.net/dtd/package-2.0.xsd"> - + + + + + + + + + + + + @@ -416,6 +456,25 @@ http://pear.php.net/dtd/package-2.0.xsd"> + + + + + + + + + + + + + + + + + + + @@ -435,20 +494,11 @@ http://pear.php.net/dtd/package-2.0.xsd"> - + - - - - - - - - - diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Attribute/BaseTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Attribute/BaseTest.php index 17bac91e3..654f8cc7f 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Attribute/BaseTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Attribute/BaseTest.php @@ -14,12 +14,12 @@ /** * Prepare the test setup. */ -require_once dirname(__FILE__) . '/../Autoload.php'; +require_once dirname(__FILE__) . '/../TestCase.php'; /** * Test the base attribute. * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * Copyright 2009 The Horde Project (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. @@ -30,16 +30,14 @@ require_once dirname(__FILE__) . '/../Autoload.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Attribute_BaseTest extends PHPUnit_Framework_TestCase +class Horde_Kolab_Server_Attribute_BaseTest extends Horde_Kolab_Server_TestCase { public function setUp() { $this->object = $this->getMock( 'Horde_Kolab_Server_Object', array(), array(), '', false ); - $this->composite = $this->getMock( - 'Horde_Kolab_Server_Composite', array(), array(), '', false - ); + $this->composite = $this->getMockedComposite(); } public function testMethodConstructHasParameterObjectTheObjectOwningTheAttributeAndParameterCompositeWhichIsTheLinkToTheServer() @@ -60,6 +58,10 @@ class Horde_Kolab_Server_Attribute_BaseTest extends PHPUnit_Framework_TestCase public function testMethodGetnameReturnsStringTheNameOfTheAttribute() { + $this->composite->structure->expects($this->exactly(1)) + ->method('getInternalAttribute') + ->with('name') + ->will($this->returnValue('name')); $attribute = new Attribute_Mock($this->object, $this->composite, 'name'); $this->assertEquals('name', $attribute->getInternalName()); } diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Attribute/ValueTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Attribute/ValueTest.php index 428c80789..61c652b1f 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Attribute/ValueTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Attribute/ValueTest.php @@ -19,7 +19,7 @@ require_once dirname(__FILE__) . '/../Autoload.php'; /** * Test the value attribute. * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * Copyright 2009 The Horde Project (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/ConfigurationTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/ConfigurationTest.php index 58ef12411..8e7a6016e 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/ConfigurationTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/ConfigurationTest.php @@ -12,9 +12,9 @@ */ /** - * Prepare the test setup. + * Require our basic test case definition */ -require_once dirname(__FILE__) . '/../../../Autoload.php'; +require_once dirname(__FILE__) . '/../../../LdapTestCase.php'; /** * Test the configuration based server factory. @@ -31,7 +31,7 @@ require_once dirname(__FILE__) . '/../../../Autoload.php'; * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Factory_ConfigurationTest -extends PHPUnit_Framework_TestCase +extends Horde_Kolab_Server_LdapTestCase { public function testMethodGetserverHasResultLoggedServerIfALoggerWasProvidedInTheConfiguration() { diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/Conn/ConfigurationTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/Conn/ConfigurationTest.php new file mode 100644 index 000000000..e081dbcfe --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/Conn/ConfigurationTest.php @@ -0,0 +1,79 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Require our basic test case definition + */ +require_once dirname(__FILE__) . '/../../../../LdapTestCase.php'; + +/** + * Test the configuration based connection factory. + * + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Class_Server_Factory_Conn_ConfigurationTest +extends Horde_Kolab_Server_LdapTestCase +{ + public function testMethodConstructHasParameterArrayConfiguration() + { + $factory = new Horde_Kolab_Server_Factory_Conn_Configuration( + array('basedn' => 'a') + ); + } + + public function testMethodConstructHasPostconditionThatTheConfigurationWasSaved() + { + $factory = new Horde_Kolab_Server_Factory_Conn_Configuration( + array('basedn' => 'a') + ); + $this->assertEquals(array('basedn' => 'a'), $factory->getConfiguration()); + } + + public function testMethodConstructHasResultArrayTheConfiguration() + { + $factory = new Horde_Kolab_Server_Factory_Conn_Configuration( + array('basedn' => 'a') + ); + $this->assertType('array', $factory->getConfiguration()); + } + + public function testMethodConstructHasPostconditionThatTheConnectionFactoryHasBeenSet() + { + $factory = new Horde_Kolab_Server_Factory_Conn_Configuration( + array('mock' => true) + ); + $this->assertType('Horde_Kolab_Server_Connection_Mock', $factory->getConnection()); + } + + public function testMethodGetconnectionHasResultMockConnectionIfConfiguredThatWay() + { + $this->testMethodConstructHasPostconditionThatTheConnectionFactoryHasBeenSet(); + } + + public function testMethodGetconnectionHasResultLdapConnectionIfConfiguredThatWay() + { + $factory = new Horde_Kolab_Server_Factory_Conn_Configuration( + array('basedn' => 'a') + ); + $this->assertType('Horde_Kolab_Server_Connection_Simpleldap', $factory->getConnection()); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/Conn/LdapTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/Conn/LdapTest.php index 7f2aaa9f1..b00c13717 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/Conn/LdapTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/Conn/LdapTest.php @@ -12,9 +12,9 @@ */ /** - * Prepare the test setup. + * Require our basic test case definition */ -require_once dirname(__FILE__) . '/../../../../Autoload.php'; +require_once dirname(__FILE__) . '/../../../../LdapTestCase.php'; /** * Test the ldap connection factory. @@ -31,7 +31,7 @@ require_once dirname(__FILE__) . '/../../../../Autoload.php'; * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Factory_Conn_LdapTest -extends PHPUnit_Framework_TestCase +extends Horde_Kolab_Server_LdapTestCase { public function testMethodSetconfigurationHasPostconditionThatTheServerParameterWasRewritten() { diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/ConstructorTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/ConstructorTest.php index 59f42df6e..ed0ca15d5 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/ConstructorTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/ConstructorTest.php @@ -12,9 +12,9 @@ */ /** - * Prepare the test setup. + * Require our basic test case definition */ -require_once dirname(__FILE__) . '/../../../Autoload.php'; +require_once dirname(__FILE__) . '/../../../LdapTestCase.php'; /** * Test the mapping server factory. @@ -31,10 +31,11 @@ require_once dirname(__FILE__) . '/../../../Autoload.php'; * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Factory_ConstructorTest -extends PHPUnit_Framework_TestCase +extends Horde_Kolab_Server_LdapTestCase { public function setUp() { + parent::setUp(); $this->factory = $this->getMock('Horde_Kolab_Server_Factory_Conn'); $this->objects = $this->getMock('Horde_Kolab_Server_Objects'); $this->structure = $this->getMock('Horde_Kolab_Server_Structure'); diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/InjectorTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/InjectorTest.php index 8dadfb108..3e522348a 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/InjectorTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/InjectorTest.php @@ -12,9 +12,9 @@ */ /** - * Prepare the test setup. + * Require our basic test case definition */ -require_once dirname(__FILE__) . '/../../../Autoload.php'; +require_once dirname(__FILE__) . '/../../../LdapTestCase.php'; /** * Test the injector based server factory. @@ -31,7 +31,7 @@ require_once dirname(__FILE__) . '/../../../Autoload.php'; * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Factory_InjectorTest -extends PHPUnit_Framework_TestCase +extends Horde_Kolab_Server_LdapTestCase { private function _getFactory(array $configuration = array()) { diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/KolabTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/KolabTest.php index 2b8a4e8b8..64e4c29ad 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/KolabTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/KolabTest.php @@ -12,9 +12,9 @@ */ /** - * Prepare the test setup. + * Require our basic test case definition */ -require_once dirname(__FILE__) . '/../../../Autoload.php'; +require_once dirname(__FILE__) . '/../../../LdapTestCase.php'; /** * Test the default Kolab server factory. @@ -31,10 +31,11 @@ require_once dirname(__FILE__) . '/../../../Autoload.php'; * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Factory_KolabTest -extends PHPUnit_Framework_TestCase +extends Horde_Kolab_Server_LdapTestCase { public function setUp() { + parent::setUp(); $this->conn_factory = $this->getMock('Horde_Kolab_Server_Factory_Conn'); $this->connection = $this->getMock('Horde_Kolab_Server_Connection'); } diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Ldap/ChangesTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Ldap/ChangesTest.php new file mode 100644 index 000000000..a0c47bc69 --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Ldap/ChangesTest.php @@ -0,0 +1,190 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Prepare the test setup. + */ +require_once dirname(__FILE__) . '/../../../Autoload.php'; + +/** + * Test the LDAP changeset handler. + * + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Class_Server_Ldap_ChangesTest extends PHPUnit_Framework_TestCase +{ + public function testMethodConstructHasParameterServerobject() + { + $changes = new Horde_Kolab_Server_Ldap_Changes( + $this->getMock('Horde_Kolab_Server_Object'), array() + ); + } + + public function testMethodConstructHasParameterArrayDataToBeStored() + { + $changes = new Horde_Kolab_Server_Ldap_Changes( + $this->getMock('Horde_Kolab_Server_Object'), + array('store' => 'value') + ); + } + + public function testMethodGetchangesetHasResultArrayEmptyIfOldAndNewDatasetsWereEmpty() + { + $object = $this->getMock('Horde_Kolab_Server_Object'); + $object->expects($this->once()) + ->method('readInternal') + ->will($this->returnValue(array())); + $changes = new Horde_Kolab_Server_Ldap_Changes( + $object, array() + ); + $this->assertEquals(array(), $changes->getChangeset()); + } + + public function testMethodGetchangesetHasResultArrayEmptyIfOldAndNewDatasetsWereEqual() + { + $object = $this->getMock('Horde_Kolab_Server_Object'); + $object->expects($this->once()) + ->method('readInternal') + ->will($this->returnValue(array('a' => array('a')))); + $changes = new Horde_Kolab_Server_Ldap_Changes( + $object, array('a' => array('a')) + ); + $this->assertEquals(array(), $changes->getChangeset()); + } + + public function testMethodGetchangesetHasResultArrayNewAttributesInNewDatasetAsAdded() + { + $object = $this->getMock('Horde_Kolab_Server_Object'); + $object->expects($this->once()) + ->method('readInternal') + ->will($this->returnValue(array())); + $changes = new Horde_Kolab_Server_Ldap_Changes( + $object, array('new' => 'a') + ); + $this->assertEquals( + array( + 'add' => array( + 'new' => 'a' + ) + ), + $changes->getChangeset() + ); + } + + public function testMethodGetchangesetHasResultArrayMissingValuesInNewDatasetAsDeleted() + { + $object = $this->getMock('Horde_Kolab_Server_Object'); + $object->expects($this->once()) + ->method('readInternal') + ->will($this->returnValue(array('old' => 'a'))); + $changes = new Horde_Kolab_Server_Ldap_Changes( + $object, array() + ); + $this->assertEquals( + array( + 'delete' => array( + 'old' + ) + ), + $changes->getChangeset() + ); + } + + public function testMethodGetchangesetHasResultArraySingleValuesWithDifferencesAsReplaced() + { + $object = $this->getMock('Horde_Kolab_Server_Object'); + $object->expects($this->once()) + ->method('readInternal') + ->will($this->returnValue(array('value' => 'a'))); + $changes = new Horde_Kolab_Server_Ldap_Changes( + $object, array('value' => 'b') + ); + $this->assertEquals( + array( + 'replace' => array( + 'value' => 'b' + ) + ), + $changes->getChangeset() + ); + } + + public function testMethodGetchangesetHasResultArrayTheNewValuesAsAdded() + { + $object = $this->getMock('Horde_Kolab_Server_Object'); + $object->expects($this->once()) + ->method('readInternal') + ->will($this->returnValue(array('value' => array('a', 'b', 'c')))); + $changes = new Horde_Kolab_Server_Ldap_Changes( + $object, array('value' => array('a', 'b', 'c', 'd')) + ); + $this->assertEquals( + array( + 'add' => array( + 'value' => array('d') + ) + ), + $changes->getChangeset() + ); + } + + public function testMethodGetchangesetHasResultArrayTheRemovedValuesAsDeleted() + { + $object = $this->getMock('Horde_Kolab_Server_Object'); + $object->expects($this->once()) + ->method('readInternal') + ->will($this->returnValue(array('value' => array('a', 'b', 'c')))); + $changes = new Horde_Kolab_Server_Ldap_Changes( + $object, array('value' => array('b', 'c')) + ); + $this->assertEquals( + array( + 'delete' => array( + 'value' => array('a') + ) + ), + $changes->getChangeset() + ); + } + + public function testMethodGetchangesetHasResultArrayTheNewValuesAsAddedAndTheRemovedValuesAsDeleted() + { + $object = $this->getMock('Horde_Kolab_Server_Object'); + $object->expects($this->once()) + ->method('readInternal') + ->will($this->returnValue(array('value' => array('a', 'b', 'c')))); + $changes = new Horde_Kolab_Server_Ldap_Changes( + $object, array('value' => array('b', 'c', 'd')) + ); + $this->assertEquals( + array( + 'add' => array( + 'value' => array('d') + ), + 'delete' => array( + 'value' => array('a') + ) + ), + $changes->getChangeset() + ); + } +} diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Ldap/FilteredTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Ldap/FilteredTest.php new file mode 100644 index 000000000..e23aabd0b --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Ldap/FilteredTest.php @@ -0,0 +1,120 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Require our basic test case definition + */ +require_once dirname(__FILE__) . '/../../../LdapTestCase.php'; + +/** + * Test the filtered LDAP driver. + * + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Class_Server_Ldap_FilteredTest extends Horde_Kolab_Server_LdapTestCase +{ + public function setUp() + { + parent::setUp(); + + $this->ldap_read = $this->getMock('Net_LDAP2'); + $this->ldap_write = $this->getMock('Net_LDAP2'); + $connection = new Horde_Kolab_Server_Connection_Splittedldap( + $this->ldap_read, + $this->ldap_write + ); + + $this->server = new Horde_Kolab_Server_Ldap_Filtered( + $connection, + 'base', + 'filter' + ); + } + + private function getSearchResultMock() + { + $result = $this->getMock( + 'Net_LDAP2_Search', array('as_struct', 'count'), array(), '', false + ); + $result->expects($this->any()) + ->method('as_struct') + ->will($this->returnValue(array(array('dn' => 'test')))); + $result->expects($this->any()) + ->method('count') + ->will($this->returnValue(1)); + return $result; + } + + public function testMethodFindbelowHasParameterQueryelementTheSearchCriteria() + { + $this->ldap_read->expects($this->exactly(1)) + ->method('search') + ->with('', '(&(filter)(equals=equals))', array()) + ->will($this->returnValue($this->getSearchResultMock())); + $this->server->findBelow('(equals=equals)', ''); + } + + public function testMethodFindbelowHasParameterStringParent() + { + $this->ldap_read->expects($this->exactly(1)) + ->method('search') + ->with('parent', '(&(filter)(equals=equals))', array()) + ->will($this->returnValue($this->getSearchResultMock())); + $this->server->findBelow('(equals=equals)', 'parent', array()); + } + + public function testMethodFindbelowHasParameterArrayAdditionalParameters() + { + $this->ldap_read->expects($this->exactly(1)) + ->method('search') + ->with('', '(&(filter)(equals=equals))', array()) + ->will($this->returnValue($this->getSearchResultMock())); + $this->server->findBelow('(equals=equals)', '', array()); + } + + public function testMethodFindbelowReturnsArraySearchResult() + { + $this->ldap_read->expects($this->exactly(1)) + ->method('search') + ->with('parent', '(&(filter)(equals=equals))', array()) + ->will($this->returnValue($this->getSearchResultMock())); + $this->assertEquals( + array(array('dn' => 'test')), + $this->server->findBelow('(equals=equals)', 'parent')->asArray() + ); + } + + public function testMethodFindbelowThrowsExceptionIfTheSearchFailed() + { + $this->ldap_read->expects($this->exactly(1)) + ->method('search') + ->will($this->returnValue(new PEAR_Error('Search failed!'))); + try { + $this->assertEquals(array('dn' => 'test'), $this->server->findBelow('(equals=equals)', '')); + $this->fail('No exception!'); + } catch (Exception $e) { + $this->assertEquals('Search failed!', $e->getMessage()); + $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); + } + } + +} diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Ldap/StandardTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Ldap/StandardTest.php new file mode 100644 index 000000000..be5bf7cfc --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Ldap/StandardTest.php @@ -0,0 +1,119 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Require our basic test case definition + */ +require_once dirname(__FILE__) . '/../../../LdapTestCase.php'; + +/** + * Test the standard LDAP driver. + * + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Class_Server_Ldap_StandardTest extends Horde_Kolab_Server_LdapTestCase +{ + public function setUp() + { + parent::setUp(); + + $this->ldap_read = $this->getMock('Net_LDAP2'); + $this->ldap_write = $this->getMock('Net_LDAP2'); + $connection = new Horde_Kolab_Server_Connection_Splittedldap( + $this->ldap_read, + $this->ldap_write + ); + + $this->server = new Horde_Kolab_Server_Ldap_Standard( + $connection, + 'base' + ); + } + + private function getSearchResultMock() + { + $result = $this->getMock( + 'Net_LDAP2_Search', array('as_struct', 'count'), array(), '', false + ); + $result->expects($this->any()) + ->method('as_struct') + ->will($this->returnValue(array(array('dn' => 'test')))); + $result->expects($this->any()) + ->method('count') + ->will($this->returnValue(1)); + return $result; + } + + public function testMethodFindbelowHasParameterQueryelementTheSearchCriteria() + { + $this->ldap_read->expects($this->exactly(1)) + ->method('search') + ->with('', '(equals=equals)', array()) + ->will($this->returnValue($this->getSearchResultMock())); + $this->server->findBelow('(equals=equals)', ''); + } + + public function testMethodFindbelowHasParameterStringParent() + { + $this->ldap_read->expects($this->exactly(1)) + ->method('search') + ->with('parent', '(equals=equals)', array()) + ->will($this->returnValue($this->getSearchResultMock())); + $this->server->findBelow('(equals=equals)', 'parent', array()); + } + + public function testMethodFindbelowHasParameterArrayAdditionalParameters() + { + $this->ldap_read->expects($this->exactly(1)) + ->method('search') + ->with('', '(equals=equals)', array()) + ->will($this->returnValue($this->getSearchResultMock())); + $this->server->findBelow('(equals=equals)', '', array()); + } + + public function testMethodFindbelowReturnsArraySearchResult() + { + $this->ldap_read->expects($this->exactly(1)) + ->method('search') + ->with('parent', '(equals=equals)', array()) + ->will($this->returnValue($this->getSearchResultMock())); + $this->assertEquals( + array(array('dn' => 'test')), + $this->server->findBelow('(equals=equals)', 'parent')->asArray() + ); + } + + public function testMethodFindbelowThrowsExceptionIfTheSearchFailed() + { + $this->ldap_read->expects($this->exactly(1)) + ->method('search') + ->will($this->returnValue(new PEAR_Error('Search failed!'))); + try { + $this->assertEquals(array('dn' => 'test'), $this->server->findBelow('(equals=equals)', '')); + $this->fail('No exception!'); + } catch (Exception $e) { + $this->assertEquals('Search failed!', $e->getMessage()); + $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); + } + } + +} diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/LdapTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/LdapTest.php new file mode 100644 index 000000000..1bdfb16c3 --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/LdapTest.php @@ -0,0 +1,510 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Require our basic test case definition + */ +require_once dirname(__FILE__) . '/../../LdapTestCase.php'; + +/** + * Test the LDAP backend. + * + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Class_Server_LdapTest extends Horde_Kolab_Server_LdapTestCase +{ + public function setUp() + { + parent::setUp(); + + $this->ldap_read = $this->getMock('Net_LDAP2'); + $this->ldap_write = $this->getMock('Net_LDAP2'); + $connection = new Horde_Kolab_Server_Connection_Splittedldap( + $this->ldap_read, + $this->ldap_write + ); + + $this->server = new Horde_Kolab_Server_Ldap_Standard( + $connection, + 'base' + ); + } + + private function getSearchResultMock() + { + $result = $this->getMock( + 'Net_LDAP2_Search', array('as_struct', 'count'), array(), '', false + ); + $result->expects($this->any()) + ->method('as_struct') + ->will($this->returnValue(array(array('dn' => 'test')))); + $result->expects($this->any()) + ->method('count') + ->will($this->returnValue(1)); + return $result; + } + + public function testMethodGetbaseguidHasResultStringBaseGuid() + { + $this->assertEquals('base', $this->server->getBaseGuid()); + } + + public function testMethodConnectguidHasStringParameterGuid() + { + $this->server->connectGuid('guid', ''); + } + + public function testMethodConnectguidHasStringParameterPass() + { + $this->server->connectGuid('', 'pass'); + } + + public function testMethodConnectguidHasPostconditionThatTheGuidIsSetIfTheConnectionWasSuccessful() + { + $this->ldap_read->expects($this->exactly(1)) + ->method('bind') + ->will($this->returnValue(true)); + $this->server->connectGuid('test', 'test'); + $this->assertEquals('test', $this->server->getGuid()); + } + + public function testMethodConnectguidDoesNotCallBindAgainIfAlreadyConnectedWithThisGuid() + { + $this->ldap_read->expects($this->exactly(1)) + ->method('bind') + ->will($this->returnValue(true)); + $this->server->connectGuid('test', 'test'); + $this->server->connectGuid('test', 'test'); + } + + public function testMethodConnectguidDoesNotCallBindAgainIfAlreadyConnectedWithThisGuidEvenIfTheGuidIsEmpty() + { + $this->ldap_read->expects($this->exactly(1)) + ->method('bind') + ->will($this->returnValue(true)); + $this->server->connectGuid('', ''); + $this->server->connectGuid('', ''); + } + + public function testMethodConnectguidThrowsExceptionIfTheConnectionFailed() + { + $this->ldap_read->expects($this->exactly(1)) + ->method('bind') + ->will($this->returnValue(new PEAR_Error('Bind failed!'))); + try { + $this->server->connectGuid('test', 'test'); + $this->fail('No exception!'); + } catch (Exception $e) { + $this->assertEquals('Bind failed!', $e->getMessage()); + $this->assertEquals(Horde_Kolab_Server_Exception::BIND_FAILED, $e->getCode()); + } + } + + public function testMethodGetguidHasResultBooleanFalseIfNotConnected() + { + $this->assertSame(false, $this->server->getGuid()); + } + + public function testMethodGetguidHasResultStringGuidIfNotConnected() + { + $this->server->connectGuid('guid', ''); + $this->assertEquals('guid', $this->server->getGuid()); + } + + public function testMethodReadHasParameterStringGuid() + { + $this->ldap_read->expects($this->exactly(1)) + ->method('search') + ->with('test', null, array('scope' => 'base')) + ->will($this->returnValue($this->getSearchResultMock())); + $this->server->read('test'); + } + + public function testMethodReadReturnsArrayReadResult() + { + $this->ldap_read->expects($this->exactly(1)) + ->method('search') + ->with('test', null, array('scope' => 'base')) + ->will($this->returnValue($this->getSearchResultMock())); + $this->assertEquals(array('dn' => 'test'), $this->server->read('test')); + } + + public function testMethodReadThrowsExceptionIfTheObjectWasNotFound() + { + $result = $this->getMock( + 'Net_LDAP2_Search', array('as_struct', 'count'), array(), '', false + ); + $result->expects($this->exactly(1)) + ->method('count') + ->will($this->returnValue(0)); + $this->ldap_read->expects($this->exactly(1)) + ->method('search') + ->will($this->returnValue($result)); + try { + $this->assertEquals(array(), $this->server->read('test')); + $this->fail('No exception!'); + } catch (Exception $e) { + $this->assertEquals('Empty result!', $e->getMessage()); + $this->assertEquals(Horde_Kolab_Server_Exception::EMPTY_RESULT, $e->getCode()); + } + } + + public function testMethodReadAttributesHasParameterStringGuid() + { + $this->ldap_read->expects($this->exactly(1)) + ->method('search') + ->with('guid', null, array('scope' => 'base', 'attributes' => array())) + ->will($this->returnValue($this->getSearchResultMock())); + $this->server->readAttributes('guid', array()); + } + + public function testMethodReadAttributesHasParameterArrayAttributes() + { + $this->ldap_read->expects($this->exactly(1)) + ->method('search') + ->with('', null, array('scope' => 'base', 'attributes' => array('a'))) + ->will($this->returnValue($this->getSearchResultMock())); + $this->server->readAttributes('', array('a')); + } + + public function testMethodReadAttributesReturnsArrayReadResult() + { + $this->ldap_read->expects($this->exactly(1)) + ->method('search') + ->with('test', null, array('scope' => 'base', 'attributes' => array('a'))) + ->will($this->returnValue($this->getSearchResultMock())); + $this->assertEquals(array('dn' => 'test'), $this->server->readAttributes('test', array('a'))); + } + + public function testMethodReadAttributesThrowsExceptionIfTheObjectWasNotFound() + { + $result = $this->getMock( + 'Net_LDAP2_Search', array('as_struct', 'count'), array(), '', false + ); + $result->expects($this->exactly(1)) + ->method('count') + ->will($this->returnValue(0)); + $this->ldap_read->expects($this->exactly(1)) + ->method('search') + ->with('test', null, array('scope' => 'base', 'attributes' => array('a'))) + ->will($this->returnValue($result)); + try { + $this->assertEquals(array(), $this->server->readAttributes('test', array('a'))); + $this->fail('No exception!'); + } catch (Exception $e) { + $this->assertEquals('Empty result!', $e->getMessage()); + $this->assertEquals(Horde_Kolab_Server_Exception::EMPTY_RESULT, $e->getCode()); + } + } + + public function testMethodFindHasParameterQueryelementTheSearchCriteria() + { + $this->ldap_read->expects($this->exactly(1)) + ->method('search') + ->with('base', '(equals=equals)', array()) + ->will($this->returnValue($this->getSearchResultMock())); + $this->server->find('(equals=equals)'); + } + + public function testMethodFindHasParameterArrayAdditionalParameters() + { + $this->ldap_read->expects($this->exactly(1)) + ->method('search') + ->with('base', '(equals=equals)', array()) + ->will($this->returnValue($this->getSearchResultMock())); + $this->server->find('(equals=equals)', array()); + } + + public function testMethodFindReturnsArraySearchResult() + { + $this->ldap_read->expects($this->exactly(1)) + ->method('search') + ->with('base', '(equals=equals)', array()) + ->will($this->returnValue($this->getSearchResultMock())); + $this->assertEquals( + array(array('dn' => 'test')), + $this->server->find('(equals=equals)')->asArray() + ); + } + + public function testMethodFindThrowsExceptionIfTheSearchFailed() + { + $this->ldap_read->expects($this->exactly(1)) + ->method('search') + ->will($this->returnValue(new PEAR_Error('Search failed!'))); + try { + $this->assertEquals(array('dn' => 'test'), $this->server->find('(equals=equals)')); + $this->fail('No exception!'); + } catch (Exception $e) { + $this->assertEquals('Search failed!', $e->getMessage()); + $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); + } + } + + public function testMethodSaveHasParameterObjectTheObjectToModifyOnTheServer() + { + $entry = $this->getMock( + 'Net_LDAP2_Entry', array(), array(), '', false + ); + $object = $this->getMock( + 'Horde_Kolab_Server_Object', array(), array(), '', false + ); + $this->ldap_write->expects($this->exactly(1)) + ->method('getEntry') + ->will($this->returnValue($entry)); + $this->ldap_write->expects($this->exactly(1)) + ->method('modify') + ->with(new PHPUnit_Framework_Constraint_IsInstanceOf('Net_LDAP2_Entry')); + $object->expects($this->exactly(1)) + ->method('readInternal') + ->will($this->returnValue(array())); + $this->server->save($object, array('attributes' => array('dn'))); + } + + public function testMethodSaveHasParameterArrayData() + { + $entry = $this->getMock( + 'Net_LDAP2_Entry', array(), array(), '', false + ); + $object = $this->getMock( + 'Horde_Kolab_Server_Object', array(), array(), '', false + ); + $this->ldap_write->expects($this->exactly(1)) + ->method('getEntry') + ->will($this->returnValue($entry)); + $this->ldap_write->expects($this->exactly(1)) + ->method('modify') + ->with(new PHPUnit_Framework_Constraint_IsInstanceOf('Net_LDAP2_Entry')); + $object->expects($this->exactly(1)) + ->method('readInternal') + ->will($this->returnValue(array())); + $this->server->save($object, array('dn' => 'test')); + } + + public function testMethodSaveHasPostconditionThatTheEntryWasModified() + { + $entry = $this->getMock( + 'Net_LDAP2_Entry', array(), array(), '', false + ); + $object = $this->getMock( + 'Horde_Kolab_Server_Object', array(), array(), '', false + ); + $this->ldap_write->expects($this->exactly(1)) + ->method('getEntry') + ->will($this->returnValue($entry)); + $this->ldap_write->expects($this->exactly(1)) + ->method('modify') + ->with(new PHPUnit_Framework_Constraint_IsInstanceOf('Net_LDAP2_Entry')); + $object->expects($this->exactly(1)) + ->method('readInternal') + ->will($this->returnValue(array())); + $this->server->save($object, array('dn' => 'test')); + } + + public function testMethodSaveThrowsExceptionIfSavingDataFailed() + { + $object = $this->getMock( + 'Horde_Kolab_Server_Object', array(), array(), '', false + ); + $this->ldap_write->expects($this->exactly(1)) + ->method('modify') + ->will($this->returnValue(new PEAR_Error('Saving failed!'))); + $object->expects($this->exactly(1)) + ->method('readInternal') + ->will($this->returnValue(array())); + try { + $this->server->save($object, array('dn' => 'test')); + $this->fail('No exception!'); + } catch (Exception $e) { + $this->assertEquals('Saving failed!', $e->getMessage()); + $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); + } + } + + public function testMethodAddHasParameterObjectTheObjectToAddToTheServer() + { + $object = $this->getMock( + 'Horde_Kolab_Server_Object', array(), array(), '', false + ); + $this->ldap_write->expects($this->exactly(1)) + ->method('add') + ->with(new PHPUnit_Framework_Constraint_IsInstanceOf('Net_LDAP2_Entry')); + $this->server->add($object, array('attributes' => array('dn'))); + } + + public function testMethodAddHasParameterArrayData() + { + $object = $this->getMock( + 'Horde_Kolab_Server_Object', array(), array(), '', false + ); + $this->ldap_write->expects($this->exactly(1)) + ->method('add') + ->with(new PHPUnit_Framework_Constraint_IsInstanceOf('Net_LDAP2_Entry')); + $this->server->add($object, array('dn' => 'test')); + } + + public function testMethodAddHasPostconditionThatTheEntryWasModified() + { + $object = $this->getMock( + 'Horde_Kolab_Server_Object', array(), array(), '', false + ); + $this->ldap_write->expects($this->exactly(1)) + ->method('add') + ->with(new PHPUnit_Framework_Constraint_IsInstanceOf('Net_LDAP2_Entry')); + $this->server->add($object, array('dn' => 'test')); + } + + public function testMethodAddThrowsExceptionIfSavingDataFailed() + { + $object = $this->getMock( + 'Horde_Kolab_Server_Object', array(), array(), '', false + ); + $this->ldap_write->expects($this->exactly(1)) + ->method('add') + ->will($this->returnValue(new PEAR_Error('Saving failed!'))); + try { + $this->server->add($object, array('add' => array('dn' => 'test'))); + $this->fail('No exception!'); + } catch (Exception $e) { + $this->assertEquals('Saving failed!', $e->getMessage()); + $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); + } + } + + public function testMethodDeleteHasParameterStringGuid() + { + $this->ldap_write->expects($this->exactly(1)) + ->method('delete') + ->with('guid'); + $this->server->delete('guid'); + } + + public function testMethodDeleteHasPostconditionThatTheEntryWasDeleted() + { + $this->ldap_write->expects($this->exactly(1)) + ->method('delete') + ->with('test'); + $this->server->delete('test'); + } + + public function testMethodDeleteThrowsExceptionIfDeletingDataFailed() + { + $this->ldap_write->expects($this->exactly(1)) + ->method('delete') + ->will($this->returnValue(new PEAR_Error('Deleting failed!'))); + try { + $this->server->delete('test'); + $this->fail('No exception!'); + } catch (Exception $e) { + $this->assertEquals('Deleting failed!', $e->getMessage()); + $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); + } + } + + public function testMethodRenameHasParameterStringOldGuid() + { + $this->ldap_write->expects($this->exactly(1)) + ->method('move') + ->with('oldguid', ''); + $this->server->rename('oldguid', ''); + } + + public function testMethodRenameHasParameterStringNewGuid() + { + $this->ldap_write->expects($this->exactly(1)) + ->method('move') + ->with('', 'newguid'); + $this->server->rename('', 'newguid'); + } + + public function testMethodRenameHasPostconditionThatTheEntryWasRenamed() + { + $this->ldap_write->expects($this->exactly(1)) + ->method('move') + ->with('test', 'new'); + $this->server->rename('test', 'new'); + } + + public function testMethodRenameThrowsExceptionIfRenamingDataFailed() + { + $this->ldap_write->expects($this->exactly(1)) + ->method('move') + ->will($this->returnValue(new PEAR_Error('Renaming failed!'))); + try { + $this->server->rename('test', 'new'); + $this->fail('No exception!'); + } catch (Exception $e) { + $this->assertEquals('Renaming failed!', $e->getMessage()); + $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); + } + } + + public function testMethodGetschemaReturnsArrayWithADescriptionOfAllObjectClasses() + { + $this->ldap_read->expects($this->exactly(1)) + ->method('schema') + ->will($this->returnValue(array('schema' => 'dummy'))); + $this->assertEquals( + array('schema' => 'dummy'), + $this->server->getSchema() + ); + } + + public function testMethodGetschemaThrowsExceptionIfTheSchemaRetrievalFailed() + { + $this->ldap_read->expects($this->exactly(1)) + ->method('schema') + ->will($this->returnValue(new PEAR_Error('Schema failed!'))); + try { + $this->server->getSchema(); + $this->fail('No exception!'); + } catch (Exception $e) { + $this->assertEquals('Schema failed!', $e->getMessage()); + $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); + } + } + + public function testMethodGetparentguidHasResultStringParentGuid() + { + $this->assertEquals( + 'cn=parent', $this->server->getParentGuid('cn=child,cn=parent') + ); + } + +/* public function testMethodSearchReturnsArrayMappedSearchResultIfMappingIsActivated() */ +/* { */ +/* $ldap = $this->getMock('Net_LDAP2', array('search')); */ +/* $ldap->expects($this->exactly(1)) */ +/* ->method('search') */ +/* ->will($this->returnValue(new Search_Mock(array(array('dn2' => 'test'))))); */ +/* $this->server->setLdap($ldap); */ +/* $this->server->setParams(array('map' => array('dn' => 'dn2'))); */ +/* $this->assertEquals( */ +/* array(array('dn' => 'test')), */ +/* $this->server->search( */ +/* 'filter', */ +/* array('attributes' => array('dn')) */ +/* ) */ +/* ); */ +/* } */ + +} diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/LoggedTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/LoggedTest.php new file mode 100644 index 000000000..f094ee9cc --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/LoggedTest.php @@ -0,0 +1,228 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Prepare the test setup. + */ +require_once dirname(__FILE__) . '/../../Autoload.php'; + +/** + * Test the log decorator for the server. + * + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Class_Server_LoggedTest extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + parent::setUp(); + + $this->logger = $this->getMock('Horde_Log_Logger'); + $this->server = $this->getMock('Horde_Kolab_Server'); + $this->logged = new Horde_Kolab_Server_Logged( + $this->server, $this->logger + ); + } + + public function testMethodGetbaseguidHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $this->server->expects($this->exactly(1)) + ->method('getBaseGuid') + ->will($this->returnValue('base')); + $this->assertEquals('base', $this->logged->getBaseGuid()); + } + + public function testMethodGetuidHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $this->server->expects($this->exactly(1)) + ->method('getGuid') + ->will($this->returnValue('guid')); + $this->assertEquals('guid', $this->logged->getGuid()); + } + + public function testMethodConnectguidHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $this->server->expects($this->exactly(1)) + ->method('connectGuid') + ->with('user', 'pass'); + $this->logged->connectGuid('user', 'pass'); + } + + public function testMethodReadHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $this->server->expects($this->exactly(1)) + ->method('read') + ->with('guid') + ->will($this->returnValue(array())); + $this->assertEquals(array(), $this->logged->read('guid')); + } + + public function testMethodReadattributesHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $this->server->expects($this->exactly(1)) + ->method('readAttributes') + ->with('guid', array('a')) + ->will($this->returnValue(array())); + $this->assertEquals( + array(), $this->logged->readAttributes('guid', array('a')) + ); + } + + public function testMethodFindHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $result = $this->getMock('Horde_Kolab_Server_Result'); + $query = $this->getMock( + 'Horde_Kolab_Server_Query_Element', array(), array(), '', false + ); + $this->server->expects($this->exactly(1)) + ->method('find') + ->with($query) + ->will($this->returnValue($result)); + $this->assertType( + 'Horde_Kolab_Server_Result', + $this->logged->find($query) + ); + } + + public function testMethodFindbelowHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $result = $this->getMock('Horde_Kolab_Server_Result'); + $query = $this->getMock( + 'Horde_Kolab_Server_Query_Element', array(), array(), '', false + ); + $this->server->expects($this->exactly(1)) + ->method('findBelow') + ->with($query, 'none') + ->will($this->returnValue($result)); + $this->assertType( + 'Horde_Kolab_Server_Result', + $this->logged->findBelow($query, 'none') + ); + } + + public function testMethodSaveHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $object = $this->getMock( + 'Horde_Kolab_Server_Object', array(), array(), '', false + ); + $this->server->expects($this->exactly(1)) + ->method('save') + ->with($object, array('a' => 'a')); + $this->logged->save($object, array('a' => 'a')); + } + + public function testMethodAddHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $object = $this->getMock( + 'Horde_Kolab_Server_Object', array(), array(), '', false + ); + $this->server->expects($this->exactly(1)) + ->method('add') + ->with($object, array('a' => 'a')); + $this->logged->add($object, array('a' => 'a')); + } + + public function testMethodDeleteHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $this->server->expects($this->exactly(1)) + ->method('delete') + ->with('a'); + $this->logged->delete('a'); + } + + public function testMethodRenameHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $this->server->expects($this->exactly(1)) + ->method('rename') + ->with('a', 'b'); + $this->logged->rename('a', 'b'); + } + + public function testMethodGetschemaHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $this->server->expects($this->exactly(1)) + ->method('getSchema'); + $this->logged->getSchema(); + } + + public function testMethodSaveHasPostconditionThatTheEventWasLogged() + { + $object = $this->getMock( + 'Horde_Kolab_Server_Object', array(), array(), '', false + ); + $object->expects($this->once()) + ->method('getGuid') + ->will($this->returnValue('a')); + $this->logger->expects($this->once()) + ->method('__call') + ->with( + 'info', array('The object "a" has been successfully saved!') + ); + $this->logged->save($object, array('a' => 'a')); + } + + public function testMethodAddHasPostconditionThatTheEventWasLogged() + { + $object = $this->getMock( + 'Horde_Kolab_Server_Object', array(), array(), '', false + ); + $object->expects($this->once()) + ->method('getGuid') + ->will($this->returnValue('a')); + $this->logger->expects($this->once()) + ->method('__call') + ->with( + 'info', array('The object "a" has been successfully added!') + ); + $this->logged->add($object, array('a' => 'a')); + } + + public function testMethodDeleteHasPostconditionThatTheEventWasLogged() + { + $this->logger->expects($this->once()) + ->method('__call') + ->with( + 'info', array('The object "a" has been successfully deleted!') + ); + $this->logged->delete('a'); + } + + public function testMethodRenameHasPostconditionThatTheEventWasLogged() + { + $this->logger->expects($this->once()) + ->method('__call') + ->with( + 'info', + array('The object "a" has been successfully renamed to "b"!') + ); + $this->logged->rename('a', 'b'); + } + + public function testMethodGetparentguidHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $this->server->expects($this->exactly(1)) + ->method('getParentGuid') + ->will($this->returnValue('parent')); + $this->assertEquals('parent', $this->logged->getParentGuid('child')); + } + +} \ No newline at end of file diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Result/LdapTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Result/LdapTest.php new file mode 100644 index 000000000..bfd508720 --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Result/LdapTest.php @@ -0,0 +1,79 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Require our basic test case definition + */ +require_once dirname(__FILE__) . '/../../../LdapTestCase.php'; + +/** + * Test the LDAP result handler. + * + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Class_Server_Result_LdapTest extends Horde_Kolab_Server_LdapTestCase +{ + public function testMethodConstructHasParameterNetldap2searchSearchResult() + { + $search = $this->getMock( + 'Net_LDAP2_Search', array(), array(), '', false + ); + $result = new Horde_Kolab_Server_Result_Ldap($search); + } + + + public function testMethodCountHasResultIntTheNumberOfElementsFound() + { + $search = $this->getMock( + 'Net_LDAP2_Search', array('count'), array(), '', false + ); + $search->expects($this->exactly(1)) + ->method('count') + ->will($this->returnValue(1)); + $result = new Horde_Kolab_Server_Result_Ldap($search); + $this->assertEquals(1, $result->count()); + } + + public function testMethodSizelimitexceededHasResultBooleanIndicatingIfTheSearchSizeLimitWasHit() + { + $search = $this->getMock( + 'Net_LDAP2_Search', array('sizeLimitExceeded'), array(), '', false + ); + $search->expects($this->exactly(1)) + ->method('sizeLimitExceeded') + ->will($this->returnValue(true)); + $result = new Horde_Kolab_Server_Result_Ldap($search); + $this->assertTrue($result->sizeLimitExceeded()); + } + + public function testMethodAsarrayHasResultArrayWithTheSearchResults() + { + $search = $this->getMock( + 'Net_LDAP2_Search', array('as_struct'), array(), '', false + ); + $search->expects($this->exactly(1)) + ->method('as_struct') + ->will($this->returnValue(array('a' => 'a'))); + $result = new Horde_Kolab_Server_Result_Ldap($search); + $this->assertEquals(array('a' => 'a'), $result->asArray()); + } +} diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/BaseTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/BaseTest.php index 5a6ca1c63..18c7bb12e 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/BaseTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/BaseTest.php @@ -48,16 +48,19 @@ extends Horde_Kolab_Server_TestCase $composite = $this->getMockedComposite(); $composite->structure->expects($this->once()) ->method('getSupportedObjects') - ->will($this->returnValue(array('Object_Search'))); + ->will($this->returnValue(array('Object_Dummy'))); $search = new Horde_Kolab_Server_Search_Base(); $search->setComposite($composite); $this->assertEquals( - array('call' => array('class' => 'Object_Search')), + array( + 'call' => array('class' => 'Object_Search'), + 'reset' => array('class' => 'Object_Search') + ), $search->getSearchOperations() ); } - public function testSetcompositeThrowsExceptionIfADeclaredSearchOperationDoesNotExist() + public function testSetcompositeThrowsExceptionIfADeclaredSearchClassDoesNotExist() { $composite = $this->getMockedComposite(); $composite->structure->expects($this->once()) @@ -67,8 +70,8 @@ extends Horde_Kolab_Server_TestCase try { $search->setComposite($composite); } catch (Horde_Kolab_Server_Exception $e) { - $this->assertContains( - 'Class "Object_Search_Fail" does not support method "call"!', + $this->assertEquals( + 'Object_Search_Fail::getSearchOperations specified non-existing class "Does_Not_Exist"!', $e->getMessage() ); } @@ -84,7 +87,7 @@ extends Horde_Kolab_Server_TestCase $composite = $this->getMockedComposite(); $composite->structure->expects($this->once()) ->method('getSupportedObjects') - ->will($this->returnValue(array('Object_Search'))); + ->will($this->returnValue(array('Object_Dummy'))); $search = new Horde_Kolab_Server_Search_Base(); $search->setComposite($composite); $this->assertEquals(1, $search->call()); @@ -95,12 +98,11 @@ extends Horde_Kolab_Server_TestCase $composite = $this->getMockedComposite(); $composite->structure->expects($this->once()) ->method('getSupportedObjects') - ->will($this->returnValue(array('Object_Search'))); + ->will($this->returnValue(array('Object_Dummy'))); $search = new Horde_Kolab_Server_Search_Base(); $search->setComposite($composite); - $search->call(); - $call = Object_Search::$last_call; - $this->assertType('Horde_Kolab_Server_Composite', $call[0]); + $search->call('a'); + $this->assertEquals(array('a'), Object_Search::$last_call); } public function testCallThrowsExceptionIfTheSearchOperationIsNotSupported() @@ -108,7 +110,7 @@ extends Horde_Kolab_Server_TestCase $composite = $this->getMockedComposite(); $composite->structure->expects($this->once()) ->method('getSupportedObjects') - ->will($this->returnValue(array('Object_Search'))); + ->will($this->returnValue(array('Object_Dummy'))); $search = new Horde_Kolab_Server_Search_Base(); $search->setComposite($composite); try { @@ -128,17 +130,20 @@ extends Horde_Kolab_Server_TestCase } } +class Object_Dummy +{ + static public function getSearchOperations() + { + return array('Object_Search'); + } +} + class Object_Search { static public $calls = 0; static public $last_call; - static public function getSearchOperations() - { - return array('call'); - } - static public function call() { self::$last_call = func_get_args(); @@ -155,6 +160,6 @@ class Object_Search_Fail { static public function getSearchOperations() { - return array('call'); + return array('Does_Not_Exist'); } } diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Structure/KolabTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Structure/KolabTest.php new file mode 100644 index 000000000..c30b1c9d8 --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Structure/KolabTest.php @@ -0,0 +1,347 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Require our basic test case definition + */ +require_once dirname(__FILE__) . '/../../../Autoload.php'; + +/** + * Test the LDAP backend. + * + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Class_Server_Structure_KolabTest extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + $server = $this->getMock('Horde_Kolab_Server'); + $this->composite = new Horde_Kolab_Server_Composite( + $server, + $this->getMock('Horde_Kolab_Server_Objects'), + new Horde_Kolab_Server_Structure_Kolab(), + $this->getMock('Horde_Kolab_Server_Search'), + $this->getMock('Horde_Kolab_Server_Schema') + ); + } + + public function testMethodGetsupportedobjectsHasResultArrayTheObjectTypesSupportedByThisStructure() + { + $this->assertType('array', $this->composite->structure->getSupportedObjects()); + } + + public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid1() + { + $this->composite->server->expects($this->exactly(1)) + ->method('read') + ->with('guid') + ->will($this->returnValue(array('objectClass' => array('kolabGroupOfNames')))); + $this->assertEquals('Horde_Kolab_Server_Object_Kolabgroupofnames', $this->composite->structure->determineType('guid')); + } + + public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid2() + { + $this->composite->server->expects($this->exactly(1)) + ->method('read') + ->with('guid') + ->will($this->returnValue(array('objectClass' => array('kolabExternalPop3Account')))); + $this->assertEquals('Horde_Kolab_Server_Object_Kolabpop3account', $this->composite->structure->determineType('guid')); + } + + public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid3() + { + $this->composite->server->expects($this->exactly(1)) + ->method('read') + ->with('guid') + ->will($this->returnValue(array('objectClass' => array('kolabSharedFolder')))); + $this->assertEquals('Horde_Kolab_Server_Object_Kolabsharedfolder', $this->composite->structure->determineType('guid')); + } + + public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid4() + { + $this->composite->server->expects($this->exactly(1)) + ->method('read') + ->with('guid') + ->will($this->returnValue(array('objectClass' => array('top')))); + $this->assertEquals('Horde_Kolab_Server_Object_Top', $this->composite->structure->determineType('guid')); + } + + public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid5() + { + $this->composite->server->expects($this->exactly(1)) + ->method('read') + ->with('guid') + ->will( + $this->returnValue( + array( + 'objectClass' => + array( + 'kolabinetorgperson', + ) + ) + ) + ); + $this->composite->search->expects($this->exactly(1)) + ->method('__call') + ->with('getGroups', array('guid')) + ->will( + $this->returnValue( + array( + ) + ) + ); + $this->assertEquals( + 'Horde_Kolab_Server_Object_Kolab_User', + $this->composite->structure->determineType('guid') + ); + } + + public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid6() + { + $this->composite->server->expects($this->exactly(1)) + ->method('read') + ->with('guid') + ->will( + $this->returnValue( + array( + 'objectClass' => + array( + 'kolabinetorgperson', + ) + ) + ) + ); + $this->composite->server->expects($this->exactly(1)) + ->method('getBaseGuid') + ->will($this->returnValue('base')); + $this->composite->search->expects($this->exactly(1)) + ->method('__call') + ->with('getGroups', array('guid')) + ->will( + $this->returnValue( + array( + 'cn=admin,cn=internal,base' + ) + ) + ); + $this->assertEquals( + 'Horde_Kolab_Server_Object_Kolab_Administrator', + $this->composite->structure->determineType('guid') + ); + } + + public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid7() + { + $this->composite->server->expects($this->exactly(1)) + ->method('read') + ->with('guid') + ->will( + $this->returnValue( + array( + 'objectClass' => + array( + 'kolabinetorgperson', + ) + ) + ) + ); + $this->composite->server->expects($this->exactly(1)) + ->method('getBaseGuid') + ->will($this->returnValue('base')); + $this->composite->search->expects($this->exactly(1)) + ->method('__call') + ->with('getGroups', array('guid')) + ->will( + $this->returnValue( + array( + 'cn=maintainer,cn=internal,base' + ) + ) + ); + $this->assertEquals( + 'Horde_Kolab_Server_Object_Kolab_Maintainer', + $this->composite->structure->determineType('guid') + ); + } + + public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid8() + { + $this->composite->server->expects($this->exactly(1)) + ->method('read') + ->with('guid') + ->will( + $this->returnValue( + array( + 'objectClass' => + array( + 'kolabinetorgperson', + ) + ) + ) + ); + $this->composite->server->expects($this->exactly(1)) + ->method('getBaseGuid') + ->will($this->returnValue('base')); + $this->composite->search->expects($this->exactly(1)) + ->method('__call') + ->with('getGroups', array('guid')) + ->will( + $this->returnValue( + array( + 'cn=domain-maintainer,cn=internal,base' + ) + ) + ); + $this->assertEquals( + 'Horde_Kolab_Server_Object_Kolab_Domainmaintainer', + $this->composite->structure->determineType('guid') + ); + } + + public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid9() + { + $this->composite->server->expects($this->exactly(1)) + ->method('read') + ->with('guid,cn=external') + ->will( + $this->returnValue( + array( + 'objectClass' => + array( + 'kolabinetorgperson', + ) + ) + ) + ); + $this->composite->search->expects($this->exactly(1)) + ->method('__call') + ->with('getGroups', array('guid,cn=external')) + ->will( + $this->returnValue( + array( + 'unknown' + ) + ) + ); + $this->assertEquals( + 'Horde_Kolab_Server_Object_Kolab_Address', + $this->composite->structure->determineType('guid,cn=external') + ); + } + + public function testMethodGenerateserverguidHasResultStringTheGuid1() + { + $this->composite->server->expects($this->exactly(1)) + ->method('getBaseGuid') + ->will($this->returnValue('base')); + $this->assertEquals('id,base', $this->composite->structure->generateServerGuid('Horde_Kolab_Server_Object_Kolabgroupofnames', 'id', array())); + } + + public function testMethodGenerateserverguidHasResultStringTheGuid2() + { + $this->composite->server->expects($this->exactly(1)) + ->method('getBaseGuid') + ->will($this->returnValue('base')); + $this->assertEquals('id,cn=internal,base', $this->composite->structure->generateServerGuid('Horde_Kolab_Server_Object_Kolabgroupofnames', 'id', array('visible' => false))); + } + + public function testMethodGenerateserverguidHasResultStringTheGuid3() + { + $this->composite->server->expects($this->exactly(1)) + ->method('getBaseGuid') + ->will($this->returnValue('base')); + $this->assertEquals('id,base', $this->composite->structure->generateServerGuid('Horde_Kolab_Server_Object_Kolabsharedfolder', 'id', array('visible' => false))); + } + + public function testMethodGenerateserverguidHasResultStringTheGuid4() + { + $this->composite->server->expects($this->exactly(1)) + ->method('getBaseGuid') + ->will($this->returnValue('base')); + $this->assertEquals('id,cn=external,base', $this->composite->structure->generateServerGuid('Horde_Kolab_Server_Object_Kolab_Address', 'id', array())); + } + + public function testMethodGenerateserverguidHasResultStringTheGuid5() + { + $this->composite->server->expects($this->exactly(1)) + ->method('getBaseGuid') + ->will($this->returnValue('base')); + $this->assertEquals( + 'id,cn=internal,base', + $this->composite->structure->generateServerGuid( + 'Horde_Kolab_Server_Object_Kolab_User', 'id', + array('user_type' => Horde_Kolab_Server_Object_Kolab_User::USERTYPE_INTERNAL) + ) + ); + } + + public function testMethodGenerateserverguidHasResultStringTheGuid6() + { + $this->composite->server->expects($this->exactly(1)) + ->method('getBaseGuid') + ->will($this->returnValue('base')); + $this->assertEquals( + 'id,cn=groups,base', + $this->composite->structure->generateServerGuid( + 'Horde_Kolab_Server_Object_Kolab_User', 'id', + array('user_type' => Horde_Kolab_Server_Object_Kolab_User::USERTYPE_GROUP) + ) + ); + } + + public function testMethodGenerateserverguidHasResultStringTheGuid7() + { + $this->composite->server->expects($this->exactly(1)) + ->method('getBaseGuid') + ->will($this->returnValue('base')); + $this->assertEquals( + 'id,cn=resources,base', + $this->composite->structure->generateServerGuid( + 'Horde_Kolab_Server_Object_Kolab_User', 'id', + array('user_type' => Horde_Kolab_Server_Object_Kolab_User::USERTYPE_RESOURCE) + ) + ); + } + + public function testMethodGenerateserverguidHasResultStringTheGuid8() + { + $this->composite->server->expects($this->exactly(1)) + ->method('getBaseGuid') + ->will($this->returnValue('base')); + $this->assertEquals('id,base', $this->composite->structure->generateServerGuid('Horde_Kolab_Server_Object_Kolab_User', 'id', array())); + } + + public function testMethodGenerateserverguidHasResultStringTheGuid9() + { + $this->composite->server->expects($this->exactly(1)) + ->method('getBaseGuid') + ->will($this->returnValue('base')); + $this->assertEquals( + 'id,base', + $this->composite->structure->generateServerGuid( + 'Horde_Kolab_Server_Object_Kolab_User', 'id', + array('user_type' => 'undefined') + ) + ); + } + +} diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Structure/LdapTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Structure/LdapTest.php new file mode 100644 index 000000000..96725b5d6 --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Structure/LdapTest.php @@ -0,0 +1,180 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Require our basic test case definition + */ +require_once dirname(__FILE__) . '/../../../Autoload.php'; + +/** + * Test the LDAP backend. + * + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Class_Server_Structure_LdapTest extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + $server = $this->getMock('Horde_Kolab_Server'); + $this->composite = new Horde_Kolab_Server_Composite( + $server, + $this->getMock('Horde_Kolab_Server_Objects'), + new Horde_Kolab_Server_Structure_Ldap(), + $this->getMock('Horde_Kolab_Server_Search'), + $this->getMock('Horde_Kolab_Server_Schema') + ); + } + + public function testMethodFindHasResultServerResultTheSearchResult() + { + $result = $this->getMock('Horde_Kolab_Server_Result'); + $this->composite->server->expects($this->exactly(1)) + ->method('find') + ->with('(objectClass=equals)', array()) + ->will($this->returnValue($result)); + $equals = new Horde_Kolab_Server_Query_Element_Equals('Objectclass', 'equals'); + $this->assertType( + 'Horde_Kolab_Server_Result', + $this->composite->structure->find($equals, array()) + ); + } + + public function testMethodFindBelowHasResultServerResultTheSearchResult() + { + $result = $this->getMock('Horde_Kolab_Server_Result'); + $this->composite->server->expects($this->exactly(1)) + ->method('findBelow') + ->with('(objectClass=equals)', 'base', array()) + ->will($this->returnValue($result)); + $equals = new Horde_Kolab_Server_Query_Element_Equals('Objectclass', 'equals'); + $this->assertType( + 'Horde_Kolab_Server_Result', + $this->composite->structure->findBelow($equals, 'base', array()) + ); + } + + public function testMethodGetsupportedobjectsHasResultArrayTheObjectTypesSupportedByThisStructure() + { + $this->assertEquals(array('Horde_Kolab_Server_Object'), $this->composite->structure->getSupportedObjects()); + } + + public function testMethodDeterminetypeHasParameterStringGuid() + { + $this->composite->server->expects($this->exactly(1)) + ->method('read') + ->with('guid') + ->will($this->returnValue(array('objectClass' => array('TOP')))); + $this->composite->structure->determineType('guid'); + } + + public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid() + { + $this->composite->server->expects($this->exactly(1)) + ->method('read') + ->with('guid') + ->will($this->returnValue(array('objectClass' => array('TOP')))); + $this->assertEquals('Horde_Kolab_Server_Object_Top', $this->composite->structure->determineType('guid')); + } + + public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid2() + { + $this->composite->server->expects($this->exactly(1)) + ->method('read') + ->with('guid') + ->will($this->returnValue(array('objectClass' => array('person')))); + $this->assertEquals('Horde_Kolab_Server_Object_Person', $this->composite->structure->determineType('guid')); + } + + public function testMethodDeterminetypeThrowsExceptionIfTheGuidHasNoAttributeObjectclass() + { + $this->composite->server->expects($this->exactly(1)) + ->method('read') + ->with('guid') + ->will($this->returnValue(array())); + try { + $this->composite->structure->determineType('guid'); + } catch (Exception $e) { + $this->assertEquals('The object guid has no objectClass attribute!', $e->getMessage()); + $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); + } + } + + public function testMethodDeterminetypeThrowsExceptionIfTheTypeIsUnknown() + { + $this->composite->server->expects($this->exactly(1)) + ->method('read') + ->with('guid') + ->will($this->returnValue(array('objectClass' => array('UNKNOWN')))); + try { + $this->composite->structure->determineType('guid'); + } catch (Exception $e) { + $this->assertEquals('Unknown object type for GUID guid.', $e->getMessage()); + $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); + } + } + + public function testMethodGenerateserverguidHasParameterStringType() + { + $this->composite->server->expects($this->exactly(1)) + ->method('getBaseGuid') + ->will($this->returnValue('base')); + $this->composite->structure->generateServerGuid('type', '', array()); + } + + public function testMethodGenerateserverguidHasParameterStringId() + { + $this->composite->server->expects($this->exactly(1)) + ->method('getBaseGuid') + ->will($this->returnValue('base')); + $this->composite->structure->generateServerGuid('', 'id', array()); + } + + public function testMethodGenerateserverguidHasParameterArrayObjectData() + { + $this->composite->server->expects($this->exactly(1)) + ->method('getBaseGuid') + ->will($this->returnValue('base')); + $this->composite->structure->generateServerGuid('', '', array('object' => 'data')); + } + + public function testMethodGenerateserverguidHasResultStringTheGuid() + { + $this->composite->server->expects($this->exactly(1)) + ->method('getBaseGuid') + ->will($this->returnValue('base')); + $this->assertEquals('id,base', $this->composite->structure->generateServerGuid('', 'id', array())); + } + + public function testMethodGetinternalattributeThrowsExceptionForUndefinedAttributeName() + { + $structure = new Horde_Kolab_Server_Structure_Ldap(); + try { + $structure->getInternalAttribute('undefined'); + $this->fail('No exception!'); + } catch (Horde_Kolab_Server_Exception $e) { + $this->assertEquals( + 'Undefined internal attribute "undefined"', + $e->getMessage() + ); + } + } +} diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/MockTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/MockTest.php index 6801ca533..64cd092ed 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/MockTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/MockTest.php @@ -14,7 +14,7 @@ /** * Require our basic test case definition */ -require_once dirname(__FILE__) . '/../LdapBase.php'; +require_once dirname(__FILE__) . '/../LdapTestCase.php'; /** * Test the test backend. @@ -30,7 +30,8 @@ require_once dirname(__FILE__) . '/../LdapBase.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Connection_MockTest extends Horde_Kolab_Server_LdapBase +class Horde_Kolab_Server_Connection_MockTest +extends Horde_Kolab_Server_LdapTestCase { /** diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/SimpleldapTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/SimpleldapTest.php index cff61dc29..c2d5f08ea 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/SimpleldapTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/SimpleldapTest.php @@ -12,14 +12,14 @@ */ /** - * Prepare the test setup. + * Require our basic test case definition */ -require_once dirname(__FILE__) . '/../Autoload.php'; +require_once dirname(__FILE__) . '/../LdapTestCase.php'; /** * Test the handler for a simple LDAP setup without read-only slaves. * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * Copyright 2009 The Horde Project (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. @@ -30,19 +30,9 @@ require_once dirname(__FILE__) . '/../Autoload.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Connection_SimpleldapTest extends PHPUnit_Framework_TestCase +class Horde_Kolab_Server_Connection_SimpleldapTest +extends Horde_Kolab_Server_LdapTestCase { - public function setUp() - { - if (!extension_loaded('ldap') && !@dl('ldap.' . PHP_SHLIB_SUFFIX)) { - $this->markTestSuiteSkipped('Ldap extension is missing!'); - }; - - if (!class_exists('Net_LDAP2')) { - $this->markTestSuiteSkipped('PEAR package Net_LDAP2 is not installed!'); - } - } - public function testMethodConstructHasParameterNetldap2Connection() { $ldap = $this->getMock('Net_LDAP2'); diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/SplittedldapTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/SplittedldapTest.php index e38d02456..1594b0f3b 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/SplittedldapTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/SplittedldapTest.php @@ -12,14 +12,14 @@ */ /** - * Prepare the test setup. + * Require our basic test case definition */ -require_once dirname(__FILE__) . '/../Autoload.php'; +require_once dirname(__FILE__) . '/../LdapTestCase.php'; /** * Test the handler for a LDAP master/slave setup. * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * Copyright 2009 The Horde Project (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. @@ -30,19 +30,9 @@ require_once dirname(__FILE__) . '/../Autoload.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Connection_SplittedldapTest extends PHPUnit_Framework_TestCase +class Horde_Kolab_Server_Connection_SplittedldapTest +extends Horde_Kolab_Server_LdapTestCase { - public function setUp() - { - if (!extension_loaded('ldap') && !@dl('ldap.' . PHP_SHLIB_SUFFIX)) { - $this->markTestSuiteSkipped('Ldap extension is missing!'); - }; - - if (!class_exists('Net_LDAP2')) { - $this->markTestSuiteSkipped('PEAR package Net_LDAP2 is not installed!'); - } - } - public function testMethodConstructHasParameterNetldap2ReadConnectionAndParameterNetldap2WriteConnection() { $ldap_read = $this->getMock('Net_LDAP2'); diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/SearchTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/SearchTest.php new file mode 100644 index 000000000..914dac193 --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/SearchTest.php @@ -0,0 +1,219 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Require our basic test case definition + */ +require_once dirname(__FILE__) . '/../LdapTestCase.php'; + +/** + * Test the search handler. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Integration_SearchTest +extends Horde_Kolab_Server_LdapTestCase +{ + public function setUp() + { + +/* $injector = new Horde_Injector(new Horde_Injector_TopLevel()); */ +/* Horde_Kolab_Server_Factory::setup(array(), $injector); */ +/* $this->server = $injector->getInstance('Horde_Kolab_Server'); */ + } + + public function testNothing() + { + } + + /** + * Test retrieving a primary mail for a mail or uid. + * + * @return NULL + */ +/* public function testMailForUidOrMail() */ +/* { */ +/* $ldap = $this->getMock('Horde_Kolab_Server_ldap', array('getAttributes', */ +/* 'search', 'count', */ +/* 'firstEntry')); */ +/* $ldap->expects($this->any()) */ +/* ->method('_getAttributes') */ +/* ->will($this->returnValue(array ( */ +/* 'mail' => */ +/* array ( */ +/* 'count' => 1, */ +/* 0 => 'wrobel@example.org', */ +/* ), */ +/* 0 => 'mail', */ +/* 'count' => 1))); */ +/* $ldap->expects($this->any()) */ +/* ->method('_search') */ +/* ->will($this->returnValue('cn=Gunnar Wrobel,dc=example,dc=org')); */ +/* $ldap->expects($this->any()) */ +/* ->method('_count') */ +/* ->will($this->returnValue(1)); */ +/* $ldap->expects($this->any()) */ +/* ->method('_firstEntry') */ +/* ->will($this->returnValue(1)); */ + +/* $mail = $ldap->mailForIdOrMail('wrobel'); */ +/* $this->assertEquals('wrobel@example.org', $mail); */ + +/* $ldap = $this->getMock('Horde_Kolab_Server_ldap', array('_getAttributes', */ +/* '_search', */ +/* '_count', */ +/* '_firstEntry', */ +/* '_errno', */ +/* '_error')); */ +/* $ldap->expects($this->any()) */ +/* ->method('_getAttributes') */ +/* ->will($this->returnValue(false)); */ +/* $ldap->expects($this->any()) */ +/* ->method('_search') */ +/* ->will($this->returnValue('cn=Gunnar Wrobel,dc=example,dc=org')); */ +/* $ldap->expects($this->any()) */ +/* ->method('_count') */ +/* ->will($this->returnValue(1)); */ +/* $ldap->expects($this->any()) */ +/* ->method('_firstEntry') */ +/* ->will($this->returnValue(1)); */ +/* $ldap->expects($this->any()) */ +/* ->method('_errno') */ +/* ->will($this->returnValue(1)); */ +/* $ldap->expects($this->any()) */ +/* ->method('_error') */ +/* ->will($this->returnValue('cn=DOES NOT EXIST,dc=example,dc=org: No such object')); */ + +/* $mail = $ldap->mailForIdOrMail('wrobel'); */ +/* $this->assertEquals('Retrieving attributes failed. Error was: cn=DOES NOT EXIST,dc=example,dc=org: No such object', */ +/* $mail->message); */ + +/* $ldap = $this->getMock('Horde_Kolab_Server_ldap', array('_getAttributes', */ +/* '_search', */ +/* '_count')); */ +/* $ldap->expects($this->any()) */ +/* ->method('_getAttributes') */ +/* ->will($this->returnValue(false)); */ +/* $ldap->expects($this->any()) */ +/* ->method('_search') */ +/* ->will($this->returnValue('cn=Gunnar Wrobel,dc=example,dc=org')); */ +/* $ldap->expects($this->any()) */ +/* ->method('_count') */ +/* ->will($this->returnValue(4)); */ + +/* $mail = $ldap->mailForIdOrMail('wrobel'); */ +/* $this->assertEquals('Found 4 results when expecting only one!', */ +/* $mail->message); */ +/* } */ + +/* /\** */ +/* * Test retrieving a DN for a mail or uid. */ +/* * */ +/* * @return NULL */ +/* *\/ */ +/* public function testDnForUidOrMail() */ +/* { */ +/* $ldap = $this->getMock('Horde_Kolab_Server_ldap', array('_getDn', */ +/* '_search', '_count', */ +/* '_firstEntry')); */ +/* $ldap->expects($this->any()) */ +/* ->method('_getDn') */ +/* ->will($this->returnValue('cn=Gunnar Wrobel,dc=example,dc=org')); */ +/* $ldap->expects($this->any()) */ +/* ->method('_search') */ +/* ->will($this->returnValue('cn=Gunnar Wrobel,dc=example,dc=org')); */ +/* $ldap->expects($this->any()) */ +/* ->method('_count') */ +/* ->will($this->returnValue(1)); */ +/* $ldap->expects($this->any()) */ +/* ->method('_firstEntry') */ +/* ->will($this->returnValue(1)); */ + +/* $dn = $ldap->uidForIdOrMail('wrobel'); */ +/* $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $dn); */ + +/* $ldap = $this->getMock('Horde_Kolab_Server_ldap', array('_getDn', */ +/* '_search', */ +/* '_count', */ +/* '_firstEntry', */ +/* '_errno', */ +/* '_error')); */ +/* $ldap->expects($this->any()) */ +/* ->method('_getDn') */ +/* ->will($this->returnValue(false)); */ +/* $ldap->expects($this->any()) */ +/* ->method('_search') */ +/* ->will($this->returnValue('cn=Gunnar Wrobel,dc=example,dc=org')); */ +/* $ldap->expects($this->any()) */ +/* ->method('_count') */ +/* ->will($this->returnValue(1)); */ +/* $ldap->expects($this->any()) */ +/* ->method('_firstEntry') */ +/* ->will($this->returnValue(1)); */ +/* $ldap->expects($this->any()) */ +/* ->method('_errno') */ +/* ->will($this->returnValue(1)); */ +/* $ldap->expects($this->any()) */ +/* ->method('_error') */ +/* ->will($this->returnValue('cn=DOES NOT EXIST,dc=example,dc=org: No such object')); */ + +/* $dn = $ldap->uidForIdOrMail('wrobel'); */ +/* $this->assertEquals('Retrieving DN failed. Error was: cn=DOES NOT EXIST,dc=example,dc=org: No such object', */ +/* $dn->message); */ + +/* $ldap = $this->getMock('Horde_Kolab_Server_ldap', array('_getDn', */ +/* '_search', */ +/* '_count')); */ +/* $ldap->expects($this->any()) */ +/* ->method('_getDn') */ +/* ->will($this->returnValue(false)); */ +/* $ldap->expects($this->any()) */ +/* ->method('_search') */ +/* ->will($this->returnValue('cn=Gunnar Wrobel,dc=example,dc=org')); */ +/* $ldap->expects($this->any()) */ +/* ->method('_count') */ +/* ->will($this->returnValue(4)); */ + +/* $dn = $ldap->uidForIdOrMail('wrobel'); */ +/* $this->assertEquals('Found 4 results when expecting only one!', */ +/* $dn->message); */ +/* } */ + +} + + +class Search_Mock +{ + public function __construct($result, $limit = false) + { + $this->result = $result; + $this->limit = $limit; + } + public function as_struct() + { + return $this->result; + } + public function sizeLimitExceeded() + { + return $this->limit; + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/LdapBase.php b/framework/Kolab_Server/test/Horde/Kolab/Server/LdapBase.php deleted file mode 100644 index c7026d9f5..000000000 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/LdapBase.php +++ /dev/null @@ -1,52 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Prepare the test setup. - */ -require_once dirname(__FILE__) . '/Autoload.php'; - -/** - * Skip LDAP based tests if we don't have ldap or Net_LDAP2. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_LdapBase extends PHPUnit_Framework_TestCase -{ - public function setUp() - { - if (!extension_loaded('ldap') && !@dl('ldap.' . PHP_SHLIB_SUFFIX)) { - $this->markTestSuiteSkipped('Ldap extension is missing!'); - }; - - /** Hide strict errors from the Net_LDAP2 library */ - $error_reporting = error_reporting(); - error_reporting($error_reporting & ~E_STRICT); - - if (!class_exists('Net_LDAP2')) { - $this->markTestSuiteSkipped('PEAR package Net_LDAP2 is not installed!'); - } - - /** Reactivate original error reporting */ - error_reporting($error_reporting); - } -} \ No newline at end of file diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/LdapTestCase.php b/framework/Kolab_Server/test/Horde/Kolab/Server/LdapTestCase.php new file mode 100644 index 000000000..fb83bc07a --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/LdapTestCase.php @@ -0,0 +1,52 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Prepare the test setup. + */ +require_once dirname(__FILE__) . '/TestCase.php'; + +/** + * Skip LDAP based tests if we don't have ldap or Net_LDAP2. + * + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_LdapTestCase extends Horde_Kolab_Server_TestCase +{ + public function setUp() + { + if (!extension_loaded('ldap') && !@dl('ldap.' . PHP_SHLIB_SUFFIX)) { + $this->markTestSuiteSkipped('Ldap extension is missing!'); + }; + + /** Hide strict errors from the Net_LDAP2 library */ + $error_reporting = error_reporting(); + error_reporting($error_reporting & ~E_STRICT); + + if (!class_exists('Net_LDAP2')) { + $this->markTestSkipped('PEAR package Net_LDAP2 is not installed!'); + } + + /** Reactivate original error reporting */ + error_reporting($error_reporting); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Object/BaseTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Object/BaseTest.php index 5e233cbda..cb7878241 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Object/BaseTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Object/BaseTest.php @@ -14,7 +14,7 @@ /** * Prepare the test setup. */ -require_once dirname(__FILE__) . '/../Autoload.php'; +require_once dirname(__FILE__) . '/../TestCase.php'; /** * Test the base object. @@ -30,7 +30,7 @@ require_once dirname(__FILE__) . '/../Autoload.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Object_BaseTest extends PHPUnit_Framework_TestCase +class Horde_Kolab_Server_Object_BaseTest extends Horde_Kolab_Server_TestCase { public function setUp() { @@ -205,6 +205,10 @@ class Horde_Kolab_Server_Object_BaseTest extends PHPUnit_Framework_TestCase public function testGetexternalHasResultArrayTheDataOfTheRequestedAttribute() { $composite = $this->getMockedComposite(); + $composite->structure->expects($this->exactly(1)) + ->method('getInternalAttribute') + ->with('Objectclass') + ->will($this->returnValue('objectClass')); $composite->schema->expects($this->exactly(1)) ->method('getExternalAttributes') ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) @@ -290,6 +294,10 @@ class Horde_Kolab_Server_Object_BaseTest extends PHPUnit_Framework_TestCase public function testSaveHasPostconditionThatTheObjectWasAddedToTheServerIfItDidNotExistBefore() { $composite = $this->getMockedComposite(); + $composite->structure->expects($this->exactly(1)) + ->method('getInternalAttribute') + ->with('Objectclass') + ->will($this->returnValue('objectClass')); $composite->schema->expects($this->exactly(1)) ->method('getInternalAttributes') ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) @@ -320,34 +328,6 @@ class Horde_Kolab_Server_Object_BaseTest extends PHPUnit_Framework_TestCase $object = new Object_Mock($composite); $object->save(array('Objectclass' => 'top')); } - - private function getComposite() - { - return $this->getMock( - 'Horde_Kolab_Server_Composite', array(), array(), '', false - ); - } - - private function getMockedComposite() - { - return new Horde_Kolab_Server_Composite( - $this->getMock( - 'Horde_Kolab_Server', array(), array(), '', false - ), - $this->getMock( - 'Horde_Kolab_Server_Objects', array(), array(), '', false - ), - $this->getMock( - 'Horde_Kolab_Server_Structure', array(), array(), '', false - ), - $this->getMock( - 'Horde_Kolab_Server_Search', array(), array(), '', false - ), - $this->getMock( - 'Horde_Kolab_Server_Schema', array(), array(), '', false - ) - ); - } } class Object_Mock extends Horde_Kolab_Server_Object_Base diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Query/ElementTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Query/ElementTest.php index 4cedaf102..ad16e0354 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Query/ElementTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Query/ElementTest.php @@ -19,7 +19,7 @@ require_once dirname(__FILE__) . '/../Autoload.php'; /** * Test the LDAP query elements. * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * Copyright 2009 The Horde Project (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Query/LdapTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Query/LdapTest.php index 2f6eef172..b6e941b6b 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Query/LdapTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Query/LdapTest.php @@ -14,12 +14,12 @@ /** * Require our basic test case definition */ -require_once dirname(__FILE__) . '/../LdapBase.php'; +require_once dirname(__FILE__) . '/../LdapTestCase.php'; /** * Test the LDAP query handler. * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * Copyright 2009 The Horde Project (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. @@ -30,19 +30,28 @@ require_once dirname(__FILE__) . '/../LdapBase.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Query_LdapTest extends Horde_Kolab_Server_LdapBase +class Horde_Kolab_Server_Query_LdapTest extends Horde_Kolab_Server_LdapTestCase { + public function setUp() + { + parent::setUp(); + $this->structure = $this->getMock('Horde_Kolab_Server_Structure'); + } + public function testMethodConstructHasParameterQueryelementTheQueryCriteria() { $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $query = new Horde_Kolab_Server_Query_Ldap($equals); + $query = new Horde_Kolab_Server_Query_Ldap($equals, $this->structure); } public function testMethodConstructHasPostconditionThatTheQueryCriteriaWereSaved() { + $this->structure->expects($this->once()) + ->method('getInternalAttribute') + ->will($this->returnValue('equals')); $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $query = new Horde_Kolab_Server_Query_Ldap($equals); + $query = new Horde_Kolab_Server_Query_Ldap($equals, $this->structure); $this->assertEquals( '(equals=equals)', (string) $query @@ -51,20 +60,26 @@ class Horde_Kolab_Server_Query_LdapTest extends Horde_Kolab_Server_LdapBase public function testMethodTostringHasResultStringTheQuery() { + $this->structure->expects($this->exactly(2)) + ->method('getInternalAttribute') + ->will($this->returnValue('internal')); $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); $contains = new Horde_Kolab_Server_Query_Element_Equals('contains', 'contains'); $or = new Horde_Kolab_Server_Query_Element_Or(array($equals, $contains)); - $query = new Horde_Kolab_Server_Query_Ldap($or); + $query = new Horde_Kolab_Server_Query_Ldap($or, $this->structure); $this->assertEquals( - '(|(equals=equals)(contains=contains))', + '(|(internal=equals)(internal=contains))', (string) $query ); } public function testMethodConvertequealsHasResultNetldapfilter() { + $this->structure->expects($this->once()) + ->method('getInternalAttribute') + ->will($this->returnValue('equals')); $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $query = new Horde_Kolab_Server_Query_Ldap($equals); + $query = new Horde_Kolab_Server_Query_Ldap($equals, $this->structure); $this->assertEquals( '(equals=equals)', $query->convertEquals($equals)->asString() @@ -73,8 +88,11 @@ class Horde_Kolab_Server_Query_LdapTest extends Horde_Kolab_Server_LdapBase public function testMethodConvertbeginsHasResultNetldapfilter() { + $this->structure->expects($this->once()) + ->method('getInternalAttribute') + ->will($this->returnValue('begins')); $begins = new Horde_Kolab_Server_Query_Element_Begins('begins', 'begins'); - $query = new Horde_Kolab_Server_Query_Ldap($begins); + $query = new Horde_Kolab_Server_Query_Ldap($begins, $this->structure); $this->assertEquals( '(begins=begins*)', $query->convertBegins($begins)->asString() @@ -83,8 +101,11 @@ class Horde_Kolab_Server_Query_LdapTest extends Horde_Kolab_Server_LdapBase public function testMethodConvertendsHasResultNetldapfilter() { + $this->structure->expects($this->once()) + ->method('getInternalAttribute') + ->will($this->returnValue('ends')); $ends = new Horde_Kolab_Server_Query_Element_Ends('ends', 'ends'); - $query = new Horde_Kolab_Server_Query_Ldap($ends); + $query = new Horde_Kolab_Server_Query_Ldap($ends, $this->structure); $this->assertEquals( '(ends=*ends)', $query->convertEnds($ends)->asString() @@ -93,8 +114,11 @@ class Horde_Kolab_Server_Query_LdapTest extends Horde_Kolab_Server_LdapBase public function testMethodConvertcontainsHasResultNetldapfilter() { + $this->structure->expects($this->once()) + ->method('getInternalAttribute') + ->will($this->returnValue('contains')); $contains = new Horde_Kolab_Server_Query_Element_Contains('contains', 'contains'); - $query = new Horde_Kolab_Server_Query_Ldap($contains); + $query = new Horde_Kolab_Server_Query_Ldap($contains, $this->structure); $this->assertEquals( '(contains=*contains*)', $query->convertContains($contains)->asString() @@ -103,8 +127,11 @@ class Horde_Kolab_Server_Query_LdapTest extends Horde_Kolab_Server_LdapBase public function testMethodConvertlessHasResultNetldapfilter() { + $this->structure->expects($this->once()) + ->method('getInternalAttribute') + ->will($this->returnValue('less')); $less = new Horde_Kolab_Server_Query_Element_Less('less', 'less'); - $query = new Horde_Kolab_Server_Query_Ldap($less); + $query = new Horde_Kolab_Server_Query_Ldap($less, $this->structure); $this->assertEquals( '(lessconvertLess($less)->asString() @@ -113,8 +140,11 @@ class Horde_Kolab_Server_Query_LdapTest extends Horde_Kolab_Server_LdapBase public function testMethodConvertgreaterHasResultNetldapfilter() { + $this->structure->expects($this->once()) + ->method('getInternalAttribute') + ->will($this->returnValue('greater')); $greater = new Horde_Kolab_Server_Query_Element_Greater('greater', 'greater'); - $query = new Horde_Kolab_Server_Query_Ldap($greater); + $query = new Horde_Kolab_Server_Query_Ldap($greater, $this->structure); $this->assertEquals( '(greater>greater)', $query->convertGreater($greater)->asString() @@ -123,8 +153,11 @@ class Horde_Kolab_Server_Query_LdapTest extends Horde_Kolab_Server_LdapBase public function testMethodConvertapproxHasResultNetldapfilter() { + $this->structure->expects($this->once()) + ->method('getInternalAttribute') + ->will($this->returnValue('approx')); $approx = new Horde_Kolab_Server_Query_Element_Approx('approx', 'approx'); - $query = new Horde_Kolab_Server_Query_Ldap($approx); + $query = new Horde_Kolab_Server_Query_Ldap($approx, $this->structure); $this->assertEquals( '(approx~=approx)', $query->convertApprox($approx)->asString() @@ -133,9 +166,12 @@ class Horde_Kolab_Server_Query_LdapTest extends Horde_Kolab_Server_LdapBase public function testMethodConvertnotHasResultNetldapfilter() { + $this->structure->expects($this->once()) + ->method('getInternalAttribute') + ->will($this->returnValue('equals')); $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $not = new Horde_Kolab_Server_Query_Element_Not($equals); - $query = new Horde_Kolab_Server_Query_Ldap($not); + $not = new Horde_Kolab_Server_Query_Element_Not($equals, $this->structure); + $query = new Horde_Kolab_Server_Query_Ldap($not, $this->structure); $this->assertEquals( '(!(equals=equals))', $query->convertNot($not)->asString() @@ -144,24 +180,30 @@ class Horde_Kolab_Server_Query_LdapTest extends Horde_Kolab_Server_LdapBase public function testMethodConvertandHasResultNetldapfilter() { + $this->structure->expects($this->exactly(2)) + ->method('getInternalAttribute') + ->will($this->returnValue('internal')); $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); $contains = new Horde_Kolab_Server_Query_Element_Equals('contains', 'contains'); $and = new Horde_Kolab_Server_Query_Element_And(array($equals, $contains)); - $query = new Horde_Kolab_Server_Query_Ldap($and); + $query = new Horde_Kolab_Server_Query_Ldap($and, $this->structure); $this->assertEquals( - '(&(equals=equals)(contains=contains))', + '(&(internal=equals)(internal=contains))', $query->convertAnd($and)->asString() ); } public function testMethodConvertorHasResultNetldapfilter() { + $this->structure->expects($this->exactly(2)) + ->method('getInternalAttribute') + ->will($this->returnValue('internal')); $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); $contains = new Horde_Kolab_Server_Query_Element_Equals('contains', 'contains'); $or = new Horde_Kolab_Server_Query_Element_Or(array($equals, $contains)); - $query = new Horde_Kolab_Server_Query_Ldap($or); + $query = new Horde_Kolab_Server_Query_Ldap($or, $this->structure); $this->assertEquals( - '(|(equals=equals)(contains=contains))', + '(|(internal=equals)(internal=contains))', $query->convertOr($or)->asString() ); } @@ -170,7 +212,7 @@ class Horde_Kolab_Server_Query_LdapTest extends Horde_Kolab_Server_LdapBase { $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); $or = new Horde_Kolab_Server_Query_Element_Or(array($equals)); - $query = new Horde_Kolab_Server_Query_Ldap($or); + $query = new Horde_Kolab_Server_Query_Ldap($or, $this->structure); /** Hide strict errors from the Net_LDAP2 library */ $error_reporting = error_reporting(); diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Result/LdapTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Result/LdapTest.php deleted file mode 100644 index 668a68e4f..000000000 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Result/LdapTest.php +++ /dev/null @@ -1,79 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Require our basic test case definition - */ -require_once dirname(__FILE__) . '/../LdapBase.php'; - -/** - * Test the LDAP result handler. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Result_LdapTest extends Horde_Kolab_Server_LdapBase -{ - public function testMethodConstructHasParameterNetldap2searchSearchResult() - { - $search = $this->getMock( - 'Net_LDAP2_Search', array(), array(), '', false - ); - $result = new Horde_Kolab_Server_Result_Ldap($search); - } - - - public function testMethodCountHasResultIntTheNumberOfElementsFound() - { - $search = $this->getMock( - 'Net_LDAP2_Search', array('count'), array(), '', false - ); - $search->expects($this->exactly(1)) - ->method('count') - ->will($this->returnValue(1)); - $result = new Horde_Kolab_Server_Result_Ldap($search); - $this->assertEquals(1, $result->count()); - } - - public function testMethodSizelimitexceededHasResultBooleanIndicatingIfTheSearchSizeLimitWasHit() - { - $search = $this->getMock( - 'Net_LDAP2_Search', array('sizeLimitExceeded'), array(), '', false - ); - $search->expects($this->exactly(1)) - ->method('sizeLimitExceeded') - ->will($this->returnValue(true)); - $result = new Horde_Kolab_Server_Result_Ldap($search); - $this->assertTrue($result->sizeLimitExceeded()); - } - - public function testMethodAsarrayHasResultArrayWithTheSearchResults() - { - $search = $this->getMock( - 'Net_LDAP2_Search', array('as_struct'), array(), '', false - ); - $search->expects($this->exactly(1)) - ->method('as_struct') - ->will($this->returnValue(array('a' => 'a'))); - $result = new Horde_Kolab_Server_Result_Ldap($search); - $this->assertEquals(array('a' => 'a'), $result->asArray()); - } -} diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Search/SearchTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Search/SearchTest.php deleted file mode 100644 index 7211f3d60..000000000 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Search/SearchTest.php +++ /dev/null @@ -1,227 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Prepare the test setup. - */ -require_once dirname(__FILE__) . '/../Autoload.php'; - -/** - * Test the search handler. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Search_SearchTest extends PHPUnit_Framework_TestCase -{ - public function setUp() - { - if (!extension_loaded('ldap') && !@dl('ldap.' . PHP_SHLIB_SUFFIX)) { - $this->markTestSuiteSkipped('Ldap extension is missing!'); - }; - - if (!class_exists('Net_LDAP2')) { - $this->markTestSuiteSkipped('PEAR package Net_LDAP2 is not installed!'); - } - - $this->markTestIncomplete('Needs to be fixed'); - -/* $injector = new Horde_Injector(new Horde_Injector_TopLevel()); */ -/* Horde_Kolab_Server_Factory::setup(array(), $injector); */ -/* $this->server = $injector->getInstance('Horde_Kolab_Server'); */ - } - - public function testNothing() - { - } - - /** - * Test retrieving a primary mail for a mail or uid. - * - * @return NULL - */ -/* public function testMailForUidOrMail() */ -/* { */ -/* $ldap = $this->getMock('Horde_Kolab_Server_ldap', array('getAttributes', */ -/* 'search', 'count', */ -/* 'firstEntry')); */ -/* $ldap->expects($this->any()) */ -/* ->method('_getAttributes') */ -/* ->will($this->returnValue(array ( */ -/* 'mail' => */ -/* array ( */ -/* 'count' => 1, */ -/* 0 => 'wrobel@example.org', */ -/* ), */ -/* 0 => 'mail', */ -/* 'count' => 1))); */ -/* $ldap->expects($this->any()) */ -/* ->method('_search') */ -/* ->will($this->returnValue('cn=Gunnar Wrobel,dc=example,dc=org')); */ -/* $ldap->expects($this->any()) */ -/* ->method('_count') */ -/* ->will($this->returnValue(1)); */ -/* $ldap->expects($this->any()) */ -/* ->method('_firstEntry') */ -/* ->will($this->returnValue(1)); */ - -/* $mail = $ldap->mailForIdOrMail('wrobel'); */ -/* $this->assertEquals('wrobel@example.org', $mail); */ - -/* $ldap = $this->getMock('Horde_Kolab_Server_ldap', array('_getAttributes', */ -/* '_search', */ -/* '_count', */ -/* '_firstEntry', */ -/* '_errno', */ -/* '_error')); */ -/* $ldap->expects($this->any()) */ -/* ->method('_getAttributes') */ -/* ->will($this->returnValue(false)); */ -/* $ldap->expects($this->any()) */ -/* ->method('_search') */ -/* ->will($this->returnValue('cn=Gunnar Wrobel,dc=example,dc=org')); */ -/* $ldap->expects($this->any()) */ -/* ->method('_count') */ -/* ->will($this->returnValue(1)); */ -/* $ldap->expects($this->any()) */ -/* ->method('_firstEntry') */ -/* ->will($this->returnValue(1)); */ -/* $ldap->expects($this->any()) */ -/* ->method('_errno') */ -/* ->will($this->returnValue(1)); */ -/* $ldap->expects($this->any()) */ -/* ->method('_error') */ -/* ->will($this->returnValue('cn=DOES NOT EXIST,dc=example,dc=org: No such object')); */ - -/* $mail = $ldap->mailForIdOrMail('wrobel'); */ -/* $this->assertEquals('Retrieving attributes failed. Error was: cn=DOES NOT EXIST,dc=example,dc=org: No such object', */ -/* $mail->message); */ - -/* $ldap = $this->getMock('Horde_Kolab_Server_ldap', array('_getAttributes', */ -/* '_search', */ -/* '_count')); */ -/* $ldap->expects($this->any()) */ -/* ->method('_getAttributes') */ -/* ->will($this->returnValue(false)); */ -/* $ldap->expects($this->any()) */ -/* ->method('_search') */ -/* ->will($this->returnValue('cn=Gunnar Wrobel,dc=example,dc=org')); */ -/* $ldap->expects($this->any()) */ -/* ->method('_count') */ -/* ->will($this->returnValue(4)); */ - -/* $mail = $ldap->mailForIdOrMail('wrobel'); */ -/* $this->assertEquals('Found 4 results when expecting only one!', */ -/* $mail->message); */ -/* } */ - -/* /\** */ -/* * Test retrieving a DN for a mail or uid. */ -/* * */ -/* * @return NULL */ -/* *\/ */ -/* public function testDnForUidOrMail() */ -/* { */ -/* $ldap = $this->getMock('Horde_Kolab_Server_ldap', array('_getDn', */ -/* '_search', '_count', */ -/* '_firstEntry')); */ -/* $ldap->expects($this->any()) */ -/* ->method('_getDn') */ -/* ->will($this->returnValue('cn=Gunnar Wrobel,dc=example,dc=org')); */ -/* $ldap->expects($this->any()) */ -/* ->method('_search') */ -/* ->will($this->returnValue('cn=Gunnar Wrobel,dc=example,dc=org')); */ -/* $ldap->expects($this->any()) */ -/* ->method('_count') */ -/* ->will($this->returnValue(1)); */ -/* $ldap->expects($this->any()) */ -/* ->method('_firstEntry') */ -/* ->will($this->returnValue(1)); */ - -/* $dn = $ldap->uidForIdOrMail('wrobel'); */ -/* $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $dn); */ - -/* $ldap = $this->getMock('Horde_Kolab_Server_ldap', array('_getDn', */ -/* '_search', */ -/* '_count', */ -/* '_firstEntry', */ -/* '_errno', */ -/* '_error')); */ -/* $ldap->expects($this->any()) */ -/* ->method('_getDn') */ -/* ->will($this->returnValue(false)); */ -/* $ldap->expects($this->any()) */ -/* ->method('_search') */ -/* ->will($this->returnValue('cn=Gunnar Wrobel,dc=example,dc=org')); */ -/* $ldap->expects($this->any()) */ -/* ->method('_count') */ -/* ->will($this->returnValue(1)); */ -/* $ldap->expects($this->any()) */ -/* ->method('_firstEntry') */ -/* ->will($this->returnValue(1)); */ -/* $ldap->expects($this->any()) */ -/* ->method('_errno') */ -/* ->will($this->returnValue(1)); */ -/* $ldap->expects($this->any()) */ -/* ->method('_error') */ -/* ->will($this->returnValue('cn=DOES NOT EXIST,dc=example,dc=org: No such object')); */ - -/* $dn = $ldap->uidForIdOrMail('wrobel'); */ -/* $this->assertEquals('Retrieving DN failed. Error was: cn=DOES NOT EXIST,dc=example,dc=org: No such object', */ -/* $dn->message); */ - -/* $ldap = $this->getMock('Horde_Kolab_Server_ldap', array('_getDn', */ -/* '_search', */ -/* '_count')); */ -/* $ldap->expects($this->any()) */ -/* ->method('_getDn') */ -/* ->will($this->returnValue(false)); */ -/* $ldap->expects($this->any()) */ -/* ->method('_search') */ -/* ->will($this->returnValue('cn=Gunnar Wrobel,dc=example,dc=org')); */ -/* $ldap->expects($this->any()) */ -/* ->method('_count') */ -/* ->will($this->returnValue(4)); */ - -/* $dn = $ldap->uidForIdOrMail('wrobel'); */ -/* $this->assertEquals('Found 4 results when expecting only one!', */ -/* $dn->message); */ -/* } */ - -} - - -class Search_Mock -{ - public function __construct($result, $limit = false) - { - $this->result = $result; - $this->limit = $limit; - } - public function as_struct() - { - return $this->result; - } - public function sizeLimitExceeded() - { - return $this->limit; - } -} \ No newline at end of file diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Server/FactoryTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Server/FactoryTest.php deleted file mode 100644 index 2fe39d0b8..000000000 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Server/FactoryTest.php +++ /dev/null @@ -1,228 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Prepare the test setup. - */ -require_once dirname(__FILE__) . '/../Autoload.php'; - -/** - * Test the server factory interface. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Server_FactoryTest extends PHPUnit_Framework_TestCase -{ - public function setUp() - { - $this->markTestIncomplete(); - $this->injector = new Horde_Injector(new Horde_Injector_TopLevel()); - } - - public function testMethodSetupHasPostconditionThatAObjectHandlerOfTypeBaseIsBoundToObjects() - { - Horde_Kolab_Server_Factory::setup($this->injector, array()); - $this->assertType( - 'Horde_Kolab_Server_Objects_Base', - $this->injector->getInstance('Horde_Kolab_Server_Objects') - ); - } - - public function testMethodSetupHasPostconditionThatASchemaHandlerOfTypeBaseIsBoundToSchema() - { - Horde_Kolab_Server_Factory::setup($this->injector, array()); - $this->assertType( - 'Horde_Kolab_Server_Schema_Base', - $this->injector->getInstance('Horde_Kolab_Server_Schema') - ); - } - - public function testMethodSetupHasPostconditionThatASearchHandlerOfTypeBaseIsBoundToSearch() - { - Horde_Kolab_Server_Factory::setup($this->injector, array()); - $this->assertType( - 'Horde_Kolab_Server_Search_Base', - $this->injector->getInstance('Horde_Kolab_Server_Search') - ); - } - - public function testMethodSetupHasPostconditionThatAStructureOfTypeKolabIsBoundToStructure() - { - Horde_Kolab_Server_Factory::setup($this->injector, array()); - $this->assertType( - 'Horde_Kolab_Server_Structure_Kolab', - $this->injector->getInstance('Horde_Kolab_Server_Structure') - ); - } - - public function testMethodSetupHasPostconditionThatAStructureHandlerOfTypeLdapIsBoundToStructureIfConfiguredThatWay() - { - Horde_Kolab_Server_Factory::setup( - $this->injector, - array('structure' => array('driver' => 'ldap')) - ); - $this->assertType( - 'Horde_Kolab_Server_Structure_Ldap', - $this->injector->getInstance('Horde_Kolab_Server_Structure') - ); - } - - public function testMethodSetupHasPostconditionThatAServerOfTypeLdapIsBoundToServer() - { - Horde_Kolab_Server_Factory::setup($this->injector, array('basedn' => 'dc=example,dc=com')); - $this->assertType( - 'Horde_Kolab_Server_Ldap_Standard', - $this->injector->getInstance('Horde_Kolab_Server') - ); - } - - public function testMethodSetupHasPostconditionThatAServerOfTypeFileIsBoundToServerIfConfiguredThatWay() - { - Horde_Kolab_Server_Factory::setup( - $this->injector, - array('driver' => 'file', 'params' => array('basedn' => '', 'file' => '/tmp/nix')) - ); - $this->assertType( - 'Horde_Kolab_Server_Ldap_Standard', - $this->injector->getInstance('Horde_Kolab_Server') - ); - } - - public function testMethodSetupHasPostconditionThatAServerOfTypeFilteredLdapIsBoundToServerIfAFilterHasBeenProvided() - { - Horde_Kolab_Server_Factory::setup( - $this->injector, - array('basedn' => 'dc=example,dc=com', 'filter' => 'test') - ); - $this->assertType( - 'Horde_Kolab_Server_Ldap_Filtered', - $this->injector->getInstance('Horde_Kolab_Server') - ); - } - - public function testMethodSetupHasPostconditionThatAMappedServerIsBoundToServerIfAMapHasBeenProvided() - { - Horde_Kolab_Server_Factory::setup( - $this->injector, - array( - 'basedn' => 'dc=example,dc=com', - 'map' => array('a' => 'b'), - ) - ); - $this->assertType( - 'Horde_Kolab_Server_Mapped', - $this->injector->getInstance('Horde_Kolab_Server') - ); - } - - public function testMethodSetupHasPostconditionThatALoggedServerIsBoundToServerIfALoggerHasBeenProvided() - { - Horde_Kolab_Server_Factory::setup( - $this->injector, - array( - 'basedn' => 'dc=example,dc=com', - 'logger' => $this->getMock('Horde_Log_Logger'), - ) - ); - $this->assertType( - 'Horde_Kolab_Server_Logged', - $this->injector->getInstance('Horde_Kolab_Server') - ); - } - - public function testMethodGetserverHasPostconditionThatTheConnectionParametersGetRewrittenIfNecessary() - { - Horde_Kolab_Server_Factory::setup( - $this->injector, - array( - 'server' => 'localhost', - 'phpdn' => 'a', - 'phppw' => 'a', - 'basedn' => 'dc=example,dc=com' - ) - ); - $this->injector->getInstance('Horde_Kolab_Server'); - /**@todo: Actually not testable as we can't read the configuration again */ - } - - public function testMethodGetserverHasPostconditionThatTheConnectionIsSplittedIfRequired() - { - Horde_Kolab_Server_Factory::setup( - $this->injector, - array( - 'host' => 'localhost', - 'host_master' => 'writehost', - 'basedn' => 'dc=example,dc=com' - ) - ); - $this->injector->getInstance('Horde_Kolab_Server'); - /**@todo: Actually not testable as we can't read the configuration again */ - } - - public function testMethodGetserverThrowsExceptionIfTheBasednIsMissing() - { - try { - Horde_Kolab_Server_Factory::setup( - $this->injector, - array('dummy') - ); - $this->injector->getInstance('Horde_Kolab_Server'); - $this->fail('No exception!'); - } catch (Horde_Kolab_Server_Exception $e) { - $this->assertEquals( - 'The base DN is missing', $e->getMessage() - ); - } - } - - public function testMethodGetserverThrowsExceptionIfTheDriverIsUnknown() - { - try { - Horde_Kolab_Server_Factory::setup( - $this->injector, - array('driver' => 'unknown') - ); - $this->injector->getInstance('Horde_Kolab_Server'); - $this->fail('No exception!'); - } catch (Horde_Kolab_Server_Exception $e) { - $this->assertEquals( - 'Invalid server configuration!', $e->getMessage() - ); - } - } - - public function testMethodSingletonReturnsTheSameInstanceWithTheSameParameters() - { - $result1 = Horde_Kolab_Server_Factory::singleton(array('basedn' => 'dc=example,dc=com')); - $result2 = Horde_Kolab_Server_Factory::singleton(array('basedn' => 'dc=example,dc=com')); - $this->assertSame($result1, $result2); - } - - public function testMethodSingletonReturnsDifferentInstancesWithDifferentParameters() - { - global $conf; - $conf['kolab']['ldap']['basedn'] = 'test'; - $result1 = Horde_Kolab_Server_Factory::singleton(array('basedn' => 'dc=example,dc=com')); - $result2 = Horde_Kolab_Server_Factory::singleton(); - $this->assertTrue($result1 !== $result2); - } -} \ No newline at end of file diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Server/FilteredTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Server/FilteredTest.php deleted file mode 100644 index 10478b1ca..000000000 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Server/FilteredTest.php +++ /dev/null @@ -1,125 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Require our basic test case definition - */ -require_once dirname(__FILE__) . '/../LdapBase.php'; - -/** - * Test the filtered LDAP driver. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Server_FilteredTest extends Horde_Kolab_Server_LdapBase -{ - public function setUp() - { - parent::setUp(); - - $this->ldap_read = $this->getMock('Net_LDAP2'); - $this->ldap_write = $this->getMock('Net_LDAP2'); - $connection = new Horde_Kolab_Server_Connection_Splittedldap( - $this->ldap_read, - $this->ldap_write - ); - - $this->server = new Horde_Kolab_Server_Ldap_Filtered( - $connection, - 'base', - 'filter' - ); - } - - private function getSearchResultMock() - { - $result = $this->getMock( - 'Net_LDAP2_Search', array('as_struct', 'count'), array(), '', false - ); - $result->expects($this->any()) - ->method('as_struct') - ->will($this->returnValue(array(array('dn' => 'test')))); - $result->expects($this->any()) - ->method('count') - ->will($this->returnValue(1)); - return $result; - } - - public function testMethodFindbelowHasParameterQueryelementTheSearchCriteria() - { - $this->ldap_read->expects($this->exactly(1)) - ->method('search') - ->with('', '(&(filter)(equals=equals))', array()) - ->will($this->returnValue($this->getSearchResultMock())); - $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $this->server->findBelow($equals, ''); - } - - public function testMethodFindbelowHasParameterStringParent() - { - $this->ldap_read->expects($this->exactly(1)) - ->method('search') - ->with('parent', '(&(filter)(equals=equals))', array()) - ->will($this->returnValue($this->getSearchResultMock())); - $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $this->server->findBelow($equals, 'parent', array()); - } - - public function testMethodFindbelowHasParameterArrayAdditionalParameters() - { - $this->ldap_read->expects($this->exactly(1)) - ->method('search') - ->with('', '(&(filter)(equals=equals))', array()) - ->will($this->returnValue($this->getSearchResultMock())); - $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $this->server->findBelow($equals, '', array()); - } - - public function testMethodFindbelowReturnsArraySearchResult() - { - $this->ldap_read->expects($this->exactly(1)) - ->method('search') - ->with('parent', '(&(filter)(equals=equals))', array()) - ->will($this->returnValue($this->getSearchResultMock())); - $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $this->assertEquals( - array(array('dn' => 'test')), - $this->server->findBelow($equals, 'parent')->asArray() - ); - } - - public function testMethodFindbelowThrowsExceptionIfTheSearchFailed() - { - $this->ldap_read->expects($this->exactly(1)) - ->method('search') - ->will($this->returnValue(new PEAR_Error('Search failed!'))); - try { - $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $this->assertEquals(array('dn' => 'test'), $this->server->findBelow($equals, '')); - $this->fail('No exception!'); - } catch (Exception $e) { - $this->assertEquals('Search failed!', $e->getMessage()); - $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); - } - } - -} diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Server/LdapTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Server/LdapTest.php deleted file mode 100644 index c014d2173..000000000 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Server/LdapTest.php +++ /dev/null @@ -1,502 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Require our basic test case definition - */ -require_once dirname(__FILE__) . '/../LdapBase.php'; - -/** - * Test the LDAP backend. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Server_LdapTest extends Horde_Kolab_Server_LdapBase -{ - public function setUp() - { - parent::setUp(); - - $this->ldap_read = $this->getMock('Net_LDAP2'); - $this->ldap_write = $this->getMock('Net_LDAP2'); - $connection = new Horde_Kolab_Server_Connection_Splittedldap( - $this->ldap_read, - $this->ldap_write - ); - - $this->server = new Horde_Kolab_Server_Ldap_Standard( - $connection, - 'base' - ); - } - - private function getSearchResultMock() - { - $result = $this->getMock( - 'Net_LDAP2_Search', array('as_struct', 'count'), array(), '', false - ); - $result->expects($this->any()) - ->method('as_struct') - ->will($this->returnValue(array(array('dn' => 'test')))); - $result->expects($this->any()) - ->method('count') - ->will($this->returnValue(1)); - return $result; - } - - public function testMethodConnectguidHasStringParameterGuid() - { - $this->server->connectGuid('guid', ''); - } - - public function testMethodConnectguidHasStringParameterPass() - { - $this->server->connectGuid('', 'pass'); - } - - public function testMethodConnectguidHasPostconditionThatTheGuidIsSetIfTheConnectionWasSuccessful() - { - $this->ldap_read->expects($this->exactly(1)) - ->method('bind') - ->will($this->returnValue(true)); - $this->server->connectGuid('test', 'test'); - $this->assertEquals('test', $this->server->getGuid()); - } - - public function testMethodConnectguidDoesNotCallBindAgainIfAlreadyConnectedWithThisGuid() - { - $this->ldap_read->expects($this->exactly(1)) - ->method('bind') - ->will($this->returnValue(true)); - $this->server->connectGuid('test', 'test'); - $this->server->connectGuid('test', 'test'); - } - - public function testMethodConnectguidDoesNotCallBindAgainIfAlreadyConnectedWithThisGuidEvenIfTheGuidIsEmpty() - { - $this->ldap_read->expects($this->exactly(1)) - ->method('bind') - ->will($this->returnValue(true)); - $this->server->connectGuid('', ''); - $this->server->connectGuid('', ''); - } - - public function testMethodConnectguidThrowsExceptionIfTheConnectionFailed() - { - $this->ldap_read->expects($this->exactly(1)) - ->method('bind') - ->will($this->returnValue(new PEAR_Error('Bind failed!'))); - try { - $this->server->connectGuid('test', 'test'); - $this->fail('No exception!'); - } catch (Exception $e) { - $this->assertEquals('Bind failed!', $e->getMessage()); - $this->assertEquals(Horde_Kolab_Server_Exception::BIND_FAILED, $e->getCode()); - } - } - - public function testMethodGetguidHasResultBooleanFalseIfNotConnected() - { - $this->assertSame(false, $this->server->getGuid()); - } - - public function testMethodGetguidHasResultStringGuidIfNotConnected() - { - $this->server->connectGuid('guid', ''); - $this->assertEquals('guid', $this->server->getGuid()); - } - - public function testMethodReadHasParameterStringGuid() - { - $this->ldap_read->expects($this->exactly(1)) - ->method('search') - ->with('test', null, array('scope' => 'base')) - ->will($this->returnValue($this->getSearchResultMock())); - $this->server->read('test'); - } - - public function testMethodReadReturnsArrayReadResult() - { - $this->ldap_read->expects($this->exactly(1)) - ->method('search') - ->with('test', null, array('scope' => 'base')) - ->will($this->returnValue($this->getSearchResultMock())); - $this->assertEquals(array('dn' => 'test'), $this->server->read('test')); - } - - public function testMethodReadThrowsExceptionIfTheObjectWasNotFound() - { - $result = $this->getMock( - 'Net_LDAP2_Search', array('as_struct', 'count'), array(), '', false - ); - $result->expects($this->exactly(1)) - ->method('count') - ->will($this->returnValue(0)); - $this->ldap_read->expects($this->exactly(1)) - ->method('search') - ->will($this->returnValue($result)); - try { - $this->assertEquals(array(), $this->server->read('test')); - $this->fail('No exception!'); - } catch (Exception $e) { - $this->assertEquals('Empty result!', $e->getMessage()); - $this->assertEquals(Horde_Kolab_Server_Exception::EMPTY_RESULT, $e->getCode()); - } - } - - public function testMethodReadAttributesHasParameterStringGuid() - { - $this->ldap_read->expects($this->exactly(1)) - ->method('search') - ->with('guid', null, array('scope' => 'base', 'attributes' => array())) - ->will($this->returnValue($this->getSearchResultMock())); - $this->server->readAttributes('guid', array()); - } - - public function testMethodReadAttributesHasParameterArrayAttributes() - { - $this->ldap_read->expects($this->exactly(1)) - ->method('search') - ->with('', null, array('scope' => 'base', 'attributes' => array('a'))) - ->will($this->returnValue($this->getSearchResultMock())); - $this->server->readAttributes('', array('a')); - } - - public function testMethodReadAttributesReturnsArrayReadResult() - { - $this->ldap_read->expects($this->exactly(1)) - ->method('search') - ->with('test', null, array('scope' => 'base', 'attributes' => array('a'))) - ->will($this->returnValue($this->getSearchResultMock())); - $this->assertEquals(array('dn' => 'test'), $this->server->readAttributes('test', array('a'))); - } - - public function testMethodReadAttributesThrowsExceptionIfTheObjectWasNotFound() - { - $result = $this->getMock( - 'Net_LDAP2_Search', array('as_struct', 'count'), array(), '', false - ); - $result->expects($this->exactly(1)) - ->method('count') - ->will($this->returnValue(0)); - $this->ldap_read->expects($this->exactly(1)) - ->method('search') - ->with('test', null, array('scope' => 'base', 'attributes' => array('a'))) - ->will($this->returnValue($result)); - try { - $this->assertEquals(array(), $this->server->readAttributes('test', array('a'))); - $this->fail('No exception!'); - } catch (Exception $e) { - $this->assertEquals('Empty result!', $e->getMessage()); - $this->assertEquals(Horde_Kolab_Server_Exception::EMPTY_RESULT, $e->getCode()); - } - } - - public function testMethodFindHasParameterQueryelementTheSearchCriteria() - { - $this->ldap_read->expects($this->exactly(1)) - ->method('search') - ->with('base', '(equals=equals)', array()) - ->will($this->returnValue($this->getSearchResultMock())); - $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $this->server->find($equals); - } - - public function testMethodFindHasParameterArrayAdditionalParameters() - { - $this->ldap_read->expects($this->exactly(1)) - ->method('search') - ->with('base', '(equals=equals)', array()) - ->will($this->returnValue($this->getSearchResultMock())); - $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $this->server->find($equals, array()); - } - - public function testMethodFindReturnsArraySearchResult() - { - $this->ldap_read->expects($this->exactly(1)) - ->method('search') - ->with('base', '(equals=equals)', array()) - ->will($this->returnValue($this->getSearchResultMock())); - $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $this->assertEquals( - array(array('dn' => 'test')), - $this->server->find($equals)->asArray() - ); - } - - public function testMethodFindThrowsExceptionIfTheSearchFailed() - { - $this->ldap_read->expects($this->exactly(1)) - ->method('search') - ->will($this->returnValue(new PEAR_Error('Search failed!'))); - try { - $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $this->assertEquals(array('dn' => 'test'), $this->server->find($equals)); - $this->fail('No exception!'); - } catch (Exception $e) { - $this->assertEquals('Search failed!', $e->getMessage()); - $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); - } - } - - public function testMethodSaveHasParameterObjectTheObjectToModifyOnTheServer() - { - $entry = $this->getMock( - 'Net_LDAP2_Entry', array(), array(), '', false - ); - $object = $this->getMock( - 'Horde_Kolab_Server_Object', array(), array(), '', false - ); - $this->ldap_write->expects($this->exactly(1)) - ->method('getEntry') - ->will($this->returnValue($entry)); - $this->ldap_write->expects($this->exactly(1)) - ->method('modify') - ->with(new PHPUnit_Framework_Constraint_IsInstanceOf('Net_LDAP2_Entry')); - $object->expects($this->exactly(1)) - ->method('readInternal') - ->will($this->returnValue(array())); - $this->server->save($object, array('attributes' => array('dn'))); - } - - public function testMethodSaveHasParameterArrayData() - { - $entry = $this->getMock( - 'Net_LDAP2_Entry', array(), array(), '', false - ); - $object = $this->getMock( - 'Horde_Kolab_Server_Object', array(), array(), '', false - ); - $this->ldap_write->expects($this->exactly(1)) - ->method('getEntry') - ->will($this->returnValue($entry)); - $this->ldap_write->expects($this->exactly(1)) - ->method('modify') - ->with(new PHPUnit_Framework_Constraint_IsInstanceOf('Net_LDAP2_Entry')); - $object->expects($this->exactly(1)) - ->method('readInternal') - ->will($this->returnValue(array())); - $this->server->save($object, array('dn' => 'test')); - } - - public function testMethodSaveHasPostconditionThatTheEntryWasModified() - { - $entry = $this->getMock( - 'Net_LDAP2_Entry', array(), array(), '', false - ); - $object = $this->getMock( - 'Horde_Kolab_Server_Object', array(), array(), '', false - ); - $this->ldap_write->expects($this->exactly(1)) - ->method('getEntry') - ->will($this->returnValue($entry)); - $this->ldap_write->expects($this->exactly(1)) - ->method('modify') - ->with(new PHPUnit_Framework_Constraint_IsInstanceOf('Net_LDAP2_Entry')); - $object->expects($this->exactly(1)) - ->method('readInternal') - ->will($this->returnValue(array())); - $this->server->save($object, array('dn' => 'test')); - } - - public function testMethodSaveThrowsExceptionIfSavingDataFailed() - { - $object = $this->getMock( - 'Horde_Kolab_Server_Object', array(), array(), '', false - ); - $this->ldap_write->expects($this->exactly(1)) - ->method('modify') - ->will($this->returnValue(new PEAR_Error('Saving failed!'))); - $object->expects($this->exactly(1)) - ->method('readInternal') - ->will($this->returnValue(array())); - try { - $this->server->save($object, array('dn' => 'test')); - $this->fail('No exception!'); - } catch (Exception $e) { - $this->assertEquals('Saving failed!', $e->getMessage()); - $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); - } - } - - public function testMethodAddHasParameterObjectTheObjectToAddToTheServer() - { - $object = $this->getMock( - 'Horde_Kolab_Server_Object', array(), array(), '', false - ); - $this->ldap_write->expects($this->exactly(1)) - ->method('add') - ->with(new PHPUnit_Framework_Constraint_IsInstanceOf('Net_LDAP2_Entry')); - $this->server->add($object, array('attributes' => array('dn'))); - } - - public function testMethodAddHasParameterArrayData() - { - $object = $this->getMock( - 'Horde_Kolab_Server_Object', array(), array(), '', false - ); - $this->ldap_write->expects($this->exactly(1)) - ->method('add') - ->with(new PHPUnit_Framework_Constraint_IsInstanceOf('Net_LDAP2_Entry')); - $this->server->add($object, array('dn' => 'test')); - } - - public function testMethodAddHasPostconditionThatTheEntryWasModified() - { - $object = $this->getMock( - 'Horde_Kolab_Server_Object', array(), array(), '', false - ); - $this->ldap_write->expects($this->exactly(1)) - ->method('add') - ->with(new PHPUnit_Framework_Constraint_IsInstanceOf('Net_LDAP2_Entry')); - $this->server->add($object, array('dn' => 'test')); - } - - public function testMethodAddThrowsExceptionIfSavingDataFailed() - { - $object = $this->getMock( - 'Horde_Kolab_Server_Object', array(), array(), '', false - ); - $this->ldap_write->expects($this->exactly(1)) - ->method('add') - ->will($this->returnValue(new PEAR_Error('Saving failed!'))); - try { - $this->server->add($object, array('add' => array('dn' => 'test'))); - $this->fail('No exception!'); - } catch (Exception $e) { - $this->assertEquals('Saving failed!', $e->getMessage()); - $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); - } - } - - public function testMethodDeleteHasParameterStringGuid() - { - $this->ldap_write->expects($this->exactly(1)) - ->method('delete') - ->with('guid'); - $this->server->delete('guid'); - } - - public function testMethodDeleteHasPostconditionThatTheEntryWasDeleted() - { - $this->ldap_write->expects($this->exactly(1)) - ->method('delete') - ->with('test'); - $this->server->delete('test'); - } - - public function testMethodDeleteThrowsExceptionIfDeletingDataFailed() - { - $this->ldap_write->expects($this->exactly(1)) - ->method('delete') - ->will($this->returnValue(new PEAR_Error('Deleting failed!'))); - try { - $this->server->delete('test'); - $this->fail('No exception!'); - } catch (Exception $e) { - $this->assertEquals('Deleting failed!', $e->getMessage()); - $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); - } - } - - public function testMethodRenameHasParameterStringOldGuid() - { - $this->ldap_write->expects($this->exactly(1)) - ->method('move') - ->with('oldguid', ''); - $this->server->rename('oldguid', ''); - } - - public function testMethodRenameHasParameterStringNewGuid() - { - $this->ldap_write->expects($this->exactly(1)) - ->method('move') - ->with('', 'newguid'); - $this->server->rename('', 'newguid'); - } - - public function testMethodRenameHasPostconditionThatTheEntryWasRenamed() - { - $this->ldap_write->expects($this->exactly(1)) - ->method('move') - ->with('test', 'new'); - $this->server->rename('test', 'new'); - } - - public function testMethodRenameThrowsExceptionIfRenamingDataFailed() - { - $this->ldap_write->expects($this->exactly(1)) - ->method('move') - ->will($this->returnValue(new PEAR_Error('Renaming failed!'))); - try { - $this->server->rename('test', 'new'); - $this->fail('No exception!'); - } catch (Exception $e) { - $this->assertEquals('Renaming failed!', $e->getMessage()); - $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); - } - } - - public function testMethodGetschemaReturnsArrayWithADescriptionOfAllObjectClasses() - { - $this->ldap_read->expects($this->exactly(1)) - ->method('schema') - ->will($this->returnValue(array('schema' => 'dummy'))); - $this->assertEquals( - array('schema' => 'dummy'), - $this->server->getSchema() - ); - } - - public function testMethodGetschemaThrowsExceptionIfTheSchemaRetrievalFailed() - { - $this->ldap_read->expects($this->exactly(1)) - ->method('schema') - ->will($this->returnValue(new PEAR_Error('Schema failed!'))); - try { - $this->server->getSchema(); - $this->fail('No exception!'); - } catch (Exception $e) { - $this->assertEquals('Schema failed!', $e->getMessage()); - $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); - } - } - -/* public function testMethodSearchReturnsArrayMappedSearchResultIfMappingIsActivated() */ -/* { */ -/* $ldap = $this->getMock('Net_LDAP2', array('search')); */ -/* $ldap->expects($this->exactly(1)) */ -/* ->method('search') */ -/* ->will($this->returnValue(new Search_Mock(array(array('dn2' => 'test'))))); */ -/* $this->server->setLdap($ldap); */ -/* $this->server->setParams(array('map' => array('dn' => 'dn2'))); */ -/* $this->assertEquals( */ -/* array(array('dn' => 'test')), */ -/* $this->server->search( */ -/* 'filter', */ -/* array('attributes' => array('dn')) */ -/* ) */ -/* ); */ -/* } */ - -} diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Server/LoggedTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Server/LoggedTest.php deleted file mode 100644 index 470fa723c..000000000 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Server/LoggedTest.php +++ /dev/null @@ -1,185 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Require our basic test case definition - */ -require_once dirname(__FILE__) . '/../LdapBase.php'; - -/** - * Test the LDAP backend. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Server_LoggedTest extends Horde_Kolab_Server_LdapBase -{ - public function setUp() - { - parent::setUp(); - - $this->logger = new Horde_Log_Handler_Mock(); - $this->server = $this->getMock('Horde_Kolab_Server'); - $this->logged = new Horde_Kolab_Server_Logged( - $this->server, - new Horde_Log_Logger($this->logger) - ); - } - - public function testMethodConnectguidDelegatesToServer() - { - $this->server->expects($this->exactly(1)) - ->method('connectGuid') - ->with('user', 'pass'); - $this->logged->connectGuid('user', 'pass'); - } - - public function testMethodReadDelegatesToServer() - { - $this->server->expects($this->exactly(1)) - ->method('read') - ->with('guid'); - $this->logged->read('guid'); - } - - public function testMethodReadattributesDelegatesToServer() - { - $this->server->expects($this->exactly(1)) - ->method('readAttributes') - ->with('guid', array('a')); - $this->logged->readAttributes('guid', array('a')); - } - - public function testMethodFindDelegatesToServer() - { - $query = $this->getMock( - 'Horde_Kolab_Server_Query_Element', array(), array(), '', false - ); - $this->server->expects($this->exactly(1)) - ->method('find') - ->with($query); - $this->logged->find($query); - } - - public function testMethodFindbelowDelegatesToServer() - { - $query = $this->getMock( - 'Horde_Kolab_Server_Query_Element', array(), array(), '', false - ); - $this->server->expects($this->exactly(1)) - ->method('findBelow') - ->with($query, 'none'); - $this->logged->findBelow($query, 'none'); - } - - public function testMethodSaveDelegatesToServer() - { - $object = $this->getMock( - 'Horde_Kolab_Server_Object', array(), array(), '', false - ); - $this->server->expects($this->exactly(1)) - ->method('save') - ->with($object, array('a' => 'a')); - $this->logged->save($object, array('a' => 'a')); - } - - public function testMethodAddDelegatesToServer() - { - $object = $this->getMock( - 'Horde_Kolab_Server_Object', array(), array(), '', false - ); - $this->server->expects($this->exactly(1)) - ->method('add') - ->with($object, array('a' => 'a')); - $this->logged->add($object, array('a' => 'a')); - } - - public function testMethodDeleteDelegatesToServer() - { - $this->server->expects($this->exactly(1)) - ->method('delete') - ->with('a'); - $this->logged->delete('a'); - } - - public function testMethodRenameDelegatesToServer() - { - $this->server->expects($this->exactly(1)) - ->method('rename') - ->with('a', 'b'); - $this->logged->rename('a', 'b'); - } - - public function testMethodGetschemaDelegatesToServer() - { - $this->server->expects($this->exactly(1)) - ->method('getSchema'); - $this->logged->getSchema(); - } - - public function testMethodSaveHasPostconditionThatTheEventWasLogged() - { - $object = $this->getMock( - 'Horde_Kolab_Server_Object', array(), array(), '', false - ); - $object->expects($this->once()) - ->method('getGuid') - ->will($this->returnValue('a')); - $this->logged->save($object, array('a' => 'a')); - $this->assertEquals( - $this->logger->events[0]['message'], - 'The object "a" has been successfully saved!' - ); - } - - public function testMethodAddHasPostconditionThatTheEventWasLogged() - { - $object = $this->getMock( - 'Horde_Kolab_Server_Object', array(), array(), '', false - ); - $object->expects($this->once()) - ->method('getGuid') - ->will($this->returnValue('a')); - $this->logged->add($object, array('a' => 'a')); - $this->assertEquals( - $this->logger->events[0]['message'], - 'The object "a" has been successfully added!' - ); - } - - public function testMethodDeleteHasPostconditionThatTheEventWasLogged() - { - $this->logged->delete('a'); - $this->assertEquals( - $this->logger->events[0]['message'], - 'The object "a" has been successfully deleted!' - ); - } - - public function testMethodRenameHasPostconditionThatTheEventWasLogged() - { - $this->logged->rename('a', 'b'); - $this->assertEquals( - $this->logger->events[0]['message'], - 'The object "a" has been successfully renamed to "b"!' - ); - } -} \ No newline at end of file diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Server/StandardTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Server/StandardTest.php deleted file mode 100644 index b5486ef3a..000000000 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Server/StandardTest.php +++ /dev/null @@ -1,124 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Require our basic test case definition - */ -require_once dirname(__FILE__) . '/../LdapBase.php'; - -/** - * Test the standard LDAP driver. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Server_StandardTest extends Horde_Kolab_Server_LdapBase -{ - public function setUp() - { - parent::setUp(); - - $this->ldap_read = $this->getMock('Net_LDAP2'); - $this->ldap_write = $this->getMock('Net_LDAP2'); - $connection = new Horde_Kolab_Server_Connection_Splittedldap( - $this->ldap_read, - $this->ldap_write - ); - - $this->server = new Horde_Kolab_Server_Ldap_Standard( - $connection, - 'base' - ); - } - - private function getSearchResultMock() - { - $result = $this->getMock( - 'Net_LDAP2_Search', array('as_struct', 'count'), array(), '', false - ); - $result->expects($this->any()) - ->method('as_struct') - ->will($this->returnValue(array(array('dn' => 'test')))); - $result->expects($this->any()) - ->method('count') - ->will($this->returnValue(1)); - return $result; - } - - public function testMethodFindbelowHasParameterQueryelementTheSearchCriteria() - { - $this->ldap_read->expects($this->exactly(1)) - ->method('search') - ->with('', '(equals=equals)', array()) - ->will($this->returnValue($this->getSearchResultMock())); - $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $this->server->findBelow($equals, ''); - } - - public function testMethodFindbelowHasParameterStringParent() - { - $this->ldap_read->expects($this->exactly(1)) - ->method('search') - ->with('parent', '(equals=equals)', array()) - ->will($this->returnValue($this->getSearchResultMock())); - $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $this->server->findBelow($equals, 'parent', array()); - } - - public function testMethodFindbelowHasParameterArrayAdditionalParameters() - { - $this->ldap_read->expects($this->exactly(1)) - ->method('search') - ->with('', '(equals=equals)', array()) - ->will($this->returnValue($this->getSearchResultMock())); - $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $this->server->findBelow($equals, '', array()); - } - - public function testMethodFindbelowReturnsArraySearchResult() - { - $this->ldap_read->expects($this->exactly(1)) - ->method('search') - ->with('parent', '(equals=equals)', array()) - ->will($this->returnValue($this->getSearchResultMock())); - $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $this->assertEquals( - array(array('dn' => 'test')), - $this->server->findBelow($equals, 'parent')->asArray() - ); - } - - public function testMethodFindbelowThrowsExceptionIfTheSearchFailed() - { - $this->ldap_read->expects($this->exactly(1)) - ->method('search') - ->will($this->returnValue(new PEAR_Error('Search failed!'))); - try { - $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $this->assertEquals(array('dn' => 'test'), $this->server->findBelow($equals, '')); - $this->fail('No exception!'); - } catch (Exception $e) { - $this->assertEquals('Search failed!', $e->getMessage()); - $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); - } - } - -} diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Structure/KolabTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Structure/KolabTest.php deleted file mode 100644 index 2ff1ff110..000000000 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Structure/KolabTest.php +++ /dev/null @@ -1,347 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Require our basic test case definition - */ -require_once dirname(__FILE__) . '/../LdapBase.php'; - -/** - * Test the LDAP backend. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Structure_KolabTest extends PHPUnit_Framework_TestCase -{ - public function setUp() - { - $server = $this->getMock('Horde_Kolab_Server'); - $this->composite = new Horde_Kolab_Server_Composite( - $server, - $this->getMock('Horde_Kolab_Server_Objects'), - new Horde_Kolab_Server_Structure_Kolab(), - $this->getMock('Horde_Kolab_Server_Search'), - $this->getMock('Horde_Kolab_Server_Schema') - ); - } - - public function testMethodGetsupportedobjectsHasResultArrayTheObjectTypesSupportedByThisStructure() - { - $this->assertType('array', $this->composite->structure->getSupportedObjects()); - } - - public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid1() - { - $this->composite->server->expects($this->exactly(1)) - ->method('read') - ->with('guid') - ->will($this->returnValue(array('objectClass' => array('kolabGroupOfNames')))); - $this->assertEquals('Horde_Kolab_Server_Object_Kolabgroupofnames', $this->composite->structure->determineType('guid')); - } - - public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid2() - { - $this->composite->server->expects($this->exactly(1)) - ->method('read') - ->with('guid') - ->will($this->returnValue(array('objectClass' => array('kolabExternalPop3Account')))); - $this->assertEquals('Horde_Kolab_Server_Object_Kolabpop3account', $this->composite->structure->determineType('guid')); - } - - public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid3() - { - $this->composite->server->expects($this->exactly(1)) - ->method('read') - ->with('guid') - ->will($this->returnValue(array('objectClass' => array('kolabSharedFolder')))); - $this->assertEquals('Horde_Kolab_Server_Object_Kolabsharedfolder', $this->composite->structure->determineType('guid')); - } - - public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid4() - { - $this->composite->server->expects($this->exactly(1)) - ->method('read') - ->with('guid') - ->will($this->returnValue(array('objectClass' => array('top')))); - $this->assertEquals('Horde_Kolab_Server_Object_Top', $this->composite->structure->determineType('guid')); - } - - public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid5() - { - $this->composite->server->expects($this->exactly(1)) - ->method('read') - ->with('guid') - ->will( - $this->returnValue( - array( - 'objectClass' => - array( - 'kolabinetorgperson', - ) - ) - ) - ); - $this->composite->search->expects($this->exactly(1)) - ->method('__call') - ->with('getGroups', array('guid')) - ->will( - $this->returnValue( - array( - ) - ) - ); - $this->assertEquals( - 'Horde_Kolab_Server_Object_Kolab_User', - $this->composite->structure->determineType('guid') - ); - } - - public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid6() - { - $this->composite->server->expects($this->exactly(1)) - ->method('read') - ->with('guid') - ->will( - $this->returnValue( - array( - 'objectClass' => - array( - 'kolabinetorgperson', - ) - ) - ) - ); - $this->composite->server->expects($this->exactly(1)) - ->method('getBaseGuid') - ->will($this->returnValue('base')); - $this->composite->search->expects($this->exactly(1)) - ->method('__call') - ->with('getGroups', array('guid')) - ->will( - $this->returnValue( - array( - 'cn=admin,cn=internal,base' - ) - ) - ); - $this->assertEquals( - 'Horde_Kolab_Server_Object_Kolab_Administrator', - $this->composite->structure->determineType('guid') - ); - } - - public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid7() - { - $this->composite->server->expects($this->exactly(1)) - ->method('read') - ->with('guid') - ->will( - $this->returnValue( - array( - 'objectClass' => - array( - 'kolabinetorgperson', - ) - ) - ) - ); - $this->composite->server->expects($this->exactly(1)) - ->method('getBaseGuid') - ->will($this->returnValue('base')); - $this->composite->search->expects($this->exactly(1)) - ->method('__call') - ->with('getGroups', array('guid')) - ->will( - $this->returnValue( - array( - 'cn=maintainer,cn=internal,base' - ) - ) - ); - $this->assertEquals( - 'Horde_Kolab_Server_Object_Kolab_Maintainer', - $this->composite->structure->determineType('guid') - ); - } - - public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid8() - { - $this->composite->server->expects($this->exactly(1)) - ->method('read') - ->with('guid') - ->will( - $this->returnValue( - array( - 'objectClass' => - array( - 'kolabinetorgperson', - ) - ) - ) - ); - $this->composite->server->expects($this->exactly(1)) - ->method('getBaseGuid') - ->will($this->returnValue('base')); - $this->composite->search->expects($this->exactly(1)) - ->method('__call') - ->with('getGroups', array('guid')) - ->will( - $this->returnValue( - array( - 'cn=domain-maintainer,cn=internal,base' - ) - ) - ); - $this->assertEquals( - 'Horde_Kolab_Server_Object_Kolab_Domainmaintainer', - $this->composite->structure->determineType('guid') - ); - } - - public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid9() - { - $this->composite->server->expects($this->exactly(1)) - ->method('read') - ->with('guid,cn=external') - ->will( - $this->returnValue( - array( - 'objectClass' => - array( - 'kolabinetorgperson', - ) - ) - ) - ); - $this->composite->search->expects($this->exactly(1)) - ->method('__call') - ->with('getGroups', array('guid,cn=external')) - ->will( - $this->returnValue( - array( - 'unknown' - ) - ) - ); - $this->assertEquals( - 'Horde_Kolab_Server_Object_Kolab_Address', - $this->composite->structure->determineType('guid,cn=external') - ); - } - - public function testMethodGenerateserverguidHasResultStringTheGuid1() - { - $this->composite->server->expects($this->exactly(1)) - ->method('getBaseGuid') - ->will($this->returnValue('base')); - $this->assertEquals('id,base', $this->composite->structure->generateServerGuid('Horde_Kolab_Server_Object_Kolabgroupofnames', 'id', array())); - } - - public function testMethodGenerateserverguidHasResultStringTheGuid2() - { - $this->composite->server->expects($this->exactly(1)) - ->method('getBaseGuid') - ->will($this->returnValue('base')); - $this->assertEquals('id,cn=internal,base', $this->composite->structure->generateServerGuid('Horde_Kolab_Server_Object_Kolabgroupofnames', 'id', array('visible' => false))); - } - - public function testMethodGenerateserverguidHasResultStringTheGuid3() - { - $this->composite->server->expects($this->exactly(1)) - ->method('getBaseGuid') - ->will($this->returnValue('base')); - $this->assertEquals('id,base', $this->composite->structure->generateServerGuid('Horde_Kolab_Server_Object_Kolabsharedfolder', 'id', array('visible' => false))); - } - - public function testMethodGenerateserverguidHasResultStringTheGuid4() - { - $this->composite->server->expects($this->exactly(1)) - ->method('getBaseGuid') - ->will($this->returnValue('base')); - $this->assertEquals('id,cn=external,base', $this->composite->structure->generateServerGuid('Horde_Kolab_Server_Object_Kolab_Address', 'id', array())); - } - - public function testMethodGenerateserverguidHasResultStringTheGuid5() - { - $this->composite->server->expects($this->exactly(1)) - ->method('getBaseGuid') - ->will($this->returnValue('base')); - $this->assertEquals( - 'id,cn=internal,base', - $this->composite->structure->generateServerGuid( - 'Horde_Kolab_Server_Object_Kolab_User', 'id', - array('user_type' => Horde_Kolab_Server_Object_Kolab_User::USERTYPE_INTERNAL) - ) - ); - } - - public function testMethodGenerateserverguidHasResultStringTheGuid6() - { - $this->composite->server->expects($this->exactly(1)) - ->method('getBaseGuid') - ->will($this->returnValue('base')); - $this->assertEquals( - 'id,cn=groups,base', - $this->composite->structure->generateServerGuid( - 'Horde_Kolab_Server_Object_Kolab_User', 'id', - array('user_type' => Horde_Kolab_Server_Object_Kolab_User::USERTYPE_GROUP) - ) - ); - } - - public function testMethodGenerateserverguidHasResultStringTheGuid7() - { - $this->composite->server->expects($this->exactly(1)) - ->method('getBaseGuid') - ->will($this->returnValue('base')); - $this->assertEquals( - 'id,cn=resources,base', - $this->composite->structure->generateServerGuid( - 'Horde_Kolab_Server_Object_Kolab_User', 'id', - array('user_type' => Horde_Kolab_Server_Object_Kolab_User::USERTYPE_RESOURCE) - ) - ); - } - - public function testMethodGenerateserverguidHasResultStringTheGuid8() - { - $this->composite->server->expects($this->exactly(1)) - ->method('getBaseGuid') - ->will($this->returnValue('base')); - $this->assertEquals('id,base', $this->composite->structure->generateServerGuid('Horde_Kolab_Server_Object_Kolab_User', 'id', array())); - } - - public function testMethodGenerateserverguidHasResultStringTheGuid9() - { - $this->composite->server->expects($this->exactly(1)) - ->method('getBaseGuid') - ->will($this->returnValue('base')); - $this->assertEquals( - 'id,base', - $this->composite->structure->generateServerGuid( - 'Horde_Kolab_Server_Object_Kolab_User', 'id', - array('user_type' => 'undefined') - ) - ); - } - -} diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Structure/LdapTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Structure/LdapTest.php deleted file mode 100644 index 95ed217be..000000000 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Structure/LdapTest.php +++ /dev/null @@ -1,138 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Require our basic test case definition - */ -require_once dirname(__FILE__) . '/../LdapBase.php'; - -/** - * Test the LDAP backend. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Structure_LdapTest extends PHPUnit_Framework_TestCase -{ - public function setUp() - { - $server = $this->getMock('Horde_Kolab_Server'); - $this->composite = new Horde_Kolab_Server_Composite( - $server, - $this->getMock('Horde_Kolab_Server_Objects'), - new Horde_Kolab_Server_Structure_Ldap(), - $this->getMock('Horde_Kolab_Server_Search'), - $this->getMock('Horde_Kolab_Server_Schema') - ); - } - - public function testMethodGetsupportedobjectsHasResultArrayTheObjectTypesSupportedByThisStructure() - { - $this->assertEquals(array('Horde_Kolab_Server_Object'), $this->composite->structure->getSupportedObjects()); - } - - public function testMethodDeterminetypeHasParameterStringGuid() - { - $this->composite->server->expects($this->exactly(1)) - ->method('read') - ->with('guid') - ->will($this->returnValue(array('objectClass' => array('TOP')))); - $this->composite->structure->determineType('guid'); - } - - public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid() - { - $this->composite->server->expects($this->exactly(1)) - ->method('read') - ->with('guid') - ->will($this->returnValue(array('objectClass' => array('TOP')))); - $this->assertEquals('Horde_Kolab_Server_Object_Top', $this->composite->structure->determineType('guid')); - } - - public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid2() - { - $this->composite->server->expects($this->exactly(1)) - ->method('read') - ->with('guid') - ->will($this->returnValue(array('objectClass' => array('person')))); - $this->assertEquals('Horde_Kolab_Server_Object_Person', $this->composite->structure->determineType('guid')); - } - - public function testMethodDeterminetypeThrowsExceptionIfTheGuidHasNoAttributeObjectclass() - { - $this->composite->server->expects($this->exactly(1)) - ->method('read') - ->with('guid') - ->will($this->returnValue(array())); - try { - $this->composite->structure->determineType('guid'); - } catch (Exception $e) { - $this->assertEquals('The object guid has no objectClass attribute!', $e->getMessage()); - $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); - } - } - - public function testMethodDeterminetypeThrowsExceptionIfTheTypeIsUnknown() - { - $this->composite->server->expects($this->exactly(1)) - ->method('read') - ->with('guid') - ->will($this->returnValue(array('objectClass' => array('UNKNOWN')))); - try { - $this->composite->structure->determineType('guid'); - } catch (Exception $e) { - $this->assertEquals('Unknown object type for GUID guid.', $e->getMessage()); - $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); - } - } - - public function testMethodGenerateserverguidHasParameterStringType() - { - $this->composite->server->expects($this->exactly(1)) - ->method('getBaseGuid') - ->will($this->returnValue('base')); - $this->composite->structure->generateServerGuid('type', '', array()); - } - - public function testMethodGenerateserverguidHasParameterStringId() - { - $this->composite->server->expects($this->exactly(1)) - ->method('getBaseGuid') - ->will($this->returnValue('base')); - $this->composite->structure->generateServerGuid('', 'id', array()); - } - - public function testMethodGenerateserverguidHasParameterArrayObjectData() - { - $this->composite->server->expects($this->exactly(1)) - ->method('getBaseGuid') - ->will($this->returnValue('base')); - $this->composite->structure->generateServerGuid('', '', array('object' => 'data')); - } - - public function testMethodGenerateserverguidHasResultStringTheGuid() - { - $this->composite->server->expects($this->exactly(1)) - ->method('getBaseGuid') - ->will($this->returnValue('base')); - $this->assertEquals('id,base', $this->composite->structure->generateServerGuid('', 'id', array())); - } -} diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/TestCase.php b/framework/Kolab_Server/test/Horde/Kolab/Server/TestCase.php index fc3ac7069..cf6805600 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/TestCase.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/TestCase.php @@ -19,7 +19,7 @@ require_once dirname(__FILE__) . '/Autoload.php'; /** * Skip LDAP based tests if we don't have ldap or Net_LDAP2. * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * Copyright 2009 The Horde Project (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.