From 4f8974460e67ac64df97fd29a9377b1b4e822236 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Wed, 4 Nov 2009 10:13:30 +0100 Subject: [PATCH] Move handling the internal side of the object attributes into the structure handler. --- .../Horde/Kolab/Server/Object/Attribute/Base.php | 84 ++---- .../Kolab/Server/Object/Attribute/Decorator.php | 39 +-- .../Server/Object/Attribute/Firstnamelastname.php | 58 ++++ .../Kolab/Server/Object/Attribute/Interface.php | 29 +- .../Horde/Kolab/Server/Object/Attribute/Locked.php | 2 +- .../Kolab/Server/Object/Attribute/Openldapaci.php | 5 +- .../Horde/Kolab/Server/Object/Attribute/Single.php | 2 +- .../Horde/Kolab/Server/Object/Attribute/Value.php | 14 +- .../lib/Horde/Kolab/Server/Object/Base.php | 66 ++--- .../lib/Horde/Kolab/Server/Object/Hash.php | 10 +- .../Horde/Kolab/Server/Object/Inetorgperson.php | 67 +---- .../lib/Horde/Kolab/Server/Object/Interface.php | 8 +- .../Kolab/Server/Object/Kolabinetorgperson.php | 28 +- .../lib/Horde/Kolab/Server/Object/Mcached.php | 10 +- .../lib/Horde/Kolab/Server/Object/Person.php | 4 +- .../lib/Horde/Kolab/Server/Object/Top.php | 6 +- .../lib/Horde/Kolab/Server/Schema/Base.php | 252 +++++++--------- .../Horde/Kolab/Server/Schema/Decorator/Cache.php | 7 +- .../lib/Horde/Kolab/Server/Schema/Interface.php | 24 -- .../Horde/Kolab/Server/Search/Operation/Guid.php | 2 +- .../Server/Search/Operation/Restrictkolab.php | 2 +- .../Kolab/Server/Structure/Attribute/Double.php | 103 +++++++ .../Kolab/Server/Structure/Attribute/Interface.php | 61 ++++ .../Kolab/Server/Structure/Attribute/Value.php | 103 +++++++ .../lib/Horde/Kolab/Server/Structure/Base.php | 64 +++++ .../lib/Horde/Kolab/Server/Structure/Interface.php | 29 ++ .../lib/Horde/Kolab/Server/Structure/Ldap.php | 161 ++++++++++- framework/Kolab_Server/package.xml | 21 ++ .../Class/Server/Connection/Mock/LdapTest.php | 320 +++++++++++++++++++++ .../Class/Server/Factory/Decorator/CountTest.php | 163 +++++++++++ .../Class/Server/Object/Attribute/BaseTest.php | 40 ++- .../Kolab/Server/Class/Server/Object/BaseTest.php | 135 ++++----- .../Class/Server/Query/Element/MappedTest.php | 171 +++++++++++ .../Class/Server/Search/Operation/GuidTest.php | 4 +- .../Server/Search/Operation/RestrictkolabTest.php | 108 +++++++ .../Server/Class/Server/Structure/LdapTest.php | 20 +- .../Kolab/Server/Integration/InetorgpersonTest.php | 74 ++--- .../Integration/KolabgermanbankarrangementTest.php | 2 +- .../Server/Integration/KolabinetorgpersonTest.php | 2 +- .../Server/Integration/Kolabpop3accountTest.php | 2 +- .../Integration/SearchguidforuidormailTest.php | 78 +++++ 41 files changed, 1791 insertions(+), 589 deletions(-) create mode 100644 framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Firstnamelastname.php create mode 100644 framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Attribute/Double.php create mode 100644 framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Attribute/Interface.php create mode 100644 framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Attribute/Value.php create mode 100644 framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/Decorator/CountTest.php create mode 100644 framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Query/Element/MappedTest.php create mode 100644 framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/RestrictkolabTest.php create mode 100644 framework/Kolab_Server/test/Horde/Kolab/Server/Integration/SearchguidforuidormailTest.php 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 3ed439d9d..c66355ee2 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 @@ -29,86 +29,52 @@ abstract class Horde_Kolab_Server_Object_Attribute_Base implements Horde_Kolab_Server_Object_Attribute_Interface { /** - * The attribute name on the internal side. + * The attribute name. * * @param string */ - protected $_internal; + protected $name; /** - * The attribute name on the external side. + * The internal attribute adapter. * - * @param string - */ - private $_external; - - /** - * The object this attribute belongs to. - * - * @param Horde_Kolab_Server_Object + * @param Horde_Kolab_Server_Structure_Attribute_Interface */ - protected $_object; - - /** - * Link to the Kolab server. - * - * @var Horde_Kolab_Server_Composite - */ - protected $_composite; + protected $attribute; /** * Constructor * - * @param Horde_Kolab_Server_Object $object The object this attribute - * belongs to. - * @param Horde_Kolab_Server_Composite $composite The link to the server. - * @param string $name The name of this attribute. + * @param Horde_Kolab_Server_Structure_Attribute_Interface $attribute The internal attribute adapter. + * @param string $name The name of this attribute. */ public function __construct( - Horde_Kolab_Server_Object_Interface $object, - Horde_Kolab_Server_Composite_Interface $composite, - $external + Horde_Kolab_Server_Structure_Attribute_Interface $attribute, + $name ) { - $this->_object = $object; - $this->_composite = $composite; - $this->_external = $external; - - $this->_internal = $this->_composite->structure->mapExternalToInternalAttribute( - $this->_external - ); + $this->attribute = $attribute; + $this->name = $name; } /** - * Return the object this attribute belongs to. + * Return the internal attribute adapter. * - * @return Horde_Kolab_Server_Object The object. + * @return Horde_Kolab_Server_Structure_Attribute_Interface The internal + * attribute. */ - public function getObject() + public function getAttribute() { - return $this->_object; + return $this->attribute; } /** - * Return the internal name of this attribute. + * Return the name of this attribute. * - * @return string The name of this object. + * @return string The name of this attribute. */ - public function getInternalName() + public function getName() { - return $this->_internal; - } - - /** - * Return the external name of this attribute. - * - * @return string The name of this object. - */ - public function getExternalName() - { - if (empty($this->_external)) { - $this->_external = substr(get_class($this), 36); - } - return $this->_external; + return $this->name; } /** @@ -120,11 +86,11 @@ implements Horde_Kolab_Server_Object_Attribute_Interface */ public function isEmpty(array $changes) { - $name = $this->getExternalName(); - if ((!in_array($name, array_keys($changes)) - || $changes[$name] === null - || $changes[$name] === '' - || $changes[$name] === array())) { + if ((!in_array($this->name, array_keys($changes)) + || $changes[$this->name] === null + || $changes[$this->name] === '' + || $changes[$this->name] === array()) + ) { return true; } return false; diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Decorator.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Decorator.php index 5e7884930..e3d58eb0e 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Decorator.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Decorator.php @@ -72,33 +72,23 @@ implements Horde_Kolab_Server_Object_Attribute_Interface } /** - * Return the object this attribute belongs to. + * Return the internal attribute adapter. * - * @return Horde_Kolab_Server_Object The object. + * @return Horde_Kolab_Server_Structure_Attribute_Interface The internal */ - public function getObject() + public function getAttribute() { - return $this->_attribute->getObject(); + return $this->_attribute->getAttribute(); } /** - * Return the internal name of this attribute. + * Return the name of this attribute. * - * @return string The name of this object. - */ - public function getInternalName() - { - return $this->_attribute->getInternalName(); - } - - /** - * Return the external name of this attribute. - * - * @return string The name of this object. + * @return string The name of this attribute. */ - public function getExternalName() + public function getName() { - return $this->_attribute->getExternalName(); + return $this->_attribute->getName(); } /** @@ -112,17 +102,4 @@ implements Horde_Kolab_Server_Object_Attribute_Interface { return $this->_attribute->isEmpty($changes); } - - /** - * Indicate that a value will be saved by deleting it from the original data - * array. - * - * @param array &$changes The object data that should be changed. - * - * @return NULL - */ - public function consume(array &$changes) - { - return $this->_attribute->consume($changes); - } } \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Firstnamelastname.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Firstnamelastname.php new file mode 100644 index 000000000..aa6b106a1 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Firstnamelastname.php @@ -0,0 +1,58 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * The name of a person in "firstname lastname" format. + * + * 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_Attribute_Firstnamelastname +extends Horde_Kolab_Server_Object_Attribute_Value +{ + /** + * Constructor + * + * @param Horde_Kolab_Server_Structure_Attribute_Interface $object The object + * this attribute belongs to. + * @param string $name The name of this attribute. + */ + public function __construct( + Horde_Kolab_Server_Structure_Attribute_Double $attribute, + $name + ) { + parent::__construct($attribute, $name); + } + + /** + * Return the value of this attribute. + * + * @return array The value(s) of this attribute. + * + * @throws Horde_Kolab_Server_Exception If retrieval of the value failed. + */ + public function value() + { + $values = $this->attribute->value(); + return sprintf('%s %s', $values[0], $values[1]); + } + +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Interface.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Interface.php index 5e3b8eb03..9036686d0 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Interface.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Interface.php @@ -48,25 +48,18 @@ interface Horde_Kolab_Server_Object_Attribute_Interface public function update(array $changes); /** - * Return the object this attribute belongs to. + * Return the internal attribute adapter. * - * @return Horde_Kolab_Server_Object The object. + * @return Horde_Kolab_Server_Structure_Attribute_Interface The internal */ - public function getObject(); + public function getAttribute(); /** - * Return the internal name of this attribute. + * Return the name of this attribute. * - * @return string The name of this object. - */ - public function getInternalName(); - - /** - * Return the external name of this attribute. - * - * @return string The name of this object. + * @return string The name of this attribute. */ - public function getExternalName(); + public function getName(); /** * Return if this attribute is undefined in the given data array. @@ -76,14 +69,4 @@ interface Horde_Kolab_Server_Object_Attribute_Interface * @return string The name of this object. */ public function isEmpty(array $changes); - - /** - * Indicate that a value will be saved by deleting it from the original data - * array. - * - * @param array &$changes The object data that should be changed. - * - * @return NULL - */ - public function consume(array &$changes); } \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Locked.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Locked.php index a3eee68de..21f43cf81 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Locked.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Locked.php @@ -49,7 +49,7 @@ extends Horde_Kolab_Server_Object_Attribute_Decorator throw new Horde_Kolab_Server_Exception( sprintf( "The value for \"%s\" may not be modified on an existing object!", - $this->_attribute->getExternalName() + $this->_attribute->getName() ) ); } diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Openldapaci.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Openldapaci.php index 309447796..ba19ed088 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Openldapaci.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Openldapaci.php @@ -28,9 +28,6 @@ class Horde_Kolab_Server_Object_Attribute_Openldapaci extends Horde_Kolab_Server_Object_Attribute_Value { - /** The attribute name */ - const NAME = 'OpenLDAPaci'; - /** * Constructor * @@ -42,6 +39,6 @@ extends Horde_Kolab_Server_Object_Attribute_Value Horde_Kolab_Server_Object $object, Horde_Kolab_Server_Composite $composite ) { - parent::__construct($object, $composite, self::NAME); + parent::__construct($object, $composite, 'Openldapaci'); } } \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Single.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Single.php index f26a3d08a..818537699 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Single.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Single.php @@ -39,7 +39,7 @@ extends Horde_Kolab_Server_Object_Attribute_Decorator { $value = $this->_attribute->value(); if (is_array($value)) { - return array_pop($value); + return array_shift($value); } else { return $value; } diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Value.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Value.php index ca478865f..0c4a76fa0 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Value.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Attribute/Value.php @@ -37,7 +37,7 @@ extends Horde_Kolab_Server_Object_Attribute_Base */ public function value() { - return $this->_object->getInternal($this->getInternalName()); + return $this->attribute->value(); } /** @@ -50,8 +50,8 @@ extends Horde_Kolab_Server_Object_Attribute_Base */ public function consume(array &$changes) { - if (isset($changes[$this->getExternalName()])) { - unset($changes[$this->getExternalName()]); + if (isset($changes[$this->name])) { + unset($changes[$this->name]); } } @@ -67,15 +67,15 @@ extends Horde_Kolab_Server_Object_Attribute_Base public function update(array $changes) { if (!$this->isEmpty($changes)) { - $value = $changes[$this->getExternalName()]; + $value = $changes[$this->name]; if (!is_array($value)) { $value = array($value); } - return array($this->getInternalName() => $value); + return $this->attribute->update($value); } try { - $old = $this->_object->getInternal($this->getInternalName()); - return array($this->getInternalName() => array()); + $old = $this->attribute->value(); + return $this->attribute->update(array()); } catch (Horde_Kolab_Server_Exception_Novalue $e) { return array(); } diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Base.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Base.php index cf89916c2..317b83948 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Base.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Base.php @@ -81,7 +81,7 @@ implements Horde_Kolab_Server_Object_Interface */ public function getExternalAttributes() { - return $this->_composite->schema->getExternalAttributes($this); + return $this->_composite->structure->getExternalAttributes($this); } /** @@ -93,7 +93,7 @@ implements Horde_Kolab_Server_Object_Interface */ public function getInternalAttributes() { - return $this->_composite->schema->getInternalAttributes($this); + return $this->_composite->structure->getInternalAttributes($this); } /** @@ -124,26 +124,30 @@ implements Horde_Kolab_Server_Object_Interface } /** - * Get the specified attribute of this object + * Get the specified internal attributes. * - * @param string $attr The attribute to read + * @param array $attributes The internal attribute. * - * @return array The value(s) of this attribute + * @return array The value(s) of these attribute */ - public function getInternal($attr) + public function getInternal(array $attributes) { - if (!in_array($attr, array_keys($this->getInternalAttributes()))) { - throw new Horde_Kolab_Server_Exception( - sprintf("Attribute \"%s\" not supported!", $attr) - ); - } $result = $this->readInternal(); - if (!isset($result[$attr])) { - throw new Horde_Kolab_Server_Exception_Novalue( - sprintf("No value for attribute \"%s\"!", $attr) - ); + + $values = array(); + foreach ($attributes as $attribute) { + + if (!isset($result[$attribute])) { + throw new Horde_Kolab_Server_Exception_Novalue( + sprintf( + "No value for attribute \"%s\"!", + $attribute + ) + ); + } + $values[$attribute] = $result[$attribute]; } - return $result[$attr]; + return $values; } /** @@ -155,16 +159,14 @@ implements Horde_Kolab_Server_Object_Interface */ public function getExternal($attr) { - $attr = ucfirst($attr); - $class = 'Horde_Kolab_Server_Object_Attribute_' . $attr; - if (!in_array($attr, $this->getExternalAttributes()) - || !class_exists($class)) { - //@todo: Consider support for external classes. + if (!in_array($attr, $this->getExternalAttributes())) { throw new Horde_Kolab_Server_Exception( sprintf("Attribute \"%s\" not supported!", $attr) ); } - $attribute = new $class($this, $this->_composite); + $attribute = $this->_composite->structure->getExternalAttribute( + $attr, $this + ); return $attribute->value(); } @@ -217,24 +219,12 @@ implements Horde_Kolab_Server_Object_Interface protected function getNewInternal($info) { $internal = array(); - $consumed = $info; - $attributes = $this->getInternalAttributes(); - foreach (array_values($attributes) as $class) { - $attribute = new $class($this, $this->_composite); - $internal = array_merge($internal, $attribute->update($info)); - $attribute->consume($consumed); - } - - /** Check if all given data would be used for saving */ - if (!empty($consumed)) { - throw new Horde_Kolab_Server_Exception( - sprintf( - "Not all data would be saved. Leftover keys: %s.", - join(',', array_keys($consumed)) - ) + foreach ($info as $external => $value) { + $attribute = $this->_composite->structure->getExternalAttribute( + $external, $this ); + $internal = array_merge($internal, $attribute->update($info)); } - return $internal; } diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Hash.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Hash.php index c8486b9a3..2eef350f8 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Hash.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Hash.php @@ -100,15 +100,15 @@ implements Horde_Kolab_Server_Object_Interface } /** - * Get the specified attribute of this object + * Get the specified internal attributes. * - * @param string $attr The attribute to read + * @param array $attributes The internal attribute. * - * @return array The value(s) of this attribute + * @return array The value(s) of these attribute */ - public function getInternal($attr) + public function getInternal(array $attributes) { - return $this->_object->getInternal($attr); + return $this->_object->getInternal($attributes); } /** diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Inetorgperson.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Inetorgperson.php index 8255c5fb1..4e8d8d6c9 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Inetorgperson.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Inetorgperson.php @@ -27,63 +27,23 @@ */ class Horde_Kolab_Server_Object_Inetorgperson extends Horde_Kolab_Server_Object_Organizationalperson { - /** Define attributes specific to this object type */ - - /** The short ID */ - const ATTRIBUTE_SID = 'uid'; - - /** The organization / company */ - const ATTRIBUTE_ORGANIZATION = 'o'; - - /** The business category */ - const ATTRIBUTE_BUSINESSCATEGORY = 'businessCategory'; - - /** The phone number at home*/ - const ATTRIBUTE_HOMEPHONE = 'homePhone'; - - /** The mobile phone number */ - const ATTRIBUTE_MOBILE = 'mobile'; - - /** The photo attribute */ - const ATTRIBUTE_PHOTO = 'photo'; - - /** The photo in JPEG format */ - const ATTRIBUTE_JPEGPHOTO = 'jpegPhoto'; - - /** The given name */ - const ATTRIBUTE_GIVENNAME = 'givenName'; - - /** Middle names */ - const ATTRIBUTE_MIDDLENAMES = 'middleNames'; - - /** The mail address of this person */ - const ATTRIBUTE_MAIL = 'mail'; - - /** Home addresses */ - const ATTRIBUTE_HOMEPOSTALADDRESS = 'homePostalAddress'; - - /** Home addresses as array */ - const ATTRARRAY_HOMEPOSTALADDRESS = 'homePostalAddressArray'; - - /** Labeled URI */ - const ATTRIBUTE_LABELEDURI = 'labeledURI'; - - /** Labeled URIs as array */ - const ATTRARRAY_LABELEDURI = 'labeledURIArray'; - - /** The last name followed by the first name */ - const ATTRIBUTE_LNFN = 'lnfn'; - - /** The first name followed by the last name */ - const ATTRIBUTE_FNLN = 'fnln'; - - /** The SMIME certificate for the user */ - const ATTRIBUTE_SMIMECERTIFICATE = 'userSMIMECertificate'; - /** The specific object class of this object type */ const OBJECTCLASS_INETORGPERSON = 'inetOrgPerson'; /** + * The attributes defined for this class. + * + * @var array + */ + static public $attributes = array( + 'Uid', 'Mail','Firstnamelastname', +/* 'Organization', 'Businesscategory', 'Homephone', 'Mobile', */ +/* 'Photo', 'Jpegphoto', 'Givenname', 'Middlenames', */ +/* 'Homepostaladdress', 'Labeleduri', 'Lastnamefirstname', */ +/* 'Usersmimecertificate' */ + ); + + /** * A structure to initialize the attribute structure for this class. * * @var array @@ -92,7 +52,6 @@ class Horde_Kolab_Server_Object_Inetorgperson extends Horde_Kolab_Server_Object_ /* 'defined' => array( */ /* self::ATTRIBUTE_SID, */ /* self::ATTRIBUTE_GIVENNAME, */ -/* self::ATTRIBUTE_MAIL, */ /* self::ATTRIBUTE_LABELEDURI, */ /* self::ATTRIBUTE_HOMEPOSTALADDRESS, */ /* self::ATTRIBUTE_ORGANIZATION, */ diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Interface.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Interface.php index c82fc53bf..2d1bf0069 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Interface.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Interface.php @@ -66,13 +66,13 @@ interface Horde_Kolab_Server_Object_Interface public function readInternal(); /** - * Get the specified attribute of this object + * Get the specified internal attributes. * - * @param string $attr The attribute to read + * @param array $attributes The internal attribute. * - * @return array The value(s) of this attribute + * @return array The value(s) of these attribute */ - public function getInternal($attr); + public function getInternal(array $attributes); /** * Get the specified attribute of this object. 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 9a4c3a1f0..acc3b7b9e 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabinetorgperson.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabinetorgperson.php @@ -38,19 +38,20 @@ class Horde_Kolab_Server_Object_Kolabinetorgperson extends Horde_Kolab_Server_Ob * @var array */ 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', + 'Alias', 'Kolabhomeserver', 'Kolabfreebusyhost' +/* 'kolabDelegate', 'kolabDeleteFlag', 'kolabFreeBusyFuture', */ +/* , , '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', */ ); @@ -61,7 +62,6 @@ class Horde_Kolab_Server_Object_Kolabinetorgperson extends Horde_Kolab_Server_Ob */ /* static public $init_attributes = array( */ /* 'defined' => array( */ -/* self::ATTRIBUTE_ALIAS, */ /* self::ATTRIBUTE_DELEGATE, */ /* self::ATTRIBUTE_DELETED, */ /* self::ATTRIBUTE_FBFUTURE, */ diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Mcached.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Mcached.php index 74eeaba06..95c4ce61c 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Mcached.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Mcached.php @@ -167,15 +167,13 @@ implements Horde_Kolab_Server_Object_Interface } /** - * Get the specified attribute of this object + * Get the specified internal attributes. * - * @param string $attr The attribute to read - * @param boolean $single Should a single value be returned - * or are multiple values allowed? + * @param array $attributes The internal attribute. * - * @return string the value of this attribute + * @return array The value(s) of these attribute */ - public function getInternal($attr) + public function getInternal(array $attributes) { if (!isset($this->_cache_int[$attr])) { if (!in_array($attr, array_keys($this->getInternalAttributes()))) { 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 5d117d135..e5b37295b 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Person.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Person.php @@ -36,7 +36,9 @@ class Horde_Kolab_Server_Object_Person extends Horde_Kolab_Server_Object_Top * @var array */ static public $init_attributes = array( - 'Cn', 'Sn', 'Userpassword', 'Userpasswordraw', 'Telephonenumber' + 'Cn', 'Sn', 'Userpassword', 'Userpasswordraw', +/* 'Telephonenumber' */ + /* 'defined' => array( */ /* self::ATTRIBUTE_CN, */ /* self::ATTRIBUTE_SN, */ 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 00a61fd29..b213a294d 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Top.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Top.php @@ -40,9 +40,9 @@ implements Horde_Kolab_Server_Object_Searches * @var array */ static public $attributes = array( - 'Objectclass', 'Openldapaci', 'Guid', 'Id', - 'Createtimestamp', 'Modifyimestamp', - 'Createtimestampdate', 'Modifyimestampdate', + 'objectClass', 'Openldapaci', 'Guid', 'Id', + 'Createtimestamp', 'Modifytimestamp', + 'Createtimestampdate', 'Modifytimestampdate', ); static public $object_classes = array( diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Schema/Base.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Schema/Base.php index 5ac063d80..9435cf88a 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Schema/Base.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Schema/Base.php @@ -28,15 +28,12 @@ class Horde_Kolab_Server_Schema_Base implements Horde_Kolab_Server_Schema_Interface { - /** Maximum accepted level for the object class hierarchy */ - const MAX_HIERARCHY = 100; - /** * A link to the composite server handler. * * @var Horde_Kolab_Server_Composite */ - protected $composite; + private $_composite; /** * Set the composite server reference for this object. @@ -49,7 +46,7 @@ implements Horde_Kolab_Server_Schema_Interface public function setComposite( Horde_Kolab_Server_Composite_Interface $composite ) { - $this->composite = $composite; + $this->_composite = $composite; } /** @@ -103,155 +100,126 @@ implements Horde_Kolab_Server_Schema_Interface */ public function getExternalAttributes($class) { - if (!isset($this->attributes)) { - if (isset($this->cache)) { - register_shutdown_function(array($this, 'shutdown')); - } + $childclass = get_class($class); + $classes = array(); + $level = 0; + while ($childclass != 'Horde_Kolab_Server_Object_Top' + && $level < self::MAX_HIERARCHY) { + $classes[] = $childclass; + $childclass = get_parent_class($childclass); + $level++; } - if (empty($this->attributes[$class])) { - - if (isset($this->cache)) { - $this->attributes[$class] = @unserialize($cache->get('attributes_' . $class, - $this->params['cache_lifetime'])); - } - if (empty($this->attributes[$class])) { + /** Finally add the basic object class */ + $classes[] = $childclass; - $childclass = $class; - $classes = array(); - $level = 0; - while ($childclass != 'Horde_Kolab_Server_Object' - && $level < self::MAX_HIERARCHY) { - $classes[] = $childclass; - $childclass = get_parent_class($childclass); - $level++; - } + //@todo: Throw exception here + if ($level == self::MAX_HIERARCHY) { + if (isset($this->logger)) { + $logger->err(sprintf('The maximal level of the object hierarchy has been exceeded for class \"%s\"!', + $class)); + } + } - /** Finally add the basic object class */ - $classes[] = $childclass; + /** + * Collect attributes from bottom to top. + */ + $classes = array_reverse($classes); - if ($level == self::MAX_HIERARCHY) { - if (isset($this->logger)) { - $logger->err(sprintf('The maximal level of the object hierarchy has been exceeded for class \"%s\"!', - $class)); - } - } + $attributes = array(); + foreach ($classes as $childclass) { + $vars = get_class_vars($childclass); + if (isset($vars['attributes'])) { /** - * Collect attributes from bottom to top. + * If the user wishes to adhere to the schema + * information from the server we will skip the + * attributes defined within the object class here. */ - $classes = array_reverse($classes); - - $types = array('defined', 'required', 'derived', 'collapsed', - 'defaults', 'locked', 'object_classes'); - foreach ($types as $type) { - $$type = array(); - } - - foreach ($classes as $childclass) { - $vars = get_class_vars($childclass); - if (isset($vars['init_attributes'])) { - foreach ($types as $type) { - /** - * If the user wishes to adhere to the schema - * information from the server we will skip the - * attributes defined within the object class here. - */ - if (!empty($this->params['schema_override']) - && in_array($type, 'defined', 'required')) { - continue; - } - if (isset($vars['init_attributes'][$type])) { - $$type = array_merge($$type, - $vars['init_attributes'][$type]); - } - } - } - } - - $attrs = array(); - - foreach ($object_classes as $object_class) { - $info = $this->getObjectclassSchema($object_class); - if (isset($info['may'])) { - $defined = array_merge($defined, $info['may']); - } - if (isset($info['must'])) { - $defined = array_merge($defined, $info['must']); - $required = array_merge($required, $info['must']); - } - foreach ($defined as $attribute) { - try { - $attrs[$attribute] = $this->getAttributeSchema($attribute); - } catch (Horde_Kolab_Server_Exception $e) { - /** - * If the server considers the attribute to be - * invalid we mark it. - */ - $attrs[$attribute] = array('invalid' => true); - } - } - foreach ($required as $attribute) { - $attrs[$attribute]['required'] = true; - } - foreach ($locked as $attribute) { - $attrs[$attribute]['locked'] = true; - } - foreach ($defaults as $attribute => $default) { - $attrs[$attribute]['default'] = $default; - } - $attrs[Horde_Kolab_Server_Object::ATTRIBUTE_OC]['default'] = $object_classes; - } - foreach ($derived as $key => $attributes) { - $supported = true; - if (isset($attributes['base'])) { - foreach ($attributes['base'] as $attribute) { - /** - * Usually derived attribute are determined on basis - * of one or more attributes. If any of these is not - * supported the derived attribute should not be - * included into the set of supported attributes. - */ - if (!isset($attrs[$attribute])) { - unset($derived[$attribute]); - $supported = false; - break; - } - } - } - if ($supported) { - $attrs[$key] = $attributes; - } - } - $check_collapsed = $collapsed; - foreach ($check_collapsed as $key => $attributes) { - if (isset($attributes['base'])) { - foreach ($attributes['base'] as $attribute) { - /** - * Usually collapsed attribute are determined on basis - * of one or more attributes. If any of these is not - * supported the collapsed attribute should not be - * included into the set of supported attributes. - */ - if (!isset($attrs[$attribute])) { - unset($collapsed[$attribute]); - } - } - } + if (!empty($this->params['schema_override'])) { + continue; } - $this->attributes[$class] = array($attrs, - array( - 'derived' => array_keys($derived), - 'collapsed' => $collapsed, - 'locked' => $locked, - 'required' => $required)); + $attributes = array_merge($vars['attributes'], $attributes); } } - return $this->attributes[$class]; - } - public function getInternalAttributes($class) - { +/* $attrs = array(); */ + +/* foreach ($object_classes as $object_class) { */ +/* $info = $this->getObjectclassSchema($object_class); */ +/* if (isset($info['may'])) { */ +/* $defined = array_merge($defined, $info['may']); */ +/* } */ +/* if (isset($info['must'])) { */ +/* $defined = array_merge($defined, $info['must']); */ +/* $required = array_merge($required, $info['must']); */ +/* } */ +/* foreach ($defined as $attribute) { */ +/* try { */ +/* $attrs[$attribute] = $this->getAttributeSchema($attribute); */ +/* } catch (Horde_Kolab_Server_Exception $e) { */ +/* /\** */ +/* * If the server considers the attribute to be */ +/* * invalid we mark it. */ +/* *\/ */ +/* $attrs[$attribute] = array('invalid' => true); */ +/* } */ +/* } */ +/* foreach ($required as $attribute) { */ +/* $attrs[$attribute]['required'] = true; */ +/* } */ +/* foreach ($locked as $attribute) { */ +/* $attrs[$attribute]['locked'] = true; */ +/* } */ +/* foreach ($defaults as $attribute => $default) { */ +/* $attrs[$attribute]['default'] = $default; */ +/* } */ +/* $attrs[Horde_Kolab_Server_Object::ATTRIBUTE_OC]['default'] = $object_classes; */ +/* } */ +/* foreach ($derived as $key => $attributes) { */ +/* $supported = true; */ +/* if (isset($attributes['base'])) { */ +/* foreach ($attributes['base'] as $attribute) { */ +/* /\** */ +/* * Usually derived attribute are determined on basis */ +/* * of one or more attributes. If any of these is not */ +/* * supported the derived attribute should not be */ +/* * included into the set of supported attributes. */ +/* *\/ */ +/* if (!isset($attrs[$attribute])) { */ +/* unset($derived[$attribute]); */ +/* $supported = false; */ +/* break; */ +/* } */ +/* } */ +/* } */ +/* if ($supported) { */ +/* $attrs[$key] = $attributes; */ +/* } */ +/* } */ +/* $check_collapsed = $collapsed; */ +/* foreach ($check_collapsed as $key => $attributes) { */ +/* if (isset($attributes['base'])) { */ +/* foreach ($attributes['base'] as $attribute) { */ +/* /\** */ +/* * Usually collapsed attribute are determined on basis */ +/* * of one or more attributes. If any of these is not */ +/* * supported the collapsed attribute should not be */ +/* * included into the set of supported attributes. */ +/* *\/ */ +/* if (!isset($attrs[$attribute])) { */ +/* unset($collapsed[$attribute]); */ +/* } */ +/* } */ +/* } */ +/* } */ +/* $this->attributes[$class] = array($attrs, */ +/* array( */ +/* 'derived' => array_keys($derived), */ +/* 'collapsed' => $collapsed, */ +/* 'locked' => $locked, */ +/* 'required' => $required)); */ + return $attributes; } /** diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Schema/Decorator/Cache.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Schema/Decorator/Cache.php index ef2bfc6b7..b24704989 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Schema/Decorator/Cache.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Schema/Decorator/Cache.php @@ -25,7 +25,7 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Schema_Base +class Horde_Kolab_Server_Schema_Decorator_Cache implements Horde_Kolab_Server_Schema_Interface { /** Maximum accepted level for the object class hierarchy */ @@ -53,8 +53,9 @@ implements Horde_Kolab_Server_Schema_Interface * * @return NULL */ - public function setComposite(Horde_Kolab_Server_Composite $composite) - { + public function setComposite( + Horde_Kolab_Server_Composite_Interface $composite + ) { $this->composite = $composite; } diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Schema/Interface.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Schema/Interface.php index 23b26a78f..d2bb1dad5 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Schema/Interface.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Schema/Interface.php @@ -58,28 +58,4 @@ interface Horde_Kolab_Server_Schema_Interface * @throws Horde_Kolab_Server_Exception If retrieval of the schema failed. */ public function getAttributeSchema($attribute); - - /** - * Return the external attributes supported by the given object class. - * - * @param Horde_Kolab_Server_Object $object Determine the external - * attributes for this class. - * - * @return array The supported attributes. - * - * @throws Horde_Kolab_Server_Exception If the schema analysis fails. - */ - public function getExternalAttributes($object); - - /** - * Return the internal attributes supported by the given object class. - * - * @param Horde_Kolab_Server_Object $object Determine the internal - * attributes for this class. - * - * @return array The supported attributes. - * - * @throws Horde_Kolab_Server_Exception If the schema analysis fails. - */ - public function getInternalAttributes($object); } \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guid.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guid.php index ffc646694..bb110b561 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guid.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guid.php @@ -39,7 +39,7 @@ extends Horde_Kolab_Server_Search_Operation_Base Horde_Kolab_Server_Query_Element_Interface $criteria ) { $params = array( - 'attributes' => 'Guid' + 'attributes' => 'guid' ); $data = $this->getStructure()->find($criteria, $params); return self::guidFromResult($data); diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Restrictkolab.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Restrictkolab.php index 470ec0c14..273e7c759 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Restrictkolab.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Restrictkolab.php @@ -43,7 +43,7 @@ extends Horde_Kolab_Server_Search_Operation_Guid $criteria = new Horde_Kolab_Server_Query_Element_And( array( new Horde_Kolab_Server_Query_Element_Equals( - 'Objectclass', + 'objectClass', Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON ), $criteria diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Attribute/Double.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Attribute/Double.php new file mode 100644 index 000000000..cba38b8b7 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Attribute/Double.php @@ -0,0 +1,103 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * An adapter for attributes that rely on two internal Kolab object attributes. + * + * 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_Structure_Attribute_Double +implements Horde_Kolab_Server_Structure_Attribute_Interface +{ + /** + * The attribute names. + * + * @param array + */ + protected $names; + + /** + * The object the attribute belongs to. + * + * @param Horde_Kolab_Server_Object_Interface + */ + protected $object; + + /** + * Constructor + * + * @param Horde_Kolab_Server_Object_Interface $object The object + * this attribute belongs to. + * @param string $name The name of this attribute. + */ + public function __construct( + Horde_Kolab_Server_Object_Interface $object, + array $names + ) { + $this->object = $object; + $this->names = $names; + } + + /** + * Return the internal attribute adapter. + * + * @return Horde_Kolab_Server_Object_Interface The object the attribute belongs to. + */ + public function getObject() + { + return $this->object; + } + + /** + * Return the name of this attribute. + * + * @return string The name of this attribute. + */ + public function getName() + { + return $this->names; + } + + /** + * Return the value of this attribute. + * + * @return array The value of the attribute + */ + public function value() + { + return $this->object->getInternal($this->names); + } + + /** + * Return the new internal state for this attribute. + * + * @param array $changes The object data that should be updated. + * + * @return array The resulting internal state. + * + * @throws Horde_Kolab_Server_Exception If storing the value failed. + */ + public function update(array $changes) + { + return array(); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Attribute/Interface.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Attribute/Interface.php new file mode 100644 index 000000000..ed7ac6066 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Attribute/Interface.php @@ -0,0 +1,61 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * The interface describing internal Kolab object attributes. + * + * 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 + */ +interface Horde_Kolab_Server_Structure_Attribute_Interface +{ + /** + * Return the internal attribute adapter. + * + * @return Horde_Kolab_Server_Object_Interface The object the attribute belongs to. + */ + public function getObject(); + + /** + * Return the name of this attribute. + * + * @return string The name of this attribute. + */ + public function getName(); + + /** + * Return the value of this attribute. + * + * @return array The value of the attribute + */ + public function value(); + + /** + * Return the new internal state for this attribute. + * + * @param array $changes The object data that should be updated. + * + * @return array The resulting internal state. + * + * @throws Horde_Kolab_Server_Exception If storing the value failed. + */ + public function update(array $changes); +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Attribute/Value.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Attribute/Value.php new file mode 100644 index 000000000..594a7b785 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Attribute/Value.php @@ -0,0 +1,103 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * The base class representing internal Kolab object attributes. + * + * 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_Structure_Attribute_Value +implements Horde_Kolab_Server_Structure_Attribute_Interface +{ + /** + * The attribute name. + * + * @param string + */ + protected $name; + + /** + * The object the attribute belongs to. + * + * @param Horde_Kolab_Server_Object_Interface + */ + protected $object; + + /** + * Constructor + * + * @param Horde_Kolab_Server_Object_Interface $object The object + * this attribute belongs to. + * @param string $name The name of this attribute. + */ + public function __construct( + Horde_Kolab_Server_Object_Interface $object, + $name + ) { + $this->object = $object; + $this->name = $name; + } + + /** + * Return the internal attribute adapter. + * + * @return Horde_Kolab_Server_Object_Interface The object the attribute belongs to. + */ + public function getObject() + { + return $this->object; + } + + /** + * Return the name of this attribute. + * + * @return string The name of this attribute. + */ + public function getName() + { + return $this->name; + } + + /** + * Return the value of this attribute. + * + * @return array The value of the attribute + */ + public function value() + { + return $this->object->getInternal((array) $this->name); + } + + /** + * Return the new internal state for this attribute. + * + * @param array $changes The object data that should be updated. + * + * @return array The resulting internal state. + * + * @throws Horde_Kolab_Server_Exception If storing the value failed. + */ + public function update(array $changes) + { + return array(); + } +} \ No newline at end of file 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 565b4a6a6..3a8cdfbaf 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Base.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Base.php @@ -28,6 +28,9 @@ abstract class Horde_Kolab_Server_Structure_Base implements Horde_Kolab_Server_Structure_Interface { + /** Maximum accepted level for the object class hierarchy */ + const MAX_HIERARCHY = 100; + /** * A link to the composite server handler. * @@ -101,4 +104,65 @@ implements Horde_Kolab_Server_Structure_Interface { return $this->_composite; } + + /** + * Return the attributes supported by the given object class. + * + * @param string $class Determine the attributes for this class. + * + * @return array The supported attributes. + * + * @throws Horde_Kolab_Server_Exception If the schema analysis fails. + */ + public function getExternalAttributes($class) + { + $childclass = get_class($class); + $classes = array(); + $level = 0; + while ($childclass != 'Horde_Kolab_Server_Object_Top' + && $level < self::MAX_HIERARCHY) { + $classes[] = $childclass; + $childclass = get_parent_class($childclass); + $level++; + } + + /** Finally add the basic object class */ + $classes[] = $childclass; + + //@todo: Throw exception here + if ($level == self::MAX_HIERARCHY) { + if (isset($this->logger)) { + $logger->err(sprintf('The maximal level of the object hierarchy has been exceeded for class \"%s\"!', + $class)); + } + } + + /** + * Collect attributes from bottom to top. + */ + $classes = array_reverse($classes); + + $attributes = array(); + + foreach ($classes as $childclass) { + $vars = get_class_vars($childclass); + if (isset($vars['attributes'])) { + $attributes = array_merge($vars['attributes'], $attributes); + } + } + + return $attributes; + } + + + public function getInternalAttributes($class) + { + $external = $this->getExternalAttributes($class); + return $this->mapExternalToInternalAttributes($external); + } + + public function getInternalAttributesForExternal($class, $external) + { + return $this->mapExternalToInternalAttributes((array) $external); + } } diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Interface.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Interface.php index a6a2ebc11..7f9ff245d 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Interface.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Interface.php @@ -96,6 +96,35 @@ interface Horde_Kolab_Server_Structure_Interface public function mapExternalToInternalAttribute($external); /** + * Return the external attributes supported by the given object class. + * + * @param Horde_Kolab_Server_Object $object Determine the external + * attributes for this class. + * + * @return array The supported attributes. + * + * @throws Horde_Kolab_Server_Exception If the schema analysis fails. + */ + public function getExternalAttributes($object); + + /** + * Return the internal attributes supported by the given object class. + * + * @param Horde_Kolab_Server_Object $object Determine the internal + * attributes for this class. + * + * @return array The supported attributes. + * + * @throws Horde_Kolab_Server_Exception If the schema analysis fails. + */ + public function getInternalAttributes($object); + + public function getExternalAttribute( + $name, + Horde_Kolab_Server_Object_Interface $object + ); + + /** * Determine the type of an object by its tree position and other * parameters. * 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 bf047c2a6..911e803bf 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Ldap.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Ldap.php @@ -147,28 +147,173 @@ class Horde_Kolab_Server_Structure_Ldap extends Horde_Kolab_Server_Structure_Bas return $result; } + public function getExternalAttribute( + $name, + Horde_Kolab_Server_Object_Interface $object + ) { + $class = ucfirst(strtolower($name)); + $object_attribute_class = 'Horde_Kolab_Server_Object_Attribute_' + . $class; + $structure_attribute_class = 'Horde_Kolab_Server_Structure_Attribute_' + . $class; + + if (class_exists($structure_attribute_class)) { + $structure_attribute = new $structure_attribute_class($object, $name); + } else { + switch ($name) { + case 'Firstnamelastname': + $structure_attribute = new Horde_Kolab_Server_Structure_Attribute_Double( + $object, array('givenName', 'sn') + ); + break; + default: + $structure_attribute = new Horde_Kolab_Server_Structure_Attribute_Value( + $object, $name + ); + break; + } + } + + switch ($name) { + case 'objectClass': + $structure_attribute = new Horde_Kolab_Server_Structure_Attribute_Locked( + $structure_attribute + ); + default: + break; + } + + + if (class_exists($object_attribute_class)) { + $object_attribute = new $object_attribute_class($structure_attribute, $name); + } else { + switch ($name) { + default: + $object_attribute = new Horde_Kolab_Server_Object_Attribute_Value( + $structure_attribute, $name + ); + break; + } + } + +/* case 'Guid': */ +/* return 'dn'; */ +/* case 'Uid': */ +/* return 'uid'; */ +/* case 'Mail': */ +/* return 'mail'; */ +/* case 'Alias': */ +/* return 'alias'; */ +/* case 'Delegate': */ +/* return 'kolabDelegate'; */ +/* case 'Firstnamelastname': */ +/* return array('givenName', 'sn'); */ +/* case 'Openldapaci': */ +/* return 'openLDAPaci'; */ +/* case 'Kolabhomeserver': */ +/* return 'kolabHomeServer'; */ +/* case 'Kolabfreebusyhost': */ +/* //@todo: rename to kolabFreeBusyService(Url) */ +/* return 'kolabFreeBusyServer'; */ +/* case 'Createtimestamp': */ +/* case 'Createtimestampdate': */ +/* return 'createTimeStamp'; */ +/* case 'Modifytimestamp': */ +/* case 'Modifytimestampdate': */ +/* return 'modifyTimeStamp'; */ +/* case 'Id': */ +/* return null; */ +/* default: */ +/* throw new Horde_Kolab_Server_Exception( */ +/* sprintf('Undefined internal attribute "%s"', $external) */ +/* ); */ +/* } */ + + return $object_attribute; + } + /** - * Maps the external attribute name to its internal counterpart. + * Maps the external attribute name to its internal counterpart(s). * * @param string $external The external attribute name. * - * @return string The internal attribute name. + * @return string The internal attribute name(s). */ - public function mapExternalToInternalAttribute($external) + private function _mapExternalToInternal($external) { switch ($external) { - case 'Objectclass': - return 'objectClass'; case 'Guid': return 'dn'; case 'Uid': return 'uid'; case 'Mail': return 'mail'; + case 'Alias': + return 'alias'; + case 'Delegate': + return 'kolabDelegate'; + case 'Firstnamelastname': + return array('givenName', 'sn'); + case 'Openldapaci': + return 'openLDAPaci'; + case 'Kolabhomeserver': + return 'kolabHomeServer'; + case 'Kolabfreebusyhost': + //@todo: rename to kolabFreeBusyService(Url) + return 'kolabFreeBusyServer'; + case 'Createtimestamp': + case 'Createtimestampdate': + return 'createTimeStamp'; + case 'Modifytimestamp': + case 'Modifytimestampdate': + return 'modifyTimeStamp'; + case 'Id': + return null; default: - throw new Horde_Kolab_Server_Exception( - sprintf('Undefined internal attribute "%s"', $external) - ); + return $external; } } + + /** + * Maps the external attribute name to its internal counterpart. + * + * @param string $external The external attribute name. + * + * @return string The internal attribute name. + */ + public function mapExternalToInternalAttribute($external) + { + $internal = $this->_mapExternalToInternal($external); + if (is_string($internal)) { + return $internal; + } else if (is_array($internal)) { + throw new Horde_Kolab_Server_Exception('Multiple internal attributes!'); + } else if ($internal === null) { + throw new Horde_Kolab_Server_Exception('No internal attribute mapping!'); + } + throw new Horde_Kolab_Server_Exception( + sprintf( + 'Invalid internal attribute mapping: %s', + print_r($internal, true) + ) + ); + } + + /** + * Maps the external attribute names to their internal counterparts. + * + * @param string $external The external attribute names. + * + * @return string The internal attribute names. + */ + public function mapExternalToInternalAttributes(array $external) + { + $result = array(); + foreach ($external as $attribute) { + $internal = $this->_mapExternalToInternal($attribute); + $result = array_merge($result, (array) $internal); + } + $result = array_unique($result); + return $result; + } } diff --git a/framework/Kolab_Server/package.xml b/framework/Kolab_Server/package.xml index 89d8a1084..861c45988 100644 --- a/framework/Kolab_Server/package.xml +++ b/framework/Kolab_Server/package.xml @@ -115,6 +115,10 @@ http://pear.php.net/dtd/package-2.0.xsd"> + + + + @@ -122,6 +126,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + @@ -222,6 +227,11 @@ http://pear.php.net/dtd/package-2.0.xsd"> + + + + + @@ -376,26 +386,34 @@ http://pear.php.net/dtd/package-2.0.xsd"> + + + + + + + + @@ -464,6 +482,9 @@ http://pear.php.net/dtd/package-2.0.xsd"> + + + diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Connection/Mock/LdapTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Connection/Mock/LdapTest.php index 93f4c6779..6199e2df2 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Connection/Mock/LdapTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Connection/Mock/LdapTest.php @@ -82,6 +82,26 @@ extends Horde_Kolab_Server_LdapTestCase array('att' => 'b', 'log' => '=', 'val' => '1'), )), $a); + try { + $a = $conn->parse('dummy'); + $this->fail('No exception!'); + } catch (Horde_Kolab_Server_Exception $e) { + $this->assertEquals('Filter parsing error: dummy - filter components must be enclosed in round brackets', $e->getMessage()); + } + + try { + $a = $conn->parse('(a/b)'); + $this->fail('No exception!'); + } catch (Horde_Kolab_Server_Exception $e) { + $this->assertEquals('Filter parsing error: invalid filter syntax - unknown matching rule used', $e->getMessage()); + } + + try { + $a = $conn->parse('(a=b)(c=d)'); + $this->fail('No exception!'); + } catch (Horde_Kolab_Server_Exception $e) { + $this->assertEquals('Filter parsing error: invalid filter syntax - multiple leaf components detected!', $e->getMessage()); + } } /** @@ -192,6 +212,33 @@ extends Horde_Kolab_Server_LdapTestCase $a->as_struct() ); + $a = $conn->search(null, '(|(a=1)(b=2))', array('attributes' => array('a', 'b'))); + $this->assertEquals( + array( + 'cn=a' => array( + 'a' => '1', + 'b' => '1', + 'dn' => 'cn=a', + ), + 'cn=b' => array( + 'a' => '1', + 'b' => '2', + 'dn' => 'cn=b', + ), + 'cn=c' => array( + 'a' => '1', + 'b' => '2', + 'dn' => 'cn=c', + ), + 'cn=d' => array( + 'a' => '2', + 'b' => '2', + 'dn' => 'cn=d', + ) + ), + $a->as_struct() + ); + $a = $conn->search(null, '(&(b=2))', array('attributes' => array('b'))); $this->assertEquals( array( @@ -233,6 +280,279 @@ extends Horde_Kolab_Server_LdapTestCase ), $a->as_struct() ); + + $a = $conn->search(null, '(c=t)', array('attributes' => array('a'))); + $this->assertEquals( + array(), + $a->as_struct() + ); + + try { + $a = $conn->search(null, '(c>t)', array('attributes' => array('a'))); + $this->fail('No exception!'); + } catch (Horde_Kolab_Server_Exception $e) { + $this->assertEquals('Not implemented!', $e->getMessage()); + } + } + + public function testMethodBindHasPostconditionThatBindingOccursWithDefaultDnAndPwIfSpecified() + { + $conn = new Horde_Kolab_Server_Connection_Mock_Ldap( + array('binddn' => 'test', 'bindpw' => 'test'), + array() + ); + try { + $conn->bind('', ''); + $this->fail('No exception!'); + } catch (Horde_Kolab_Server_Exception $e) { + $this->assertEquals('User does not exist!', $e->getMessage()); + } + } + + public function testMethodBindThrowsExceptionIfTheUserDoesNotExist() + { + $this->testMethodBindHasPostconditionThatBindingOccursWithDefaultDnAndPwIfSpecified(); + } + + public function testMethodBindThrowsExceptionIfTheUserHasNoPassword() + { + $conn = new Horde_Kolab_Server_Connection_Mock_Ldap( + array('binddn' => 'test', 'bindpw' => 'test'), + array('test' => + array('data' => + array() + ) + ) + ); + try { + $conn->bind('', ''); + $this->fail('No exception!'); + } catch (Horde_Kolab_Server_Exception $e) { + $this->assertEquals('User has no password entry!', $e->getMessage()); + } + } + + public function testMethodBindThrowsExceptionIfThePasswordWasIncorrect() + { + $conn = new Horde_Kolab_Server_Connection_Mock_Ldap( + array('binddn' => 'test', 'bindpw' => 'test'), + array('test' => + array('data' => + array( + 'userPassword' => array('something') + ) + ) + ) + ); + try { + $conn->bind('', ''); + $this->fail('No exception!'); + } catch (Horde_Kolab_Server_Exception $e) { + $this->assertEquals('Incorrect password!', $e->getMessage()); + } + } + + public function testMethodBindThrowsExceptionIfAnonymousLoginIsDisabledAndTheDnIsUnset() + { + $conn = new Horde_Kolab_Server_Connection_Mock_Ldap( + array('no_anonymous_bind' => true), + array() + ); + try { + $conn->bind('', ''); + $this->fail('No exception!'); + } catch (Horde_Kolab_Server_Exception $e) { + $this->assertEquals('Anonymous bind is not allowed!', $e->getMessage()); + } + } + + public function testMethodSearchHasResultMocksearchSingleElementIfNoFilterIsSetAndSearchScopeIsBase() + { + $conn = new Horde_Kolab_Server_Connection_Mock_Ldap( + array(), + array('test' => + array('dn' => 'test', + 'data' => + array( + 'userPassword' => array('something') + ) + ), + 'testnot' => + array('dn' => 'test', + 'data' => + array( + 'userPassword' => array('something') + ) + ) + ) + ); + $conn->bind('', ''); + $result = $conn->search('test', null, array('scope' => 'base')); + $this->assertEquals( + array('test' => array( + 'userPassword' => array('something'), + 'dn' => 'test' + ) + ), + $result->as_struct() + ); + } + + public function testMethodSearchHasResultMocksearchEmptyIfNoFilterIsSetSearchScopeIsBaseAndTheSpecifiedBaseDoesNotExist() + { + $conn = new Horde_Kolab_Server_Connection_Mock_Ldap( + array(), + array() + ); + $conn->bind('', ''); + $result = $conn->search('test', null, array('scope' => 'base')); + $this->assertEquals( + array(), + $result->as_struct() + ); + } + + public function testMethodSearchHasResultMocksearchSingleElementIfNoFilterIsSetSearchScopeIsSubAndOnlyOneElementMatchesBase() + { + $conn = new Horde_Kolab_Server_Connection_Mock_Ldap( + array(), + array('test' => + array('dn' => 'test', + 'data' => + array( + 'userPassword' => array('something') + ) + ), + 'testnot' => + array('dn' => 'test', + 'data' => + array( + 'userPassword' => array('something') + ) + ) + ) + ); + $conn->bind('', ''); + $result = $conn->search('test', null, array('scope' => 'sub')); + $this->assertEquals( + array('test' => array( + 'userPassword' => array('something'), + 'dn' => 'test' + ) + ), + $result->as_struct() + ); + } + + public function testMethodSearchHasResultMocksearchWithMatchingElementsIfNoSearchScopeIsSet() + { + $conn = new Horde_Kolab_Server_Connection_Mock_Ldap( + array(), + array('test' => + array('dn' => 'test', + 'data' => + array( + 'userPassword' => array('something') + ) + ), + 'yestest' => + array('dn' => 'yestest', + 'data' => + array( + 'userPassword' => array('something') + ) + ), + 'testnot' => + array('dn' => 'testnot', + 'data' => + array( + 'userPassword' => array('something') + ) + ) + ) + ); + $conn->bind('', ''); + $result = $conn->search('test'); + $this->assertEquals( + array('test', 'yestest'), + array_keys($result->as_struct()) + ); + } + + public function testMethodSearchHasResultMocksearchWithSelectedAttributesIfSpecificAttributesWereSet() + { + $conn = new Horde_Kolab_Server_Connection_Mock_Ldap( + array(), + array('test' => + array('dn' => 'test', + 'data' => + array( + 'userPassword' => array('something'), + 'name' => array('name1') + ) + ), + 'yestest' => + array('dn' => 'yestest', + 'data' => + array( + 'userPassword' => array('something'), + 'name' => array('name2') + ) + ), + 'testnot' => + array('dn' => 'testnot', + 'data' => + array( + 'userPassword' => array('something'), + 'name' => array('name2') + ) + ) + ) + ); + $conn->bind('', ''); + $result = $conn->search('test', null, array('attributes' => 'name')); + $this->assertEquals( + array( + 'test' => array( + 'name' => array('name1'), + 'dn' => 'test' + ), + 'yestest' => array( + 'name' => array('name2'), + 'dn' => 'yestest' + ), + ), + $result->as_struct() + ); + } + + public function testMethodSearchThrowsExceptionIfSearchScopeIsOne() + { + $conn = new Horde_Kolab_Server_Connection_Mock_Ldap( + array(), + array() + ); + $conn->bind('', ''); + try { + $result = $conn->search('test', null, array('scope' => 'one')); + $this->fail('No exception!'); + } catch (Horde_Kolab_Server_Exception $e) { + $this->assertEquals('Not implemented!', $e->getMessage()); + } + } + + public function testMethodSearchThrowsExceptionIfTheConnectionIsNotBound() + { + $conn = new Horde_Kolab_Server_Connection_Mock_Ldap( + array(), + array() + ); + try { + $conn->search(); + $this->fail('No exception!'); + } catch (Horde_Kolab_Server_Exception $e) { + $this->assertEquals('Unbound connection!', $e->getMessage()); + } } } diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/Decorator/CountTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/Decorator/CountTest.php new file mode 100644 index 000000000..3e7a17e71 --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/Decorator/CountTest.php @@ -0,0 +1,163 @@ + + * @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 count decorator server 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_Decorator_CountTest +extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + $this->factory = $this->getMock( + 'Horde_Kolab_Server_Factory_Interface' + ); + } + + public function testMethodGetserverHasResultCountedServer() + { + $this->factory->expects($this->once()) + ->method('getServer') + ->will( + $this->returnValue( + $this->getMock( + 'Horde_Kolab_Server_Interface' + ) + ) + ); + $factory = new Horde_Kolab_Server_Factory_Decorator_Count( + $this->factory, 'logger' + ); + $this->assertType('Horde_Kolab_Server_Decorator_Count', $factory->getServer()); + } + + public function testMethodConstructHasParametersFactoryAndMixedLoggerParameter() + { + $factory = new Horde_Kolab_Server_Factory_Decorator_Count( + $this->factory, 'logger' + ); + } + + public function testMethodGetconnectionfactoryHasPostconditionThatTheCallWasDelegated() + { + $this->factory->expects($this->once()) + ->method('getConnectionFactory'); + $factory = new Horde_Kolab_Server_Factory_Decorator_Count( + $this->factory, 'logger' + ); + $factory->getConnectionFactory(); + } + + public function testMethodGetserverHasPostconditionThatTheCallWasDelegated() + { + $this->factory->expects($this->once()) + ->method('getServer') + ->will( + $this->returnValue( + $this->getMock( + 'Horde_Kolab_Server_Interface' + ) + ) + ); + $factory = new Horde_Kolab_Server_Factory_Decorator_Count( + $this->factory, 'logger' + ); + $factory->getServer(); + } + + public function testMethodGetconfigurationHasPostconditionThatTheCallWasDelegated() + { + $this->factory->expects($this->once()) + ->method('getConfiguration'); + $factory = new Horde_Kolab_Server_Factory_Decorator_Count( + $this->factory, 'logger' + ); + $factory->getConfiguration(); + } + + public function testMethodGetconnectionHasPostconditionThatTheCallWasDelegated() + { + $this->factory->expects($this->once()) + ->method('getConnection'); + $factory = new Horde_Kolab_Server_Factory_Decorator_Count( + $this->factory, 'logger' + ); + $factory->getConnection(); + } + + public function testMethodGetcompositeHasPostconditionThatTheCallWasDelegated() + { + $this->factory->expects($this->once()) + ->method('getComposite'); + $factory = new Horde_Kolab_Server_Factory_Decorator_Count( + $this->factory, 'logger' + ); + $factory->getComposite(); + } + + public function testMethodGetobjectsHasPostconditionThatTheCallWasDelegated() + { + $this->factory->expects($this->once()) + ->method('getObjects'); + $factory = new Horde_Kolab_Server_Factory_Decorator_Count( + $this->factory, 'logger' + ); + $factory->getObjects(); + } + + public function testMethodGetstructureHasPostconditionThatTheCallWasDelegated() + { + $this->factory->expects($this->once()) + ->method('getStructure'); + $factory = new Horde_Kolab_Server_Factory_Decorator_Count( + $this->factory, 'logger' + ); + $factory->getStructure(); + } + + public function testMethodGetsearchHasPostconditionThatTheCallWasDelegated() + { + $this->factory->expects($this->once()) + ->method('getSearch'); + $factory = new Horde_Kolab_Server_Factory_Decorator_Count( + $this->factory, 'logger' + ); + $factory->getSearch(); + } + + public function testMethodGetschemaHasPostconditionThatTheCallWasDelegated() + { + $this->factory->expects($this->once()) + ->method('getSchema'); + $factory = new Horde_Kolab_Server_Factory_Decorator_Count( + $this->factory, 'logger' + ); + $factory->getSchema(); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Object/Attribute/BaseTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Object/Attribute/BaseTest.php index 043060f5d..c4bc2f32e 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Object/Attribute/BaseTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Object/Attribute/BaseTest.php @@ -35,74 +35,69 @@ extends Horde_Kolab_Server_TestCase { public function setUp() { - $this->object = $this->getMock( - 'Horde_Kolab_Server_Object_Interface' + $this->attribute = $this->getMock( + 'Horde_Kolab_Server_Structure_Attribute_Interface' ); - $this->composite = $this->getMockedComposite(); } - public function testMethodConstructHasParameterObjectTheObjectOwningTheAttributeAndParameterCompositeWhichIsTheLinkToTheServer() + public function testMethodConstructHasParameterAttributeTheAdapterCoveringTheInternalSideOfTheAttribute() { - $attribute = new Attribute_Mock($this->object, $this->composite, ''); + $attribute = new Attribute_Mock($this->attribute, ''); } public function testMethodConstructHasParameterStringTheNameOfTheAttribute() { - $attribute = new Attribute_Mock($this->object, $this->composite, 'name'); + $attribute = new Attribute_Mock($this->attribute, 'name'); } - public function testMethodGetobjectReturnsObjectAssociatedWithThisAttribute() + public function testMethodGetattributeReturnsAttributeInteralAssociatedWithThisAttribute() { - $attribute = new Attribute_Mock($this->object, $this->composite, ''); + $attribute = new Attribute_Mock($this->attribute, ''); $this->assertType( - 'Horde_Kolab_Server_Object_Interface', - $attribute->getObject() + 'Horde_Kolab_Server_Structure_Attribute_Interface', + $attribute->getAttribute() ); } public function testMethodGetnameReturnsStringTheNameOfTheAttribute() { - $this->composite->structure->expects($this->exactly(1)) - ->method('mapExternalToInternalAttribute') - ->with('name') - ->will($this->returnValue('name')); - $attribute = new Attribute_Mock($this->object, $this->composite, 'name'); - $this->assertEquals('name', $attribute->getInternalName()); + $attribute = new Attribute_Mock($this->attribute, 'name'); + $this->assertEquals('name', $attribute->getName()); } public function testMethodIsemptyHasParameterArrayDataValues() { - $attribute = new Attribute_Mock($this->object, $this->composite, 'name'); + $attribute = new Attribute_Mock($this->attribute, 'name'); $attribute->isEmpty(array()); } public function testMethodIsemptyReturnsFalseIfTheValueIndicatedByTheAttributeNameIsNotEmptyInTheDataArray() { - $attribute = new Attribute_Mock($this->object, $this->composite, 'name', 'name'); + $attribute = new Attribute_Mock($this->attribute, 'name', 'name'); $this->assertFalse($attribute->isEmpty(array('name' => 'HELLO'))); } public function testMethodIsemptyReturnsTrueIfTheValueIndicatedByTheAttributeNameIsMissingInTheDataArray() { - $attribute = new Attribute_Mock($this->object, $this->composite, 'name'); + $attribute = new Attribute_Mock($this->attribute, 'name'); $this->assertTrue($attribute->isEmpty(array())); } public function testMethodIsemptyReturnsTrueIfTheValueIndicatedByTheAttributeNameIsStringEmptyInTheDataArray() { - $attribute = new Attribute_Mock($this->object, $this->composite, 'name'); + $attribute = new Attribute_Mock($this->attribute, 'name'); $this->assertTrue($attribute->isEmpty(array('name' => ''))); } public function testMethodIsemptyReturnsTrueIfTheValueIndicatedByTheAttributeNameIsNullInTheDataArray() { - $attribute = new Attribute_Mock($this->object, $this->composite, 'name'); + $attribute = new Attribute_Mock($this->attribute, 'name'); $this->assertTrue($attribute->isEmpty(array('name' => null))); } public function testMethodIsemptyReturnsTrueIfTheValueIndicatedByTheAttributeNameIsEmptyArrayInTheDataArray() { - $attribute = new Attribute_Mock($this->object, $this->composite, 'name'); + $attribute = new Attribute_Mock($this->attribute, 'name'); $this->assertTrue($attribute->isEmpty(array('name' => array()))); } } @@ -111,5 +106,4 @@ class Attribute_Mock extends Horde_Kolab_Server_Object_Attribute_Base { public function value() {} public function update(array $changes) {} - public function consume(array &$changes) {} } \ No newline at end of file diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Object/BaseTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Object/BaseTest.php index 32e2a8b21..9f471bde9 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Object/BaseTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Object/BaseTest.php @@ -48,14 +48,14 @@ class Horde_Kolab_Server_Class_Server_Object_BaseTest extends Horde_Kolab_Server $object = new Object_Mock($composite, 'guid'); } - public function testGetguidHasResultStringGuidTheObjectIdOnTheServer() + public function testMethodGetguidHasResultStringGuidTheObjectIdOnTheServer() { $composite = $this->getComposite(); $object = new Object_Mock($composite, 'guid'); $this->assertEquals('guid', $object->getGuid()); } - public function testGetguidThrowsExceptionIfGuidHasNotBeenSetYet() + public function testMethodGetguidThrowsExceptionIfGuidHasNotBeenSetYet() { $composite = $this->getComposite(); $object = new Object_Mock($composite); @@ -69,10 +69,10 @@ class Horde_Kolab_Server_Class_Server_Object_BaseTest extends Horde_Kolab_Server } } - public function testGetexternalattributesHasResultArrayTheExternalAttributesSupportedByTheObject() + public function testMethodGetexternalattributesHasResultArrayTheExternalAttributesSupportedByTheObject() { $composite = $this->getMockedComposite(); - $composite->schema->expects($this->once()) + $composite->structure->expects($this->once()) ->method('getExternalAttributes') ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface')) ->will($this->returnValue(array('external'))); @@ -80,10 +80,10 @@ class Horde_Kolab_Server_Class_Server_Object_BaseTest extends Horde_Kolab_Server $this->assertEquals(array('external'), $object->getExternalAttributes()); } - public function testGetinternalattributesHasResultArrayTheInternalAttributesSupportedByTheObject() + public function testMethodGetinternalattributesHasResultArrayTheInternalAttributesSupportedByTheObject() { $composite = $this->getMockedComposite(); - $composite->schema->expects($this->once()) + $composite->structure->expects($this->once()) ->method('getInternalAttributes') ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface')) ->will($this->returnValue(array('internal' => 'Internal'))); @@ -91,17 +91,17 @@ class Horde_Kolab_Server_Class_Server_Object_BaseTest extends Horde_Kolab_Server $this->assertEquals(array('internal' => 'Internal'), $object->getInternalAttributes()); } - public function testGetinternalattributesHasResultBooleanFalseIfTheGuidIsNotSpecified() + public function testMethodExistsHasResultBooleanFalseIfTheGuidIsNotSpecified() { $composite = $this->getMockedComposite(); $object = new Object_Mock($composite); $this->assertFalse($object->exists()); } - public function testGetinternalattributesHasResultBooleanFalseIfTheServerReturnedAnError() + public function testMethodExistsHasResultBooleanFalseIfTheServerReturnedAnError() { $composite = $this->getMockedComposite(); - $composite->schema->expects($this->once()) + $composite->structure->expects($this->once()) ->method('getInternalAttributes') ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface')) ->will($this->returnValue(array('internal' => 'Internal'))); @@ -113,10 +113,10 @@ class Horde_Kolab_Server_Class_Server_Object_BaseTest extends Horde_Kolab_Server $this->assertFalse($object->exists()); } - public function testGetinternalattributesHasResultBooleanTrueIfTheServerReturnedData() + public function testMethodExistsHasResultBooleanTrueIfTheServerReturnedData() { $composite = $this->getMockedComposite(); - $composite->schema->expects($this->once()) + $composite->structure->expects($this->once()) ->method('getInternalAttributes') ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface')) ->will($this->returnValue(array('internal' => 'Internal'))); @@ -128,10 +128,10 @@ class Horde_Kolab_Server_Class_Server_Object_BaseTest extends Horde_Kolab_Server $this->assertTrue($object->exists()); } - public function testReadinternalHasResultArrayDataTheInternalObjectData() + public function testMethodReadinternalHasResultArrayDataTheInternalObjectData() { $composite = $this->getMockedComposite(); - $composite->schema->expects($this->once()) + $composite->structure->expects($this->once()) ->method('getInternalAttributes') ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface')) ->will($this->returnValue(array('internal' => 'Internal'))); @@ -145,10 +145,10 @@ class Horde_Kolab_Server_Class_Server_Object_BaseTest extends Horde_Kolab_Server ); } - public function testGetinternalHasResultArrayTheDataOfTheRequestedAttribute() + public function testMethodGetinternalHasResultArrayTheDataOfTheRequestedAttribute() { $composite = $this->getMockedComposite(); - $composite->schema->expects($this->exactly(2)) + $composite->structure->expects($this->exactly(1)) ->method('getInternalAttributes') ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface')) ->will($this->returnValue(array('internal' => 'Internal'))); @@ -158,30 +158,30 @@ class Horde_Kolab_Server_Class_Server_Object_BaseTest extends Horde_Kolab_Server ->will($this->returnValue(array('internal' => array('test')))); $object = new Object_Mock($composite, 'guid'); $this->assertEquals( - array('test'), $object->getInternal('internal') + array('internal' => array('test')), $object->getInternal(array('internal')) ); } - public function testGetinternalThrowsExceptionIfTheRequestedAttributeIsNotSupported() + public function testMethodGetinternalThrowsExceptionIfTheRequestedAttributeIsNotSupported() { $composite = $this->getMockedComposite(); - $composite->schema->expects($this->once()) + $composite->structure->expects($this->once()) ->method('getInternalAttributes') ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface')) ->will($this->returnValue(array('internal' => 'Internal'))); $object = new Object_Mock($composite, 'guid'); try { - $object->getInternal('test'); + $object->getInternal(array('test')); $this->fail('No exception!'); } catch (Horde_Kolab_Server_Exception $e) { - $this->assertEquals('Attribute "test" not supported!', $e->getMessage()); + $this->assertEquals('No value for attribute "test"!', $e->getMessage()); } } - public function testGetinternalThrowsExceptionIfTheRequestedAttributeHasNoValue() + public function testMethodGetinternalThrowsExceptionIfTheRequestedAttributeHasNoValue() { $composite = $this->getMockedComposite(); - $composite->schema->expects($this->exactly(2)) + $composite->structure->expects($this->exactly(1)) ->method('getInternalAttributes') ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface')) ->will( @@ -195,42 +195,42 @@ class Horde_Kolab_Server_Class_Server_Object_BaseTest extends Horde_Kolab_Server ->will($this->returnValue(array('internal' => array('test')))); $object = new Object_Mock($composite, 'guid'); try { - $object->getInternal('test'); + $object->getInternal(array('test')); $this->fail('No exception!'); } catch (Horde_Kolab_Server_Exception_Novalue $e) { $this->assertEquals('No value for attribute "test"!', $e->getMessage()); } } - public function testGetexternalHasResultArrayTheDataOfTheRequestedAttribute() + public function testMethodGetexternalHasResultArrayTheDataOfTheRequestedAttribute() { $composite = $this->getMockedComposite(); $composite->structure->expects($this->exactly(1)) - ->method('mapExternalToInternalAttribute') - ->with('Objectclass') - ->will($this->returnValue('objectClass')); - $composite->schema->expects($this->exactly(1)) ->method('getExternalAttributes') ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface')) - ->will($this->returnValue(array('Objectclass'))); - $composite->schema->expects($this->exactly(2)) - ->method('getInternalAttributes') - ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface')) - ->will($this->returnValue(array('objectClass' => 'Objectclass'))); - $composite->server->expects($this->once()) - ->method('readAttributes') - ->with('guid', array('objectClass')) - ->will($this->returnValue(array('objectClass' => array('test')))); + ->will($this->returnValue(array('objectClass'))); + $external = $this->getMock('Horde_Kolab_Server_Object_Attribute_Interface'); + $external->expects($this->once()) + ->method('value') + ->will($this->returnValue(array('test'))); + $composite->structure->expects($this->exactly(1)) + ->method('getExternalAttribute') + ->with('objectClass') + ->will( + $this->returnValue( + $external + ) + ); $object = new Object_Mock($composite, 'guid'); $this->assertEquals( - array('test'), $object->getExternal('Objectclass') + array('test'), $object->getExternal('objectClass') ); } - public function testGetexternalThrowsExceptionIfTheRequestedAttributeIsNotSupported() + public function testMethodGetexternalThrowsExceptionIfTheRequestedAttributeIsNotSupported() { $composite = $this->getMockedComposite(); - $composite->schema->expects($this->once()) + $composite->structure->expects($this->once()) ->method('getExternalAttributes') ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface')) ->will($this->returnValue(array('external'))); @@ -239,27 +239,11 @@ class Horde_Kolab_Server_Class_Server_Object_BaseTest extends Horde_Kolab_Server $object->getExternal('test'); $this->fail('No exception!'); } catch (Horde_Kolab_Server_Exception $e) { - $this->assertEquals('Attribute "Test" not supported!', $e->getMessage()); - } - } - - public function testGetexternalThrowsExceptionIfTheRequestedClassDoesNotExist() - { - $composite = $this->getMockedComposite(); - $composite->schema->expects($this->once()) - ->method('getExternalAttributes') - ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface')) - ->will($this->returnValue(array('Test'))); - $object = new Object_Mock($composite, 'guid'); - try { - $object->getExternal('test'); - $this->fail('No exception!'); - } catch (Horde_Kolab_Server_Exception $e) { - $this->assertEquals('Attribute "Test" not supported!', $e->getMessage()); + $this->assertEquals('Attribute "test" not supported!', $e->getMessage()); } } - public function testDeleteHasPostconditionThatTheObjectWasDeletedOnTheServer() + public function testMethodDeleteHasPostconditionThatTheObjectWasDeletedOnTheServer() { $composite = $this->getMockedComposite(); $composite->server->expects($this->once()) @@ -269,10 +253,10 @@ class Horde_Kolab_Server_Class_Server_Object_BaseTest extends Horde_Kolab_Server $object->delete(); } - public function testSaveHasParameterArrayTheDataToSave() + public function testMethodSaveHasParameterArrayTheDataToSave() { $composite = $this->getMockedComposite(); - $composite->schema->expects($this->exactly(3)) + $composite->structure->expects($this->exactly(1)) ->method('getInternalAttributes') ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface')) ->will( @@ -283,7 +267,7 @@ class Horde_Kolab_Server_Class_Server_Object_BaseTest extends Horde_Kolab_Server ) ) ); - $composite->server->expects($this->exactly(2)) + $composite->server->expects($this->exactly(1)) ->method('readAttributes') ->with('guid', array('objectClass')) ->will($this->returnValue(array('objectClass' => array('test')))); @@ -291,16 +275,14 @@ class Horde_Kolab_Server_Class_Server_Object_BaseTest extends Horde_Kolab_Server $object->save(array()); } - public function testSaveHasPostconditionThatTheObjectWasAddedToTheServerIfItDidNotExistBefore() + public function testMethodSaveHasPostconditionThatTheObjectWasAddedToTheServerIfItDidNotExistBefore() { $composite = $this->getMockedComposite(); $composite->structure->expects($this->exactly(1)) - ->method('mapExternalToInternalAttribute') - ->with('Objectclass') - ->will($this->returnValue('objectClass')); - $composite->schema->expects($this->exactly(1)) - ->method('getInternalAttributes') - ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface')) + ->method('generateServerGuid') + ->with( + 'Object_Mock', null, + array('objectClass' => array('top'))) ->will( $this->returnValue( array( @@ -309,24 +291,23 @@ class Horde_Kolab_Server_Class_Server_Object_BaseTest extends Horde_Kolab_Server ) ) ); + $external = $this->getMock('Horde_Kolab_Server_Object_Attribute_Interface'); + $external->expects($this->exactly(1)) + ->method('update') + ->will($this->returnValue(array('objectClass' => array('top')))); $composite->structure->expects($this->exactly(1)) - ->method('generateServerGuid') - ->with( - 'Object_Mock', null, - array('objectClass' => array('top'))) + ->method('getExternalAttribute') + ->with('objectClass') ->will( $this->returnValue( - array( - 'objectClass' => - 'Horde_Kolab_Server_Object_Attribute_Objectclass' - ) + $external ) ); $composite->server->expects($this->exactly(1)) ->method('add') ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface'), array('objectClass' => array('top'))); $object = new Object_Mock($composite); - $object->save(array('Objectclass' => 'top')); + $object->save(array('objectClass' => 'top')); } } diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Query/Element/MappedTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Query/Element/MappedTest.php new file mode 100644 index 000000000..9e6b22707 --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Query/Element/MappedTest.php @@ -0,0 +1,171 @@ + + * @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 mapped query element. + * + * 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_Query_Element_MappedTest +extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + $this->element = $this->getMock( + 'Horde_Kolab_Server_Query_Element_Interface' + ); + $this->mapper = $this->getMock( + 'Horde_Kolab_Server_Decorator_Map', array(), array(), '', false, false + ); + } + + public function testMethodConstructHasParameterElementTheDecoratedElement() + { + $element = new Horde_Kolab_Server_Query_Element_Mapped( + $this->element, + $this->mapper + ); + } + + public function testMethodConstructHasParameterMapper() + { + $this->testMethodConstructHasParameterElementTheDecoratedElement(); + } + + public function testMethodGetnameHasResultStringTheMappedNameOfTheElement() + { + $this->element->expects($this->once()) + ->method('getName') + ->will($this->returnValue('test')); + $this->mapper->expects($this->once()) + ->method('mapField') + ->with('test') + ->will($this->returnValue('mapped')); + $element = new Horde_Kolab_Server_Query_Element_Mapped( + $this->element, + $this->mapper + ); + $this->assertEquals('mapped', $element->getName()); + } + + public function testMethodGetvalueHasResultTheValueOfTheMappedElement() + { + $this->element->expects($this->once()) + ->method('getValue') + ->will($this->returnValue('test')); + $element = new Horde_Kolab_Server_Query_Element_Mapped( + $this->element, + $this->mapper + ); + $this->assertEquals('test', $element->getValue()); + } + + public function testMethodGetelementsHasResultArrayOfMappedElements() + { + $elements = array( + $this->getMock( + 'Horde_Kolab_Server_Query_Element_Interface' + ), + $this->getMock( + 'Horde_Kolab_Server_Query_Element_Interface' + ), + ); + $this->element->expects($this->once()) + ->method('getElements') + ->will($this->returnValue($elements)); + $element = new Horde_Kolab_Server_Query_Element_Mapped( + $this->element, + $this->mapper + ); + $elements = $element->getElements(); + foreach ($elements as $element) { + $this->assertType( + 'Horde_Kolab_Server_Query_Element_Mapped', $element + ); + } + } + + public function testMethodConvertHasResultStringTheConvertedElement() + { + $this->element->expects($this->once()) + ->method('convert') + ->will($this->returnValue('test')); + $element = new Horde_Kolab_Server_Query_Element_Mapped( + $this->element, + $this->mapper + ); + $query = $this->getMock('Horde_Kolab_Server_Query_Interface'); + $this->assertEquals('test', $element->convert($query)); + } + + public function testMethodGetnameHasPostconditionThatTheCallWasDelegated() + { + $this->element->expects($this->once()) + ->method('getName'); + $element = new Horde_Kolab_Server_Query_Element_Mapped( + $this->element, + $this->mapper + ); + $element->getName(); + } + + public function testMethodGetvalueHasPostconditionThatTheCallWasDelegated() + { + $this->element->expects($this->once()) + ->method('getValue'); + $element = new Horde_Kolab_Server_Query_Element_Mapped( + $this->element, + $this->mapper + ); + $element->getValue(); + } + + public function testMethodGetelementsHasPostconditionThatTheCallWasDelegated() + { + $elements = array(); + $this->element->expects($this->once()) + ->method('getElements') + ->will($this->returnValue($elements)); + $element = new Horde_Kolab_Server_Query_Element_Mapped( + $this->element, + $this->mapper + ); + $element->getElements(); + } + + public function testMethodConvertHasPostconditionThatTheCallWasDelegated() + { + $this->element->expects($this->once()) + ->method('convert'); + $element = new Horde_Kolab_Server_Query_Element_Mapped( + $this->element, + $this->mapper + ); + $query = $this->getMock('Horde_Kolab_Server_Query_Interface'); + $element->convert($query); + } +} diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidTest.php index 0f605a369..a7f556dfc 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidTest.php @@ -67,7 +67,7 @@ extends PHPUnit_Framework_TestCase $this->isInstanceOf( 'Horde_Kolab_Server_Query_Element_Interface' ), - array('attributes' => 'Guid') + array('attributes' => 'guid') ) ->will($this->returnValue($result)); $search = new Horde_Kolab_Server_Search_Operation_Guid($this->structure); @@ -87,7 +87,7 @@ extends PHPUnit_Framework_TestCase $this->isInstanceOf( 'Horde_Kolab_Server_Query_Element_Interface' ), - array('attributes' => 'Guid') + array('attributes' => 'guid') ) ->will($this->returnValue($result)); $search = new Horde_Kolab_Server_Search_Operation_Guid($this->structure); diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/RestrictkolabTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/RestrictkolabTest.php new file mode 100644 index 000000000..2f44cf322 --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/RestrictkolabTest.php @@ -0,0 +1,108 @@ + + * @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 operations restricted to Kolab users. + * + * 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_Search_Operation_RestrictkolabTest +extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + $this->structure = $this->getMock('Horde_Kolab_Server_Structure_Interface'); + } + + public function testMethodRestrictkolabHasResultRestrictedToKolabUsers() + { + $result = $this->getMock('Horde_Kolab_Server_Result_Interface'); + $result->expects($this->once()) + ->method('asArray') + ->will($this->returnValue(array('a' => 'a'))); + $this->structure->expects($this->once()) + ->method('find') + ->with( + $this->isRestrictedToKolabUsers(), + array('attributes' => 'guid') + ) + ->will($this->returnValue($result)); + $search = new Horde_Kolab_Server_Search_Operation_Restrictkolab($this->structure); + $criteria = $this->getMock('Horde_Kolab_Server_Query_Element_Interface'); + $this->assertEquals(array('a'), $search->searchRestrictkolab($criteria)); + } + + public function isRestrictedToKolabUsers() + { + return new Constraint_RestrictedToKolabUsers(); + } +} + +class Constraint_RestrictedToKolabUsers extends PHPUnit_Framework_Constraint +{ + public function evaluate($other) + { + if ($other instanceOf Horde_Kolab_Server_Query_Element_Interface) { + if ($other instanceOf Horde_Kolab_Server_Query_Element_Group) { + $elements = $other->getElements(); + foreach ($elements as $element) { + if ($this->evaluate($element)) { + return true; + } + } + return true; + } else { + if ($other->getName() == 'objectClass' + && $other->getValue() == Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON) { + return true; + } else { + return false; + } + } + } else { + return false; + } + } + + public function fail($other, $description, $not = FALSE) + { + throw new PHPUnit_Framework_ExpectationFailedException( + sprintf( + '%sFailed asserting that %s contains a query element that restricts the search to Kolab users', + + !empty($description) ? $description . "\n" : '', + PHPUnit_Util_Type::toString($other, TRUE) + ), + NULL + ); + } + + public function toString() + { + return 'contains a query element that restricts the search to Kolab users'; + } +} 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 index 8b3220de6..b1473b3c2 100644 --- 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 @@ -52,7 +52,7 @@ class Horde_Kolab_Server_Class_Server_Structure_LdapTest extends Horde_Kolab_Ser ->method('find') ->with('(objectClass=equals)', array()) ->will($this->returnValue($result)); - $equals = new Horde_Kolab_Server_Query_Element_Equals('Objectclass', 'equals'); + $equals = new Horde_Kolab_Server_Query_Element_Equals('objectClass', 'equals'); $this->assertType( 'Horde_Kolab_Server_Result', $this->composite->structure->find($equals, array()) @@ -67,7 +67,7 @@ class Horde_Kolab_Server_Class_Server_Structure_LdapTest extends Horde_Kolab_Ser ->method('findBelow') ->with('(objectClass=equals)', 'base', array()) ->will($this->returnValue($result)); - $equals = new Horde_Kolab_Server_Query_Element_Equals('Objectclass', 'equals'); + $equals = new Horde_Kolab_Server_Query_Element_Equals('objectClass', 'equals'); $this->assertType( 'Horde_Kolab_Server_Result', $this->composite->structure->findBelow($equals, 'base', array()) @@ -165,18 +165,4 @@ class Horde_Kolab_Server_Class_Server_Structure_LdapTest extends Horde_Kolab_Ser ->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->mapExternalToInternalAttribute('undefined'); - $this->fail('No exception!'); - } catch (Horde_Kolab_Server_Exception $e) { - $this->assertEquals( - 'Undefined internal attribute "undefined"', - $e->getMessage() - ); - } - } -} +} \ No newline at end of file diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/InetorgpersonTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/InetorgpersonTest.php index 1fb72f61e..00f500cc5 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/InetorgpersonTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/InetorgpersonTest.php @@ -41,7 +41,7 @@ class Horde_Kolab_Server_Integration_InetorgpersonTest extends Horde_Kolab_Serve /* Default inetOrgPerson */ array( 'type' => 'Horde_Kolab_Server_Object_Inetorgperson', - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => 'Frank', + 'givenName' => 'Frank', 'Sn' => 'Mustermann', 'Userpassword' => 'Kolab_Server_OrgPersonTest_123', ), @@ -54,8 +54,8 @@ class Horde_Kolab_Server_Integration_InetorgpersonTest extends Horde_Kolab_Serve /* Person with middle names */ array( 'type' => 'Horde_Kolab_Server_Object_Inetorgperson', - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => 'Frank', - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => 'Günter Eloic', + 'givenName' => 'Frank', + 'Middlenames' => 'Günter Eloic', 'Sn' => 'Mustermann', 'Userpassword' => 'Kolab_Server_OrgPersonTest_123', ), @@ -109,42 +109,42 @@ class Horde_Kolab_Server_Integration_InetorgpersonTest extends Horde_Kolab_Serve { foreach ($this->servers as $server) { $person = $this->assertAdd($server, $this->objects[2], - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => $this->objects[2][Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME], - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => $this->objects[2][Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES])); + array('givenName' => $this->objects[2]['givenName'], + 'Middlenames' => $this->objects[2]['Middlenames'])); $this->assertStoreFetch($person, $server, - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => 'Kolab_Server_InetorgpersonTest_123$123', - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => 'Kolab_Server_InetorgpersonTest_123$123'), - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => 'Kolab_Server_InetorgpersonTest_123$123', - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => 'Kolab_Server_InetorgpersonTest_123$123')); + array('givenName' => 'Kolab_Server_InetorgpersonTest_123$123', + 'Middlenames' => 'Kolab_Server_InetorgpersonTest_123$123'), + array('givenName' => 'Kolab_Server_InetorgpersonTest_123$123', + 'Middlenames' => 'Kolab_Server_InetorgpersonTest_123$123')); $this->assertStoreFetch($person, $server, - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => 'Kolab_Server_InetorgpersonTest_123$456', - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => ''), - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => 'Kolab_Server_InetorgpersonTest_123$456', - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => '')); + array('givenName' => 'Kolab_Server_InetorgpersonTest_123$456', + 'Middlenames' => ''), + array('givenName' => 'Kolab_Server_InetorgpersonTest_123$456', + 'Middlenames' => '')); $this->assertStoreFetch($person, $server, - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => 'Kolab_Server_InetorgpersonTest_789'), - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => 'Kolab_Server_InetorgpersonTest_123$456', - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => 'Kolab_Server_InetorgpersonTest_789')); + array('Middlenames' => 'Kolab_Server_InetorgpersonTest_789'), + array('givenName' => 'Kolab_Server_InetorgpersonTest_123$456', + 'Middlenames' => 'Kolab_Server_InetorgpersonTest_789')); $this->assertStoreFetch($person, $server, - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => '', - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => ''), - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => '', - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => '')); + array('givenName' => '', + 'Middlenames' => ''), + array('givenName' => '', + 'Middlenames' => '')); $this->assertStoreFetch($person, $server, - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => 'Kolab_Server_InetorgpersonTest_789'), - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => '', - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => 'Kolab_Server_InetorgpersonTest_789')); + array('Middlenames' => 'Kolab_Server_InetorgpersonTest_789'), + array('givenName' => '', + 'Middlenames' => 'Kolab_Server_InetorgpersonTest_789')); $this->assertStoreFetch($person, $server, - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => 'Frank', - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => ''), - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => 'Frank', - Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MIDDLENAMES => '')); + array('givenName' => 'Frank', + 'Middlenames' => ''), + array('givenName' => 'Frank', + 'Middlenames' => '')); } } @@ -157,30 +157,30 @@ class Horde_Kolab_Server_Integration_InetorgpersonTest extends Horde_Kolab_Serve { foreach ($this->servers as $server) { $person = $this->assertAdd($server, $this->objects[0], - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME => $this->objects[0][Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_GIVENNAME], - Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array())); + array('givenName' => $this->objects[0]['givenName'], + 'labelledURI' => array())); $this->assertStoreFetch($person, $server, - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array('a' => 'http://a.example.com', + array('labelledURI' => array('a' => 'http://a.example.com', 'b' => 'http://b.example.com')), - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array('a' => array('http://a.example.com'), + array('labelledURI' => array('a' => array('http://a.example.com'), 'b' => array('http://b.example.com')))); $this->assertStoreFetch($person, $server, - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array('a' => 'http://a.example.com', + array('labelledURI' => array('a' => 'http://a.example.com', 'b' => 'http://b.example.com', 'c' => 'http://c.example.com')), - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array('a' => array('http://a.example.com'), + array('labelledURI' => array('a' => array('http://a.example.com'), 'b' => array('http://b.example.com'), 'c' => array('http://c.example.com')))); $this->assertStoreFetch($person, $server, - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array()), - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array())); + array('labelledURI' => array()), + array('labelledURI' => array())); $this->assertStoreFetch($person, $server, - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array('a' => 'http://a.example.com')), - array(Horde_Kolab_Server_Object_Inetorgperson::ATTRARRAY_LABELEDURI => array('a' => array('http://a.example.com')))); + array('labelledURI' => array('a' => 'http://a.example.com')), + array('labelledURI' => array('a' => array('http://a.example.com')))); } } diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/KolabgermanbankarrangementTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/KolabgermanbankarrangementTest.php index 39fc2a0a4..af9c3770a 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/KolabgermanbankarrangementTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/KolabgermanbankarrangementTest.php @@ -41,7 +41,7 @@ class Horde_Kolab_Server_Integration_KolabgermanbankarrangementTest extends Hord /* Default bank account owner */ array( 'type' => 'Horde_Kolab_Server_Object_Kolabinetorgperson', - Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_GIVENNAME => 'Frank', + 'givenName' => 'Frank', 'Sn' => 'Mustermann', 'Userpassword' => 'Kolab_Server_OrgPersonTest_123', ), diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/KolabinetorgpersonTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/KolabinetorgpersonTest.php index 6a3a0a969..a94de8e45 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/KolabinetorgpersonTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/KolabinetorgpersonTest.php @@ -41,7 +41,7 @@ class Horde_Kolab_Server_Integration_KolabinetorgpersonTest extends Horde_Kolab_ /* Default kolabInetOrgPerson */ array( 'type' => 'Horde_Kolab_Server_Object_Kolabinetorgperson', - Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_GIVENNAME => 'Frank', + 'givenName' => 'Frank', 'Sn' => 'Mustermann', 'Userpassword' => 'Kolab_Server_OrgPersonTest_123', ), diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/Kolabpop3accountTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/Kolabpop3accountTest.php index 084d6a138..24890098d 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/Kolabpop3accountTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/Kolabpop3accountTest.php @@ -41,7 +41,7 @@ class Horde_Kolab_Server_Integration_Kolabpop3accountTest extends Horde_Kolab_Se /* Default bank account owner */ array( 'type' => 'Horde_Kolab_Server_Object_Kolabinetorgperson', - Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_GIVENNAME => 'Frank', + 'givenName' => 'Frank', 'Sn' => 'Mustermann', 'Userpassword' => 'Kolab_Server_OrgPersonTest_123', ), diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/SearchguidforuidormailTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/SearchguidforuidormailTest.php new file mode 100644 index 000000000..92c99c43c --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/SearchguidforuidormailTest.php @@ -0,0 +1,78 @@ + + * @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 "GuidForUidOrMail" search using the mock 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_Integration_SearchguidforuidormailTest +extends Horde_Kolab_Server_LdapTestCase +{ + public function setUp() + { + $conf['basedn'] = 'dc=test'; + $conf['mock'] = true; + $conf['data'] = array( + 'dn=user,dc=test' => array( + 'dn' => 'dn=user,dc=test', + 'data' => array( + 'uid' => array('user'), + 'mail' => array('user@example.org'), + 'objectClass' => array('top', 'kolabInetOrgPerson'), + ) + ) + ); + $server_factory = new Horde_Kolab_Server_Factory_Configuration( + $conf + ); + + $this->composite = $server_factory->getComposite(); + $this->composite->server->connectGuid(); + } + + public function testSearchingForUnknownUserReturnsEmptyGuid() + { + $this->composite->search->searchGuidForUidOrMail('unknown'); + } + + public function testSearchingForUserByMailReturnsTheGuid() + { + $this->assertEquals( + 'dn=user,dc=test', + $this->composite->search->searchGuidForUidOrMail('user@example.org') + ); + } + + public function testSearchingForUserByUidReturnsTheGuid() + { + $this->assertEquals( + 'dn=user,dc=test', + $this->composite->search->searchGuidForUidOrMail('user') + ); + } +} -- 2.11.0