From 712379bc7027b05858da2404a1120002b163bbe5 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Mon, 2 Nov 2009 17:10:08 +0100 Subject: [PATCH] Move search handlers from Object/ to Search/. Additional testing. Some Interfaces moved to Interface.php. --- .../lib/Horde/Kolab/Server/Cleaner.php | 8 +- .../lib/Horde/Kolab/Server/Composite.php | 4 +- .../lib/Horde/Kolab/Server/Connection/Mock.php | 646 +-------------------- .../Horde/Kolab/Server/Connection/Mock/Ldap.php | 606 +++++++++++++++++++ .../lib/Horde/Kolab/Server/Factory/Conn/Mock.php | 10 +- .../lib/Horde/Kolab/Server/Factory/Constructor.php | 4 +- .../lib/Horde/Kolab/Server/Factory/Injector.php | 10 +- .../Kolab/Server/Object/Kolabinetorgperson.php | 21 - .../lib/Horde/Kolab/Server/Object/Person.php | 12 - .../lib/Horde/Kolab/Server/Object/Searches.php | 7 - .../lib/Horde/Kolab/Server/Object/Top.php | 15 - .../lib/Horde/Kolab/Server/Objects/Base.php | 12 +- .../lib/Horde/Kolab/Server/Query/Ldap.php | 2 +- .../lib/Horde/Kolab/Server/Result/Ldap.php | 2 +- .../lib/Horde/Kolab/Server/Search/Base.php | 40 +- .../Server/{Search.php => Search/Interface.php} | 2 +- .../Operation}/Addressesforuidormail.php | 10 +- .../Search => Search/Operation}/Attributes.php | 4 +- .../{Object/Search => Search/Operation}/Base.php | 37 +- .../Search => Search/Operation}/Children.php | 4 +- .../Operation}/Constraint/Single.php | 21 +- .../Operation}/Constraint/Strict.php | 21 +- .../{Object/Search => Search/Operation}/Guid.php | 6 +- .../Search => Search/Operation}/Guidforalias.php | 4 +- .../Search => Search/Operation}/Guidforcn.php | 4 +- .../Operation}/Guidforkolabusers.php | 4 +- .../Search => Search/Operation}/Guidformail.php | 4 +- .../Operation}/Guidformailoralias.php | 4 +- .../Search => Search/Operation}/Guidforuid.php | 4 +- .../Operation}/Guidforuidormail.php | 40 +- .../Operation}/Guidforuidormailoralias.php | 4 +- .../Search.php => Search/Operation/Interface.php} | 8 +- .../Operation}/Mailforuidormail.php | 10 +- .../Search => Search/Operation}/Restrictkolab.php | 4 +- .../lib/Horde/Kolab/Server/Structure/Base.php | 3 +- .../{Structure.php => Structure/Interface.php} | 9 +- .../lib/Horde/Kolab/Server/Structure/Kolab.php | 25 + .../lib/Horde/Kolab/Server/Structure/Ldap.php | 16 + framework/Kolab_Server/package.xml | 144 ++--- .../Kolab/Server/Class/Server/CleanerTest.php | 210 +++++++ .../Kolab/Server/Class/Server/CompositeTest.php | 63 ++ .../Server/Connection/Mock/LdapTest.php} | 77 ++- .../Server/Class/Server/Connection/MockTest.php | 74 +++ .../Server}/Connection/SimpleldapTest.php | 4 +- .../Server}/Connection/SplittedldapTest.php | 4 +- .../Class/Server/Factory/ConfigurationTest.php | 4 +- .../Server/Class/Server/Factory/Conn/MockTest.php | 7 +- .../Class/Server/Factory/ConstructorTest.php | 4 +- .../Server/Class/Server/Factory/InjectorTest.php | 2 +- .../Server/Object}/Attribute/BaseTest.php | 5 +- .../Server/Object}/Attribute/ValueTest.php | 5 +- .../Server/{ => Class/Server}/Object/BaseTest.php | 4 +- .../{ => Class/Server}/Query/ElementTest.php | 4 +- .../Server/{ => Class/Server}/Query/LdapTest.php | 8 +- .../Kolab/Server/Class/Server/Search/BaseTest.php | 36 +- .../Class/Server/Search/Operation/GuidTest.php | 93 +++ .../Server/Class/Server/Structure/KolabTest.php | 2 +- .../Server/Class/Server/Structure/LdapTest.php | 2 +- .../ServerTest.php => Integration/ObjectsTest.php} | 2 +- .../test/Horde/Kolab/Server/TestCase.php | 4 +- 60 files changed, 1429 insertions(+), 976 deletions(-) create mode 100644 framework/Kolab_Server/lib/Horde/Kolab/Server/Connection/Mock/Ldap.php rename framework/Kolab_Server/lib/Horde/Kolab/Server/{Search.php => Search/Interface.php} (97%) rename framework/Kolab_Server/lib/Horde/Kolab/Server/{Object/Search => Search/Operation}/Addressesforuidormail.php (92%) rename framework/Kolab_Server/lib/Horde/Kolab/Server/{Object/Search => Search/Operation}/Attributes.php (92%) rename framework/Kolab_Server/lib/Horde/Kolab/Server/{Object/Search => Search/Operation}/Base.php (56%) rename framework/Kolab_Server/lib/Horde/Kolab/Server/{Object/Search => Search/Operation}/Children.php (93%) rename framework/Kolab_Server/lib/Horde/Kolab/Server/{Object/Search => Search/Operation}/Constraint/Single.php (74%) rename framework/Kolab_Server/lib/Horde/Kolab/Server/{Object/Search => Search/Operation}/Constraint/Strict.php (78%) rename framework/Kolab_Server/lib/Horde/Kolab/Server/{Object/Search => Search/Operation}/Guid.php (86%) rename framework/Kolab_Server/lib/Horde/Kolab/Server/{Object/Search => Search/Operation}/Guidforalias.php (91%) rename framework/Kolab_Server/lib/Horde/Kolab/Server/{Object/Search => Search/Operation}/Guidforcn.php (92%) rename framework/Kolab_Server/lib/Horde/Kolab/Server/{Object/Search => Search/Operation}/Guidforkolabusers.php (91%) rename framework/Kolab_Server/lib/Horde/Kolab/Server/{Object/Search => Search/Operation}/Guidformail.php (91%) rename framework/Kolab_Server/lib/Horde/Kolab/Server/{Object/Search => Search/Operation}/Guidformailoralias.php (92%) rename framework/Kolab_Server/lib/Horde/Kolab/Server/{Object/Search => Search/Operation}/Guidforuid.php (91%) rename framework/Kolab_Server/lib/Horde/Kolab/Server/{Object/Search => Search/Operation}/Guidforuidormail.php (57%) rename framework/Kolab_Server/lib/Horde/Kolab/Server/{Object/Search => Search/Operation}/Guidforuidormailoralias.php (93%) rename framework/Kolab_Server/lib/Horde/Kolab/Server/{Object/Search.php => Search/Operation/Interface.php} (80%) rename framework/Kolab_Server/lib/Horde/Kolab/Server/{Object/Search => Search/Operation}/Mailforuidormail.php (89%) rename framework/Kolab_Server/lib/Horde/Kolab/Server/{Object/Search => Search/Operation}/Restrictkolab.php (93%) rename framework/Kolab_Server/lib/Horde/Kolab/Server/{Structure.php => Structure/Interface.php} (93%) create mode 100644 framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/CleanerTest.php create mode 100644 framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/CompositeTest.php rename framework/Kolab_Server/test/Horde/Kolab/Server/{Connection/MockTest.php => Class/Server/Connection/Mock/LdapTest.php} (80%) create mode 100644 framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Connection/MockTest.php rename framework/Kolab_Server/test/Horde/Kolab/Server/{ => Class/Server}/Connection/SimpleldapTest.php (93%) rename framework/Kolab_Server/test/Horde/Kolab/Server/{ => Class/Server}/Connection/SplittedldapTest.php (94%) rename framework/Kolab_Server/test/Horde/Kolab/Server/{ => Class/Server/Object}/Attribute/BaseTest.php (95%) rename framework/Kolab_Server/test/Horde/Kolab/Server/{ => Class/Server/Object}/Attribute/ValueTest.php (98%) rename framework/Kolab_Server/test/Horde/Kolab/Server/{ => Class/Server}/Object/BaseTest.php (98%) rename framework/Kolab_Server/test/Horde/Kolab/Server/{ => Class/Server}/Query/ElementTest.php (98%) rename framework/Kolab_Server/test/Horde/Kolab/Server/{ => Class/Server}/Query/LdapTest.php (97%) create mode 100644 framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidTest.php rename framework/Kolab_Server/test/Horde/Kolab/Server/{Objects/ServerTest.php => Integration/ObjectsTest.php} (97%) diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Cleaner.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Cleaner.php index 5c1026683..9df64e515 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Cleaner.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Cleaner.php @@ -75,7 +75,7 @@ class Horde_Kolab_Server_Cleaner implements Horde_Kolab_Server */ public function getGuid() { - $this->_server->getGuid(); + return $this->_server->getGuid(); } /** @@ -85,7 +85,7 @@ class Horde_Kolab_Server_Cleaner implements Horde_Kolab_Server */ public function getBaseGuid() { - $this->_server->getBaseGuid(); + return $this->_server->getBaseGuid(); } /** @@ -133,7 +133,7 @@ class Horde_Kolab_Server_Cleaner implements Horde_Kolab_Server */ public function find($query, array $params = array()) { - return $this->_server->find($criteria, $params); + return $this->_server->find($query, $params); } /** @@ -149,7 +149,7 @@ class Horde_Kolab_Server_Cleaner implements Horde_Kolab_Server */ public function findBelow($query, $parent, array $params = array()) { - return $this->_server->findBelow($criteria, $parent, $params); + return $this->_server->findBelow($query, $parent, $params); } /** diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Composite.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Composite.php index 7f03c37c1..78bec71ea 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Composite.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Composite.php @@ -70,8 +70,8 @@ class Horde_Kolab_Server_Composite public function __construct( Horde_Kolab_Server $server, Horde_Kolab_Server_Objects $objects, - Horde_Kolab_Server_Structure $structure, - Horde_Kolab_Server_Search $search, + Horde_Kolab_Server_Structure_Interface $structure, + Horde_Kolab_Server_Search_Interface $search, Horde_Kolab_Server_Schema $schema ) { $this->_server = $server; diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Connection/Mock.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Connection/Mock.php index 3a1ecffa1..e78597fea 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Connection/Mock.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Connection/Mock.php @@ -28,86 +28,21 @@ class Horde_Kolab_Server_Connection_Mock implements Horde_Kolab_Server_Connection { - - /** - * The current database data. - * - * @var array - */ - protected $data = array(); - - /** - * Indicates if we are bound. - * - * @var array - */ - protected $bound; - - /** - * Array holding the current result set. - * - * @var array - */ - private $_result; - - /** - * Buffer for error numbers. - * - * @var int - */ - private $_errno = 0; - /** - * Buffer for error descriptions. + * The LDAP connection handle. * - * @var int + * @var Net_LDAP2 */ - private $_error = ''; + private $_ldap; /** - * Attribute used for sorting. + * Constructor * - * @var string + * @param Net_LDAP2 $ldap The ldap connection. */ - private $_sort_by; - - /** - * A result cache for iterating over the result. - * - * @var array - */ - private $_current_result; - - /** - * An index into the current result for iterating. - * - * @var int - */ - private $_current_index; - - /** - * Set configuration parameters. - * - * @param array $params The parameters. - * - * @return NULL - */ - public function __construct(array $params) + public function __construct(Horde_Kolab_Server_Connection_Mock_Ldap $ldap) { - if (isset($params['data'])) { - $this->data = $params['data']; - } - - if (isset($this->params['admin']) - && isset($this->params['admin']['type'])) { - $type = $this->params['admin']['type']; - $data = $this->params['admin']; - unset($data['type']); - $admin = new $type($this, null, $data); - if (!$admin->exists()) { - $admin->save(); - } - } + $this->_ldap = $ldap; } /** @@ -117,7 +52,7 @@ implements Horde_Kolab_Server_Connection */ public function getRead() { - return $this; + return $this->_ldap; } /** @@ -127,567 +62,6 @@ implements Horde_Kolab_Server_Connection */ public function getWrite() { - return $this; - } - - /** - * Binds the LDAP connection with a specific user and pass. - * - * @param string $dn DN to bind with - * @param string $pw Password associated to this DN. - * - * @return boolean Whether or not the binding succeeded. - * - * @throws Horde_Kolab_Server_Exception If the user does not exit, he has no - * password, provided an incorrect - * password or anonymous binding is not - * allowed. - */ - public function bind($dn = '', $pw = '') - { - if ($this->bound && empty($dn) && empty($pw)) { - return true; - } - - if (!$dn) { - if (isset($this->params['uid'])) { - $dn = $this->params['uid']; - } else { - $dn = ''; - } - } - if (!$pw) { - if (isset($this->params['pass'])) { - $pw = $this->params['pass']; - } - } - - if (!empty($dn)) { - if (!isset($this->data[$dn])) { - throw new Horde_Kolab_Server_Exception('User does not exist!'); - } - - $this->bound = true; - - try { - $data = $this->read($dn, array(Horde_Kolab_Server_Object_Person::ATTRIBUTE_USERPASSWORD)); - } catch (Horde_Kolab_Server_Exception $e) { - $this->bound = false; - throw $e; - } - if (!isset($data[Horde_Kolab_Server_Object_Person::ATTRIBUTE_USERPASSWORD])) { - $this->bound = false; - throw new Horde_Kolab_Server_Exception('User has no password entry!'); - } - $this->bound = $data['userPassword'][0] == $pw; - if (!$this->bound) { - throw new Horde_Kolab_Server_Exception('Incorrect password!'); - } - } else if (!empty($this->params['no_anonymous_bind'])) { - $this->bound = false; - throw new Horde_Kolab_Server_Exception('Anonymous bind is not allowed!'); - } else { - $this->bound = true; - } - - if ($this->bound) { - $this->load(); - } - - return $this->bound; - } - - /** - * Get a specific entry based on the DN - * - * @param string $dn DN of the entry that should be fetched - * @param array $attr Array of Attributes to select. If ommitted, all attributes are fetched. - * - * @return Net_LDAP2_Entry|Net_LDAP2_Error Reference to a Net_LDAP2_Entry object or Net_LDAP2_Error object - * @todo Maybe check against the shema should be done to be sure the attribute type exists - */ - public function getEntry($dn, $attr = array()) - { - if (!is_array($attr)) { - $attr = array($attr); - } - $result = $this->search($dn, '(objectClass=*)', - array('scope' => 'base', 'attributes' => $attr)); - if ($result->count() == 0) { - throw new Horde_Kolab_Server_Exception('Could not fetch entry '.$dn.': no entry found'); - } - $entry = $result->shiftEntry(); - if (false == $entry) { - throw new Horde_Kolab_Server_Exception('Could not fetch entry (error retrieving entry from search result)'); - } - return $entry; - } - - /** - * Search for object data. - * - * @param string $base The search base - * @param string $filter The LDAP search filter. - * @param string $params Additional search parameters. - * - * @return array The result array. - * - * @throws Horde_Kolab_Server_Exception If the search operation encountered - * a problem. - */ - public function search($base = null, $filter = null, $params = array()) - { - $this->bind(); - - $filter = $this->parse($filter); - if (isset($params['attributes'])) { - $attributes = $params['attributes']; - if (!is_array($attributes)) { - $attributes = array($attributes); - } - } else { - $attributes = array(); - } - - $result = $this->doSearch($filter, $attributes); - - if (empty($result)) { - $search = new Horde_Kolab_Server_Connection_Mock_Search(array()); - return $search; - } - - if (!empty($base)) { - $subtree = array(); - foreach ($result as $entry) { - if (strpos($entry['dn'], $base)) { - $subtree[] = $entry; - } - } - $result = $subtree; - } - - $search = new Horde_Kolab_Server_Connection_Mock_Search($this->getEntries($result)); - return $search; - } - - /** - * Return the entries of a result. - * - * @param array $result The LDAP search result. - * - * @return mixed The entries of the result or false. - */ - public function getEntries($result) - { - if (is_array($result)) { - $data = array(); - foreach ($result as $entry) { - $t = $entry['data']; - $t['dn'] = $entry['dn']; - $data[$entry['dn']] = $t; - } - return $data; - } - return false; - } - - /** - * Parse LDAP filter. - * Partially derived from Net_LDAP_Filter. - * - * @param string $filter The filter string. - * - * @return array An array of the parsed filter. - * - * @throws Horde_Kolab_Server_Exception If parsing the filter expression - * fails. - */ - public function parse($filter) - { - $result = array(); - if (preg_match('/^\((.+?)\)$/', $filter, $matches)) { - if (in_array(substr($matches[1], 0, 1), array('!', '|', '&'))) { - $result['op'] = substr($matches[1], 0, 1); - $result['sub'] = $this->parseSub(substr($matches[1], 1)); - return $result; - } else { - if (stristr($matches[1], ')(')) { - throw new Horde_Kolab_Server_Exception('Filter parsing error: invalid filter syntax - multiple leaf components detected!'); - } else { - $filter_parts = preg_split('/(?|<|>=|<=)/', - $matches[1], 2, - PREG_SPLIT_DELIM_CAPTURE); - if (count($filter_parts) != 3) { - throw new Horde_Kolab_Server_Exception('Filter parsing error: invalid filter syntax - unknown matching rule used'); - } else { - $result['att'] = $filter_parts[0]; - $result['log'] = $filter_parts[1]; - $val = Net_LDAP2_Util::unescape_filter_value($filter_parts[2]); - $result['val'] = $val[0]; - return $result; - } - } - } - } else { - throw new Horde_Kolab_Server_Exception(sprintf("Filter parsing error: %s - filter components must be enclosed in round brackets", - $filter)); - } - } - - /** - * Parse a LDAP subfilter. - * - * @param string $filter The subfilter string. - * - * @return array An array of the parsed subfilter. - * - * @throws Horde_Kolab_Server_Exception - */ - public function parseSub($filter) - { - $result = array(); - $level = 0; - $collect = ''; - while (preg_match('/^(\(.+?\))(.*)/', $filter, $matches)) { - if (in_array(substr($matches[1], 0, 2), array('(!', '(|', '(&'))) { - $level++; - } - if ($level) { - $collect .= $matches[1]; - if (substr($matches[2], 0, 1) == ')') { - $collect .= ')'; - $matches[2] = substr($matches[2], 1); - $level--; - if (!$level) { - $result[] = $this->parse($collect); - } - } - } else { - $result[] = $this->parse($matches[1]); - } - $filter = $matches[2]; - } - return $result; - } - - /** - * Perform the search. - * - * @param array $filter Filter criteria- - * @param array $attributes Restrict the search result to - * these attributes. - * - * @return array A LDAP serach result. - * - * @throws Horde_Kolab_Server_Exception If the search operation is not - * available. - */ - public function doSearch($filter, $attributes = null) - { - if (isset($filter['log'])) { - $result = array(); - foreach ($this->data as $element) { - if (isset($element['data'][$filter['att']])) { - switch ($filter['log']) { - case '=': - $value = $element['data'][$filter['att']]; - if (!empty($value) && is_array($value)) { - $keys = array_keys($value); - $first = $value[$keys[0]]; - } else { - $first = $value; - } - if ((($filter['val'] == '*') - && !empty($value)) - || $value == $filter['val'] - || (substr($filter['val'], 0, 1) == '*' - && substr($filter['val'], strlen($filter['val']) - 1) == '*' - && strpos($first, substr($filter['val'], 1, strlen($filter['val']) - 2)) !== false) - || (is_array($value) - && in_array($filter['val'], $value))) { - if (empty($attributes)) { - $result[] = $element; - } else { - $selection = $element; - foreach ($element['data'] as $attr => $value) { - if (!in_array($attr, $attributes)) { - unset($selection['data'][$attr]); - } - } - $result[] = $selection; - } - } - break; - default: - throw new Horde_Kolab_Server_Exception("Not implemented!"); - } - } - } - return $result; - } else { - $subresult = array(); - $filtercount = count($filter['sub']); - foreach ($filter['sub'] as $subfilter) { - $subresult = array_merge($subresult, - $this->doSearch($subfilter, - $attributes)); - } - $result = array(); - $dns = array(); - foreach ($subresult as $element) { - $dns[] = $element['dn']; - - $result[$element['dn']] = $element; - } - switch ($filter['op']) { - case '&': - $count = array_count_values($dns); - $selection = array(); - foreach ($count as $dn => $value) { - if ($value == $filtercount) { - $selection[] = $result[$dn]; - } - } - return $selection; - case '|': - return array_values($result); - case '!': - $dns = array(); - foreach ($result as $entry) { - if (!in_array($entry['dn'], $dns) ) { - $dns[] = $entry['dn']; - } - } - $all_dns = array_keys($this->data); - $diff = array_diff($all_dns, $dns); - - $result = array(); - foreach ($diff as $dn) { - if (empty($attributes)) { - $result[] = $this->data[$dn]; - } else { - $selection = $this->data[$dn]; - foreach ($this->data[$dn]['data'] - as $attr => $value) { - if (!in_array($attr, $attributes)) { - unset($selection['data'][$attr]); - } - } - $result[] = $selection; - } - } - return $result; - default: - throw new Horde_Kolab_Server_Exception("Not implemented!"); - } - } - } - - /** - * Add a new entryobject to a directory. - * - * @param Net_LDAP2_Entry $entry Net_LDAP2_Entry - * - * @return Net_LDAP2_Error|true Net_LDAP2_Error object or true - */ - public function add($entry) - { - $this->bind(); - - $ldap_data = $this->toStorage($entry->getValues()); - - $guid = $entry->getDn(); - - $this->data[$guid] = array( - 'dn' => $guid, - 'data' => array_merge($ldap_data, - array('dn' => $guid)), - ); - - $this->store(); - } - - /** - * Modify an ldapentry directly on the server - * - * @param string|Net_LDAP2_Entry &$entry DN-string or Net_LDAP2_Entry - * @param array $parms Array of changes - * - * @access public - * @return Net_LDAP2_Error|true Net_LDAP2_Error object or true - */ - public function modify($entry, $data = array()) - { - $this->bind(); - - $guid = $entry->getDn(); - - if (isset($data['delete'])) { - foreach ($data['delete'] as $k => $v) { - if (is_int($k)) { - if (isset($this->data[$guid]['data'][$w])) { - /** Delete a complete attribute */ - unset($this->data[$guid]['data'][$w]); - } - } else { - if (isset($this->data[$guid]['data'][$l])) { - if (!is_array($v)) { - $v = array($v); - } - foreach ($v as $w) { - $key = array_search($w, $this->data[$guid]['data'][$l]); - if ($key !== false) { - /** Delete a single value */ - unset($this->data[$guid]['data'][$l][$key]); - } - } - } - } - } - } - - if (isset($data['replace'])) { - $ldap_data = $this->toStorage($data['replace']); - - $this->data[$guid] = array( - 'dn' => $guid, - 'data' => array_merge($this->data[$guid]['data'], - $ldap_data, - array('dn' => $guid)), - ); - } - - if (isset($data['add'])) { - $ldap_data = $this->toStorage($data['add']); - - foreach ($ldap_data as $k => $v) { - if (is_array($v)) { - foreach ($v as $w) { - $this->data[$guid]['data'][$k][] = $w; - } - } else { - $this->data[$guid]['data'][$k][] = $v; - } - $this->data[$guid]['data'][$k] = array_values($this->data[$guid]['data'][$k]); - } - } - - $this->store(); - } - - /** - * Delete an object. - * - * @param string $uid The UID of the object to be deleted. - * - * @return NULL - * - * @throws Horde_Kolab_Server_Exception - */ - public function delete($uid) - { - if (isset($this->data[$uid])) { - unset($this->data[$uid]); - } else { - throw new Horde_Kolab_Server_MissingObjectException(sprintf("No such object: %s", - $uid)); - } - - $this->store(); - } - - /** - * Rename an object. - * - * @param string $uid The UID of the object to be renamed. - * @param string $new The new UID of the object. - * - * @return NULL - * - * @throws Horde_Kolab_Server_Exception - */ - public function move($uid, $new) - { - if (isset($this->data[$uid])) { - $this->data[$new] = $this->data[$uid]; - unset($this->data[$uid]); - } - - $this->store(); - } - - public function schema() - { - //@todo: implement - } - - /** - * Cleans the current state of the database. - * - * @return NULL - */ - public function clean() - { - $this->unbind(); - - $GLOBALS['KOLAB_SERVER_TEST_DATA'] = array(); - - $this->data = array(); - } - - /** - * Disconnect from LDAP. - * - * @return NULL - */ - public function unbind() - { - $this->bound = false; - } - - /** - * Load the current state of the database. - * - * @return NULL - */ - protected function load() - { - /** - * @todo: remove as it does not make much sense. The file based handler - * can do the same thing as a decorator. - */ - if (isset($GLOBALS['KOLAB_SERVER_TEST_DATA'])) { - $this->data = $GLOBALS['KOLAB_SERVER_TEST_DATA']; - } - } - - /** - * Store the current state of the database. - * - * @return NULL - */ - protected function store() - { - $GLOBALS['KOLAB_SERVER_TEST_DATA'] = $this->data; - } - - - /** - * Rewrite a data array to our internal storage format. - * - * @param array $data The attributes of the object to be added/replaced. - * - * @return array The transformed data set. - */ - protected function toStorage($data) - { - $ldap_data = array(); - foreach ($data as $key => $val) { - if (!is_array($val)) { - $val = array($val); - } - $ldap_data[$key] = $val; - } - return $ldap_data; + return $this->_ldap; } -} +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Connection/Mock/Ldap.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Connection/Mock/Ldap.php new file mode 100644 index 000000000..c97c6718a --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Connection/Mock/Ldap.php @@ -0,0 +1,606 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * This class provides a class for testing the Kolab Server DB. + * + * 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_Connection_Mock_Ldap +{ + /** + * Connection parameters. + * + * @var array + */ + private $_params; + + /** + * The current database data. + * + * @var array + */ + private $_data; + + /** + * Is the connection bound via username / password? + * + * @var boolean + */ + private $_bound = false; + + /** + * Constructor. + * + * @param array $params Connection parameters. + * @param array $data Mockup LDAP data. + */ + public function __construct(array $params, array $data) + { + $this->_params = $params; + $this->_data = $data; + } + + /** + * Binds the LDAP connection with a specific user and pass. + * + * @param string $dn DN to bind with + * @param string $pw Password associated to this DN. + * + * @return NULL + * + * @throws Horde_Kolab_Server_Exception If the user does not exit, he has no + * password, provided an incorrect + * password or anonymous binding is not + * allowed. + */ + public function bind($dn = '', $pw = '') + { + if ($dn == '' && $pw == '') { + if (isset($this->_params['binddn']) + && isset($this->_params['bindpw'])) { + $dn = $this->_params['binddn']; + $pw = $this->_params['bindpw']; + } + } + + if ($dn != '') { + if (!isset($this->_data[$dn])) { + throw new Horde_Kolab_Server_Exception('User does not exist!'); + } + + if (!isset($this->_data[$dn]['userPassword'][0])) { + throw new Horde_Kolab_Server_Exception('User has no password entry!'); + } + if ($this->_data[$dn]['userPassword'][0] != $pw) { + throw new Horde_Kolab_Server_Exception('Incorrect password!'); + } + } else if (!empty($this->params_['no_anonymous_bind'])) { + throw new Horde_Kolab_Server_Exception('Anonymous bind is not allowed!'); + } + + $this->_bound = true; + } + + /** + * Get a specific entry based on the DN + * + * @param string $dn DN of the entry that should be fetched + * @param array $attr Array of Attributes to select. If ommitted, all attributes are fetched. + * + * @return Net_LDAP2_Entry|Net_LDAP2_Error Reference to a Net_LDAP2_Entry object or Net_LDAP2_Error object + * @todo Maybe check against the shema should be done to be sure the attribute type exists + */ + public function getEntry($dn, $attr = array()) + { + $this->_checkBound(); + + if (!is_array($attr)) { + $attr = array($attr); + } + $result = $this->search($dn, '(objectClass=*)', + array('scope' => 'base', 'attributes' => $attr)); + if ($result->count() == 0) { + throw new Horde_Kolab_Server_Exception('Could not fetch entry '.$dn.': no entry found'); + } + $entry = $result->shiftEntry(); + if (false == $entry) { + throw new Horde_Kolab_Server_Exception('Could not fetch entry (error retrieving entry from search result)'); + } + return $entry; + } + + /** + * Search for object data. + * + * @param string $base The search base + * @param string $filter The LDAP search filter. + * @param string $params Additional search parameters. + * + * @return array The result array. + * + * @throws Horde_Kolab_Server_Exception If the search operation encountered + * a problem. + */ + public function search($base = null, $filter = null, $params = array()) + { + $this->_checkBound(); + + if (isset($params['attributes'])) { + $attributes = $params['attributes']; + if (!is_array($attributes)) { + $attributes = array($attributes); + } + } else { + $attributes = array(); + } + + $result = array(); + + if (!empty($filter)) { + $filter = $this->parse($filter); + $result = $this->doSearch($filter, $attributes); + } else { + if (isset($params['scope'])) { + if ($params['scope'] == 'base') { + if (isset($this->_data[$base])) { + $result = $this->_data[$base]; + } else { + $result = array(); + } + } else if ($params['scope'] == 'sub') { + //@todo: separate function + foreach (array_keys($this->_data) as $dn) { + if (empty($attributes)) { + $result[] = $this->_data[$dn]; + } else { + $selection = $this->_data[$dn]; + foreach ($this->_data[$dn]['data'] + as $attr => $value) { + if (!in_array($attr, $attributes)) { + unset($selection['data'][$attr]); + } + } + $result[] = $selection; + } + } + } else if ($params['scope'] == 'one') { + throw new Horde_Kolab_Server_Exception('Not implemented!'); + } + } else { + //@todo: separate function + foreach (array_keys($this->_data) as $dn) { + if (empty($attributes)) { + $result[] = $this->_data[$dn]; + } else { + $selection = $this->_data[$dn]; + foreach ($this->_data[$dn]['data'] + as $attr => $value) { + if (!in_array($attr, $attributes)) { + unset($selection['data'][$attr]); + } + } + $result[] = $selection; + } + } + } + } + + if (empty($result)) { + $search = new Horde_Kolab_Server_Connection_Mock_Search(array()); + return $search; + } + + if (!empty($base)) { + $subtree = array(); + foreach ($result as $entry) { + if (strpos($entry['dn'], $base)) { + $subtree[] = $entry; + } + } + $result = $subtree; + } + + $search = new Horde_Kolab_Server_Connection_Mock_Search($this->getEntries($result)); + return $search; + } + + /** + * Return the entries of a result. + * + * @param array $result The LDAP search result. + * + * @return mixed The entries of the result or false. + */ + public function getEntries($result) + { + if (is_array($result)) { + $data = array(); + foreach ($result as $entry) { + $t = $entry['data']; + $t['dn'] = $entry['dn']; + $data[$entry['dn']] = $t; + } + return $data; + } + return false; + } + + /** + * Parse LDAP filter. + * Partially derived from Net_LDAP_Filter. + * + * @param string $filter The filter string. + * + * @return array An array of the parsed filter. + * + * @throws Horde_Kolab_Server_Exception If parsing the filter expression + * fails. + */ + public function parse($filter) + { + $result = array(); + if (preg_match('/^\((.+?)\)$/', $filter, $matches)) { + if (in_array(substr($matches[1], 0, 1), array('!', '|', '&'))) { + $result['op'] = substr($matches[1], 0, 1); + $result['sub'] = $this->parseSub(substr($matches[1], 1)); + return $result; + } else { + if (stristr($matches[1], ')(')) { + throw new Horde_Kolab_Server_Exception('Filter parsing error: invalid filter syntax - multiple leaf components detected!'); + } else { + $filter_parts = preg_split('/(?|<|>=|<=)/', + $matches[1], 2, + PREG_SPLIT_DELIM_CAPTURE); + if (count($filter_parts) != 3) { + throw new Horde_Kolab_Server_Exception('Filter parsing error: invalid filter syntax - unknown matching rule used'); + } else { + $result['att'] = $filter_parts[0]; + $result['log'] = $filter_parts[1]; + $val = Net_LDAP2_Util::unescape_filter_value($filter_parts[2]); + $result['val'] = $val[0]; + return $result; + } + } + } + } else { + throw new Horde_Kolab_Server_Exception(sprintf("Filter parsing error: %s - filter components must be enclosed in round brackets", + $filter)); + } + } + + /** + * Parse a LDAP subfilter. + * + * @param string $filter The subfilter string. + * + * @return array An array of the parsed subfilter. + * + * @throws Horde_Kolab_Server_Exception + */ + public function parseSub($filter) + { + $result = array(); + $level = 0; + $collect = ''; + while (preg_match('/^(\(.+?\))(.*)/', $filter, $matches)) { + if (in_array(substr($matches[1], 0, 2), array('(!', '(|', '(&'))) { + $level++; + } + if ($level) { + $collect .= $matches[1]; + if (substr($matches[2], 0, 1) == ')') { + $collect .= ')'; + $matches[2] = substr($matches[2], 1); + $level--; + if (!$level) { + $result[] = $this->parse($collect); + } + } + } else { + $result[] = $this->parse($matches[1]); + } + $filter = $matches[2]; + } + return $result; + } + + /** + * Perform the search. + * + * @param array $filter Filter criteria- + * @param array $attributes Restrict the search result to + * these attributes. + * + * @return array A LDAP serach result. + * + * @throws Horde_Kolab_Server_Exception If the search operation is not + * available. + */ + public function doSearch($filter, $attributes = null) + { + if (isset($filter['log'])) { + $result = array(); + foreach ($this->_data as $element) { + if (isset($element['data'][$filter['att']])) { + switch ($filter['log']) { + case '=': + $value = $element['data'][$filter['att']]; + if (!empty($value) && is_array($value)) { + $keys = array_keys($value); + $first = $value[$keys[0]]; + } else { + $first = $value; + } + if ((($filter['val'] == '*') + && !empty($value)) + || $value == $filter['val'] + || (substr($filter['val'], 0, 1) == '*' + && substr($filter['val'], strlen($filter['val']) - 1) == '*' + && strpos($first, substr($filter['val'], 1, strlen($filter['val']) - 2)) !== false) + || (is_array($value) + && in_array($filter['val'], $value))) { + if (empty($attributes)) { + $result[] = $element; + } else { + $selection = $element; + foreach ($element['data'] as $attr => $value) { + if (!in_array($attr, $attributes)) { + unset($selection['data'][$attr]); + } + } + $result[] = $selection; + } + } + break; + default: + throw new Horde_Kolab_Server_Exception("Not implemented!"); + } + } + } + return $result; + } else { + $subresult = array(); + $filtercount = count($filter['sub']); + foreach ($filter['sub'] as $subfilter) { + $subresult = array_merge($subresult, + $this->doSearch($subfilter, + $attributes)); + } + $result = array(); + $dns = array(); + foreach ($subresult as $element) { + $dns[] = $element['dn']; + + $result[$element['dn']] = $element; + } + switch ($filter['op']) { + case '&': + $count = array_count_values($dns); + $selection = array(); + foreach ($count as $dn => $value) { + if ($value == $filtercount) { + $selection[] = $result[$dn]; + } + } + return $selection; + case '|': + return array_values($result); + case '!': + $dns = array(); + foreach ($result as $entry) { + if (!in_array($entry['dn'], $dns) ) { + $dns[] = $entry['dn']; + } + } + $all_dns = array_keys($this->_data); + $diff = array_diff($all_dns, $dns); + + $result = array(); + foreach ($diff as $dn) { + if (empty($attributes)) { + $result[] = $this->_data[$dn]; + } else { + $selection = $this->_data[$dn]; + foreach ($this->_data[$dn]['data'] + as $attr => $value) { + if (!in_array($attr, $attributes)) { + unset($selection['data'][$attr]); + } + } + $result[] = $selection; + } + } + return $result; + default: + throw new Horde_Kolab_Server_Exception("Not implemented!"); + } + } + } + + /** + * Add a new entryobject to a directory. + * + * @param Net_LDAP2_Entry $entry Net_LDAP2_Entry + * + * @return Net_LDAP2_Error|true Net_LDAP2_Error object or true + */ + public function add($entry) + { + $this->_checkBound(); + + $ldap_data = $this->toStorage($entry->getValues()); + + $guid = $entry->getDn(); + + $this->_data[$guid] = array( + 'dn' => $guid, + 'data' => array_merge($ldap_data, + array('dn' => $guid)), + ); + } + + /** + * Modify an ldapentry directly on the server + * + * @param string|Net_LDAP2_Entry &$entry DN-string or Net_LDAP2_Entry + * @param array $parms Array of changes + * + * @access public + * @return Net_LDAP2_Error|true Net_LDAP2_Error object or true + */ + public function modify($entry, $data = array()) + { + $this->_checkBound(); + + $guid = $entry->getDn(); + + if (isset($data['delete'])) { + foreach ($data['delete'] as $k => $v) { + if (is_int($k)) { + if (isset($this->_data[$guid]['data'][$w])) { + /** Delete a complete attribute */ + unset($this->_data[$guid]['data'][$w]); + } + } else { + if (isset($this->_data[$guid]['data'][$l])) { + if (!is_array($v)) { + $v = array($v); + } + foreach ($v as $w) { + $key = array_search($w, $this->_data[$guid]['data'][$l]); + if ($key !== false) { + /** Delete a single value */ + unset($this->_data[$guid]['data'][$l][$key]); + } + } + } + } + } + } + + if (isset($data['replace'])) { + $ldap_data = $this->toStorage($data['replace']); + + $this->_data[$guid] = array( + 'dn' => $guid, + 'data' => array_merge($this->_data[$guid]['data'], + $ldap_data, + array('dn' => $guid)), + ); + } + + if (isset($data['add'])) { + $ldap_data = $this->toStorage($data['add']); + + foreach ($ldap_data as $k => $v) { + if (is_array($v)) { + foreach ($v as $w) { + $this->_data[$guid]['data'][$k][] = $w; + } + } else { + $this->_data[$guid]['data'][$k][] = $v; + } + $this->_data[$guid]['data'][$k] = array_values($this->_data[$guid]['data'][$k]); + } + } + } + + /** + * Delete an object. + * + * @param string $uid The UID of the object to be deleted. + * + * @return NULL + * + * @throws Horde_Kolab_Server_Exception + */ + public function delete($uid) + { + $this->_checkBound(); + + if (isset($this->_data[$uid])) { + unset($this->_data[$uid]); + } else { + throw new Horde_Kolab_Server_MissingObjectException(sprintf("No such object: %s", + $uid)); + } + } + + /** + * Rename an object. + * + * @param string $uid The UID of the object to be renamed. + * @param string $new The new UID of the object. + * + * @return NULL + * + * @throws Horde_Kolab_Server_Exception + */ + public function move($uid, $new) + { + $this->_checkBound(); + + if (isset($this->_data[$uid])) { + $this->_data[$new] = $this->_data[$uid]; + unset($this->_data[$uid]); + } + } + + public function schema() + { + //@todo: implement + } + + /** + * Rewrite a data array to our internal storage format. + * + * @param array $data The attributes of the object to be added/replaced. + * + * @return array The transformed data set. + */ + protected function toStorage($data) + { + $ldap_data = array(); + foreach ($data as $key => $val) { + if (!is_array($val)) { + $val = array($val); + } + $ldap_data[$key] = $val; + } + return $ldap_data; + } + + /** + * Check if the current connection is bound. + * + * @return NULL + * + * @throws Horde_Kolab_Server_Exception If the connection is not bound. + */ + private function _checkBound() + { + if (!$this->_bound) { + throw new Horde_Kolab_Server_Exception('Unbound connection!'); + } + } +} diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn/Mock.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn/Mock.php index 8578f50e8..253821143 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn/Mock.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn/Mock.php @@ -35,8 +35,16 @@ extends Horde_Kolab_Server_Factory_Conn_Base */ public function getConnection() { + $config = $this->getConfiguration(); + if (isset($config['data'])) { + $data = $config['data']; + } else { + $data = array(); + } $connection = new Horde_Kolab_Server_Connection_Mock( - $this->getConfiguration() + new Horde_Kolab_Server_Connection_Mock_Ldap( + $config, $data + ) ); return $connection; } diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Constructor.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Constructor.php index f9e26d5c6..0762abcf0 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Constructor.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Constructor.php @@ -76,8 +76,8 @@ extends Horde_Kolab_Server_Factory_Base public function __construct( Horde_Kolab_Server_Factory_Conn $factory, Horde_Kolab_Server_Objects $objects, - Horde_Kolab_Server_Structure $structure, - Horde_Kolab_Server_Search $search, + Horde_Kolab_Server_Structure_Interface $structure, + Horde_Kolab_Server_Search_Interface $search, Horde_Kolab_Server_Schema $schema, array $config ) { diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Injector.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Injector.php index 0699c40c0..e3b3ba1f3 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Injector.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Injector.php @@ -138,7 +138,7 @@ implements Horde_Kolab_Server_Factory private function _setupSearch() { $this->_injector->bindImplementation( - 'Horde_Kolab_Server_Search', + 'Horde_Kolab_Server_Search_Interface', 'Horde_Kolab_Server_Search_Base' ); } @@ -170,7 +170,9 @@ implements Horde_Kolab_Server_Factory $driver = $configuration['structure']['driver']; } - $this->_injector->bindImplementation('Horde_Kolab_Server_Structure', $driver); + $this->_injector->bindImplementation( + 'Horde_Kolab_Server_Structure_Interface', $driver + ); } /** @@ -290,7 +292,7 @@ implements Horde_Kolab_Server_Factory */ public function getStructure() { - return $this->_injector->getInstance('Horde_Kolab_Server_Structure'); + return $this->_injector->getInstance('Horde_Kolab_Server_Structure_Interface'); } /** @@ -300,7 +302,7 @@ implements Horde_Kolab_Server_Factory */ public function getSearch() { - return $this->_injector->getInstance('Horde_Kolab_Server_Search'); + return $this->_injector->getInstance('Horde_Kolab_Server_Search_Interface'); } /** 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 08eacba14..9f4e85017 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabinetorgperson.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabinetorgperson.php @@ -269,27 +269,6 @@ class Horde_Kolab_Server_Object_Kolabinetorgperson extends Horde_Kolab_Server_Ob } /** - * Returns the set of search operations supported by this object type. - * - * @return array An array of supported search operations. - */ - static public function getSearchOperations() - { - $searches = array( - 'Horde_Kolab_Server_Object_Search_Guidforkolabusers', - 'Horde_Kolab_Server_Object_Search_Guidforuid', - 'Horde_Kolab_Server_Object_Search_Guidformail', - 'Horde_Kolab_Server_Object_Search_Guidforuidormail', - 'Horde_Kolab_Server_Object_Search_Guidforalias', - 'Horde_Kolab_Server_Object_Search_Guidformailoralias', - 'Horde_Kolab_Server_Object_Search_Guidforuidormailoralias', - 'Horde_Kolab_Server_Object_Search_Mailforuidormail', - 'Horde_Kolab_Server_Object_Search_Addressesforuidormail', - ); - return $searches; - } - - /** * Returns the server url of the given type for this user. * * This method is used to encapsulate multidomain support. diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Person.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Person.php index e0c72f000..5d117d135 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Person.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Person.php @@ -215,16 +215,4 @@ class Horde_Kolab_Server_Object_Person extends Horde_Kolab_Server_Object_Top unset($info[self::ATTRIBUTE_USERPASSWORD]); } } - - /** - * Returns the set of search operations supported by this object type. - * - * @return array An array of supported search operations. - */ - static public function getSearchOperations() - { - return array( - 'Horde_Kolab_Server_Object_Search_Guidforcn', - ); - } } \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Searches.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Searches.php index bb60d7d5b..c7e9635ef 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Searches.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Searches.php @@ -36,11 +36,4 @@ interface Horde_Kolab_Server_Object_Searches * database. */ public static function getFilter(); - - /** - * Returns the set of search operations supported by this object type. - * - * @return array An array of supported search operations. - */ - public static function getSearchOperations(); } \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Top.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Top.php index 5b50743b5..00a61fd29 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Top.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Top.php @@ -86,21 +86,6 @@ implements Horde_Kolab_Server_Object_Searches } /** - * Returns the set of search operations supported by this object type. - * - * @return array An array of supported search operations. - */ - static public function getSearchOperations() - { - $searches = array( - 'Horde_Kolab_Server_Object_Search_Guid', - 'Horde_Kolab_Server_Object_Search_Attributes', - 'Horde_Kolab_Server_Object_Search_Children', - ); - return $searches; - } - - /** * Returns the set of actions supported by this object type. * * @return array An array of supported actions. diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Objects/Base.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Objects/Base.php index 36a242367..1c38fbdab 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Objects/Base.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Objects/Base.php @@ -33,7 +33,7 @@ class Horde_Kolab_Server_Objects_Base implements Horde_Kolab_Server_Objects * * @var Horde_Kolab_Server_Composite */ - protected $composite; + private $_composite; /** * Set the composite server reference for this object. @@ -45,7 +45,7 @@ class Horde_Kolab_Server_Objects_Base implements Horde_Kolab_Server_Objects */ public function setComposite(Horde_Kolab_Server_Composite $composite) { - $this->composite = $composite; + $this->_composite = $composite; } /** @@ -79,13 +79,15 @@ class Horde_Kolab_Server_Objects_Base implements Horde_Kolab_Server_Objects public function fetch($uid = null, $type = null) { if (!isset($uid)) { - $uid = $this->uid; + $guid = $this->_composite->server->getGuid(); } if (empty($type)) { - $type = $this->determineType($uid); + $type = $this->_composite->structure->determineType($guid); } - $object = &Horde_Kolab_Server_Object::factory($type, $uid, $this); + $object = &Horde_Kolab_Server_Object_Factory::factory( + $type, $guid, $this->_composite->server + ); return $object; } diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Query/Ldap.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Query/Ldap.php index ddb05bb2b..ae24422ad 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Query/Ldap.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Query/Ldap.php @@ -48,7 +48,7 @@ class Horde_Kolab_Server_Query_Ldap implements Horde_Kolab_Server_Query */ public function __construct( Horde_Kolab_Server_Query_Element $criteria, - Horde_Kolab_Server_Structure $structure + Horde_Kolab_Server_Structure_Interface $structure ) { $this->_criteria = $criteria; $this->_structure = $structure; diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Result/Ldap.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Result/Ldap.php index 273a0c0ff..7494569bd 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Result/Ldap.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Result/Ldap.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_Result_Ldap implements Horde_Kolab_Server_Result +class Horde_Kolab_Server_Result_Ldap implements Horde_Kolab_Server_Result { /** * The search result. diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Base.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Base.php index 18f4604cc..0f3042a22 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Base.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Base.php @@ -27,7 +27,8 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Search_Base implements Horde_Kolab_Server_Search +class Horde_Kolab_Server_Search_Base +implements Horde_Kolab_Server_Search_Interface { /** * A link to the composite server handler. @@ -65,28 +66,21 @@ class Horde_Kolab_Server_Search_Base implements Horde_Kolab_Server_Search private function _getSearchOperations() { $server_searches = array(); - foreach ($this->_composite->structure->getSupportedObjects() as $sobj) { - $methods = get_class_methods($sobj); - if (!in_array('getSearchOperations', $methods)) { - continue; + foreach ($this->_composite->structure->getSearchOperations() as $search_class) { + if (!class_exists($search_class)) { + throw new Horde_Kolab_Server_Exception( + sprintf( + "%s::getSearchOperations specified non-existing class \"%s\"!", + get_class($this->_composite->structure), + $search_class + ) + ); } - $search_classes = call_user_func(array($sobj, 'getSearchOperations')); - foreach ($search_classes as $search_class) { - if (!class_exists($search_class)) { - throw new Horde_Kolab_Server_Exception( - sprintf( - "%s::getSearchOperations specified non-existing class \"%s\"!", - $sobj, - $search_class - ) - ); - } - $methods = get_class_methods($search_class); - unset($methods['getComposite']); - unset($methods['__construct']); - foreach ($methods as $method) { - $server_searches[$method] = array('class' => $search_class); - } + $methods = get_class_methods($search_class); + unset($methods['getComposite']); + unset($methods['__construct']); + foreach ($methods as $method) { + $server_searches[$method] = array('class' => $search_class); } } return $server_searches; @@ -116,7 +110,7 @@ class Horde_Kolab_Server_Search_Base implements Horde_Kolab_Server_Search { if (in_array($method, array_keys($this->_searches))) { $class = $this->_searches[$method]['class']; - $search = new $class($this->_composite); + $search = new $class($this->_composite->structure); return call_user_func_array(array($search, $method), $args); } throw new Horde_Kolab_Server_Exception( diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Interface.php similarity index 97% rename from framework/Kolab_Server/lib/Horde/Kolab/Server/Search.php rename to framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Interface.php index 51137f3d9..740b49462 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Interface.php @@ -25,7 +25,7 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -interface Horde_Kolab_Server_Search +interface Horde_Kolab_Server_Search_Interface { /** * Set the composite server reference for this object. diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Addressesforuidormail.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Addressesforuidormail.php similarity index 92% rename from framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Addressesforuidormail.php rename to framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Addressesforuidormail.php index 21a24bdcb..06358e6d2 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Addressesforuidormail.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Addressesforuidormail.php @@ -27,14 +27,14 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Object_Search_Addressesforuidormail -extends Horde_Kolab_Server_Object_Search_Base +class Horde_Kolab_Server_Search_Operation_Addressesforuidormail +extends Horde_Kolab_Server_Search_Operation_Base { /** * The basic attribute search. * - * @var Horde_Kolab_Server_Object_Search + * @var Horde_Kolab_Server_Search_Operation */ private $_search; @@ -47,7 +47,7 @@ extends Horde_Kolab_Server_Object_Search_Base public function __construct(Horde_Kolab_Server_Composite $composite) { $this->_composite = $composite; - $this->_search = new Horde_Kolab_Server_Object_Search_Attributes( + $this->_search = new Horde_Kolab_Server_Search_Operation_Attributes( $this->getComposite() ); } @@ -79,7 +79,7 @@ extends Horde_Kolab_Server_Object_Search_Base ) ) ); - $search = new Horde_Kolab_Server_Object_Search_Constraint_Strict( + $search = new Horde_Kolab_Server_Search_Operation_Constraint_Strict( $this->_search ); diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Attributes.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Attributes.php similarity index 92% rename from framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Attributes.php rename to framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Attributes.php index 058023552..01abc4242 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Attributes.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Attributes.php @@ -25,8 +25,8 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Object_Search_Attributes -extends Horde_Kolab_Server_Object_Search_Base +class Horde_Kolab_Server_Search_Operation_Attributes +extends Horde_Kolab_Server_Search_Operation_Base { /** * Perform the search. diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Base.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Base.php similarity index 56% rename from framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Base.php rename to framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Base.php index b14446e3e..17df4fbb7 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Base.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Base.php @@ -25,35 +25,37 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -abstract class Horde_Kolab_Server_Object_Search_Base -implements Horde_Kolab_Server_Object_Search +abstract class Horde_Kolab_Server_Search_Operation_Base +implements Horde_Kolab_Server_Search_Operation_Interface { /** - * A link to the composite server handler. + * A link to the server structure. * - * @var Horde_Kolab_Server_Composite + * @var Horde_Kolab_Server_Structure_Interface */ - private $_composite; + private $_structure; /** * Constructor * - * @param Horde_Kolab_Server_Composite $composite A link to the composite - * server handler. + * @param Horde_Kolab_Server_Structure_Interface $structure A link to the + * server + * structure. */ - public function __construct(Horde_Kolab_Server_Composite $composite) - { - $this->_composite = $composite; + public function __construct( + Horde_Kolab_Server_Structure_Interface $structure + ) { + $this->_structure = $structure; } /** - * Return the refernce to the composite server. + * Return the reference to the server structure. * - * @return Horde_Kolab_Server_Composite + * @return Horde_Kolab_Server_Structure_Interface */ - public function getComposite() + public function getStructure() { - return $this->_composite; + return $this->_structure; } /** @@ -63,11 +65,8 @@ implements Horde_Kolab_Server_Object_Search * * @return boolean|array The GUID(s) or false if there was no result. */ - protected function guidFromResult($result) + protected function guidFromResult(Horde_Kolab_Server_Result $result) { - if (empty($result)) { - return false; - } - return array_keys($result); + return array_keys($result->asArray()); } } \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Children.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Children.php similarity index 93% rename from framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Children.php rename to framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Children.php index 8d18c8abf..2f211672e 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Children.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Children.php @@ -25,8 +25,8 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Object_Search_Children -extends Horde_Kolab_Server_Object_Search_Base +class Horde_Kolab_Server_Search_Operation_Children +extends Horde_Kolab_Server_Search_Operation_Base { /** * Perform the search. diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Constraint/Single.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Constraint/Single.php similarity index 74% rename from framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Constraint/Single.php rename to framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Constraint/Single.php index c935a5dd9..bf7aba0b5 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Constraint/Single.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Constraint/Single.php @@ -25,13 +25,13 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Object_Search_Constraint_Single -implements Horde_Kolab_Server_Object_Search +class Horde_Kolab_Server_Search_Operation_Constraint_Single +implements Horde_Kolab_Server_Search_Operation_Interface { /** * A link to the search. * - * @var Horde_Kolab_Server_Object_Search + * @var Horde_Kolab_Server_Search_Operation */ private $_search; @@ -40,19 +40,20 @@ implements Horde_Kolab_Server_Object_Search * * @param Horde_Kolab_Server_Search $search The search being restricted. */ - public function __construct(Horde_Kolab_Server_Object_Search $search) - { + public function __construct( + Horde_Kolab_Server_Search_Operation_Interface $search + ) { $this->_search = $search; } /** - * Return the refernce to the composite server. + * Return the reference to the server structure. * - * @return Horde_Kolab_Server_Composite + * @return Horde_Kolab_Server_Structure_Interface */ - public function getComposite() + public function getStructure() { - return $this->_search->getComposite(); + return $this->_search->getStructure(); } /** @@ -67,6 +68,6 @@ implements Horde_Kolab_Server_Object_Search { $args = func_get_args(); $result = call_user_func_array(array($this->_search, $method), $args); - return array_pop($result); + return array_shift($result); } } \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Constraint/Strict.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Constraint/Strict.php similarity index 78% rename from framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Constraint/Strict.php rename to framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Constraint/Strict.php index b1e740d73..d81863673 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Constraint/Strict.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Constraint/Strict.php @@ -25,8 +25,8 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Object_Search_Constraint_Strict -implements Horde_Kolab_Server_Object_Search +class Horde_Kolab_Server_Search_Operation_Constraint_Strict +implements Horde_Kolab_Server_Search_Operation_Interface { /** * A link to the search. @@ -40,19 +40,20 @@ implements Horde_Kolab_Server_Object_Search * * @param Horde_Kolab_Server_Search $search The search being restricted. */ - public function __construct(Horde_Kolab_Server_Search $search) - { + public function __construct( + Horde_Kolab_Server_Search_Operation_Interface $search + ) { $this->_search = $search; } /** - * Return the refernce to the composite server. + * Return the reference to the server structure. * - * @return Horde_Kolab_Server_Composite + * @return Horde_Kolab_Server_Structure_Interface */ - public function getComposite() + public function getStructure() { - return $this->_search->getComposite(); + return $this->_search->getStructure(); } /** @@ -65,9 +66,7 @@ implements Horde_Kolab_Server_Object_Search */ public function __call($method, $args) { - $args = func_get_args(); $result = call_user_func_array(array($this->_search, $method), $args); - $result = call_user_func_array(array($this->_search, 'search'), $args); if (count($result) > 1) { throw new Horde_Kolab_Server_Exception( sprintf( @@ -77,6 +76,6 @@ implements Horde_Kolab_Server_Object_Search Horde_Kolab_Server_Exception::SEARCH_CONSTRAINT_TOO_MANY ); } - return $result; + return array_shift($result); } } \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guid.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guid.php similarity index 86% rename from framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guid.php rename to framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guid.php index 45dc17e6b..d0049bc0c 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guid.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guid.php @@ -25,8 +25,8 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Object_Search_Guid -extends Horde_Kolab_Server_Object_Search_Base +class Horde_Kolab_Server_Search_Operation_Guid +extends Horde_Kolab_Server_Search_Operation_Base { /** * Perform the search. @@ -40,7 +40,7 @@ extends Horde_Kolab_Server_Object_Search_Base $params = array( 'attributes' => 'Guid' ); - $data = $this->getComposite()->structure->find($criteria, $params); + $data = $this->getStructure()->find($criteria, $params); return self::guidFromResult($data); } } \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforalias.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforalias.php similarity index 91% rename from framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforalias.php rename to framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforalias.php index 9592bca39..ba2398a10 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforalias.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforalias.php @@ -25,8 +25,8 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Object_Search_Guidforalias -extends Horde_Kolab_Server_Object_Search_Restrictkolab +class Horde_Kolab_Server_Search_Operation_Guidforalias +extends Horde_Kolab_Server_Search_Operation_Restrictkolab { /** * Return all KolabInetOrgPersons with the given alias. diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforcn.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforcn.php similarity index 92% rename from framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforcn.php rename to framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforcn.php index 5b31bd31d..dba8d5ac7 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforcn.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforcn.php @@ -25,8 +25,8 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Object_Search_Guidforcn -extends Horde_Kolab_Server_Object_Search_Guid +class Horde_Kolab_Server_Search_Operation_Guidforcn +extends Horde_Kolab_Server_Search_Operation_Guid { /** * Identify the GUID for the objects found with the given common name. diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforkolabusers.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforkolabusers.php similarity index 91% rename from framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforkolabusers.php rename to framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforkolabusers.php index 3266c6320..3f003978b 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforkolabusers.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforkolabusers.php @@ -25,8 +25,8 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Object_Search_Guidforkolabusers -extends Horde_Kolab_Server_Object_Search_Guid +class Horde_Kolab_Server_Search_Operation_Guidforkolabusers +extends Horde_Kolab_Server_Search_Operation_Guid { /** * Return the GUIDs of all KolabInetOrgPersons. diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidformail.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidformail.php similarity index 91% rename from framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidformail.php rename to framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidformail.php index 3974c7124..71b739dd9 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidformail.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidformail.php @@ -25,8 +25,8 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Object_Search_Guidformail -extends Horde_Kolab_Server_Object_Search_Restrictkolab +class Horde_Kolab_Server_Search_Operation_Guidformail +extends Horde_Kolab_Server_Search_Operation_Restrictkolab { /** * Return all KolabInetOrgPersons with the given mail. diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidformailoralias.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidformailoralias.php similarity index 92% rename from framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidformailoralias.php rename to framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidformailoralias.php index 6ca3fe585..7cb8f290c 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidformailoralias.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidformailoralias.php @@ -25,8 +25,8 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Object_Search_Guidformailoralias -extends Horde_Kolab_Server_Object_Search_Restrictkolab +class Horde_Kolab_Server_Search_Operation_Guidformailoralias +extends Horde_Kolab_Server_Search_Operation_Restrictkolab { /** * Return all KolabInetOrgPersons with the given mail or alias address. diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuid.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforuid.php similarity index 91% rename from framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuid.php rename to framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforuid.php index 0c62c859d..0acbc678f 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuid.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforuid.php @@ -25,8 +25,8 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Object_Search_Guidforuid -extends Horde_Kolab_Server_Object_Search_Restrictkolab +class Horde_Kolab_Server_Search_Operation_Guidforuid +extends Horde_Kolab_Server_Search_Operation_Restrictkolab { /** * Return all KolabInetOrgPersons with the given uid. diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuidormail.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforuidormail.php similarity index 57% rename from framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuidormail.php rename to framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforuidormail.php index 3d5eb60d6..020a15bba 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuidormail.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforuidormail.php @@ -25,10 +25,44 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Object_Search_Guidforuidormail -extends Horde_Kolab_Server_Object_Search_Restrictkolab +class Horde_Kolab_Server_Search_Operation_Guidforuidormail +implements Horde_Kolab_Server_Search_Operation_Interface { /** + * A link to the search. + * + * @var Horde_Kolab_Server_Search + */ + private $_search; + + /** + * Constructor + * + * @param Horde_Kolab_Server_Structure_Interface $structure A link to the + * server + * structure. + */ + public function __construct( + Horde_Kolab_Server_Structure_Interface $structure + ) { + $this->_search = new Horde_Kolab_Server_Search_Operation_Constraint_Strict( + new Horde_Kolab_Server_Search_Operation_Restrictkolab( + $structure + ) + ); + } + + /** + * Return the reference to the server structure. + * + * @return Horde_Kolab_Server_Structure_Interface + */ + public function getStructure() + { + return $this->_search->getStructure(); + } + + /** * Return all KolabInetOrgPersons with the given uid or mail address. * * @param string $id The uid or mail address to search for. @@ -49,6 +83,6 @@ extends Horde_Kolab_Server_Object_Search_Restrictkolab ) ) ); - return parent::searchRestrictKolab($criteria); + return $this->_search->searchRestrictKolab($criteria); } } \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuidormailoralias.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforuidormailoralias.php similarity index 93% rename from framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuidormailoralias.php rename to framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforuidormailoralias.php index 177ef9669..0fa1dd9e4 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuidormailoralias.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforuidormailoralias.php @@ -25,8 +25,8 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Object_Search_Guidforuidormailoralias -extends Horde_Kolab_Server_Object_Search_Restrictkolab +class Horde_Kolab_Server_Search_Operation_Guidforuidormailoralias +extends Horde_Kolab_Server_Search_Operation_Restrictkolab { /** * Return all KolabInetOrgPersons with the given uid, mail or alias address. diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Interface.php similarity index 80% rename from framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search.php rename to framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Interface.php index 445989b33..a6214aacf 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Interface.php @@ -25,12 +25,12 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -interface Horde_Kolab_Server_Object_Search +interface Horde_Kolab_Server_Search_Operation_Interface { /** - * Return the refernce to the composite server. + * Return the reference to the server structure. * - * @return Horde_Kolab_Server_Composite + * @return Horde_Kolab_Server_Structure_Interface */ - public function getComposite(); + public function getStructure(); } \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Mailforuidormail.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Mailforuidormail.php similarity index 89% rename from framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Mailforuidormail.php rename to framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Mailforuidormail.php index 3006cf1e0..62df3c191 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Mailforuidormail.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Mailforuidormail.php @@ -27,14 +27,14 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Object_Search_Mailforuidormail -extends Horde_Kolab_Server_Object_Search_Base +class Horde_Kolab_Server_Search_Operation_Mailforuidormail +extends Horde_Kolab_Server_Search_Operation_Base { /** * The base attribute search. * - * @var Horde_Kolab_Server_Object_Search + * @var Horde_Kolab_Server_Search_Operation */ private $_search; @@ -47,8 +47,8 @@ extends Horde_Kolab_Server_Object_Search_Base public function __construct(Horde_Kolab_Server_Composite $composite) { $this->_composite = $composite; - $this->_search = new Horde_Kolab_Server_Object_Search_Constraint_Strict( - new Horde_Kolab_Server_Object_Search_Attributes( + $this->_search = new Horde_Kolab_Server_Search_Operation_Constraint_Strict( + new Horde_Kolab_Server_Search_Operation_Attributes( $this->getComposite() ) ); diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Restrictkolab.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Restrictkolab.php similarity index 93% rename from framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Restrictkolab.php rename to framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Restrictkolab.php index c7c7e2517..f60f2a6e8 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Restrictkolab.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Restrictkolab.php @@ -25,8 +25,8 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Object_Search_Restrictkolab -extends Horde_Kolab_Server_Object_Search_Guid +class Horde_Kolab_Server_Search_Operation_Restrictkolab +extends Horde_Kolab_Server_Search_Operation_Guid { /** * Restrict a search to KolabInetOrgPersons. 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 d840ef3d2..a851db8ec 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Base.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Base.php @@ -25,7 +25,8 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -abstract class Horde_Kolab_Server_Structure_Base implements Horde_Kolab_Server_Structure +abstract class Horde_Kolab_Server_Structure_Base +implements Horde_Kolab_Server_Structure_Interface { /** * A link to the composite server handler. diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Interface.php similarity index 93% rename from framework/Kolab_Server/lib/Horde/Kolab/Server/Structure.php rename to framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Interface.php index 9b38e8040..01f2d12e9 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Interface.php @@ -26,7 +26,7 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -interface Horde_Kolab_Server_Structure +interface Horde_Kolab_Server_Structure_Interface { /** * Finds object data matching a given set of criteria. @@ -78,6 +78,13 @@ interface Horde_Kolab_Server_Structure public function getSupportedObjects(); /** + * Returns the set of search operations supported by this object type. + * + * @return array An array of supported search operations. + */ + public function getSearchOperations(); + + /** * Maps the external attribute name to its internal counterpart. * * @param string $external The external attribute name. diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Kolab.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Kolab.php index 28c9a5616..819a9b970 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Kolab.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Kolab.php @@ -57,6 +57,31 @@ class Horde_Kolab_Server_Structure_Kolab extends Horde_Kolab_Server_Structure_Ld } /** + * Returns the set of search operations supported by this object type. + * + * @return array An array of supported search operations. + */ + public function getSearchOperations() + { + $searches = array( + 'Horde_Kolab_Server_Search_Operation_Guid', + 'Horde_Kolab_Server_Search_Operation_Attributes', + 'Horde_Kolab_Server_Search_Operation_Children', + 'Horde_Kolab_Server_Search_Operation_Guidforcn', + 'Horde_Kolab_Server_Search_Operation_Guidforkolabusers', + 'Horde_Kolab_Server_Search_Operation_Guidforuid', + 'Horde_Kolab_Server_Search_Operation_Guidformail', + 'Horde_Kolab_Server_Search_Operation_Guidforuidormail', + 'Horde_Kolab_Server_Search_Operation_Guidforalias', + 'Horde_Kolab_Server_Search_Operation_Guidformailoralias', + 'Horde_Kolab_Server_Search_Operation_Guidforuidormailoralias', + 'Horde_Kolab_Server_Search_Operation_Mailforuidormail', + 'Horde_Kolab_Server_Search_Operation_Addressesforuidormail', + ); + return $searches; + } + + /** * 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 8518d0b2c..64f0f028d 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Ldap.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Ldap.php @@ -40,6 +40,22 @@ class Horde_Kolab_Server_Structure_Ldap extends Horde_Kolab_Server_Structure_Bas } /** + * Returns the set of search operations supported by this object type. + * + * @return array An array of supported search operations. + */ + public function getSearchOperations() + { + $searches = array( + 'Horde_Kolab_Server_Search_Operation_Guid', + 'Horde_Kolab_Server_Search_Operation_Attributes', + 'Horde_Kolab_Server_Search_Operation_Children', + 'Horde_Kolab_Server_Search_Operation_Guidforcn', + ); + return $searches; + } + + /** * Determine the type of an object by its tree position and other * parameters. * diff --git a/framework/Kolab_Server/package.xml b/framework/Kolab_Server/package.xml index 58265c3fc..898267f92 100644 --- a/framework/Kolab_Server/package.xml +++ b/framework/Kolab_Server/package.xml @@ -68,6 +68,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + @@ -139,28 +140,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - - - - - - - - - - - - - - - - - - - - - - @@ -205,13 +184,35 @@ http://pear.php.net/dtd/package-2.0.xsd"> - + + + + + + + + + + + + + + + + + + + + + + + - + @@ -224,13 +225,14 @@ http://pear.php.net/dtd/package-2.0.xsd"> - - - - + + + + + @@ -252,6 +254,17 @@ http://pear.php.net/dtd/package-2.0.xsd"> + + + + + + + + + + + @@ -264,11 +277,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - - - - - @@ -281,6 +289,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + @@ -288,16 +297,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - - - - - - - - - - @@ -339,6 +338,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + @@ -404,24 +404,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - - - - - - - - - - - - - - - - - - @@ -446,16 +428,37 @@ http://pear.php.net/dtd/package-2.0.xsd"> - - + + + + + + + + + + + + + + + + + + + + - - + + + + + @@ -471,13 +474,13 @@ http://pear.php.net/dtd/package-2.0.xsd"> + + + - - - @@ -489,16 +492,13 @@ http://pear.php.net/dtd/package-2.0.xsd"> + - - - - diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/CleanerTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/CleanerTest.php new file mode 100644 index 000000000..cf72621d2 --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/CleanerTest.php @@ -0,0 +1,210 @@ + + * @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 cleanup decorator for the server. + * + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Class_Server_CleanerTest extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + parent::setUp(); + + $this->server = $this->getMock('Horde_Kolab_Server'); + $this->cleaner = new Horde_Kolab_Server_Cleaner($this->server); + } + + public function testMethodGetbaseguidHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $this->server->expects($this->exactly(1)) + ->method('getBaseGuid') + ->will($this->returnValue('base')); + $this->assertEquals('base', $this->cleaner->getBaseGuid()); + } + + public function testMethodGetuidHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $this->server->expects($this->exactly(1)) + ->method('getGuid') + ->will($this->returnValue('guid')); + $this->assertEquals('guid', $this->cleaner->getGuid()); + } + + public function testMethodConnectguidHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $this->server->expects($this->exactly(1)) + ->method('connectGuid') + ->with('user', 'pass'); + $this->cleaner->connectGuid('user', 'pass'); + } + + public function testMethodReadHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $this->server->expects($this->exactly(1)) + ->method('read') + ->with('guid') + ->will($this->returnValue(array())); + $this->assertEquals(array(), $this->cleaner->read('guid')); + } + + public function testMethodReadattributesHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $this->server->expects($this->exactly(1)) + ->method('readAttributes') + ->with('guid', array('a')) + ->will($this->returnValue(array())); + $this->assertEquals( + array(), $this->cleaner->readAttributes('guid', array('a')) + ); + } + + public function testMethodFindHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $result = $this->getMock('Horde_Kolab_Server_Result'); + $query = $this->getMock( + 'Horde_Kolab_Server_Query_Element', array(), array(), '', false + ); + $this->server->expects($this->exactly(1)) + ->method('find') + ->with($query) + ->will($this->returnValue($result)); + $this->assertType( + 'Horde_Kolab_Server_Result', + $this->cleaner->find($query) + ); + } + + public function testMethodFindbelowHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $result = $this->getMock('Horde_Kolab_Server_Result'); + $query = $this->getMock( + 'Horde_Kolab_Server_Query_Element', array(), array(), '', false + ); + $this->server->expects($this->exactly(1)) + ->method('findBelow') + ->with($query, 'none') + ->will($this->returnValue($result)); + $this->assertType( + 'Horde_Kolab_Server_Result', + $this->cleaner->findBelow($query, 'none') + ); + } + + public function testMethodSaveHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $object = $this->getMock( + 'Horde_Kolab_Server_Object', array(), array(), '', false + ); + $this->server->expects($this->exactly(1)) + ->method('save') + ->with($object, array('a' => 'a')); + $this->cleaner->save($object, array('a' => 'a')); + } + + public function testMethodAddHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $object = $this->getMock( + 'Horde_Kolab_Server_Object', array(), array(), '', false + ); + $this->server->expects($this->exactly(1)) + ->method('add') + ->with($object, array('a' => 'a')); + $this->cleaner->add($object, array('a' => 'a')); + } + + public function testMethodDeleteHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $this->server->expects($this->exactly(1)) + ->method('delete') + ->with('a'); + $this->cleaner->delete('a'); + } + + public function testMethodRenameHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $this->server->expects($this->exactly(1)) + ->method('rename') + ->with('a', 'b'); + $this->cleaner->rename('a', 'b'); + } + + public function testMethodGetschemaHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $this->server->expects($this->exactly(1)) + ->method('getSchema'); + $this->cleaner->getSchema(); + } + + public function testMethodGetparentguidHasPostconditionThatTheCallWasDelegatedToTheServer() + { + $this->server->expects($this->exactly(1)) + ->method('getParentGuid') + ->will($this->returnValue('parent')); + $this->assertEquals('parent', $this->cleaner->getParentGuid('child')); + } + + public function testMethodAddHasPostconditionThatTheGuidOfTheAddedObjectIsRememberedAndDeletedOnDestruction() + { + $object = $this->getMock( + 'Horde_Kolab_Server_Object', array(), array(), '', false + ); + $object->expects($this->exactly(1)) + ->method('getGuid') + ->will($this->returnValue('a')); + $this->server->expects($this->exactly(1)) + ->method('add') + ->with($object, array('a' => 'a')); + $this->server->expects($this->exactly(1)) + ->method('delete') + ->with('a'); + $this->cleaner->add($object, array('a' => 'a')); + unset($this->cleaner); + } + + public function testMethodAddHasPostconditionThatTheGuidOfTheAddedObjectIsNotDeletedOnDestructionIfItWasDeletedBefore() + { + $object = $this->getMock( + 'Horde_Kolab_Server_Object', array(), array(), '', false + ); + $object->expects($this->exactly(1)) + ->method('getGuid') + ->will($this->returnValue('a')); + $this->server->expects($this->exactly(1)) + ->method('add') + ->with($object, array('a' => 'a')); + $this->server->expects($this->exactly(1)) + ->method('delete') + ->with('a'); + $this->cleaner->add($object, array('a' => 'a')); + $this->cleaner->delete('a'); + unset($this->cleaner); + } + + +} \ No newline at end of file diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/CompositeTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/CompositeTest.php new file mode 100644 index 000000000..dcdabf534 --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/CompositeTest.php @@ -0,0 +1,63 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Prepare the test setup. + */ +require_once dirname(__FILE__) . '/../../TestCase.php'; + +/** + * Test the composite server. + * + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Class_Server_CompositeTest extends Horde_Kolab_Server_TestCase +{ + public function testMethodGetReturnsServerElement() + { + $composite = $this->getMockedComposite(); + $this->assertType('Horde_Kolab_Server', $composite->server); + $this->assertType('Horde_Kolab_Server_Objects', $composite->objects); + $this->assertType('Horde_Kolab_Server_Structure_Interface', $composite->structure); + $this->assertType('Horde_Kolab_Server_Search_Interface', $composite->search); + $this->assertType('Horde_Kolab_Server_Schema', $composite->schema); + try { + $a = $composite->something; + $this->fail('No exception!'); + } catch (Horde_Kolab_Server_Exception $e) { + $this->assertEquals( + 'Attribute something not supported!', $e->getMessage() + ); + } + } + + public function testMethodConnectHasPostconditionThatTheServerIsBound() + { + $composite = $this->getMockedComposite(); + $composite->server->expects($this->exactly(2)) + ->method('connectGuid'); + $composite->search->expects($this->exactly(1)) + ->method('__call') + ->with('searchGuidForUidOrMail', array('user')); + $composite->connect('user', 'pass'); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/MockTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Connection/Mock/LdapTest.php similarity index 80% rename from framework/Kolab_Server/test/Horde/Kolab/Server/Connection/MockTest.php rename to framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Connection/Mock/LdapTest.php index 23a4206ca..93f4c6779 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/MockTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Connection/Mock/LdapTest.php @@ -14,7 +14,7 @@ /** * Require our basic test case definition */ -require_once dirname(__FILE__) . '/../LdapTestCase.php'; +require_once dirname(__FILE__) . '/../../../../LdapTestCase.php'; /** * Test the test backend. @@ -30,7 +30,7 @@ require_once dirname(__FILE__) . '/../LdapTestCase.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Connection_MockTest +class Horde_Kolab_Server_Class_Server_Connection_Mock_LdapTest extends Horde_Kolab_Server_LdapTestCase { /** @@ -42,7 +42,7 @@ extends Horde_Kolab_Server_LdapTestCase { $this->skipIfNoLdap(); - $conn = new Horde_Kolab_Server_Connection_Mock(array()); + $conn = new Horde_Kolab_Server_Connection_Mock_Ldap(array(), array()); $a = $conn->parse('(a=b)'); $this->assertEquals(array('att' => 'a', 'log' => '=', 'val' => 'b'), @@ -93,45 +93,44 @@ extends Horde_Kolab_Server_LdapTestCase { $this->skipIfNoLdap(); - $conn = new Horde_Kolab_Server_Connection_Mock( + $conn = new Horde_Kolab_Server_Connection_Mock_Ldap( + array(), array( - 'data' => - array( - 'cn=a' => array( - 'dn' => 'cn=a', - 'data' => array( - 'a' => '1', - 'b' => '1', - 'c' => '1', - ) - ), - 'cn=b' => array( - 'dn' => 'cn=b', - 'data' => array( - 'a' => '1', - 'b' => '2', - 'c' => '2', - ) - ), - 'cn=c' => array( - 'dn' => 'cn=c', - 'data' => array( - 'a' => '1', - 'b' => '2', - 'c' => '3', - ) - ), - 'cn=d' => array( - 'dn' => 'cn=d', - 'data' => array( - 'a' => '2', - 'b' => '2', - 'c' => '1', - ) - ), - ) + 'cn=a' => array( + 'dn' => 'cn=a', + 'data' => array( + 'a' => '1', + 'b' => '1', + 'c' => '1', + ) + ), + 'cn=b' => array( + 'dn' => 'cn=b', + 'data' => array( + 'a' => '1', + 'b' => '2', + 'c' => '2', + ) + ), + 'cn=c' => array( + 'dn' => 'cn=c', + 'data' => array( + 'a' => '1', + 'b' => '2', + 'c' => '3', + ) + ), + 'cn=d' => array( + 'dn' => 'cn=d', + 'data' => array( + 'a' => '2', + 'b' => '2', + 'c' => '1', + ) + ), ) ); + $conn->bind(); $a = $conn->search(null, '(c=1)'); $this->assertEquals( diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Connection/MockTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Connection/MockTest.php new file mode 100644 index 000000000..ac95287b8 --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Connection/MockTest.php @@ -0,0 +1,74 @@ + + * @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 handler for a mock connection. + * + * 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_Connection_MockTest +extends PHPUnit_Framework_TestCase +{ + public function testMethodConstructHasParameterMockldapConnection() + { + $ldap = $this->getMock( + 'Horde_Kolab_Server_Connection_Mock_Ldap', + array(), array(), '', false, false + ); + $conn = new Horde_Kolab_Server_Connection_Mock($ldap); + } + + public function testMethodConstructHasPostconditionThatTheGivenServerWasStored() + { + $ldap = $this->getMock( + 'Horde_Kolab_Server_Connection_Mock_Ldap', + array(), array(), '', false, false + ); + $conn = new Horde_Kolab_Server_Connection_Mock($ldap); + $this->assertSame($ldap, $conn->getRead()); + } + + public function testMethodGetreadHasResultMockldapTheHandledConnection() + { + $ldap = $this->getMock( + 'Horde_Kolab_Server_Connection_Mock_Ldap', + array(), array(), '', false, false + ); + $conn = new Horde_Kolab_Server_Connection_Mock($ldap); + $this->assertType('Horde_Kolab_Server_Connection_Mock_Ldap', $conn->getRead()); + } + + public function testMethodGetwriteHasResultMockldapTheHandledConnection() + { + $ldap = $this->getMock( + 'Horde_Kolab_Server_Connection_Mock_Ldap', + array(), array(), '', false, false + ); + $conn = new Horde_Kolab_Server_Connection_Mock($ldap); + $this->assertSame($conn->getWrite(), $conn->getRead()); + } +} diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/SimpleldapTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Connection/SimpleldapTest.php similarity index 93% rename from framework/Kolab_Server/test/Horde/Kolab/Server/Connection/SimpleldapTest.php rename to framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Connection/SimpleldapTest.php index c2d5f08ea..7340f6589 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/SimpleldapTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Connection/SimpleldapTest.php @@ -14,7 +14,7 @@ /** * Require our basic test case definition */ -require_once dirname(__FILE__) . '/../LdapTestCase.php'; +require_once dirname(__FILE__) . '/../../../LdapTestCase.php'; /** * Test the handler for a simple LDAP setup without read-only slaves. @@ -30,7 +30,7 @@ require_once dirname(__FILE__) . '/../LdapTestCase.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Connection_SimpleldapTest +class Horde_Kolab_Server_Class_Server_Connection_SimpleldapTest extends Horde_Kolab_Server_LdapTestCase { public function testMethodConstructHasParameterNetldap2Connection() diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/SplittedldapTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Connection/SplittedldapTest.php similarity index 94% rename from framework/Kolab_Server/test/Horde/Kolab/Server/Connection/SplittedldapTest.php rename to framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Connection/SplittedldapTest.php index 1594b0f3b..987b61a4f 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/SplittedldapTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Connection/SplittedldapTest.php @@ -14,7 +14,7 @@ /** * Require our basic test case definition */ -require_once dirname(__FILE__) . '/../LdapTestCase.php'; +require_once dirname(__FILE__) . '/../../../LdapTestCase.php'; /** * Test the handler for a LDAP master/slave setup. @@ -30,7 +30,7 @@ require_once dirname(__FILE__) . '/../LdapTestCase.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Connection_SplittedldapTest +class Horde_Kolab_Server_Class_Server_Connection_SplittedldapTest extends Horde_Kolab_Server_LdapTestCase { public function testMethodConstructHasParameterNetldap2ReadConnectionAndParameterNetldap2WriteConnection() diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/ConfigurationTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/ConfigurationTest.php index 03650533c..5939ce322 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/ConfigurationTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/ConfigurationTest.php @@ -142,7 +142,7 @@ extends Horde_Kolab_Server_LdapTestCase array('basedn' => '') ); $this->assertType( - 'Horde_Kolab_Server_Structure', + 'Horde_Kolab_Server_Structure_Interface', $factory->getStructure() ); } @@ -153,7 +153,7 @@ extends Horde_Kolab_Server_LdapTestCase array('basedn' => '') ); $this->assertType( - 'Horde_Kolab_Server_Search', + 'Horde_Kolab_Server_Search_Interface', $factory->getSearch() ); } diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/Conn/MockTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/Conn/MockTest.php index a5518794f..5e741204a 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/Conn/MockTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/Conn/MockTest.php @@ -70,7 +70,12 @@ extends PHPUnit_Framework_TestCase public function testMethodGetconnectionHasResultConnectionmock() { $factory = new Horde_Kolab_Server_Factory_Conn_Mock(); - $factory->setConfiguration(array('basedn' => 'test')); + $factory->setConfiguration( + array( + 'basedn' => 'test', + 'data' => array() + ) + ); $this->assertType( 'Horde_Kolab_Server_Connection_Mock', $factory->getConnection() diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/ConstructorTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/ConstructorTest.php index 6b719e9e6..0fc37e604 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/ConstructorTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/ConstructorTest.php @@ -38,8 +38,8 @@ extends Horde_Kolab_Server_LdapTestCase parent::setUp(); $this->factory = $this->getMock('Horde_Kolab_Server_Factory_Conn'); $this->objects = $this->getMock('Horde_Kolab_Server_Objects'); - $this->structure = $this->getMock('Horde_Kolab_Server_Structure'); - $this->search = $this->getMock('Horde_Kolab_Server_Search'); + $this->structure = $this->getMock('Horde_Kolab_Server_Structure_Interface'); + $this->search = $this->getMock('Horde_Kolab_Server_Search_Interface'); $this->schema = $this->getMock('Horde_Kolab_Server_Schema'); } diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/InjectorTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/InjectorTest.php index 85787a0e6..024b50f3e 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/InjectorTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/InjectorTest.php @@ -134,7 +134,7 @@ extends Horde_Kolab_Server_LdapTestCase { $factory = $this->_getFactory(array()); $this->assertType( - 'Horde_Kolab_Server_Search', + 'Horde_Kolab_Server_Search_Interface', $factory->getSearch() ); } diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Attribute/BaseTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Object/Attribute/BaseTest.php similarity index 95% rename from framework/Kolab_Server/test/Horde/Kolab/Server/Attribute/BaseTest.php rename to framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Object/Attribute/BaseTest.php index 654f8cc7f..0b10da10d 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Attribute/BaseTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Object/Attribute/BaseTest.php @@ -14,7 +14,7 @@ /** * Prepare the test setup. */ -require_once dirname(__FILE__) . '/../TestCase.php'; +require_once dirname(__FILE__) . '/../../../../TestCase.php'; /** * Test the base attribute. @@ -30,7 +30,8 @@ require_once dirname(__FILE__) . '/../TestCase.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Attribute_BaseTest extends Horde_Kolab_Server_TestCase +class Horde_Kolab_Server_Class_Server_Object_Attribute_BaseTest +extends Horde_Kolab_Server_TestCase { public function setUp() { diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Attribute/ValueTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Object/Attribute/ValueTest.php similarity index 98% rename from framework/Kolab_Server/test/Horde/Kolab/Server/Attribute/ValueTest.php rename to framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Object/Attribute/ValueTest.php index 61c652b1f..ed0eb59a8 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Attribute/ValueTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Object/Attribute/ValueTest.php @@ -14,7 +14,7 @@ /** * Prepare the test setup. */ -require_once dirname(__FILE__) . '/../Autoload.php'; +require_once dirname(__FILE__) . '/../../../../Autoload.php'; /** * Test the value attribute. @@ -30,7 +30,8 @@ require_once dirname(__FILE__) . '/../Autoload.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Attribute_ValueTest extends PHPUnit_Framework_TestCase +class Horde_Kolab_Server_Class_Server_Object_Attribute_ValueTest +extends PHPUnit_Framework_TestCase { public function setUp() { diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Object/BaseTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Object/BaseTest.php similarity index 98% rename from framework/Kolab_Server/test/Horde/Kolab/Server/Object/BaseTest.php rename to framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Object/BaseTest.php index cb7878241..26932b5c7 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Object/BaseTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Object/BaseTest.php @@ -14,7 +14,7 @@ /** * Prepare the test setup. */ -require_once dirname(__FILE__) . '/../TestCase.php'; +require_once dirname(__FILE__) . '/../../../TestCase.php'; /** * Test the base object. @@ -30,7 +30,7 @@ require_once dirname(__FILE__) . '/../TestCase.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Object_BaseTest extends Horde_Kolab_Server_TestCase +class Horde_Kolab_Server_Class_Server_Object_BaseTest extends Horde_Kolab_Server_TestCase { public function setUp() { diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Query/ElementTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Query/ElementTest.php similarity index 98% rename from framework/Kolab_Server/test/Horde/Kolab/Server/Query/ElementTest.php rename to framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Query/ElementTest.php index ad16e0354..59c553d12 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Query/ElementTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Query/ElementTest.php @@ -14,7 +14,7 @@ /** * Require our basic test case definition */ -require_once dirname(__FILE__) . '/../Autoload.php'; +require_once dirname(__FILE__) . '/../../../Autoload.php'; /** * Test the LDAP query elements. @@ -30,7 +30,7 @@ require_once dirname(__FILE__) . '/../Autoload.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Query_ElementTest extends PHPUnit_Framework_TestCase +class Horde_Kolab_Server_Class_Server_Query_ElementTest extends PHPUnit_Framework_TestCase { public function setUp() { diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Query/LdapTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Query/LdapTest.php similarity index 97% rename from framework/Kolab_Server/test/Horde/Kolab/Server/Query/LdapTest.php rename to framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Query/LdapTest.php index b8733af49..9b5d05aa2 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Query/LdapTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Query/LdapTest.php @@ -14,7 +14,7 @@ /** * Require our basic test case definition */ -require_once dirname(__FILE__) . '/../LdapTestCase.php'; +require_once dirname(__FILE__) . '/../../../LdapTestCase.php'; /** * Test the LDAP query handler. @@ -30,12 +30,14 @@ require_once dirname(__FILE__) . '/../LdapTestCase.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Query_LdapTest extends Horde_Kolab_Server_LdapTestCase +class Horde_Kolab_Server_Class_Server_Query_LdapTest extends Horde_Kolab_Server_LdapTestCase { public function setUp() { $this->skipIfNoLdap(); - $this->structure = $this->getMock('Horde_Kolab_Server_Structure'); + $this->structure = $this->getMock( + 'Horde_Kolab_Server_Structure_Interface' + ); } diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/BaseTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/BaseTest.php index 18c7bb12e..a861d8a8f 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/BaseTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/BaseTest.php @@ -37,7 +37,7 @@ extends Horde_Kolab_Server_TestCase { $composite = $this->getMockedComposite(); $composite->structure->expects($this->once()) - ->method('getSupportedObjects') + ->method('getSearchOperations') ->will($this->returnValue(array())); $search = new Horde_Kolab_Server_Search_Base(); $search->setComposite($composite); @@ -47,8 +47,8 @@ extends Horde_Kolab_Server_TestCase { $composite = $this->getMockedComposite(); $composite->structure->expects($this->once()) - ->method('getSupportedObjects') - ->will($this->returnValue(array('Object_Dummy'))); + ->method('getSearchOperations') + ->will($this->returnValue(array('Object_Search'))); $search = new Horde_Kolab_Server_Search_Base(); $search->setComposite($composite); $this->assertEquals( @@ -64,14 +64,14 @@ extends Horde_Kolab_Server_TestCase { $composite = $this->getMockedComposite(); $composite->structure->expects($this->once()) - ->method('getSupportedObjects') - ->will($this->returnValue(array('Object_Search_Fail'))); + ->method('getSearchOperations') + ->will($this->returnValue(array('Object_Search_NoSuchClass'))); $search = new Horde_Kolab_Server_Search_Base(); try { $search->setComposite($composite); } catch (Horde_Kolab_Server_Exception $e) { - $this->assertEquals( - 'Object_Search_Fail::getSearchOperations specified non-existing class "Does_Not_Exist"!', + $this->assertContains( + 'getSearchOperations specified non-existing class "Object_Search_NoSuchClass"!', $e->getMessage() ); } @@ -86,8 +86,8 @@ extends Horde_Kolab_Server_TestCase { $composite = $this->getMockedComposite(); $composite->structure->expects($this->once()) - ->method('getSupportedObjects') - ->will($this->returnValue(array('Object_Dummy'))); + ->method('getSearchOperations') + ->will($this->returnValue(array('Object_Search'))); $search = new Horde_Kolab_Server_Search_Base(); $search->setComposite($composite); $this->assertEquals(1, $search->call()); @@ -97,8 +97,8 @@ extends Horde_Kolab_Server_TestCase { $composite = $this->getMockedComposite(); $composite->structure->expects($this->once()) - ->method('getSupportedObjects') - ->will($this->returnValue(array('Object_Dummy'))); + ->method('getSearchOperations') + ->will($this->returnValue(array('Object_Search'))); $search = new Horde_Kolab_Server_Search_Base(); $search->setComposite($composite); $search->call('a'); @@ -109,8 +109,8 @@ extends Horde_Kolab_Server_TestCase { $composite = $this->getMockedComposite(); $composite->structure->expects($this->once()) - ->method('getSupportedObjects') - ->will($this->returnValue(array('Object_Dummy'))); + ->method('getSearchOperations') + ->will($this->returnValue(array('Object_Search'))); $search = new Horde_Kolab_Server_Search_Base(); $search->setComposite($composite); try { @@ -154,12 +154,4 @@ class Object_Search { self::$calls = 0; } -} - -class Object_Search_Fail -{ - static public function getSearchOperations() - { - return array('Does_Not_Exist'); - } -} +} \ No newline at end of file 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 new file mode 100644 index 000000000..fd268c64d --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidTest.php @@ -0,0 +1,93 @@ + + * @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 guid search operation. + * + * 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_GuidTest +extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + $this->structure = $this->getMock('Horde_Kolab_Server_Structure_Interface'); + } + + public function testMethodConstructHasParameterStructure() + { + $search = new Horde_Kolab_Server_Search_Operation_Guid($this->structure); + } + + public function testMethodConstructHasPostconditionThatTheServerStructureGetsStored() + { + $search = new Horde_Kolab_Server_Search_Operation_Guid($this->structure); + $this->assertSame($this->structure, $search->getStructure()); + } + + public function testMethodGetStructureHasResultStructureTheStructureAssociatedWithThisSearch() + { + $search = new Horde_Kolab_Server_Search_Operation_Guid($this->structure); + $this->assertType('Horde_Kolab_Server_Structure_Interface', $search->getStructure()); + } + + public function testMethodSearchguidHasResultArrayTheGuidsOfTheSearchResult() + { + $result = $this->getMock('Horde_Kolab_Server_Result'); + $result->expects($this->once()) + ->method('asArray') + ->will($this->returnValue(array('a' => 'a'))); + $this->structure->expects($this->once()) + ->method('find') + ->with( + $this->isInstanceOf('Horde_Kolab_Server_Query_Element'), + array('attributes' => 'Guid') + ) + ->will($this->returnValue($result)); + $search = new Horde_Kolab_Server_Search_Operation_Guid($this->structure); + $criteria = $this->getMock('Horde_Kolab_Server_Query_Element'); + $this->assertEquals(array('a'), $search->searchGuid($criteria)); + } + + public function testMethodSearchguidHasResultArrayEmptyIfTheSearchReturnedNoResults() + { + $result = $this->getMock('Horde_Kolab_Server_Result'); + $result->expects($this->once()) + ->method('asArray') + ->will($this->returnValue(array())); + $this->structure->expects($this->once()) + ->method('find') + ->with( + $this->isInstanceOf('Horde_Kolab_Server_Query_Element'), + array('attributes' => 'Guid') + ) + ->will($this->returnValue($result)); + $search = new Horde_Kolab_Server_Search_Operation_Guid($this->structure); + $criteria = $this->getMock('Horde_Kolab_Server_Query_Element'); + $this->assertEquals(array(), $search->searchGuid($criteria)); + } +} diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Structure/KolabTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Structure/KolabTest.php index c30b1c9d8..5930dcc74 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Structure/KolabTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Structure/KolabTest.php @@ -39,7 +39,7 @@ class Horde_Kolab_Server_Class_Server_Structure_KolabTest extends PHPUnit_Framew $server, $this->getMock('Horde_Kolab_Server_Objects'), new Horde_Kolab_Server_Structure_Kolab(), - $this->getMock('Horde_Kolab_Server_Search'), + $this->getMock('Horde_Kolab_Server_Search_Interface'), $this->getMock('Horde_Kolab_Server_Schema') ); } 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 3db79724a..ac4a9908b 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 @@ -39,7 +39,7 @@ class Horde_Kolab_Server_Class_Server_Structure_LdapTest extends Horde_Kolab_Ser $server, $this->getMock('Horde_Kolab_Server_Objects'), new Horde_Kolab_Server_Structure_Ldap(), - $this->getMock('Horde_Kolab_Server_Search'), + $this->getMock('Horde_Kolab_Server_Search_Interface'), $this->getMock('Horde_Kolab_Server_Schema') ); } diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Objects/ServerTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/ObjectsTest.php similarity index 97% rename from framework/Kolab_Server/test/Horde/Kolab/Server/Objects/ServerTest.php rename to framework/Kolab_Server/test/Horde/Kolab/Server/Integration/ObjectsTest.php index 415540e08..b9ffe127e 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Objects/ServerTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/ObjectsTest.php @@ -30,7 +30,7 @@ require_once dirname(__FILE__) . '/../Autoload.php'; * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Objects_ServerTest extends PHPUnit_Framework_TestCase +class Horde_Kolab_Server_Integration_ObjectsTest extends PHPUnit_Framework_TestCase { public function setUp() { diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/TestCase.php b/framework/Kolab_Server/test/Horde/Kolab/Server/TestCase.php index cf6805600..a4a7bcd0f 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/TestCase.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/TestCase.php @@ -49,10 +49,10 @@ class Horde_Kolab_Server_TestCase extends PHPUnit_Framework_TestCase 'Horde_Kolab_Server_Objects', array(), array(), '', false ), $this->getMock( - 'Horde_Kolab_Server_Structure', array(), array(), '', false + 'Horde_Kolab_Server_Structure_Interface', array(), array(), '', false ), $this->getMock( - 'Horde_Kolab_Server_Search', array(), array(), '', false + 'Horde_Kolab_Server_Search_Interface', array(), array(), '', false ), $this->getMock( 'Horde_Kolab_Server_Schema', array(), array(), '', false -- 2.11.0