From: Gunnar Wrobel Date: Mon, 2 Nov 2009 16:10:08 +0000 (+0100) Subject: Move search handlers from Object/ to Search/. Additional testing. Some Interfaces... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=712379bc7027b05858da2404a1120002b163bbe5;p=horde.git Move search handlers from Object/ to Search/. Additional testing. Some Interfaces moved to Interface.php. --- 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/Search.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search.php deleted file mode 100644 index 445989b33..000000000 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search.php +++ /dev/null @@ -1,36 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * An interface marking object class search operations. - * - * 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 - */ -interface Horde_Kolab_Server_Object_Search -{ - /** - * Return the refernce to the composite server. - * - * @return Horde_Kolab_Server_Composite - */ - public function getComposite(); -} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Addressesforuidormail.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Addressesforuidormail.php deleted file mode 100644 index 21a24bdcb..000000000 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Addressesforuidormail.php +++ /dev/null @@ -1,136 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Return the mail addresses of the KolabInetOrgPersons with the given uid or - * mail address and include all alias and delegate addresses. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Object_Search_Addressesforuidormail -extends Horde_Kolab_Server_Object_Search_Base -{ - - /** - * The basic attribute search. - * - * @var Horde_Kolab_Server_Object_Search - */ - private $_search; - - /** - * Constructor - * - * @param Horde_Kolab_Server_Composite $composite A link to the composite - * server handler. - */ - public function __construct(Horde_Kolab_Server_Composite $composite) - { - $this->_composite = $composite; - $this->_search = new Horde_Kolab_Server_Object_Search_Attributes( - $this->getComposite() - ); - } - - /** - * Return the mail addresses of the KolabInetOrgPersons with the given uid - * or mail address and include all alias and delegate addresses. - * - * @param string $uid The uid to search for. - * @param string $mail The mail address to search for. - * - * @return array The GUID(s). - * - * @throws Horde_Kolab_Server_Exception - */ - public function searchAddressesForUidOrMail($uid, $mail) - { - $criteria = new Horde_Kolab_Server_Query_Element_And( - new Horde_Kolab_Server_Query_Element_Equals( - 'Objectclass', - Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON - ), - new Horde_Kolab_Server_Query_Element_Or( - new Horde_Kolab_Server_Query_Element_Equals( - 'Uid', $uid - ), - new Horde_Kolab_Server_Query_Element_Equals( - 'Mail', $mail - ) - ) - ); - $search = new Horde_Kolab_Server_Object_Search_Constraint_Strict( - $this->_search - ); - - $data = $search->searchAttributes( - $criteria, array('Mail', 'Alias') - ); - - if (empty($data)) { - return array(); - } - - $mail = $this->getComposite()->structure->getAttributeInternal( - 'Mail' - ); - $alias = $this->getComposite()->structure->getAttributeInternal( - 'Alias' - ); - - if (isset($result[$alias])) { - $addrs = array_merge($data[$mail], $data[$alias]); - } else { - $addrs = $data[$mail]; - } - - $criteria = new Horde_Kolab_Server_Query_Element_And( - new Horde_Kolab_Server_Query_Element_Equals( - 'Objectclass', - Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON - ), - new Horde_Kolab_Server_Query_Element_Equals( - 'Delegate', $data[$mail][0] - ) - ); - - $data = $this->_search->searchAttributes( - $criteria, array('Mail', 'Alias') - ); - - if (!empty($data)) { - foreach ($data as $adr) { - if (isset($adr[$mail])) { - $addrs = array_merge($addrs, $adr[$mail]); - } - if (isset($adr[$alias])) { - $addrs = array_merge($addrs, $adr[$alias]); - } - } - } - - $addrs = array_map('strtolower', $addrs); - - return $addrs; - } -} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Attributes.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Attributes.php deleted file mode 100644 index 058023552..000000000 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Attributes.php +++ /dev/null @@ -1,47 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Basic attributes search. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Object_Search_Attributes -extends Horde_Kolab_Server_Object_Search_Base -{ - /** - * Perform the search. - * - * @param Horde_Kolab_Server_Query_Element $criteria The search criteria. - * @param array $attributes The attributes to - * retrieve. - * - * @return mixed The search result. - */ - public function searchAttributes( - Horde_Kolab_Server_Query_Element $criteria, - array $attributes - ) { - $params = array('attributes' => $attributes); - return $this->getComposite()->structure->find($criteria, $params); - } -} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Base.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Base.php deleted file mode 100644 index b14446e3e..000000000 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Base.php +++ /dev/null @@ -1,73 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * An interface marking object class search operations. - * - * 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 - */ -abstract class Horde_Kolab_Server_Object_Search_Base -implements Horde_Kolab_Server_Object_Search -{ - /** - * A link to the composite server handler. - * - * @var Horde_Kolab_Server_Composite - */ - private $_composite; - - /** - * Constructor - * - * @param Horde_Kolab_Server_Composite $composite A link to the composite - * server handler. - */ - public function __construct(Horde_Kolab_Server_Composite $composite) - { - $this->_composite = $composite; - } - - /** - * Return the refernce to the composite server. - * - * @return Horde_Kolab_Server_Composite - */ - public function getComposite() - { - return $this->_composite; - } - - /** - * Identify the GUID(s) of the result entry(s). - * - * @param array $result The LDAP search result. - * - * @return boolean|array The GUID(s) or false if there was no result. - */ - protected function guidFromResult($result) - { - if (empty($result)) { - return false; - } - return array_keys($result); - } -} \ 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/Object/Search/Children.php deleted file mode 100644 index 8d18c8abf..000000000 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Children.php +++ /dev/null @@ -1,52 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Basic GUID search. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Object_Search_Children -extends Horde_Kolab_Server_Object_Search_Base -{ - /** - * Perform the search. - * - * @param string $parent_guid The guid of the parent. - * @param string $objectclass The type of children to return. - * - * @return mixed The search result. - */ - public function searchChildren($parent_guid, $objectclass) - { - $criteria = new Horde_Kolab_Server_Query_Element_Equals( - 'Objectclass', $objectclass - ); - $params = array( - 'attributes' => Horde_Kolab_Server_Object_Top::ATTRIBUTE_GUID - ); - $data = $this->_composite->server->findBelow( - $criteria, $parent, $params - ); - return self::guidFromResult($data); - } -} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Constraint/Single.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Constraint/Single.php deleted file mode 100644 index c935a5dd9..000000000 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Constraint/Single.php +++ /dev/null @@ -1,72 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Return only a single search result. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Object_Search_Constraint_Single -implements Horde_Kolab_Server_Object_Search -{ - /** - * A link to the search. - * - * @var Horde_Kolab_Server_Object_Search - */ - private $_search; - - /** - * Constructor - * - * @param Horde_Kolab_Server_Search $search The search being restricted. - */ - public function __construct(Horde_Kolab_Server_Object_Search $search) - { - $this->_search = $search; - } - - /** - * Return the refernce to the composite server. - * - * @return Horde_Kolab_Server_Composite - */ - public function getComposite() - { - return $this->_search->getComposite(); - } - - /** - * Delegate to the actual search operation. - * - * @param string $method The name of the called method. - * @param array $args Arguments of the call. - * - * @return array The search result. - */ - public function __call($method, $args) - { - $args = func_get_args(); - $result = call_user_func_array(array($this->_search, $method), $args); - return array_pop($result); - } -} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Constraint/Strict.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Constraint/Strict.php deleted file mode 100644 index b1e740d73..000000000 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Constraint/Strict.php +++ /dev/null @@ -1,82 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Ensures that a search yields only a single return value. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Object_Search_Constraint_Strict -implements Horde_Kolab_Server_Object_Search -{ - /** - * A link to the search. - * - * @var Horde_Kolab_Server_Search - */ - private $_search; - - /** - * Constructor - * - * @param Horde_Kolab_Server_Search $search The search being restricted. - */ - public function __construct(Horde_Kolab_Server_Search $search) - { - $this->_search = $search; - } - - /** - * Return the refernce to the composite server. - * - * @return Horde_Kolab_Server_Composite - */ - public function getComposite() - { - return $this->_search->getComposite(); - } - - /** - * Delegate to the actual search operation. - * - * @param string $method The name of the called method. - * @param array $args Arguments of the call. - * - * @return array The search result. - */ - public function __call($method, $args) - { - $args = func_get_args(); - $result = call_user_func_array(array($this->_search, $method), $args); - $result = call_user_func_array(array($this->_search, 'search'), $args); - if (count($result) > 1) { - throw new Horde_Kolab_Server_Exception( - sprintf( - "Found %s results when expecting only one!", - count($result) - ), - Horde_Kolab_Server_Exception::SEARCH_CONSTRAINT_TOO_MANY - ); - } - return $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/Object/Search/Guid.php deleted file mode 100644 index 45dc17e6b..000000000 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guid.php +++ /dev/null @@ -1,46 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Basic GUID search. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Object_Search_Guid -extends Horde_Kolab_Server_Object_Search_Base -{ - /** - * Perform the search. - * - * @param Horde_Kolab_Server_Query_Element $criteria The search criteria. - * - * @return array The search result. - */ - public function searchGuid(Horde_Kolab_Server_Query_Element $criteria) - { - $params = array( - 'attributes' => 'Guid' - ); - $data = $this->getComposite()->structure->find($criteria, $params); - return self::guidFromResult($data); - } -} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforalias.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforalias.php deleted file mode 100644 index 9592bca39..000000000 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforalias.php +++ /dev/null @@ -1,47 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Return all KolabInetOrgPersons with the given alias address. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Object_Search_Guidforalias -extends Horde_Kolab_Server_Object_Search_Restrictkolab -{ - /** - * Return all KolabInetOrgPersons with the given alias. - * - * @param string $alias The alias address to search for. - * - * @return array The GUID(s). - * - * @throws Horde_Kolab_Server_Exception - */ - public function searchGuidForAlias($alias) - { - $criteria = new Horde_Kolab_Server_Query_Element_Equals( - 'Alias', $alias - ); - return parent::searchRestrictKolab($criteria); - } -} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforcn.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforcn.php deleted file mode 100644 index 5b31bd31d..000000000 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforcn.php +++ /dev/null @@ -1,47 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Identify the GUID for the objects found with the given common name. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Object_Search_Guidforcn -extends Horde_Kolab_Server_Object_Search_Guid -{ - /** - * Identify the GUID for the objects found with the given common name. - * - * @param string $cn Search for objects with this common name. - * - * @return array The GUID(s). - * - * @throws Horde_Kolab_Server_Exception - */ - public function searchGuidForCn($cn) - { - $criteria = new Horde_Kolab_Server_Query_Element_Equals( - 'Cn', $cn - ); - return parent::searchGuid($criteria); - } -} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforkolabusers.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforkolabusers.php deleted file mode 100644 index 3266c6320..000000000 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforkolabusers.php +++ /dev/null @@ -1,46 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Return the GUIDs of all KolabInetOrgPersons. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Object_Search_Guidforkolabusers -extends Horde_Kolab_Server_Object_Search_Guid -{ - /** - * Return the GUIDs of all KolabInetOrgPersons. - * - * @return array The GUID(s). - * - * @throws Horde_Kolab_Server_Exception - */ - public function searchGuidForKolabUsers() - { - $criteria = new Horde_Kolab_Server_Query_Element_Equals( - 'Objectclass', - Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON - ); - return parent::searchGuid($criteria); - } -} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidformail.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidformail.php deleted file mode 100644 index 3974c7124..000000000 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidformail.php +++ /dev/null @@ -1,47 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Return all KolabInetOrgPersons with the given mail address. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Object_Search_Guidformail -extends Horde_Kolab_Server_Object_Search_Restrictkolab -{ - /** - * Return all KolabInetOrgPersons with the given mail. - * - * @param string $mail The mail to search for. - * - * @return array The GUID(s). - * - * @throws Horde_Kolab_Server_Exception - */ - public function searchGuidForMail($mail) - { - $criteria = new Horde_Kolab_Server_Query_Element_Equals( - 'Mail', $mail - ); - return parent::searchRestrictKolab($criteria); - } -} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidformailoralias.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidformailoralias.php deleted file mode 100644 index 6ca3fe585..000000000 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidformailoralias.php +++ /dev/null @@ -1,53 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Return all KolabInetOrgPersons with the given mail or alias address. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Object_Search_Guidformailoralias -extends Horde_Kolab_Server_Object_Search_Restrictkolab -{ - /** - * Return all KolabInetOrgPersons with the given mail or alias address. - * - * @param string $mail The mail address to search for. - * @param string $alias The alias address to search for. - * - * @return array The GUID(s). - * - * @throws Horde_Kolab_Server_Exception - */ - public function searchGuidForMailOrAlias($mail, $alias) - { - $criteria = new Horde_Kolab_Server_Query_Element_Or( - new Horde_Kolab_Server_Query_Element_Equals( - 'Mail', $mail - ), - new Horde_Kolab_Server_Query_Element_Equals( - 'Alias', $alias - ) - ); - return parent::searchRestrictKolab($criteria); - } -} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuid.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuid.php deleted file mode 100644 index 0c62c859d..000000000 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuid.php +++ /dev/null @@ -1,47 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Return all KolabInetOrgPersons with the given uid. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Object_Search_Guidforuid -extends Horde_Kolab_Server_Object_Search_Restrictkolab -{ - /** - * Return all KolabInetOrgPersons with the given uid. - * - * @param string $uid The uid to search for. - * - * @return array The GUID(s). - * - * @throws Horde_Kolab_Server_Exception - */ - public function searchGuidForUid($uid) - { - $criteria = new Horde_Kolab_Server_Query_Element_Equals( - 'Uid', $uid - ); - return parent::searchRestrictKolab($criteria); - } -} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuidormail.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuidormail.php deleted file mode 100644 index 3d5eb60d6..000000000 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuidormail.php +++ /dev/null @@ -1,54 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Return all KolabInetOrgPersons with the given uid or mail address. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Object_Search_Guidforuidormail -extends Horde_Kolab_Server_Object_Search_Restrictkolab -{ - /** - * Return all KolabInetOrgPersons with the given uid or mail address. - * - * @param string $id The uid or mail address to search for. - * - * @return array The GUID(s). - * - * @throws Horde_Kolab_Server_Exception - */ - public function searchGuidForUidOrMail($id) - { - $criteria = new Horde_Kolab_Server_Query_Element_Or( - array( - new Horde_Kolab_Server_Query_Element_Equals( - 'Uid', $id - ), - new Horde_Kolab_Server_Query_Element_Equals( - 'Mail', $id - ) - ) - ); - return parent::searchRestrictKolab($criteria); - } -} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuidormailoralias.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuidormailoralias.php deleted file mode 100644 index 177ef9669..000000000 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Guidforuidormailoralias.php +++ /dev/null @@ -1,57 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Return all KolabInetOrgPersons with the given uid, mail or alias address. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Object_Search_Guidforuidormailoralias -extends Horde_Kolab_Server_Object_Search_Restrictkolab -{ - /** - * Return all KolabInetOrgPersons with the given uid, mail or alias address. - * - * @param string $id The uid or mail address or alias address to search for. - * - * @return array The GUID(s). - * - * @throws Horde_Kolab_Server_Exception - */ - public function searchGuidForUidOrMailOrAlias($id) - { - $criteria = new Horde_Kolab_Server_Query_Element_Or( - array( - new Horde_Kolab_Server_Query_Element_Equals( - 'Uid', $id - ), - new Horde_Kolab_Server_Query_Element_Equals( - 'Mail', $id - ), - new Horde_Kolab_Server_Query_Element_Equals( - 'Alias', $id - ) - ) - ); - return parent::searchRestrictKolab($criteria); - } -} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Mailforuidormail.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Mailforuidormail.php deleted file mode 100644 index 3006cf1e0..000000000 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Mailforuidormail.php +++ /dev/null @@ -1,95 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Return the mail address of the KolabInetOrgPersons with the given uid or mail - * address. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Object_Search_Mailforuidormail -extends Horde_Kolab_Server_Object_Search_Base -{ - - /** - * The base attribute search. - * - * @var Horde_Kolab_Server_Object_Search - */ - private $_search; - - /** - * Constructor - * - * @param Horde_Kolab_Server_Composite $composite A link to the composite - * server handler. - */ - public function __construct(Horde_Kolab_Server_Composite $composite) - { - $this->_composite = $composite; - $this->_search = new Horde_Kolab_Server_Object_Search_Constraint_Strict( - new Horde_Kolab_Server_Object_Search_Attributes( - $this->getComposite() - ) - ); - } - - /** - * Return the mail address of the KolabInetOrgPersons with the given uid or - * mail address. - * - * @param string $uid The uid to search for. - * @param string $mail The mail address to search for. - * - * @return array The GUID(s). - * - * @throws Horde_Kolab_Server_Exception - */ - public function searchMailForUidOrMail($uid, $mail) - { - $criteria = new Horde_Kolab_Server_Query_Element_And( - new Horde_Kolab_Server_Query_Element_Equals( - 'Objectclass', - Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON - ), - new Horde_Kolab_Server_Query_Element_Or( - new Horde_Kolab_Server_Query_Element_Equals( - 'Uid', $uid - ), - new Horde_Kolab_Server_Query_Element_Equals( - 'Mail', $mail - ) - ) - ); - $data = $this->_search->searchAttributes($criteria, array('Mail')); - - $internal = $this->getComposite()->structure->getAttributeInternal( - 'Mail' - ); - if (!empty($data)) { - return $data[$internal][0]; - } else { - return false; - } - } -} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Restrictkolab.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Restrictkolab.php deleted file mode 100644 index c7c7e2517..000000000 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Search/Restrictkolab.php +++ /dev/null @@ -1,54 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Restrict a search to KolabInetOrgPersons. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Object_Search_Restrictkolab -extends Horde_Kolab_Server_Object_Search_Guid -{ - /** - * Restrict a search to KolabInetOrgPersons. - * - * @param Horde_Kolab_Server_Query_Element $criteria The search criteria. - * - * @return array The GUID(s). - * - * @throws Horde_Kolab_Server_Exception - */ - public function searchRestrictKolab( - Horde_Kolab_Server_Query_Element $criteria - ) { - $criteria = new Horde_Kolab_Server_Query_Element_And( - array( - new Horde_Kolab_Server_Query_Element_Equals( - 'Objectclass', - Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON - ), - $criteria - ) - ); - return parent::searchGuid($criteria); - } -} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/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.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search.php deleted file mode 100644 index 51137f3d9..000000000 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search.php +++ /dev/null @@ -1,56 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Defines the interface of the search handler for a Kolab Server. - * - * 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 - */ -interface Horde_Kolab_Server_Search -{ - /** - * Set the composite server reference for this object. - * - * @param Horde_Kolab_Server_Composite $composite A link to the composite - * server handler. - */ - public function setComposite(Horde_Kolab_Server_Composite $composite); - - /** - * Returns the set of search operations supported by this server type. - * - * @return array An array of supported search operations. - */ - public function getSearchOperations(); - - /** - * Capture undefined calls. - * - * @param string $method The name of the called method. - * @param array $args Arguments of the call. - * - * @return NULL. - * - * @throws Horde_Kolab_Server_Exception - */ - public function __call($method, $args); -} \ No newline at end of file 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/Interface.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Interface.php new file mode 100644 index 000000000..740b49462 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Interface.php @@ -0,0 +1,56 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Defines the interface of the search handler for a Kolab Server. + * + * 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 + */ +interface Horde_Kolab_Server_Search_Interface +{ + /** + * Set the composite server reference for this object. + * + * @param Horde_Kolab_Server_Composite $composite A link to the composite + * server handler. + */ + public function setComposite(Horde_Kolab_Server_Composite $composite); + + /** + * Returns the set of search operations supported by this server type. + * + * @return array An array of supported search operations. + */ + public function getSearchOperations(); + + /** + * Capture undefined calls. + * + * @param string $method The name of the called method. + * @param array $args Arguments of the call. + * + * @return NULL. + * + * @throws Horde_Kolab_Server_Exception + */ + public function __call($method, $args); +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Addressesforuidormail.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Addressesforuidormail.php new file mode 100644 index 000000000..06358e6d2 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Addressesforuidormail.php @@ -0,0 +1,136 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Return the mail addresses of the KolabInetOrgPersons with the given uid or + * mail address and include all alias and delegate addresses. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Search_Operation_Addressesforuidormail +extends Horde_Kolab_Server_Search_Operation_Base +{ + + /** + * The basic attribute search. + * + * @var Horde_Kolab_Server_Search_Operation + */ + private $_search; + + /** + * Constructor + * + * @param Horde_Kolab_Server_Composite $composite A link to the composite + * server handler. + */ + public function __construct(Horde_Kolab_Server_Composite $composite) + { + $this->_composite = $composite; + $this->_search = new Horde_Kolab_Server_Search_Operation_Attributes( + $this->getComposite() + ); + } + + /** + * Return the mail addresses of the KolabInetOrgPersons with the given uid + * or mail address and include all alias and delegate addresses. + * + * @param string $uid The uid to search for. + * @param string $mail The mail address to search for. + * + * @return array The GUID(s). + * + * @throws Horde_Kolab_Server_Exception + */ + public function searchAddressesForUidOrMail($uid, $mail) + { + $criteria = new Horde_Kolab_Server_Query_Element_And( + new Horde_Kolab_Server_Query_Element_Equals( + 'Objectclass', + Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON + ), + new Horde_Kolab_Server_Query_Element_Or( + new Horde_Kolab_Server_Query_Element_Equals( + 'Uid', $uid + ), + new Horde_Kolab_Server_Query_Element_Equals( + 'Mail', $mail + ) + ) + ); + $search = new Horde_Kolab_Server_Search_Operation_Constraint_Strict( + $this->_search + ); + + $data = $search->searchAttributes( + $criteria, array('Mail', 'Alias') + ); + + if (empty($data)) { + return array(); + } + + $mail = $this->getComposite()->structure->getAttributeInternal( + 'Mail' + ); + $alias = $this->getComposite()->structure->getAttributeInternal( + 'Alias' + ); + + if (isset($result[$alias])) { + $addrs = array_merge($data[$mail], $data[$alias]); + } else { + $addrs = $data[$mail]; + } + + $criteria = new Horde_Kolab_Server_Query_Element_And( + new Horde_Kolab_Server_Query_Element_Equals( + 'Objectclass', + Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON + ), + new Horde_Kolab_Server_Query_Element_Equals( + 'Delegate', $data[$mail][0] + ) + ); + + $data = $this->_search->searchAttributes( + $criteria, array('Mail', 'Alias') + ); + + if (!empty($data)) { + foreach ($data as $adr) { + if (isset($adr[$mail])) { + $addrs = array_merge($addrs, $adr[$mail]); + } + if (isset($adr[$alias])) { + $addrs = array_merge($addrs, $adr[$alias]); + } + } + } + + $addrs = array_map('strtolower', $addrs); + + return $addrs; + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Attributes.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Attributes.php new file mode 100644 index 000000000..01abc4242 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Attributes.php @@ -0,0 +1,47 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Basic attributes search. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Search_Operation_Attributes +extends Horde_Kolab_Server_Search_Operation_Base +{ + /** + * Perform the search. + * + * @param Horde_Kolab_Server_Query_Element $criteria The search criteria. + * @param array $attributes The attributes to + * retrieve. + * + * @return mixed The search result. + */ + public function searchAttributes( + Horde_Kolab_Server_Query_Element $criteria, + array $attributes + ) { + $params = array('attributes' => $attributes); + return $this->getComposite()->structure->find($criteria, $params); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Base.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Base.php new file mode 100644 index 000000000..17df4fbb7 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Base.php @@ -0,0 +1,72 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * An interface marking object class search operations. + * + * 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 + */ +abstract class Horde_Kolab_Server_Search_Operation_Base +implements Horde_Kolab_Server_Search_Operation_Interface +{ + /** + * A link to the server structure. + * + * @var Horde_Kolab_Server_Structure_Interface + */ + private $_structure; + + /** + * Constructor + * + * @param Horde_Kolab_Server_Structure_Interface $structure A link to the + * server + * structure. + */ + public function __construct( + Horde_Kolab_Server_Structure_Interface $structure + ) { + $this->_structure = $structure; + } + + /** + * Return the reference to the server structure. + * + * @return Horde_Kolab_Server_Structure_Interface + */ + public function getStructure() + { + return $this->_structure; + } + + /** + * Identify the GUID(s) of the result entry(s). + * + * @param array $result The LDAP search result. + * + * @return boolean|array The GUID(s) or false if there was no result. + */ + protected function guidFromResult(Horde_Kolab_Server_Result $result) + { + return array_keys($result->asArray()); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Children.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Children.php new file mode 100644 index 000000000..2f211672e --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Children.php @@ -0,0 +1,52 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Basic GUID search. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Search_Operation_Children +extends Horde_Kolab_Server_Search_Operation_Base +{ + /** + * Perform the search. + * + * @param string $parent_guid The guid of the parent. + * @param string $objectclass The type of children to return. + * + * @return mixed The search result. + */ + public function searchChildren($parent_guid, $objectclass) + { + $criteria = new Horde_Kolab_Server_Query_Element_Equals( + 'Objectclass', $objectclass + ); + $params = array( + 'attributes' => Horde_Kolab_Server_Object_Top::ATTRIBUTE_GUID + ); + $data = $this->_composite->server->findBelow( + $criteria, $parent, $params + ); + return self::guidFromResult($data); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Constraint/Single.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Constraint/Single.php new file mode 100644 index 000000000..bf7aba0b5 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Constraint/Single.php @@ -0,0 +1,73 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Return only a single search result. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Search_Operation_Constraint_Single +implements Horde_Kolab_Server_Search_Operation_Interface +{ + /** + * A link to the search. + * + * @var Horde_Kolab_Server_Search_Operation + */ + private $_search; + + /** + * Constructor + * + * @param Horde_Kolab_Server_Search $search The search being restricted. + */ + public function __construct( + Horde_Kolab_Server_Search_Operation_Interface $search + ) { + $this->_search = $search; + } + + /** + * Return the reference to the server structure. + * + * @return Horde_Kolab_Server_Structure_Interface + */ + public function getStructure() + { + return $this->_search->getStructure(); + } + + /** + * Delegate to the actual search operation. + * + * @param string $method The name of the called method. + * @param array $args Arguments of the call. + * + * @return array The search result. + */ + public function __call($method, $args) + { + $args = func_get_args(); + $result = call_user_func_array(array($this->_search, $method), $args); + return array_shift($result); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Constraint/Strict.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Constraint/Strict.php new file mode 100644 index 000000000..d81863673 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Constraint/Strict.php @@ -0,0 +1,81 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Ensures that a search yields only a single return value. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Search_Operation_Constraint_Strict +implements Horde_Kolab_Server_Search_Operation_Interface +{ + /** + * A link to the search. + * + * @var Horde_Kolab_Server_Search + */ + private $_search; + + /** + * Constructor + * + * @param Horde_Kolab_Server_Search $search The search being restricted. + */ + public function __construct( + Horde_Kolab_Server_Search_Operation_Interface $search + ) { + $this->_search = $search; + } + + /** + * Return the reference to the server structure. + * + * @return Horde_Kolab_Server_Structure_Interface + */ + public function getStructure() + { + return $this->_search->getStructure(); + } + + /** + * Delegate to the actual search operation. + * + * @param string $method The name of the called method. + * @param array $args Arguments of the call. + * + * @return array The search result. + */ + public function __call($method, $args) + { + $result = call_user_func_array(array($this->_search, $method), $args); + if (count($result) > 1) { + throw new Horde_Kolab_Server_Exception( + sprintf( + "Found %s results when expecting only one!", + count($result) + ), + Horde_Kolab_Server_Exception::SEARCH_CONSTRAINT_TOO_MANY + ); + } + return array_shift($result); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guid.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guid.php new file mode 100644 index 000000000..d0049bc0c --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guid.php @@ -0,0 +1,46 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Basic GUID search. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Search_Operation_Guid +extends Horde_Kolab_Server_Search_Operation_Base +{ + /** + * Perform the search. + * + * @param Horde_Kolab_Server_Query_Element $criteria The search criteria. + * + * @return array The search result. + */ + public function searchGuid(Horde_Kolab_Server_Query_Element $criteria) + { + $params = array( + 'attributes' => 'Guid' + ); + $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/Search/Operation/Guidforalias.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforalias.php new file mode 100644 index 000000000..ba2398a10 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforalias.php @@ -0,0 +1,47 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Return all KolabInetOrgPersons with the given alias address. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Search_Operation_Guidforalias +extends Horde_Kolab_Server_Search_Operation_Restrictkolab +{ + /** + * Return all KolabInetOrgPersons with the given alias. + * + * @param string $alias The alias address to search for. + * + * @return array The GUID(s). + * + * @throws Horde_Kolab_Server_Exception + */ + public function searchGuidForAlias($alias) + { + $criteria = new Horde_Kolab_Server_Query_Element_Equals( + 'Alias', $alias + ); + return parent::searchRestrictKolab($criteria); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforcn.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforcn.php new file mode 100644 index 000000000..dba8d5ac7 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforcn.php @@ -0,0 +1,47 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Identify the GUID for the objects found with the given common name. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Search_Operation_Guidforcn +extends Horde_Kolab_Server_Search_Operation_Guid +{ + /** + * Identify the GUID for the objects found with the given common name. + * + * @param string $cn Search for objects with this common name. + * + * @return array The GUID(s). + * + * @throws Horde_Kolab_Server_Exception + */ + public function searchGuidForCn($cn) + { + $criteria = new Horde_Kolab_Server_Query_Element_Equals( + 'Cn', $cn + ); + return parent::searchGuid($criteria); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforkolabusers.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforkolabusers.php new file mode 100644 index 000000000..3f003978b --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforkolabusers.php @@ -0,0 +1,46 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Return the GUIDs of all KolabInetOrgPersons. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Search_Operation_Guidforkolabusers +extends Horde_Kolab_Server_Search_Operation_Guid +{ + /** + * Return the GUIDs of all KolabInetOrgPersons. + * + * @return array The GUID(s). + * + * @throws Horde_Kolab_Server_Exception + */ + public function searchGuidForKolabUsers() + { + $criteria = new Horde_Kolab_Server_Query_Element_Equals( + 'Objectclass', + Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON + ); + return parent::searchGuid($criteria); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidformail.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidformail.php new file mode 100644 index 000000000..71b739dd9 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidformail.php @@ -0,0 +1,47 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Return all KolabInetOrgPersons with the given mail address. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Search_Operation_Guidformail +extends Horde_Kolab_Server_Search_Operation_Restrictkolab +{ + /** + * Return all KolabInetOrgPersons with the given mail. + * + * @param string $mail The mail to search for. + * + * @return array The GUID(s). + * + * @throws Horde_Kolab_Server_Exception + */ + public function searchGuidForMail($mail) + { + $criteria = new Horde_Kolab_Server_Query_Element_Equals( + 'Mail', $mail + ); + return parent::searchRestrictKolab($criteria); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidformailoralias.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidformailoralias.php new file mode 100644 index 000000000..7cb8f290c --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidformailoralias.php @@ -0,0 +1,53 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Return all KolabInetOrgPersons with the given mail or alias address. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Search_Operation_Guidformailoralias +extends Horde_Kolab_Server_Search_Operation_Restrictkolab +{ + /** + * Return all KolabInetOrgPersons with the given mail or alias address. + * + * @param string $mail The mail address to search for. + * @param string $alias The alias address to search for. + * + * @return array The GUID(s). + * + * @throws Horde_Kolab_Server_Exception + */ + public function searchGuidForMailOrAlias($mail, $alias) + { + $criteria = new Horde_Kolab_Server_Query_Element_Or( + new Horde_Kolab_Server_Query_Element_Equals( + 'Mail', $mail + ), + new Horde_Kolab_Server_Query_Element_Equals( + 'Alias', $alias + ) + ); + return parent::searchRestrictKolab($criteria); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforuid.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforuid.php new file mode 100644 index 000000000..0acbc678f --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforuid.php @@ -0,0 +1,47 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Return all KolabInetOrgPersons with the given uid. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Search_Operation_Guidforuid +extends Horde_Kolab_Server_Search_Operation_Restrictkolab +{ + /** + * Return all KolabInetOrgPersons with the given uid. + * + * @param string $uid The uid to search for. + * + * @return array The GUID(s). + * + * @throws Horde_Kolab_Server_Exception + */ + public function searchGuidForUid($uid) + { + $criteria = new Horde_Kolab_Server_Query_Element_Equals( + 'Uid', $uid + ); + return parent::searchRestrictKolab($criteria); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforuidormail.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforuidormail.php new file mode 100644 index 000000000..020a15bba --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforuidormail.php @@ -0,0 +1,88 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Return all KolabInetOrgPersons with the given uid or mail address. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_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. + * + * @return array The GUID(s). + * + * @throws Horde_Kolab_Server_Exception + */ + public function searchGuidForUidOrMail($id) + { + $criteria = new Horde_Kolab_Server_Query_Element_Or( + array( + new Horde_Kolab_Server_Query_Element_Equals( + 'Uid', $id + ), + new Horde_Kolab_Server_Query_Element_Equals( + 'Mail', $id + ) + ) + ); + return $this->_search->searchRestrictKolab($criteria); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforuidormailoralias.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforuidormailoralias.php new file mode 100644 index 000000000..0fa1dd9e4 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforuidormailoralias.php @@ -0,0 +1,57 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Return all KolabInetOrgPersons with the given uid, mail or alias address. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Search_Operation_Guidforuidormailoralias +extends Horde_Kolab_Server_Search_Operation_Restrictkolab +{ + /** + * Return all KolabInetOrgPersons with the given uid, mail or alias address. + * + * @param string $id The uid or mail address or alias address to search for. + * + * @return array The GUID(s). + * + * @throws Horde_Kolab_Server_Exception + */ + public function searchGuidForUidOrMailOrAlias($id) + { + $criteria = new Horde_Kolab_Server_Query_Element_Or( + array( + new Horde_Kolab_Server_Query_Element_Equals( + 'Uid', $id + ), + new Horde_Kolab_Server_Query_Element_Equals( + 'Mail', $id + ), + new Horde_Kolab_Server_Query_Element_Equals( + 'Alias', $id + ) + ) + ); + return parent::searchRestrictKolab($criteria); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Interface.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Interface.php new file mode 100644 index 000000000..a6214aacf --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Interface.php @@ -0,0 +1,36 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * An interface marking object class search operations. + * + * 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 + */ +interface Horde_Kolab_Server_Search_Operation_Interface +{ + /** + * Return the reference to the server structure. + * + * @return Horde_Kolab_Server_Structure_Interface + */ + public function getStructure(); +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Mailforuidormail.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Mailforuidormail.php new file mode 100644 index 000000000..62df3c191 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Mailforuidormail.php @@ -0,0 +1,95 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Return the mail address of the KolabInetOrgPersons with the given uid or mail + * address. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Search_Operation_Mailforuidormail +extends Horde_Kolab_Server_Search_Operation_Base +{ + + /** + * The base attribute search. + * + * @var Horde_Kolab_Server_Search_Operation + */ + private $_search; + + /** + * Constructor + * + * @param Horde_Kolab_Server_Composite $composite A link to the composite + * server handler. + */ + public function __construct(Horde_Kolab_Server_Composite $composite) + { + $this->_composite = $composite; + $this->_search = new Horde_Kolab_Server_Search_Operation_Constraint_Strict( + new Horde_Kolab_Server_Search_Operation_Attributes( + $this->getComposite() + ) + ); + } + + /** + * Return the mail address of the KolabInetOrgPersons with the given uid or + * mail address. + * + * @param string $uid The uid to search for. + * @param string $mail The mail address to search for. + * + * @return array The GUID(s). + * + * @throws Horde_Kolab_Server_Exception + */ + public function searchMailForUidOrMail($uid, $mail) + { + $criteria = new Horde_Kolab_Server_Query_Element_And( + new Horde_Kolab_Server_Query_Element_Equals( + 'Objectclass', + Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON + ), + new Horde_Kolab_Server_Query_Element_Or( + new Horde_Kolab_Server_Query_Element_Equals( + 'Uid', $uid + ), + new Horde_Kolab_Server_Query_Element_Equals( + 'Mail', $mail + ) + ) + ); + $data = $this->_search->searchAttributes($criteria, array('Mail')); + + $internal = $this->getComposite()->structure->getAttributeInternal( + 'Mail' + ); + if (!empty($data)) { + return $data[$internal][0]; + } else { + return false; + } + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Restrictkolab.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Restrictkolab.php new file mode 100644 index 000000000..f60f2a6e8 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Restrictkolab.php @@ -0,0 +1,54 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Restrict a search to KolabInetOrgPersons. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Search_Operation_Restrictkolab +extends Horde_Kolab_Server_Search_Operation_Guid +{ + /** + * Restrict a search to KolabInetOrgPersons. + * + * @param Horde_Kolab_Server_Query_Element $criteria The search criteria. + * + * @return array The GUID(s). + * + * @throws Horde_Kolab_Server_Exception + */ + public function searchRestrictKolab( + Horde_Kolab_Server_Query_Element $criteria + ) { + $criteria = new Horde_Kolab_Server_Query_Element_And( + array( + new Horde_Kolab_Server_Query_Element_Equals( + 'Objectclass', + Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON + ), + $criteria + ) + ); + return parent::searchGuid($criteria); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure.php deleted file mode 100644 index 9b38e8040..000000000 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure.php +++ /dev/null @@ -1,113 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * The interface definition for the handlers dealing with the Kolab Server - * object tree structure. - * - * Copyright 2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -interface Horde_Kolab_Server_Structure -{ - /** - * Finds object data matching a given set of criteria. - * - * @param Horde_Kolab_Server_Query_Element $criteria The criteria for the search. - * @param array $params Additional search parameters. - * - * @return Horde_Kolab_Server_Result The result object. - * - * @throws Horde_Kolab_Server_Exception - */ - public function find( - Horde_Kolab_Server_Query_Element $criteria, - array $params = array() - ); - - /** - * Finds all object data below a parent matching a given set of criteria. - * - * @param Horde_Kolab_Server_Query_Element $criteria The criteria for the search. - * @param string $parent The parent to search below. - * @param array $params Additional search parameters. - * - * @return Horde_Kolab_Server_Result The result object. - * - * @throws Horde_Kolab_Server_Exception - */ - public function findBelow( - Horde_Kolab_Server_Query_Element $criteria, - $parent, - array $params = array() - ); - - /** - * Set the composite server reference for this object. - * - * @param Horde_Kolab_Server_Composite $composite A link to the composite - * server handler. - * - * @return NULL - */ - public function setComposite(Horde_Kolab_Server_Composite $composite); - - /** - * Returns the set of objects supported by this structure. - * - * @return array An array of supported objects. - */ - public function getSupportedObjects(); - - /** - * Maps the external attribute name to its internal counterpart. - * - * @param string $external The external attribute name. - * - * @return string The internal attribute name. - */ - public function getInternalAttribute($external); - - /** - * Determine the type of an object by its tree position and other - * parameters. - * - * @param string $guid The GUID of the object to examine. - * - * @return string The class name of the corresponding object type. - * - * @throws Horde_Kolab_Server_Exception If the object type is unknown. - */ - public function determineType($guid); - - /** - * Generates a UID for the given information. - * - * @param string $type The class name of the object to create. - * @param string $id The id of the object. - * @param array $info Any additional information about the object to create. - * - * @return string The GUID. - * - * @throws Horde_Kolab_Server_Exception If the given type is unknown. - */ - public function generateServerGuid($type, $id, array $info); -} 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/Interface.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Interface.php new file mode 100644 index 000000000..01f2d12e9 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Interface.php @@ -0,0 +1,120 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * The interface definition for the handlers dealing with the Kolab Server + * object tree structure. + * + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +interface Horde_Kolab_Server_Structure_Interface +{ + /** + * Finds object data matching a given set of criteria. + * + * @param Horde_Kolab_Server_Query_Element $criteria The criteria for the search. + * @param array $params Additional search parameters. + * + * @return Horde_Kolab_Server_Result The result object. + * + * @throws Horde_Kolab_Server_Exception + */ + public function find( + Horde_Kolab_Server_Query_Element $criteria, + array $params = array() + ); + + /** + * Finds all object data below a parent matching a given set of criteria. + * + * @param Horde_Kolab_Server_Query_Element $criteria The criteria for the search. + * @param string $parent The parent to search below. + * @param array $params Additional search parameters. + * + * @return Horde_Kolab_Server_Result The result object. + * + * @throws Horde_Kolab_Server_Exception + */ + public function findBelow( + Horde_Kolab_Server_Query_Element $criteria, + $parent, + array $params = array() + ); + + /** + * Set the composite server reference for this object. + * + * @param Horde_Kolab_Server_Composite $composite A link to the composite + * server handler. + * + * @return NULL + */ + public function setComposite(Horde_Kolab_Server_Composite $composite); + + /** + * Returns the set of objects supported by this structure. + * + * @return array An array of supported objects. + */ + 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. + * + * @return string The internal attribute name. + */ + public function getInternalAttribute($external); + + /** + * Determine the type of an object by its tree position and other + * parameters. + * + * @param string $guid The GUID of the object to examine. + * + * @return string The class name of the corresponding object type. + * + * @throws Horde_Kolab_Server_Exception If the object type is unknown. + */ + public function determineType($guid); + + /** + * Generates a UID for the given information. + * + * @param string $type The class name of the object to create. + * @param string $id The id of the object. + * @param array $info Any additional information about the object to create. + * + * @return string The GUID. + * + * @throws Horde_Kolab_Server_Exception If the given type is unknown. + */ + public function generateServerGuid($type, $id, array $info); +} 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/Attribute/BaseTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Attribute/BaseTest.php deleted file mode 100644 index 654f8cc7f..000000000 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Attribute/BaseTest.php +++ /dev/null @@ -1,111 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Prepare the test setup. - */ -require_once dirname(__FILE__) . '/../TestCase.php'; - -/** - * Test the base attribute. - * - * 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_Attribute_BaseTest extends Horde_Kolab_Server_TestCase -{ - public function setUp() - { - $this->object = $this->getMock( - 'Horde_Kolab_Server_Object', array(), array(), '', false - ); - $this->composite = $this->getMockedComposite(); - } - - public function testMethodConstructHasParameterObjectTheObjectOwningTheAttributeAndParameterCompositeWhichIsTheLinkToTheServer() - { - $attribute = new Attribute_Mock($this->object, $this->composite, ''); - } - - public function testMethodConstructHasParameterStringTheNameOfTheAttribute() - { - $attribute = new Attribute_Mock($this->object, $this->composite, 'name'); - } - - public function testMethodGetobjectReturnsObjectAssociatedWithThisAttribute() - { - $attribute = new Attribute_Mock($this->object, $this->composite, ''); - $this->assertType('Horde_Kolab_Server_Object', $attribute->getObject()); - } - - public function testMethodGetnameReturnsStringTheNameOfTheAttribute() - { - $this->composite->structure->expects($this->exactly(1)) - ->method('getInternalAttribute') - ->with('name') - ->will($this->returnValue('name')); - $attribute = new Attribute_Mock($this->object, $this->composite, 'name'); - $this->assertEquals('name', $attribute->getInternalName()); - } - - public function testMethodIsemptyHasParameterArrayDataValues() - { - $attribute = new Attribute_Mock($this->object, $this->composite, 'name'); - $attribute->isEmpty(array()); - } - - public function testMethodIsemptyReturnsFalseIfTheValueIndicatedByTheAttributeNameIsNotEmptyInTheDataArray() - { - $attribute = new Attribute_Mock($this->object, $this->composite, 'name', 'name'); - $this->assertFalse($attribute->isEmpty(array('name' => 'HELLO'))); - } - - public function testMethodIsemptyReturnsTrueIfTheValueIndicatedByTheAttributeNameIsMissingInTheDataArray() - { - $attribute = new Attribute_Mock($this->object, $this->composite, 'name'); - $this->assertTrue($attribute->isEmpty(array())); - } - - public function testMethodIsemptyReturnsTrueIfTheValueIndicatedByTheAttributeNameIsStringEmptyInTheDataArray() - { - $attribute = new Attribute_Mock($this->object, $this->composite, 'name'); - $this->assertTrue($attribute->isEmpty(array('name' => ''))); - } - - public function testMethodIsemptyReturnsTrueIfTheValueIndicatedByTheAttributeNameIsNullInTheDataArray() - { - $attribute = new Attribute_Mock($this->object, $this->composite, 'name'); - $this->assertTrue($attribute->isEmpty(array('name' => null))); - } - - public function testMethodIsemptyReturnsTrueIfTheValueIndicatedByTheAttributeNameIsEmptyArrayInTheDataArray() - { - $attribute = new Attribute_Mock($this->object, $this->composite, 'name'); - $this->assertTrue($attribute->isEmpty(array('name' => array()))); - } -} - -class Attribute_Mock extends Horde_Kolab_Server_Object_Attribute_Base -{ - public function value() {} - public function update(array $changes) {} - public function consume(array &$changes) {} -} \ No newline at end of file diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Attribute/ValueTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Attribute/ValueTest.php deleted file mode 100644 index 61c652b1f..000000000 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Attribute/ValueTest.php +++ /dev/null @@ -1,244 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Prepare the test setup. - */ -require_once dirname(__FILE__) . '/../Autoload.php'; - -/** - * Test the value attribute. - * - * 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_Attribute_ValueTest extends PHPUnit_Framework_TestCase -{ - public function setUp() - { - $this->object = $this->getMock( - 'Horde_Kolab_Server_Object', array(), array(), '', false - ); - $this->composite = $this->getMock( - 'Horde_Kolab_Server_Composite', array(), array(), '', false - ); - - $this->markTestIncomplete('Needs to be fixed'); - } - - public function testMethodValueHasResultArrayTheValuesOfTheAttribute() - { - $attribute = new Horde_Kolab_Server_Object_Attribute_Value( - $this->object, $this->composite, 'name' - ); - $this->object->expects($this->once()) - ->method('getInternal') - ->with('name') - ->will($this->returnValue(array(1, 2))); - $this->assertEquals(array(1, 2), $attribute->value()); - } - - public function testMethodConsumeHasParameterArrayData() - { - $attribute = new Horde_Kolab_Server_Object_Attribute_Value( - $this->object, $this->composite, 'name' - ); - $data = array(); - $attribute->consume($data); - } - - public function testMethodConsumeHasPostconditionThatTheAttributeValueHasBeenRemovedFromTheDataArray() - { - $attribute = new Horde_Kolab_Server_Object_Attribute_Value( - $this->object, $this->composite, 'name', 'name' - ); - $data = array('name' => 'test'); - $attribute->consume($data); - $this->assertEquals(array(), $data); - } - - public function testMethodChangesHasParameterArrayData() - { - $attribute = new Horde_Kolab_Server_Object_Attribute_Value( - $this->object, $this->composite, 'name' - ); - $this->object->expects($this->once()) - ->method('exists') - ->with() - ->will($this->returnValue(false)); - $data = array(); - $attribute->update($data); - } - - public function testMethodChangesHasResultArrayEmptyIfTheObjectDoesNotExistAndThereAreNoChangesToTheAttribute() - { - $attribute = new Horde_Kolab_Server_Object_Attribute_Value( - $this->object, $this->composite, 'name' - ); - $this->object->expects($this->once()) - ->method('exists') - ->with() - ->will($this->returnValue(false)); - $data = array(); - $this->assertEquals(array(), $attribute->update($data)); - } - - public function testMethodChangesHasResultArrayWithAddedValuesIfTheObjectDoesNotExistAndThereAreChangesToTheAttribute() - { - $attribute = new Horde_Kolab_Server_Object_Attribute_Value( - $this->object, $this->composite, 'name', 'name' - ); - $this->object->expects($this->once()) - ->method('exists') - ->with() - ->will($this->returnValue(false)); - $data = array('name' => 'a'); - $this->assertEquals( - array(array('name' => array('a'))), - $attribute->update($data) - ); - } - - public function testMethodChangesHasResultArrayWithAddedValuesIfTheObjectExistsButHadNoValueForTheAttributeAndThereAreNoChangesToTheAttribute() - { - $attribute = new Horde_Kolab_Server_Object_Attribute_Value( - $this->object, $this->composite, 'name' - ); - $this->object->expects($this->once()) - ->method('exists') - ->with() - ->will($this->returnValue(true)); - $this->object->expects($this->once()) - ->method('getInternal') - ->with('name') - ->will( - $this->throwException( - new Horde_Kolab_Server_Exception_Novalue('') - ) - ); - $data = array(); - $this->assertEquals(array(), $attribute->update($data)); - } - - public function testMethodChangesHasResultArrayWithAddedValuesIfTheObjectExistsButHadNoValueForTheAttributeAndThereAreChangesToTheAttribute() - { - $attribute = new Horde_Kolab_Server_Object_Attribute_Value( - $this->object, $this->composite, 'name' - ); - $this->object->expects($this->once()) - ->method('exists') - ->with() - ->will($this->returnValue(true)); - $this->object->expects($this->once()) - ->method('getInternal') - ->with('name') - ->will( - $this->throwException( - new Horde_Kolab_Server_Exception_Novalue('') - ) - ); - $data = array('name' => 'a'); - $this->assertEquals( - array('add' => array('name' => array('a'))), - $attribute->update($data) - ); - } - - public function testMethodChangesHasResultArrayWithDeletedValuesIfTheObjectExistsAndHadAValueForTheAttributeAndTheNewValueIsEmpty() - { - $attribute = new Horde_Kolab_Server_Object_Attribute_Value( - $this->object, $this->composite, 'name' - ); - $this->object->expects($this->once()) - ->method('exists') - ->with() - ->will($this->returnValue(true)); - $this->object->expects($this->once()) - ->method('getInternal') - ->with('name') - ->will($this->returnValue(array('a'))); - $data = array('name' => null); - $this->assertEquals( - array('delete' => array('name' => array('a'))), - $attribute->update($data) - ); - } - - public function testMethodChangesHasResultArrayWithReplacedValuesIfTheObjectExistsAndHadASingleValueForTheAttributeAndTheNewValueHasASingleNewValue() - { - $attribute = new Horde_Kolab_Server_Object_Attribute_Value( - $this->object, $this->composite, 'name' - ); - $this->object->expects($this->once()) - ->method('exists') - ->with() - ->will($this->returnValue(true)); - $this->object->expects($this->once()) - ->method('getInternal') - ->with('name') - ->will($this->returnValue(array('a'))); - $data = array('name' => array('b')); - $this->assertEquals( - array('replace' => array('name' => array('b'))), - $attribute->update($data) - ); - } - - public function testMethodChangesHasResultArrayEmptyIfTheObjectExistsAndHadASingleValueForTheAttributeAndTheNewValueHasASingleNewValueAndBothAreEqual() - { - $attribute = new Horde_Kolab_Server_Object_Attribute_Value( - $this->object, $this->composite, 'name' - ); - $this->object->expects($this->once()) - ->method('exists') - ->with() - ->will($this->returnValue(true)); - $this->object->expects($this->once()) - ->method('getInternal') - ->with('name') - ->will($this->returnValue(array('a'))); - $data = array('name' => array('a')); - $this->assertEquals(array(), $attribute->update($data)); - } - - public function testMethodChangesHasResultArrayWithAddedAndDeletedValuesIfTheObjectExistsAndHadValuesForTheAttributeAndNewValuesHaveBeenProvided() - { - $attribute = new Horde_Kolab_Server_Object_Attribute_Value( - $this->object, $this->composite, 'name' - ); - $this->object->expects($this->once()) - ->method('exists') - ->with() - ->will($this->returnValue(true)); - $this->object->expects($this->once()) - ->method('getInternal') - ->with('name') - ->will($this->returnValue(array('a', 'c'))); - $data = array('name' => array('b', 'c', 'd')); - $this->assertEquals( - array( - 'add' => array('name' => array('b', 'd')), - 'delete' => array('name' => array('a')) - ), - $attribute->update($data) - ); - } -} \ No newline at end of file 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/Class/Server/Connection/Mock/LdapTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Connection/Mock/LdapTest.php new file mode 100644 index 000000000..93f4c6779 --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Connection/Mock/LdapTest.php @@ -0,0 +1,238 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Require our basic test case definition + */ +require_once dirname(__FILE__) . '/../../../../LdapTestCase.php'; + +/** + * Test the test backend. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Class_Server_Connection_Mock_LdapTest +extends Horde_Kolab_Server_LdapTestCase +{ + /** + * Test parsing of LDAP filters. + * + * @return NULL + */ + public function testFilterParse() + { + $this->skipIfNoLdap(); + + $conn = new Horde_Kolab_Server_Connection_Mock_Ldap(array(), array()); + + $a = $conn->parse('(a=b)'); + $this->assertEquals(array('att' => 'a', 'log' => '=', 'val' => 'b'), + $a); + + $a = $conn->parse('(&(a=b)(c=d))'); + $this->assertEquals(array('op' => '&', 'sub' => array( + array('att' => 'a', 'log' => '=', 'val' => 'b'), + array('att' => 'c', 'log' => '=', 'val' => 'd'), + )), $a); + + $a = $conn->parse('(&(a=1)(|(b=2)(c=3)))'); + $this->assertEquals(array('op' => '&', 'sub' => array( + array('att' => 'a', 'log' => '=', 'val' => '1'), + array('op' => '|', 'sub' => + array( + array('att' => 'b', 'log' => '=', 'val' => '2'), + array('att' => 'c', 'log' => '=', 'val' => '3'), + )))), $a); + + $a = $conn->parseSub('(!(x=2))(b=1)'); + $this->assertEquals(array(array('op' => '!', 'sub' => + array( + array('att' => 'x', 'log' => '=', 'val' => '2'), + ) + ), + array('att' => 'b', 'log' => '=', 'val' => '1'), + ), $a); + + $a = $conn->parse('(&(!(x=2))(b=1))'); + $this->assertEquals(array('op' => '&', 'sub' => array( + array('op' => '!', 'sub' => + array( + array('att' => 'x', 'log' => '=', 'val' => '2'), + ) + ), + array('att' => 'b', 'log' => '=', 'val' => '1'), + )), $a); + + } + + /** + * Test searching in the simulated LDAP data. + * + * @return NULL + */ + public function testSearch() + { + $this->skipIfNoLdap(); + + $conn = new Horde_Kolab_Server_Connection_Mock_Ldap( + array(), + 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', + ) + ), + ) + ); + $conn->bind(); + + $a = $conn->search(null, '(c=1)'); + $this->assertEquals( + array( + 'cn=a' => array( + 'a' => '1', + 'b' => '1', + 'c' => '1', + 'dn' => 'cn=a', + ), + 'cn=d' => array( + 'a' => '2', + 'b' => '2', + 'c' => '1', + 'dn' => 'cn=d', + ), + ), + $a->as_struct() + ); + + $a = $conn->search(null, '(c=3)'); + $this->assertEquals( + array( + 'cn=c' => array( + 'a' => '1', + 'b' => '2', + 'c' => '3', + 'dn' => 'cn=c', + ), + ), + $a->as_struct() + ); + + $a = $conn->search(null, '(c=3)', array('attributes' => array('a'))); + $this->assertEquals( + array( + 'cn=c' => array( + 'a' => '1', + 'dn' => 'cn=c', + ), + ), + $a->as_struct() + ); + + $a = $conn->search(null, '(&(a=1)(b=2))', array('attributes' => array('a', 'b'))); + $this->assertEquals( + array( + 'cn=b' => array( + 'a' => '1', + 'b' => '2', + 'dn' => 'cn=b', + ), + 'cn=c' => array( + 'a' => '1', + 'b' => '2', + 'dn' => 'cn=c', + ), + ), + $a->as_struct() + ); + + $a = $conn->search(null, '(&(b=2))', array('attributes' => array('b'))); + $this->assertEquals( + array( + 'cn=b' => array( + 'b' => '2', + 'dn' => 'cn=b', + ), + 'cn=c' => array( + 'b' => '2', + 'dn' => 'cn=c', + ), + 'cn=d' => array( + 'b' => '2', + 'dn' => 'cn=d', + ), + ), + $a->as_struct() + ); + + $a = $conn->search(null, '(!(b=2))', array('attributes' => array('a', 'b'))); + $this->assertEquals( + array( + 'cn=a' => array( + 'a' => '1', + 'b' => '1', + 'dn' => 'cn=a', + ), + ), + $a->as_struct() + ); + + $a = $conn->search(null, '(&(!(x=2))(b=1))', array('attributes' => array('b'))); + $this->assertEquals( + array( + 'cn=a' => array( + 'b' => '1', + 'dn' => 'cn=a', + ), + ), + $a->as_struct() + ); + } + +} 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/Class/Server/Connection/SimpleldapTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Connection/SimpleldapTest.php new file mode 100644 index 000000000..7340f6589 --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Connection/SimpleldapTest.php @@ -0,0 +1,62 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Require our basic test case definition + */ +require_once dirname(__FILE__) . '/../../../LdapTestCase.php'; + +/** + * Test the handler for a simple LDAP setup without read-only slaves. + * + * 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_SimpleldapTest +extends Horde_Kolab_Server_LdapTestCase +{ + public function testMethodConstructHasParameterNetldap2Connection() + { + $ldap = $this->getMock('Net_LDAP2'); + $conn = new Horde_Kolab_Server_Connection_Simpleldap($ldap); + } + + public function testMethodConstructHasPostconditionThatTheGivenServerWasStored() + { + $ldap = $this->getMock('Net_LDAP2'); + $conn = new Horde_Kolab_Server_Connection_Simpleldap($ldap); + $this->assertSame($ldap, $conn->getRead()); + } + + public function testMethodGetreadHasResultNetldap2TheHandledConnection() + { + $ldap = $this->getMock('Net_LDAP2'); + $conn = new Horde_Kolab_Server_Connection_Simpleldap($ldap); + $this->assertType('Net_LDAP2', $conn->getRead()); + } + + public function testMethodGetwriteHasResultNetldap2TheHandledConnection() + { + $ldap = $this->getMock('Net_LDAP2'); + $conn = new Horde_Kolab_Server_Connection_Simpleldap($ldap); + $this->assertSame($conn->getWrite(), $conn->getRead()); + } +} diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Connection/SplittedldapTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Connection/SplittedldapTest.php new file mode 100644 index 000000000..987b61a4f --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Connection/SplittedldapTest.php @@ -0,0 +1,68 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Require our basic test case definition + */ +require_once dirname(__FILE__) . '/../../../LdapTestCase.php'; + +/** + * Test the handler for a LDAP master/slave setup. + * + * 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_SplittedldapTest +extends Horde_Kolab_Server_LdapTestCase +{ + public function testMethodConstructHasParameterNetldap2ReadConnectionAndParameterNetldap2WriteConnection() + { + $ldap_read = $this->getMock('Net_LDAP2'); + $ldap_write = $this->getMock('Net_LDAP2'); + $conn = new Horde_Kolab_Server_Connection_Splittedldap($ldap_read, $ldap_write); + } + + public function testMethodConstructHasPostconditionThatTheGivenServersWereStored() + { + $ldap_read = $this->getMock('Net_LDAP2'); + $ldap_write = $this->getMock('Net_LDAP2'); + $conn = new Horde_Kolab_Server_Connection_Splittedldap($ldap_read, $ldap_write); + $this->assertSame($ldap_read, $conn->getRead()); + $this->assertSame($ldap_write, $conn->getWrite()); + } + + public function testMethodGetreadHasResultNetldap2TheHandledConnection() + { + $ldap_read = $this->getMock('Net_LDAP2'); + $ldap_write = $this->getMock('Net_LDAP2'); + $conn = new Horde_Kolab_Server_Connection_Splittedldap($ldap_read, $ldap_write); + $this->assertType('Net_LDAP2', $conn->getRead()); + $this->assertType('Net_LDAP2', $conn->getWrite()); + } + + public function testMethodGetwriteHasResultNetldap2TheHandledConnection() + { + $ldap_read = $this->getMock('Net_LDAP2'); + $ldap_write = $this->getMock('Net_LDAP2'); + $conn = new Horde_Kolab_Server_Connection_Splittedldap($ldap_read, $ldap_write); + $this->assertFalse($conn->getWrite() === $conn->getRead()); + } +} 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/Class/Server/Object/Attribute/BaseTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Object/Attribute/BaseTest.php new file mode 100644 index 000000000..0b10da10d --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Object/Attribute/BaseTest.php @@ -0,0 +1,112 @@ + + * @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 base attribute. + * + * 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_Object_Attribute_BaseTest +extends Horde_Kolab_Server_TestCase +{ + public function setUp() + { + $this->object = $this->getMock( + 'Horde_Kolab_Server_Object', array(), array(), '', false + ); + $this->composite = $this->getMockedComposite(); + } + + public function testMethodConstructHasParameterObjectTheObjectOwningTheAttributeAndParameterCompositeWhichIsTheLinkToTheServer() + { + $attribute = new Attribute_Mock($this->object, $this->composite, ''); + } + + public function testMethodConstructHasParameterStringTheNameOfTheAttribute() + { + $attribute = new Attribute_Mock($this->object, $this->composite, 'name'); + } + + public function testMethodGetobjectReturnsObjectAssociatedWithThisAttribute() + { + $attribute = new Attribute_Mock($this->object, $this->composite, ''); + $this->assertType('Horde_Kolab_Server_Object', $attribute->getObject()); + } + + public function testMethodGetnameReturnsStringTheNameOfTheAttribute() + { + $this->composite->structure->expects($this->exactly(1)) + ->method('getInternalAttribute') + ->with('name') + ->will($this->returnValue('name')); + $attribute = new Attribute_Mock($this->object, $this->composite, 'name'); + $this->assertEquals('name', $attribute->getInternalName()); + } + + public function testMethodIsemptyHasParameterArrayDataValues() + { + $attribute = new Attribute_Mock($this->object, $this->composite, 'name'); + $attribute->isEmpty(array()); + } + + public function testMethodIsemptyReturnsFalseIfTheValueIndicatedByTheAttributeNameIsNotEmptyInTheDataArray() + { + $attribute = new Attribute_Mock($this->object, $this->composite, 'name', 'name'); + $this->assertFalse($attribute->isEmpty(array('name' => 'HELLO'))); + } + + public function testMethodIsemptyReturnsTrueIfTheValueIndicatedByTheAttributeNameIsMissingInTheDataArray() + { + $attribute = new Attribute_Mock($this->object, $this->composite, 'name'); + $this->assertTrue($attribute->isEmpty(array())); + } + + public function testMethodIsemptyReturnsTrueIfTheValueIndicatedByTheAttributeNameIsStringEmptyInTheDataArray() + { + $attribute = new Attribute_Mock($this->object, $this->composite, 'name'); + $this->assertTrue($attribute->isEmpty(array('name' => ''))); + } + + public function testMethodIsemptyReturnsTrueIfTheValueIndicatedByTheAttributeNameIsNullInTheDataArray() + { + $attribute = new Attribute_Mock($this->object, $this->composite, 'name'); + $this->assertTrue($attribute->isEmpty(array('name' => null))); + } + + public function testMethodIsemptyReturnsTrueIfTheValueIndicatedByTheAttributeNameIsEmptyArrayInTheDataArray() + { + $attribute = new Attribute_Mock($this->object, $this->composite, 'name'); + $this->assertTrue($attribute->isEmpty(array('name' => array()))); + } +} + +class Attribute_Mock extends Horde_Kolab_Server_Object_Attribute_Base +{ + public function value() {} + public function update(array $changes) {} + public function consume(array &$changes) {} +} \ No newline at end of file diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Object/Attribute/ValueTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Object/Attribute/ValueTest.php new file mode 100644 index 000000000..ed0eb59a8 --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Object/Attribute/ValueTest.php @@ -0,0 +1,245 @@ + + * @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 value attribute. + * + * 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_Object_Attribute_ValueTest +extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + $this->object = $this->getMock( + 'Horde_Kolab_Server_Object', array(), array(), '', false + ); + $this->composite = $this->getMock( + 'Horde_Kolab_Server_Composite', array(), array(), '', false + ); + + $this->markTestIncomplete('Needs to be fixed'); + } + + public function testMethodValueHasResultArrayTheValuesOfTheAttribute() + { + $attribute = new Horde_Kolab_Server_Object_Attribute_Value( + $this->object, $this->composite, 'name' + ); + $this->object->expects($this->once()) + ->method('getInternal') + ->with('name') + ->will($this->returnValue(array(1, 2))); + $this->assertEquals(array(1, 2), $attribute->value()); + } + + public function testMethodConsumeHasParameterArrayData() + { + $attribute = new Horde_Kolab_Server_Object_Attribute_Value( + $this->object, $this->composite, 'name' + ); + $data = array(); + $attribute->consume($data); + } + + public function testMethodConsumeHasPostconditionThatTheAttributeValueHasBeenRemovedFromTheDataArray() + { + $attribute = new Horde_Kolab_Server_Object_Attribute_Value( + $this->object, $this->composite, 'name', 'name' + ); + $data = array('name' => 'test'); + $attribute->consume($data); + $this->assertEquals(array(), $data); + } + + public function testMethodChangesHasParameterArrayData() + { + $attribute = new Horde_Kolab_Server_Object_Attribute_Value( + $this->object, $this->composite, 'name' + ); + $this->object->expects($this->once()) + ->method('exists') + ->with() + ->will($this->returnValue(false)); + $data = array(); + $attribute->update($data); + } + + public function testMethodChangesHasResultArrayEmptyIfTheObjectDoesNotExistAndThereAreNoChangesToTheAttribute() + { + $attribute = new Horde_Kolab_Server_Object_Attribute_Value( + $this->object, $this->composite, 'name' + ); + $this->object->expects($this->once()) + ->method('exists') + ->with() + ->will($this->returnValue(false)); + $data = array(); + $this->assertEquals(array(), $attribute->update($data)); + } + + public function testMethodChangesHasResultArrayWithAddedValuesIfTheObjectDoesNotExistAndThereAreChangesToTheAttribute() + { + $attribute = new Horde_Kolab_Server_Object_Attribute_Value( + $this->object, $this->composite, 'name', 'name' + ); + $this->object->expects($this->once()) + ->method('exists') + ->with() + ->will($this->returnValue(false)); + $data = array('name' => 'a'); + $this->assertEquals( + array(array('name' => array('a'))), + $attribute->update($data) + ); + } + + public function testMethodChangesHasResultArrayWithAddedValuesIfTheObjectExistsButHadNoValueForTheAttributeAndThereAreNoChangesToTheAttribute() + { + $attribute = new Horde_Kolab_Server_Object_Attribute_Value( + $this->object, $this->composite, 'name' + ); + $this->object->expects($this->once()) + ->method('exists') + ->with() + ->will($this->returnValue(true)); + $this->object->expects($this->once()) + ->method('getInternal') + ->with('name') + ->will( + $this->throwException( + new Horde_Kolab_Server_Exception_Novalue('') + ) + ); + $data = array(); + $this->assertEquals(array(), $attribute->update($data)); + } + + public function testMethodChangesHasResultArrayWithAddedValuesIfTheObjectExistsButHadNoValueForTheAttributeAndThereAreChangesToTheAttribute() + { + $attribute = new Horde_Kolab_Server_Object_Attribute_Value( + $this->object, $this->composite, 'name' + ); + $this->object->expects($this->once()) + ->method('exists') + ->with() + ->will($this->returnValue(true)); + $this->object->expects($this->once()) + ->method('getInternal') + ->with('name') + ->will( + $this->throwException( + new Horde_Kolab_Server_Exception_Novalue('') + ) + ); + $data = array('name' => 'a'); + $this->assertEquals( + array('add' => array('name' => array('a'))), + $attribute->update($data) + ); + } + + public function testMethodChangesHasResultArrayWithDeletedValuesIfTheObjectExistsAndHadAValueForTheAttributeAndTheNewValueIsEmpty() + { + $attribute = new Horde_Kolab_Server_Object_Attribute_Value( + $this->object, $this->composite, 'name' + ); + $this->object->expects($this->once()) + ->method('exists') + ->with() + ->will($this->returnValue(true)); + $this->object->expects($this->once()) + ->method('getInternal') + ->with('name') + ->will($this->returnValue(array('a'))); + $data = array('name' => null); + $this->assertEquals( + array('delete' => array('name' => array('a'))), + $attribute->update($data) + ); + } + + public function testMethodChangesHasResultArrayWithReplacedValuesIfTheObjectExistsAndHadASingleValueForTheAttributeAndTheNewValueHasASingleNewValue() + { + $attribute = new Horde_Kolab_Server_Object_Attribute_Value( + $this->object, $this->composite, 'name' + ); + $this->object->expects($this->once()) + ->method('exists') + ->with() + ->will($this->returnValue(true)); + $this->object->expects($this->once()) + ->method('getInternal') + ->with('name') + ->will($this->returnValue(array('a'))); + $data = array('name' => array('b')); + $this->assertEquals( + array('replace' => array('name' => array('b'))), + $attribute->update($data) + ); + } + + public function testMethodChangesHasResultArrayEmptyIfTheObjectExistsAndHadASingleValueForTheAttributeAndTheNewValueHasASingleNewValueAndBothAreEqual() + { + $attribute = new Horde_Kolab_Server_Object_Attribute_Value( + $this->object, $this->composite, 'name' + ); + $this->object->expects($this->once()) + ->method('exists') + ->with() + ->will($this->returnValue(true)); + $this->object->expects($this->once()) + ->method('getInternal') + ->with('name') + ->will($this->returnValue(array('a'))); + $data = array('name' => array('a')); + $this->assertEquals(array(), $attribute->update($data)); + } + + public function testMethodChangesHasResultArrayWithAddedAndDeletedValuesIfTheObjectExistsAndHadValuesForTheAttributeAndNewValuesHaveBeenProvided() + { + $attribute = new Horde_Kolab_Server_Object_Attribute_Value( + $this->object, $this->composite, 'name' + ); + $this->object->expects($this->once()) + ->method('exists') + ->with() + ->will($this->returnValue(true)); + $this->object->expects($this->once()) + ->method('getInternal') + ->with('name') + ->will($this->returnValue(array('a', 'c'))); + $data = array('name' => array('b', 'c', 'd')); + $this->assertEquals( + array( + 'add' => array('name' => array('b', 'd')), + 'delete' => array('name' => array('a')) + ), + $attribute->update($data) + ); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Object/BaseTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Object/BaseTest.php new file mode 100644 index 000000000..26932b5c7 --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Object/BaseTest.php @@ -0,0 +1,339 @@ + + * @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 base object. + * + * 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_Class_Server_Object_BaseTest extends Horde_Kolab_Server_TestCase +{ + public function setUp() + { + } + + public function testMethodConstructHasParameterCompositeWhichIsTheLinkToTheServer() + { + $composite = $this->getComposite(); + $object = new Object_Mock($composite, ''); + } + + public function testMethodConstructHasParameterStringTheGuidOfTheObject() + { + $composite = $this->getComposite(); + $object = new Object_Mock($composite, 'guid'); + } + + public function testGetguidHasResultStringGuidTheObjectIdOnTheServer() + { + $composite = $this->getComposite(); + $object = new Object_Mock($composite, 'guid'); + $this->assertEquals('guid', $object->getGuid()); + } + + public function testGetguidThrowsExceptionIfGuidHasNotBeenSetYet() + { + $composite = $this->getComposite(); + $object = new Object_Mock($composite); + try { + $this->assertEquals('newGuid', $object->getGuid()); + $this->fail('No exception!'); + } catch (Horde_Kolab_Server_Exception $e) { + $this->assertEquals( + 'Uninitialized object is missing GUID!', $e->getMessage() + ); + } + } + + public function testGetexternalattributesHasResultArrayTheExternalAttributesSupportedByTheObject() + { + $composite = $this->getMockedComposite(); + $composite->schema->expects($this->once()) + ->method('getExternalAttributes') + ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) + ->will($this->returnValue(array('external'))); + $object = new Object_Mock($composite, 'guid'); + $this->assertEquals(array('external'), $object->getExternalAttributes()); + } + + public function testGetinternalattributesHasResultArrayTheInternalAttributesSupportedByTheObject() + { + $composite = $this->getMockedComposite(); + $composite->schema->expects($this->once()) + ->method('getInternalAttributes') + ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) + ->will($this->returnValue(array('internal' => 'Internal'))); + $object = new Object_Mock($composite, 'guid'); + $this->assertEquals(array('internal' => 'Internal'), $object->getInternalAttributes()); + } + + public function testGetinternalattributesHasResultBooleanFalseIfTheGuidIsNotSpecified() + { + $composite = $this->getMockedComposite(); + $object = new Object_Mock($composite); + $this->assertFalse($object->exists()); + } + + public function testGetinternalattributesHasResultBooleanFalseIfTheServerReturnedAnError() + { + $composite = $this->getMockedComposite(); + $composite->schema->expects($this->once()) + ->method('getInternalAttributes') + ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) + ->will($this->returnValue(array('internal' => 'Internal'))); + $composite->server->expects($this->once()) + ->method('readAttributes') + ->with('guid', array('internal')) + ->will($this->throwException(new Horde_Kolab_Server_Exception(''))); + $object = new Object_Mock($composite, 'guid'); + $this->assertFalse($object->exists()); + } + + public function testGetinternalattributesHasResultBooleanTrueIfTheServerReturnedData() + { + $composite = $this->getMockedComposite(); + $composite->schema->expects($this->once()) + ->method('getInternalAttributes') + ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) + ->will($this->returnValue(array('internal' => 'Internal'))); + $composite->server->expects($this->once()) + ->method('readAttributes') + ->with('guid', array('internal')) + ->will($this->returnValue(array('a' => 'a'))); + $object = new Object_Mock($composite, 'guid'); + $this->assertTrue($object->exists()); + } + + public function testReadinternalHasResultArrayDataTheInternalObjectData() + { + $composite = $this->getMockedComposite(); + $composite->schema->expects($this->once()) + ->method('getInternalAttributes') + ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) + ->will($this->returnValue(array('internal' => 'Internal'))); + $composite->server->expects($this->once()) + ->method('readAttributes') + ->with('guid', array('internal')) + ->will($this->returnValue(array('internal' => 'test'))); + $object = new Object_Mock($composite, 'guid'); + $this->assertEquals( + array('internal' => 'test'), $object->readInternal() + ); + } + + public function testGetinternalHasResultArrayTheDataOfTheRequestedAttribute() + { + $composite = $this->getMockedComposite(); + $composite->schema->expects($this->exactly(2)) + ->method('getInternalAttributes') + ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) + ->will($this->returnValue(array('internal' => 'Internal'))); + $composite->server->expects($this->once()) + ->method('readAttributes') + ->with('guid', array('internal')) + ->will($this->returnValue(array('internal' => array('test')))); + $object = new Object_Mock($composite, 'guid'); + $this->assertEquals( + array('test'), $object->getInternal('internal') + ); + } + + public function testGetinternalThrowsExceptionIfTheRequestedAttributeIsNotSupported() + { + $composite = $this->getMockedComposite(); + $composite->schema->expects($this->once()) + ->method('getInternalAttributes') + ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) + ->will($this->returnValue(array('internal' => 'Internal'))); + $object = new Object_Mock($composite, 'guid'); + try { + $object->getInternal('test'); + $this->fail('No exception!'); + } catch (Horde_Kolab_Server_Exception $e) { + $this->assertEquals('Attribute "test" not supported!', $e->getMessage()); + } + } + + public function testGetinternalThrowsExceptionIfTheRequestedAttributeHasNoValue() + { + $composite = $this->getMockedComposite(); + $composite->schema->expects($this->exactly(2)) + ->method('getInternalAttributes') + ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) + ->will( + $this->returnValue( + array('internal' => 'Internal', 'test' => 'Test') + ) + ); + $composite->server->expects($this->once()) + ->method('readAttributes') + ->with('guid', array('internal', 'test')) + ->will($this->returnValue(array('internal' => array('test')))); + $object = new Object_Mock($composite, 'guid'); + try { + $object->getInternal('test'); + $this->fail('No exception!'); + } catch (Horde_Kolab_Server_Exception_Novalue $e) { + $this->assertEquals('No value for attribute "test"!', $e->getMessage()); + } + } + + public function testGetexternalHasResultArrayTheDataOfTheRequestedAttribute() + { + $composite = $this->getMockedComposite(); + $composite->structure->expects($this->exactly(1)) + ->method('getInternalAttribute') + ->with('Objectclass') + ->will($this->returnValue('objectClass')); + $composite->schema->expects($this->exactly(1)) + ->method('getExternalAttributes') + ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) + ->will($this->returnValue(array('Objectclass'))); + $composite->schema->expects($this->exactly(2)) + ->method('getInternalAttributes') + ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) + ->will($this->returnValue(array('objectClass' => 'Objectclass'))); + $composite->server->expects($this->once()) + ->method('readAttributes') + ->with('guid', array('objectClass')) + ->will($this->returnValue(array('objectClass' => array('test')))); + $object = new Object_Mock($composite, 'guid'); + $this->assertEquals( + array('test'), $object->getExternal('Objectclass') + ); + } + + public function testGetexternalThrowsExceptionIfTheRequestedAttributeIsNotSupported() + { + $composite = $this->getMockedComposite(); + $composite->schema->expects($this->once()) + ->method('getExternalAttributes') + ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) + ->will($this->returnValue(array('external'))); + $object = new Object_Mock($composite, 'guid'); + try { + $object->getExternal('test'); + $this->fail('No exception!'); + } catch (Horde_Kolab_Server_Exception $e) { + $this->assertEquals('Attribute "Test" not supported!', $e->getMessage()); + } + } + + public function testGetexternalThrowsExceptionIfTheRequestedClassDoesNotExist() + { + $composite = $this->getMockedComposite(); + $composite->schema->expects($this->once()) + ->method('getExternalAttributes') + ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) + ->will($this->returnValue(array('Test'))); + $object = new Object_Mock($composite, 'guid'); + try { + $object->getExternal('test'); + $this->fail('No exception!'); + } catch (Horde_Kolab_Server_Exception $e) { + $this->assertEquals('Attribute "Test" not supported!', $e->getMessage()); + } + } + + public function testDeleteHasPostconditionThatTheObjectWasDeletedOnTheServer() + { + $composite = $this->getMockedComposite(); + $composite->server->expects($this->once()) + ->method('delete') + ->with('guid'); + $object = new Object_Mock($composite, 'guid'); + $object->delete(); + } + + public function testSaveHasParameterArrayTheDataToSave() + { + $composite = $this->getMockedComposite(); + $composite->schema->expects($this->exactly(3)) + ->method('getInternalAttributes') + ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) + ->will( + $this->returnValue( + array( + 'objectClass' => + 'Horde_Kolab_Server_Object_Attribute_Objectclass' + ) + ) + ); + $composite->server->expects($this->exactly(2)) + ->method('readAttributes') + ->with('guid', array('objectClass')) + ->will($this->returnValue(array('objectClass' => array('test')))); + $object = new Object_Mock($composite, 'guid'); + $object->save(array()); + } + + public function testSaveHasPostconditionThatTheObjectWasAddedToTheServerIfItDidNotExistBefore() + { + $composite = $this->getMockedComposite(); + $composite->structure->expects($this->exactly(1)) + ->method('getInternalAttribute') + ->with('Objectclass') + ->will($this->returnValue('objectClass')); + $composite->schema->expects($this->exactly(1)) + ->method('getInternalAttributes') + ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) + ->will( + $this->returnValue( + array( + 'objectClass' => + 'Horde_Kolab_Server_Object_Attribute_Objectclass' + ) + ) + ); + $composite->structure->expects($this->exactly(1)) + ->method('generateServerGuid') + ->with( + 'Object_Mock', null, + array('objectClass' => array('top'))) + ->will( + $this->returnValue( + array( + 'objectClass' => + 'Horde_Kolab_Server_Object_Attribute_Objectclass' + ) + ) + ); + $composite->server->expects($this->exactly(1)) + ->method('add') + ->with($this->isInstanceOf('Horde_Kolab_Server_Object'), array('objectClass' => array('top'))); + $object = new Object_Mock($composite); + $object->save(array('Objectclass' => 'top')); + } +} + +class Object_Mock extends Horde_Kolab_Server_Object_Base +{ + public function getActions() {} + static public function getFilter() {} + public function generateId(array &$info) {} + public function prepareObjectInformation(array &$info) {} +} \ No newline at end of file diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Query/ElementTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Query/ElementTest.php new file mode 100644 index 000000000..59c553d12 --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Query/ElementTest.php @@ -0,0 +1,212 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Require our basic test case definition + */ +require_once dirname(__FILE__) . '/../../../Autoload.php'; + +/** + * Test the LDAP query elements. + * + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Class_Server_Query_ElementTest extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + $this->writer = $this->getMock( + 'Horde_Kolab_Server_Query_Ldap', array(), array(), '', false + ); + } + + public function testClassAndMethodConvertHasResultMixedTheConvertedElement() + { + $this->writer->expects($this->exactly(1)) + ->method('convertAnd') + ->will($this->returnValue('converted')); + $and = new Horde_Kolab_Server_Query_Element_And(array()); + $this->assertEquals('converted', $and->convert($this->writer)); + } + + public function testClassApproxMethodConvertHasResultMixedTheConvertedElement() + { + $this->writer->expects($this->exactly(1)) + ->method('convertApprox') + ->will($this->returnValue('converted')); + $approx = new Horde_Kolab_Server_Query_Element_Approx('', ''); + $this->assertEquals('converted', $approx->convert($this->writer)); + } + + public function testClassBeginsMethodConvertHasResultMixedTheConvertedElement() + { + $this->writer->expects($this->exactly(1)) + ->method('convertBegins') + ->will($this->returnValue('converted')); + $begins = new Horde_Kolab_Server_Query_Element_Begins('', ''); + $this->assertEquals('converted', $begins->convert($this->writer)); + } + + public function testClassContainsMethodConvertHasResultMixedTheConvertedElement() + { + $this->writer->expects($this->exactly(1)) + ->method('convertContains') + ->will($this->returnValue('converted')); + $contains = new Horde_Kolab_Server_Query_Element_Contains('', ''); + $this->assertEquals('converted', $contains->convert($this->writer)); + } + + public function testClassEndsMethodConvertHasResultMixedTheConvertedElement() + { + $this->writer->expects($this->exactly(1)) + ->method('convertEnds') + ->will($this->returnValue('converted')); + $ends = new Horde_Kolab_Server_Query_Element_Ends('', ''); + $this->assertEquals('converted', $ends->convert($this->writer)); + } + + public function testClassEqualsMethodConvertHasResultMixedTheConvertedElement() + { + $this->writer->expects($this->exactly(1)) + ->method('convertEquals') + ->will($this->returnValue('converted')); + $equals = new Horde_Kolab_Server_Query_Element_Equals('', ''); + $this->assertEquals('converted', $equals->convert($this->writer)); + } + + public function testClassGreaterMethodConvertHasResultMixedTheConvertedElement() + { + $this->writer->expects($this->exactly(1)) + ->method('convertGreater') + ->will($this->returnValue('converted')); + $greater = new Horde_Kolab_Server_Query_Element_Greater('', ''); + $this->assertEquals('converted', $greater->convert($this->writer)); + } + + public function testClassLessMethodConvertHasResultMixedTheConvertedElement() + { + $this->writer->expects($this->exactly(1)) + ->method('convertLess') + ->will($this->returnValue('converted')); + $less = new Horde_Kolab_Server_Query_Element_Less('', ''); + $this->assertEquals('converted', $less->convert($this->writer)); + } + + public function testClassNotMethodConstructHasPostconditionThatTheElementWasSavedAsArray() + { + $less = new Horde_Kolab_Server_Query_Element_Less('', ''); + $not = new Horde_Kolab_Server_Query_Element_Not($less); + $this->assertType('array', $not->getElements()); + } + + public function testClassNotMethodConvertHasResultMixedTheConvertedElement() + { + $this->writer->expects($this->exactly(1)) + ->method('convertNot') + ->will($this->returnValue('converted')); + $less = new Horde_Kolab_Server_Query_Element_Less('', ''); + $not = new Horde_Kolab_Server_Query_Element_Not($less); + $this->assertEquals('converted', $not->convert($this->writer)); + } + + public function testClassOrMethodConvertHasResultMixedTheConvertedElement() + { + $this->writer->expects($this->exactly(1)) + ->method('convertOr') + ->will($this->returnValue('converted')); + $or = new Horde_Kolab_Server_Query_Element_Or(array()); + $this->assertEquals('converted', $or->convert($this->writer)); + } + + public function testClassGroupMethodConstructHasParameterArrayElements() + { + $or = new Horde_Kolab_Server_Query_Element_Or(array()); + } + + public function testClassGroupMethodConstructHasPostconditionThatTheElementsWereSaved() + { + $or = new Horde_Kolab_Server_Query_Element_Or(array()); + $this->assertEquals(array(), $or->getElements()); + } + + /** + * @expectedException Exception + */ + public function testClassGroupMethodGetnameThrowsException() + { + $or = new Horde_Kolab_Server_Query_Element_Or(array()); + $or->getName(); + } + + /** + * @expectedException Exception + */ + public function testClassGroupMethodGetvalueThrowsException() + { + $or = new Horde_Kolab_Server_Query_Element_Or(array()); + $or->getValue(); + } + + public function testClassGroupMethodGetelementsHasResultArrayTheGroupElements() + { + $or = new Horde_Kolab_Server_Query_Element_Or(array()); + $this->assertEquals(array(), $or->getElements()); + } + + public function testClassSingleMethodConstructHasParameterStringName() + { + $equals = new Horde_Kolab_Server_Query_Element_Equals('name', ''); + } + + public function testClassSingleMethodConstructHasParameterStringValue() + { + $equals = new Horde_Kolab_Server_Query_Element_Equals('', 'value'); + } + + public function testClassSingleMethodConstructHasPostconditionThatNameAndValueWereSaved() + { + $equals = new Horde_Kolab_Server_Query_Element_Equals('name', 'value'); + $this->assertEquals('name', $equals->getName()); + $this->assertEquals('value', $equals->getValue()); + } + + public function testClassSingleMethodGetnameHasResultStringTheName() + { + $equals = new Horde_Kolab_Server_Query_Element_Equals('name', ''); + $this->assertEquals('name', $equals->getName()); + } + + public function testClassSingleMethodGetvalueHasResultStringTheValue() + { + $equals = new Horde_Kolab_Server_Query_Element_Equals('', 'value'); + $this->assertEquals('value', $equals->getValue()); + } + + /** + * @expectedException Exception + */ + public function testClassSingleMethodGetelementsThrowsException() + { + $equals = new Horde_Kolab_Server_Query_Element_Equals('', ''); + $equals->getElements(); + } +} diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Query/LdapTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Query/LdapTest.php new file mode 100644 index 000000000..9b5d05aa2 --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Query/LdapTest.php @@ -0,0 +1,233 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * Require our basic test case definition + */ +require_once dirname(__FILE__) . '/../../../LdapTestCase.php'; + +/** + * Test the LDAP query handler. + * + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Class_Server_Query_LdapTest extends Horde_Kolab_Server_LdapTestCase +{ + public function setUp() + { + $this->skipIfNoLdap(); + $this->structure = $this->getMock( + 'Horde_Kolab_Server_Structure_Interface' + ); + } + + + public function testMethodConstructHasParameterQueryelementTheQueryCriteria() + { + $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); + $query = new Horde_Kolab_Server_Query_Ldap($equals, $this->structure); + } + + public function testMethodConstructHasPostconditionThatTheQueryCriteriaWereSaved() + { + $this->structure->expects($this->once()) + ->method('getInternalAttribute') + ->will($this->returnValue('equals')); + $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); + $query = new Horde_Kolab_Server_Query_Ldap($equals, $this->structure); + $this->assertEquals( + '(equals=equals)', + (string) $query + ); + } + + public function testMethodTostringHasResultStringTheQuery() + { + $this->structure->expects($this->exactly(2)) + ->method('getInternalAttribute') + ->will($this->returnValue('internal')); + $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); + $contains = new Horde_Kolab_Server_Query_Element_Equals('contains', 'contains'); + $or = new Horde_Kolab_Server_Query_Element_Or(array($equals, $contains)); + $query = new Horde_Kolab_Server_Query_Ldap($or, $this->structure); + $this->assertEquals( + '(|(internal=equals)(internal=contains))', + (string) $query + ); + } + + public function testMethodConvertequealsHasResultNetldapfilter() + { + $this->structure->expects($this->once()) + ->method('getInternalAttribute') + ->will($this->returnValue('equals')); + $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); + $query = new Horde_Kolab_Server_Query_Ldap($equals, $this->structure); + $this->assertEquals( + '(equals=equals)', + $query->convertEquals($equals)->asString() + ); + } + + public function testMethodConvertbeginsHasResultNetldapfilter() + { + $this->structure->expects($this->once()) + ->method('getInternalAttribute') + ->will($this->returnValue('begins')); + $begins = new Horde_Kolab_Server_Query_Element_Begins('begins', 'begins'); + $query = new Horde_Kolab_Server_Query_Ldap($begins, $this->structure); + $this->assertEquals( + '(begins=begins*)', + $query->convertBegins($begins)->asString() + ); + } + + public function testMethodConvertendsHasResultNetldapfilter() + { + $this->structure->expects($this->once()) + ->method('getInternalAttribute') + ->will($this->returnValue('ends')); + $ends = new Horde_Kolab_Server_Query_Element_Ends('ends', 'ends'); + $query = new Horde_Kolab_Server_Query_Ldap($ends, $this->structure); + $this->assertEquals( + '(ends=*ends)', + $query->convertEnds($ends)->asString() + ); + } + + public function testMethodConvertcontainsHasResultNetldapfilter() + { + $this->structure->expects($this->once()) + ->method('getInternalAttribute') + ->will($this->returnValue('contains')); + $contains = new Horde_Kolab_Server_Query_Element_Contains('contains', 'contains'); + $query = new Horde_Kolab_Server_Query_Ldap($contains, $this->structure); + $this->assertEquals( + '(contains=*contains*)', + $query->convertContains($contains)->asString() + ); + } + + public function testMethodConvertlessHasResultNetldapfilter() + { + $this->structure->expects($this->once()) + ->method('getInternalAttribute') + ->will($this->returnValue('less')); + $less = new Horde_Kolab_Server_Query_Element_Less('less', 'less'); + $query = new Horde_Kolab_Server_Query_Ldap($less, $this->structure); + $this->assertEquals( + '(lessconvertLess($less)->asString() + ); + } + + public function testMethodConvertgreaterHasResultNetldapfilter() + { + $this->structure->expects($this->once()) + ->method('getInternalAttribute') + ->will($this->returnValue('greater')); + $greater = new Horde_Kolab_Server_Query_Element_Greater('greater', 'greater'); + $query = new Horde_Kolab_Server_Query_Ldap($greater, $this->structure); + $this->assertEquals( + '(greater>greater)', + $query->convertGreater($greater)->asString() + ); + } + + public function testMethodConvertapproxHasResultNetldapfilter() + { + $this->structure->expects($this->once()) + ->method('getInternalAttribute') + ->will($this->returnValue('approx')); + $approx = new Horde_Kolab_Server_Query_Element_Approx('approx', 'approx'); + $query = new Horde_Kolab_Server_Query_Ldap($approx, $this->structure); + $this->assertEquals( + '(approx~=approx)', + $query->convertApprox($approx)->asString() + ); + } + + public function testMethodConvertnotHasResultNetldapfilter() + { + $this->structure->expects($this->once()) + ->method('getInternalAttribute') + ->will($this->returnValue('equals')); + $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); + $not = new Horde_Kolab_Server_Query_Element_Not($equals, $this->structure); + $query = new Horde_Kolab_Server_Query_Ldap($not, $this->structure); + $this->assertEquals( + '(!(equals=equals))', + $query->convertNot($not)->asString() + ); + } + + public function testMethodConvertandHasResultNetldapfilter() + { + $this->structure->expects($this->exactly(2)) + ->method('getInternalAttribute') + ->will($this->returnValue('internal')); + $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); + $contains = new Horde_Kolab_Server_Query_Element_Equals('contains', 'contains'); + $and = new Horde_Kolab_Server_Query_Element_And(array($equals, $contains)); + $query = new Horde_Kolab_Server_Query_Ldap($and, $this->structure); + $this->assertEquals( + '(&(internal=equals)(internal=contains))', + $query->convertAnd($and)->asString() + ); + } + + public function testMethodConvertorHasResultNetldapfilter() + { + $this->structure->expects($this->exactly(2)) + ->method('getInternalAttribute') + ->will($this->returnValue('internal')); + $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); + $contains = new Horde_Kolab_Server_Query_Element_Equals('contains', 'contains'); + $or = new Horde_Kolab_Server_Query_Element_Or(array($equals, $contains)); + $query = new Horde_Kolab_Server_Query_Ldap($or, $this->structure); + $this->assertEquals( + '(|(internal=equals)(internal=contains))', + $query->convertOr($or)->asString() + ); + } + + public function testMethodConvertorThrowsExceptionIfLessThanTwoElementsWereProvided() + { + $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); + $or = new Horde_Kolab_Server_Query_Element_Or(array($equals)); + $query = new Horde_Kolab_Server_Query_Ldap($or, $this->structure); + + /** Hide strict errors from the Net_LDAP2 library */ + $error_reporting = error_reporting(); + error_reporting($error_reporting & ~E_STRICT); + + try { + $query->convertOr($or)->asString(); + $this->fail('No exception!'); + } catch (Horde_Kolab_Server_Exception $e) { + $this->assertEquals(Horde_Kolab_Server_Exception::INVALID_QUERY, $e->getCode()); + } + + /** Reactivate original error reporting */ + error_reporting($error_reporting); + } +} 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/Connection/MockTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/MockTest.php deleted file mode 100644 index 23a4206ca..000000000 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/MockTest.php +++ /dev/null @@ -1,239 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Require our basic test case definition - */ -require_once dirname(__FILE__) . '/../LdapTestCase.php'; - -/** - * Test the test backend. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Connection_MockTest -extends Horde_Kolab_Server_LdapTestCase -{ - /** - * Test parsing of LDAP filters. - * - * @return NULL - */ - public function testFilterParse() - { - $this->skipIfNoLdap(); - - $conn = new Horde_Kolab_Server_Connection_Mock(array()); - - $a = $conn->parse('(a=b)'); - $this->assertEquals(array('att' => 'a', 'log' => '=', 'val' => 'b'), - $a); - - $a = $conn->parse('(&(a=b)(c=d))'); - $this->assertEquals(array('op' => '&', 'sub' => array( - array('att' => 'a', 'log' => '=', 'val' => 'b'), - array('att' => 'c', 'log' => '=', 'val' => 'd'), - )), $a); - - $a = $conn->parse('(&(a=1)(|(b=2)(c=3)))'); - $this->assertEquals(array('op' => '&', 'sub' => array( - array('att' => 'a', 'log' => '=', 'val' => '1'), - array('op' => '|', 'sub' => - array( - array('att' => 'b', 'log' => '=', 'val' => '2'), - array('att' => 'c', 'log' => '=', 'val' => '3'), - )))), $a); - - $a = $conn->parseSub('(!(x=2))(b=1)'); - $this->assertEquals(array(array('op' => '!', 'sub' => - array( - array('att' => 'x', 'log' => '=', 'val' => '2'), - ) - ), - array('att' => 'b', 'log' => '=', 'val' => '1'), - ), $a); - - $a = $conn->parse('(&(!(x=2))(b=1))'); - $this->assertEquals(array('op' => '&', 'sub' => array( - array('op' => '!', 'sub' => - array( - array('att' => 'x', 'log' => '=', 'val' => '2'), - ) - ), - array('att' => 'b', 'log' => '=', 'val' => '1'), - )), $a); - - } - - /** - * Test searching in the simulated LDAP data. - * - * @return NULL - */ - public function testSearch() - { - $this->skipIfNoLdap(); - - $conn = new Horde_Kolab_Server_Connection_Mock( - 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', - ) - ), - ) - ) - ); - - $a = $conn->search(null, '(c=1)'); - $this->assertEquals( - array( - 'cn=a' => array( - 'a' => '1', - 'b' => '1', - 'c' => '1', - 'dn' => 'cn=a', - ), - 'cn=d' => array( - 'a' => '2', - 'b' => '2', - 'c' => '1', - 'dn' => 'cn=d', - ), - ), - $a->as_struct() - ); - - $a = $conn->search(null, '(c=3)'); - $this->assertEquals( - array( - 'cn=c' => array( - 'a' => '1', - 'b' => '2', - 'c' => '3', - 'dn' => 'cn=c', - ), - ), - $a->as_struct() - ); - - $a = $conn->search(null, '(c=3)', array('attributes' => array('a'))); - $this->assertEquals( - array( - 'cn=c' => array( - 'a' => '1', - 'dn' => 'cn=c', - ), - ), - $a->as_struct() - ); - - $a = $conn->search(null, '(&(a=1)(b=2))', array('attributes' => array('a', 'b'))); - $this->assertEquals( - array( - 'cn=b' => array( - 'a' => '1', - 'b' => '2', - 'dn' => 'cn=b', - ), - 'cn=c' => array( - 'a' => '1', - 'b' => '2', - 'dn' => 'cn=c', - ), - ), - $a->as_struct() - ); - - $a = $conn->search(null, '(&(b=2))', array('attributes' => array('b'))); - $this->assertEquals( - array( - 'cn=b' => array( - 'b' => '2', - 'dn' => 'cn=b', - ), - 'cn=c' => array( - 'b' => '2', - 'dn' => 'cn=c', - ), - 'cn=d' => array( - 'b' => '2', - 'dn' => 'cn=d', - ), - ), - $a->as_struct() - ); - - $a = $conn->search(null, '(!(b=2))', array('attributes' => array('a', 'b'))); - $this->assertEquals( - array( - 'cn=a' => array( - 'a' => '1', - 'b' => '1', - 'dn' => 'cn=a', - ), - ), - $a->as_struct() - ); - - $a = $conn->search(null, '(&(!(x=2))(b=1))', array('attributes' => array('b'))); - $this->assertEquals( - array( - 'cn=a' => array( - 'b' => '1', - 'dn' => 'cn=a', - ), - ), - $a->as_struct() - ); - } - -} diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/SimpleldapTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/SimpleldapTest.php deleted file mode 100644 index c2d5f08ea..000000000 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/SimpleldapTest.php +++ /dev/null @@ -1,62 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Require our basic test case definition - */ -require_once dirname(__FILE__) . '/../LdapTestCase.php'; - -/** - * Test the handler for a simple LDAP setup without read-only slaves. - * - * 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_Connection_SimpleldapTest -extends Horde_Kolab_Server_LdapTestCase -{ - public function testMethodConstructHasParameterNetldap2Connection() - { - $ldap = $this->getMock('Net_LDAP2'); - $conn = new Horde_Kolab_Server_Connection_Simpleldap($ldap); - } - - public function testMethodConstructHasPostconditionThatTheGivenServerWasStored() - { - $ldap = $this->getMock('Net_LDAP2'); - $conn = new Horde_Kolab_Server_Connection_Simpleldap($ldap); - $this->assertSame($ldap, $conn->getRead()); - } - - public function testMethodGetreadHasResultNetldap2TheHandledConnection() - { - $ldap = $this->getMock('Net_LDAP2'); - $conn = new Horde_Kolab_Server_Connection_Simpleldap($ldap); - $this->assertType('Net_LDAP2', $conn->getRead()); - } - - public function testMethodGetwriteHasResultNetldap2TheHandledConnection() - { - $ldap = $this->getMock('Net_LDAP2'); - $conn = new Horde_Kolab_Server_Connection_Simpleldap($ldap); - $this->assertSame($conn->getWrite(), $conn->getRead()); - } -} diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/SplittedldapTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/SplittedldapTest.php deleted file mode 100644 index 1594b0f3b..000000000 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Connection/SplittedldapTest.php +++ /dev/null @@ -1,68 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Require our basic test case definition - */ -require_once dirname(__FILE__) . '/../LdapTestCase.php'; - -/** - * Test the handler for a LDAP master/slave setup. - * - * 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_Connection_SplittedldapTest -extends Horde_Kolab_Server_LdapTestCase -{ - public function testMethodConstructHasParameterNetldap2ReadConnectionAndParameterNetldap2WriteConnection() - { - $ldap_read = $this->getMock('Net_LDAP2'); - $ldap_write = $this->getMock('Net_LDAP2'); - $conn = new Horde_Kolab_Server_Connection_Splittedldap($ldap_read, $ldap_write); - } - - public function testMethodConstructHasPostconditionThatTheGivenServersWereStored() - { - $ldap_read = $this->getMock('Net_LDAP2'); - $ldap_write = $this->getMock('Net_LDAP2'); - $conn = new Horde_Kolab_Server_Connection_Splittedldap($ldap_read, $ldap_write); - $this->assertSame($ldap_read, $conn->getRead()); - $this->assertSame($ldap_write, $conn->getWrite()); - } - - public function testMethodGetreadHasResultNetldap2TheHandledConnection() - { - $ldap_read = $this->getMock('Net_LDAP2'); - $ldap_write = $this->getMock('Net_LDAP2'); - $conn = new Horde_Kolab_Server_Connection_Splittedldap($ldap_read, $ldap_write); - $this->assertType('Net_LDAP2', $conn->getRead()); - $this->assertType('Net_LDAP2', $conn->getWrite()); - } - - public function testMethodGetwriteHasResultNetldap2TheHandledConnection() - { - $ldap_read = $this->getMock('Net_LDAP2'); - $ldap_write = $this->getMock('Net_LDAP2'); - $conn = new Horde_Kolab_Server_Connection_Splittedldap($ldap_read, $ldap_write); - $this->assertFalse($conn->getWrite() === $conn->getRead()); - } -} diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/ObjectsTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/ObjectsTest.php new file mode 100644 index 000000000..b9ffe127e --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Integration/ObjectsTest.php @@ -0,0 +1,132 @@ + + * @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'; + +/** + * Tests for the main server class. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Integration_ObjectsTest extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + $this->markTestIncomplete('Needs to be fixed'); + } + + /** + * Provide a mock server. + * + * @return Horde_Kolab_Server The mock server. + */ + protected function getMockServer() + { + $injector = new Horde_Injector(new Horde_Injector_TopLevel()); + $config = new stdClass; + $config->driver = 'none'; + $injector->setInstance('Horde_Kolab_Server_Config', $config); + $injector->bindFactory('Horde_Kolab_Server_Structure', + 'Horde_Kolab_Server_Factory', + 'getStructure'); + $injector->bindFactory('Horde_Kolab_Server', + 'Horde_Kolab_Server_Factory', + 'getServer'); + return $injector->getInstance('Horde_Kolab_Server'); + } + + /** + * The generating a uid for an object. + * + * @return NULL + */ + public function testGenerateUid() + { + $ks = $this->getMockServer(); + $user = new Horde_Kolab_Server_Object($ks, null, null); + $this->assertEquals(preg_replace('/[0-9a-f]*/', '', $user->get(Horde_Kolab_Server_Object::ATTRIBUTE_UID)), ''); + } + + /** + * Test creating the server object. + * + * @return NULL + */ + public function testCreation() + { + try { + $injector = new Horde_Injector(new Horde_Injector_TopLevel()); + $config = new stdClass; + $config->driver = 'dummy'; + $injector->setInstance('Horde_Kolab_Server_Config', $config); + $injector->bindFactory('Horde_Kolab_Server_Structure', + 'Horde_Kolab_Server_Factory', + 'getStructure'); + $injector->bindFactory('Horde_Kolab_Server', + 'Horde_Kolab_Server_Factory', + 'getServer'); + Horde_Kolab_Server_Factory::getServer($injector); + $this->assertFail('No error!'); + } catch (Horde_Kolab_Server_Exception $e) { + $this->assertEquals('Server type definition "Horde_Kolab_Server_Dummy" missing.', + $e->getMessage()); + } + } + + /** + * The base class provides no abilities for reading data. So it + * should mainly return error. But it should be capable of + * returning a dummy Kolab user object. + * + * @return NULL + */ + public function testFetch() + { + $ks = $this->getMockServer(); + $user = $ks->fetch('test'); + $this->assertEquals('Horde_Kolab_Server_Object_Kolab_User', get_class($user)); + + $ks = $this->getMockServer(); + $user = $ks->fetch(); + $this->assertEquals('Horde_Kolab_Server_Object_Kolab_User', get_class($user)); + } + + /** + * Test listing objects. + * + * @return NULL + */ + public function testList() + { + $ks = $this->getMockServer(); + $hash = $ks->listHash('Horde_Kolab_Server_Object'); + $this->assertEquals($hash, array()); + + $ks = $this->getMockServer(); + $hash = $ks->listHash('Horde_Kolab_Server_Object'); + $this->assertEquals($hash, array()); + } + +} diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Object/BaseTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Object/BaseTest.php deleted file mode 100644 index cb7878241..000000000 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Object/BaseTest.php +++ /dev/null @@ -1,339 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Prepare the test setup. - */ -require_once dirname(__FILE__) . '/../TestCase.php'; - -/** - * Test the base object. - * - * Copyright 2008-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Object_BaseTest extends Horde_Kolab_Server_TestCase -{ - public function setUp() - { - } - - public function testMethodConstructHasParameterCompositeWhichIsTheLinkToTheServer() - { - $composite = $this->getComposite(); - $object = new Object_Mock($composite, ''); - } - - public function testMethodConstructHasParameterStringTheGuidOfTheObject() - { - $composite = $this->getComposite(); - $object = new Object_Mock($composite, 'guid'); - } - - public function testGetguidHasResultStringGuidTheObjectIdOnTheServer() - { - $composite = $this->getComposite(); - $object = new Object_Mock($composite, 'guid'); - $this->assertEquals('guid', $object->getGuid()); - } - - public function testGetguidThrowsExceptionIfGuidHasNotBeenSetYet() - { - $composite = $this->getComposite(); - $object = new Object_Mock($composite); - try { - $this->assertEquals('newGuid', $object->getGuid()); - $this->fail('No exception!'); - } catch (Horde_Kolab_Server_Exception $e) { - $this->assertEquals( - 'Uninitialized object is missing GUID!', $e->getMessage() - ); - } - } - - public function testGetexternalattributesHasResultArrayTheExternalAttributesSupportedByTheObject() - { - $composite = $this->getMockedComposite(); - $composite->schema->expects($this->once()) - ->method('getExternalAttributes') - ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) - ->will($this->returnValue(array('external'))); - $object = new Object_Mock($composite, 'guid'); - $this->assertEquals(array('external'), $object->getExternalAttributes()); - } - - public function testGetinternalattributesHasResultArrayTheInternalAttributesSupportedByTheObject() - { - $composite = $this->getMockedComposite(); - $composite->schema->expects($this->once()) - ->method('getInternalAttributes') - ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) - ->will($this->returnValue(array('internal' => 'Internal'))); - $object = new Object_Mock($composite, 'guid'); - $this->assertEquals(array('internal' => 'Internal'), $object->getInternalAttributes()); - } - - public function testGetinternalattributesHasResultBooleanFalseIfTheGuidIsNotSpecified() - { - $composite = $this->getMockedComposite(); - $object = new Object_Mock($composite); - $this->assertFalse($object->exists()); - } - - public function testGetinternalattributesHasResultBooleanFalseIfTheServerReturnedAnError() - { - $composite = $this->getMockedComposite(); - $composite->schema->expects($this->once()) - ->method('getInternalAttributes') - ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) - ->will($this->returnValue(array('internal' => 'Internal'))); - $composite->server->expects($this->once()) - ->method('readAttributes') - ->with('guid', array('internal')) - ->will($this->throwException(new Horde_Kolab_Server_Exception(''))); - $object = new Object_Mock($composite, 'guid'); - $this->assertFalse($object->exists()); - } - - public function testGetinternalattributesHasResultBooleanTrueIfTheServerReturnedData() - { - $composite = $this->getMockedComposite(); - $composite->schema->expects($this->once()) - ->method('getInternalAttributes') - ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) - ->will($this->returnValue(array('internal' => 'Internal'))); - $composite->server->expects($this->once()) - ->method('readAttributes') - ->with('guid', array('internal')) - ->will($this->returnValue(array('a' => 'a'))); - $object = new Object_Mock($composite, 'guid'); - $this->assertTrue($object->exists()); - } - - public function testReadinternalHasResultArrayDataTheInternalObjectData() - { - $composite = $this->getMockedComposite(); - $composite->schema->expects($this->once()) - ->method('getInternalAttributes') - ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) - ->will($this->returnValue(array('internal' => 'Internal'))); - $composite->server->expects($this->once()) - ->method('readAttributes') - ->with('guid', array('internal')) - ->will($this->returnValue(array('internal' => 'test'))); - $object = new Object_Mock($composite, 'guid'); - $this->assertEquals( - array('internal' => 'test'), $object->readInternal() - ); - } - - public function testGetinternalHasResultArrayTheDataOfTheRequestedAttribute() - { - $composite = $this->getMockedComposite(); - $composite->schema->expects($this->exactly(2)) - ->method('getInternalAttributes') - ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) - ->will($this->returnValue(array('internal' => 'Internal'))); - $composite->server->expects($this->once()) - ->method('readAttributes') - ->with('guid', array('internal')) - ->will($this->returnValue(array('internal' => array('test')))); - $object = new Object_Mock($composite, 'guid'); - $this->assertEquals( - array('test'), $object->getInternal('internal') - ); - } - - public function testGetinternalThrowsExceptionIfTheRequestedAttributeIsNotSupported() - { - $composite = $this->getMockedComposite(); - $composite->schema->expects($this->once()) - ->method('getInternalAttributes') - ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) - ->will($this->returnValue(array('internal' => 'Internal'))); - $object = new Object_Mock($composite, 'guid'); - try { - $object->getInternal('test'); - $this->fail('No exception!'); - } catch (Horde_Kolab_Server_Exception $e) { - $this->assertEquals('Attribute "test" not supported!', $e->getMessage()); - } - } - - public function testGetinternalThrowsExceptionIfTheRequestedAttributeHasNoValue() - { - $composite = $this->getMockedComposite(); - $composite->schema->expects($this->exactly(2)) - ->method('getInternalAttributes') - ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) - ->will( - $this->returnValue( - array('internal' => 'Internal', 'test' => 'Test') - ) - ); - $composite->server->expects($this->once()) - ->method('readAttributes') - ->with('guid', array('internal', 'test')) - ->will($this->returnValue(array('internal' => array('test')))); - $object = new Object_Mock($composite, 'guid'); - try { - $object->getInternal('test'); - $this->fail('No exception!'); - } catch (Horde_Kolab_Server_Exception_Novalue $e) { - $this->assertEquals('No value for attribute "test"!', $e->getMessage()); - } - } - - public function testGetexternalHasResultArrayTheDataOfTheRequestedAttribute() - { - $composite = $this->getMockedComposite(); - $composite->structure->expects($this->exactly(1)) - ->method('getInternalAttribute') - ->with('Objectclass') - ->will($this->returnValue('objectClass')); - $composite->schema->expects($this->exactly(1)) - ->method('getExternalAttributes') - ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) - ->will($this->returnValue(array('Objectclass'))); - $composite->schema->expects($this->exactly(2)) - ->method('getInternalAttributes') - ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) - ->will($this->returnValue(array('objectClass' => 'Objectclass'))); - $composite->server->expects($this->once()) - ->method('readAttributes') - ->with('guid', array('objectClass')) - ->will($this->returnValue(array('objectClass' => array('test')))); - $object = new Object_Mock($composite, 'guid'); - $this->assertEquals( - array('test'), $object->getExternal('Objectclass') - ); - } - - public function testGetexternalThrowsExceptionIfTheRequestedAttributeIsNotSupported() - { - $composite = $this->getMockedComposite(); - $composite->schema->expects($this->once()) - ->method('getExternalAttributes') - ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) - ->will($this->returnValue(array('external'))); - $object = new Object_Mock($composite, 'guid'); - try { - $object->getExternal('test'); - $this->fail('No exception!'); - } catch (Horde_Kolab_Server_Exception $e) { - $this->assertEquals('Attribute "Test" not supported!', $e->getMessage()); - } - } - - public function testGetexternalThrowsExceptionIfTheRequestedClassDoesNotExist() - { - $composite = $this->getMockedComposite(); - $composite->schema->expects($this->once()) - ->method('getExternalAttributes') - ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) - ->will($this->returnValue(array('Test'))); - $object = new Object_Mock($composite, 'guid'); - try { - $object->getExternal('test'); - $this->fail('No exception!'); - } catch (Horde_Kolab_Server_Exception $e) { - $this->assertEquals('Attribute "Test" not supported!', $e->getMessage()); - } - } - - public function testDeleteHasPostconditionThatTheObjectWasDeletedOnTheServer() - { - $composite = $this->getMockedComposite(); - $composite->server->expects($this->once()) - ->method('delete') - ->with('guid'); - $object = new Object_Mock($composite, 'guid'); - $object->delete(); - } - - public function testSaveHasParameterArrayTheDataToSave() - { - $composite = $this->getMockedComposite(); - $composite->schema->expects($this->exactly(3)) - ->method('getInternalAttributes') - ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) - ->will( - $this->returnValue( - array( - 'objectClass' => - 'Horde_Kolab_Server_Object_Attribute_Objectclass' - ) - ) - ); - $composite->server->expects($this->exactly(2)) - ->method('readAttributes') - ->with('guid', array('objectClass')) - ->will($this->returnValue(array('objectClass' => array('test')))); - $object = new Object_Mock($composite, 'guid'); - $object->save(array()); - } - - public function testSaveHasPostconditionThatTheObjectWasAddedToTheServerIfItDidNotExistBefore() - { - $composite = $this->getMockedComposite(); - $composite->structure->expects($this->exactly(1)) - ->method('getInternalAttribute') - ->with('Objectclass') - ->will($this->returnValue('objectClass')); - $composite->schema->expects($this->exactly(1)) - ->method('getInternalAttributes') - ->with($this->isInstanceOf('Horde_Kolab_Server_Object')) - ->will( - $this->returnValue( - array( - 'objectClass' => - 'Horde_Kolab_Server_Object_Attribute_Objectclass' - ) - ) - ); - $composite->structure->expects($this->exactly(1)) - ->method('generateServerGuid') - ->with( - 'Object_Mock', null, - array('objectClass' => array('top'))) - ->will( - $this->returnValue( - array( - 'objectClass' => - 'Horde_Kolab_Server_Object_Attribute_Objectclass' - ) - ) - ); - $composite->server->expects($this->exactly(1)) - ->method('add') - ->with($this->isInstanceOf('Horde_Kolab_Server_Object'), array('objectClass' => array('top'))); - $object = new Object_Mock($composite); - $object->save(array('Objectclass' => 'top')); - } -} - -class Object_Mock extends Horde_Kolab_Server_Object_Base -{ - public function getActions() {} - static public function getFilter() {} - public function generateId(array &$info) {} - public function prepareObjectInformation(array &$info) {} -} \ No newline at end of file diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Objects/ServerTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Objects/ServerTest.php deleted file mode 100644 index 415540e08..000000000 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Objects/ServerTest.php +++ /dev/null @@ -1,132 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Prepare the test setup. - */ -require_once dirname(__FILE__) . '/../Autoload.php'; - -/** - * Tests for the main server class. - * - * 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_Objects_ServerTest extends PHPUnit_Framework_TestCase -{ - public function setUp() - { - $this->markTestIncomplete('Needs to be fixed'); - } - - /** - * Provide a mock server. - * - * @return Horde_Kolab_Server The mock server. - */ - protected function getMockServer() - { - $injector = new Horde_Injector(new Horde_Injector_TopLevel()); - $config = new stdClass; - $config->driver = 'none'; - $injector->setInstance('Horde_Kolab_Server_Config', $config); - $injector->bindFactory('Horde_Kolab_Server_Structure', - 'Horde_Kolab_Server_Factory', - 'getStructure'); - $injector->bindFactory('Horde_Kolab_Server', - 'Horde_Kolab_Server_Factory', - 'getServer'); - return $injector->getInstance('Horde_Kolab_Server'); - } - - /** - * The generating a uid for an object. - * - * @return NULL - */ - public function testGenerateUid() - { - $ks = $this->getMockServer(); - $user = new Horde_Kolab_Server_Object($ks, null, null); - $this->assertEquals(preg_replace('/[0-9a-f]*/', '', $user->get(Horde_Kolab_Server_Object::ATTRIBUTE_UID)), ''); - } - - /** - * Test creating the server object. - * - * @return NULL - */ - public function testCreation() - { - try { - $injector = new Horde_Injector(new Horde_Injector_TopLevel()); - $config = new stdClass; - $config->driver = 'dummy'; - $injector->setInstance('Horde_Kolab_Server_Config', $config); - $injector->bindFactory('Horde_Kolab_Server_Structure', - 'Horde_Kolab_Server_Factory', - 'getStructure'); - $injector->bindFactory('Horde_Kolab_Server', - 'Horde_Kolab_Server_Factory', - 'getServer'); - Horde_Kolab_Server_Factory::getServer($injector); - $this->assertFail('No error!'); - } catch (Horde_Kolab_Server_Exception $e) { - $this->assertEquals('Server type definition "Horde_Kolab_Server_Dummy" missing.', - $e->getMessage()); - } - } - - /** - * The base class provides no abilities for reading data. So it - * should mainly return error. But it should be capable of - * returning a dummy Kolab user object. - * - * @return NULL - */ - public function testFetch() - { - $ks = $this->getMockServer(); - $user = $ks->fetch('test'); - $this->assertEquals('Horde_Kolab_Server_Object_Kolab_User', get_class($user)); - - $ks = $this->getMockServer(); - $user = $ks->fetch(); - $this->assertEquals('Horde_Kolab_Server_Object_Kolab_User', get_class($user)); - } - - /** - * Test listing objects. - * - * @return NULL - */ - public function testList() - { - $ks = $this->getMockServer(); - $hash = $ks->listHash('Horde_Kolab_Server_Object'); - $this->assertEquals($hash, array()); - - $ks = $this->getMockServer(); - $hash = $ks->listHash('Horde_Kolab_Server_Object'); - $this->assertEquals($hash, array()); - } - -} diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Query/ElementTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Query/ElementTest.php deleted file mode 100644 index ad16e0354..000000000 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Query/ElementTest.php +++ /dev/null @@ -1,212 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Require our basic test case definition - */ -require_once dirname(__FILE__) . '/../Autoload.php'; - -/** - * Test the LDAP query elements. - * - * 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_Query_ElementTest extends PHPUnit_Framework_TestCase -{ - public function setUp() - { - $this->writer = $this->getMock( - 'Horde_Kolab_Server_Query_Ldap', array(), array(), '', false - ); - } - - public function testClassAndMethodConvertHasResultMixedTheConvertedElement() - { - $this->writer->expects($this->exactly(1)) - ->method('convertAnd') - ->will($this->returnValue('converted')); - $and = new Horde_Kolab_Server_Query_Element_And(array()); - $this->assertEquals('converted', $and->convert($this->writer)); - } - - public function testClassApproxMethodConvertHasResultMixedTheConvertedElement() - { - $this->writer->expects($this->exactly(1)) - ->method('convertApprox') - ->will($this->returnValue('converted')); - $approx = new Horde_Kolab_Server_Query_Element_Approx('', ''); - $this->assertEquals('converted', $approx->convert($this->writer)); - } - - public function testClassBeginsMethodConvertHasResultMixedTheConvertedElement() - { - $this->writer->expects($this->exactly(1)) - ->method('convertBegins') - ->will($this->returnValue('converted')); - $begins = new Horde_Kolab_Server_Query_Element_Begins('', ''); - $this->assertEquals('converted', $begins->convert($this->writer)); - } - - public function testClassContainsMethodConvertHasResultMixedTheConvertedElement() - { - $this->writer->expects($this->exactly(1)) - ->method('convertContains') - ->will($this->returnValue('converted')); - $contains = new Horde_Kolab_Server_Query_Element_Contains('', ''); - $this->assertEquals('converted', $contains->convert($this->writer)); - } - - public function testClassEndsMethodConvertHasResultMixedTheConvertedElement() - { - $this->writer->expects($this->exactly(1)) - ->method('convertEnds') - ->will($this->returnValue('converted')); - $ends = new Horde_Kolab_Server_Query_Element_Ends('', ''); - $this->assertEquals('converted', $ends->convert($this->writer)); - } - - public function testClassEqualsMethodConvertHasResultMixedTheConvertedElement() - { - $this->writer->expects($this->exactly(1)) - ->method('convertEquals') - ->will($this->returnValue('converted')); - $equals = new Horde_Kolab_Server_Query_Element_Equals('', ''); - $this->assertEquals('converted', $equals->convert($this->writer)); - } - - public function testClassGreaterMethodConvertHasResultMixedTheConvertedElement() - { - $this->writer->expects($this->exactly(1)) - ->method('convertGreater') - ->will($this->returnValue('converted')); - $greater = new Horde_Kolab_Server_Query_Element_Greater('', ''); - $this->assertEquals('converted', $greater->convert($this->writer)); - } - - public function testClassLessMethodConvertHasResultMixedTheConvertedElement() - { - $this->writer->expects($this->exactly(1)) - ->method('convertLess') - ->will($this->returnValue('converted')); - $less = new Horde_Kolab_Server_Query_Element_Less('', ''); - $this->assertEquals('converted', $less->convert($this->writer)); - } - - public function testClassNotMethodConstructHasPostconditionThatTheElementWasSavedAsArray() - { - $less = new Horde_Kolab_Server_Query_Element_Less('', ''); - $not = new Horde_Kolab_Server_Query_Element_Not($less); - $this->assertType('array', $not->getElements()); - } - - public function testClassNotMethodConvertHasResultMixedTheConvertedElement() - { - $this->writer->expects($this->exactly(1)) - ->method('convertNot') - ->will($this->returnValue('converted')); - $less = new Horde_Kolab_Server_Query_Element_Less('', ''); - $not = new Horde_Kolab_Server_Query_Element_Not($less); - $this->assertEquals('converted', $not->convert($this->writer)); - } - - public function testClassOrMethodConvertHasResultMixedTheConvertedElement() - { - $this->writer->expects($this->exactly(1)) - ->method('convertOr') - ->will($this->returnValue('converted')); - $or = new Horde_Kolab_Server_Query_Element_Or(array()); - $this->assertEquals('converted', $or->convert($this->writer)); - } - - public function testClassGroupMethodConstructHasParameterArrayElements() - { - $or = new Horde_Kolab_Server_Query_Element_Or(array()); - } - - public function testClassGroupMethodConstructHasPostconditionThatTheElementsWereSaved() - { - $or = new Horde_Kolab_Server_Query_Element_Or(array()); - $this->assertEquals(array(), $or->getElements()); - } - - /** - * @expectedException Exception - */ - public function testClassGroupMethodGetnameThrowsException() - { - $or = new Horde_Kolab_Server_Query_Element_Or(array()); - $or->getName(); - } - - /** - * @expectedException Exception - */ - public function testClassGroupMethodGetvalueThrowsException() - { - $or = new Horde_Kolab_Server_Query_Element_Or(array()); - $or->getValue(); - } - - public function testClassGroupMethodGetelementsHasResultArrayTheGroupElements() - { - $or = new Horde_Kolab_Server_Query_Element_Or(array()); - $this->assertEquals(array(), $or->getElements()); - } - - public function testClassSingleMethodConstructHasParameterStringName() - { - $equals = new Horde_Kolab_Server_Query_Element_Equals('name', ''); - } - - public function testClassSingleMethodConstructHasParameterStringValue() - { - $equals = new Horde_Kolab_Server_Query_Element_Equals('', 'value'); - } - - public function testClassSingleMethodConstructHasPostconditionThatNameAndValueWereSaved() - { - $equals = new Horde_Kolab_Server_Query_Element_Equals('name', 'value'); - $this->assertEquals('name', $equals->getName()); - $this->assertEquals('value', $equals->getValue()); - } - - public function testClassSingleMethodGetnameHasResultStringTheName() - { - $equals = new Horde_Kolab_Server_Query_Element_Equals('name', ''); - $this->assertEquals('name', $equals->getName()); - } - - public function testClassSingleMethodGetvalueHasResultStringTheValue() - { - $equals = new Horde_Kolab_Server_Query_Element_Equals('', 'value'); - $this->assertEquals('value', $equals->getValue()); - } - - /** - * @expectedException Exception - */ - public function testClassSingleMethodGetelementsThrowsException() - { - $equals = new Horde_Kolab_Server_Query_Element_Equals('', ''); - $equals->getElements(); - } -} diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Query/LdapTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Query/LdapTest.php deleted file mode 100644 index b8733af49..000000000 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/Query/LdapTest.php +++ /dev/null @@ -1,231 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ - -/** - * Require our basic test case definition - */ -require_once dirname(__FILE__) . '/../LdapTestCase.php'; - -/** - * Test the LDAP query handler. - * - * Copyright 2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Server - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Server - */ -class Horde_Kolab_Server_Query_LdapTest extends Horde_Kolab_Server_LdapTestCase -{ - public function setUp() - { - $this->skipIfNoLdap(); - $this->structure = $this->getMock('Horde_Kolab_Server_Structure'); - } - - - public function testMethodConstructHasParameterQueryelementTheQueryCriteria() - { - $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $query = new Horde_Kolab_Server_Query_Ldap($equals, $this->structure); - } - - public function testMethodConstructHasPostconditionThatTheQueryCriteriaWereSaved() - { - $this->structure->expects($this->once()) - ->method('getInternalAttribute') - ->will($this->returnValue('equals')); - $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $query = new Horde_Kolab_Server_Query_Ldap($equals, $this->structure); - $this->assertEquals( - '(equals=equals)', - (string) $query - ); - } - - public function testMethodTostringHasResultStringTheQuery() - { - $this->structure->expects($this->exactly(2)) - ->method('getInternalAttribute') - ->will($this->returnValue('internal')); - $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $contains = new Horde_Kolab_Server_Query_Element_Equals('contains', 'contains'); - $or = new Horde_Kolab_Server_Query_Element_Or(array($equals, $contains)); - $query = new Horde_Kolab_Server_Query_Ldap($or, $this->structure); - $this->assertEquals( - '(|(internal=equals)(internal=contains))', - (string) $query - ); - } - - public function testMethodConvertequealsHasResultNetldapfilter() - { - $this->structure->expects($this->once()) - ->method('getInternalAttribute') - ->will($this->returnValue('equals')); - $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $query = new Horde_Kolab_Server_Query_Ldap($equals, $this->structure); - $this->assertEquals( - '(equals=equals)', - $query->convertEquals($equals)->asString() - ); - } - - public function testMethodConvertbeginsHasResultNetldapfilter() - { - $this->structure->expects($this->once()) - ->method('getInternalAttribute') - ->will($this->returnValue('begins')); - $begins = new Horde_Kolab_Server_Query_Element_Begins('begins', 'begins'); - $query = new Horde_Kolab_Server_Query_Ldap($begins, $this->structure); - $this->assertEquals( - '(begins=begins*)', - $query->convertBegins($begins)->asString() - ); - } - - public function testMethodConvertendsHasResultNetldapfilter() - { - $this->structure->expects($this->once()) - ->method('getInternalAttribute') - ->will($this->returnValue('ends')); - $ends = new Horde_Kolab_Server_Query_Element_Ends('ends', 'ends'); - $query = new Horde_Kolab_Server_Query_Ldap($ends, $this->structure); - $this->assertEquals( - '(ends=*ends)', - $query->convertEnds($ends)->asString() - ); - } - - public function testMethodConvertcontainsHasResultNetldapfilter() - { - $this->structure->expects($this->once()) - ->method('getInternalAttribute') - ->will($this->returnValue('contains')); - $contains = new Horde_Kolab_Server_Query_Element_Contains('contains', 'contains'); - $query = new Horde_Kolab_Server_Query_Ldap($contains, $this->structure); - $this->assertEquals( - '(contains=*contains*)', - $query->convertContains($contains)->asString() - ); - } - - public function testMethodConvertlessHasResultNetldapfilter() - { - $this->structure->expects($this->once()) - ->method('getInternalAttribute') - ->will($this->returnValue('less')); - $less = new Horde_Kolab_Server_Query_Element_Less('less', 'less'); - $query = new Horde_Kolab_Server_Query_Ldap($less, $this->structure); - $this->assertEquals( - '(lessconvertLess($less)->asString() - ); - } - - public function testMethodConvertgreaterHasResultNetldapfilter() - { - $this->structure->expects($this->once()) - ->method('getInternalAttribute') - ->will($this->returnValue('greater')); - $greater = new Horde_Kolab_Server_Query_Element_Greater('greater', 'greater'); - $query = new Horde_Kolab_Server_Query_Ldap($greater, $this->structure); - $this->assertEquals( - '(greater>greater)', - $query->convertGreater($greater)->asString() - ); - } - - public function testMethodConvertapproxHasResultNetldapfilter() - { - $this->structure->expects($this->once()) - ->method('getInternalAttribute') - ->will($this->returnValue('approx')); - $approx = new Horde_Kolab_Server_Query_Element_Approx('approx', 'approx'); - $query = new Horde_Kolab_Server_Query_Ldap($approx, $this->structure); - $this->assertEquals( - '(approx~=approx)', - $query->convertApprox($approx)->asString() - ); - } - - public function testMethodConvertnotHasResultNetldapfilter() - { - $this->structure->expects($this->once()) - ->method('getInternalAttribute') - ->will($this->returnValue('equals')); - $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $not = new Horde_Kolab_Server_Query_Element_Not($equals, $this->structure); - $query = new Horde_Kolab_Server_Query_Ldap($not, $this->structure); - $this->assertEquals( - '(!(equals=equals))', - $query->convertNot($not)->asString() - ); - } - - public function testMethodConvertandHasResultNetldapfilter() - { - $this->structure->expects($this->exactly(2)) - ->method('getInternalAttribute') - ->will($this->returnValue('internal')); - $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $contains = new Horde_Kolab_Server_Query_Element_Equals('contains', 'contains'); - $and = new Horde_Kolab_Server_Query_Element_And(array($equals, $contains)); - $query = new Horde_Kolab_Server_Query_Ldap($and, $this->structure); - $this->assertEquals( - '(&(internal=equals)(internal=contains))', - $query->convertAnd($and)->asString() - ); - } - - public function testMethodConvertorHasResultNetldapfilter() - { - $this->structure->expects($this->exactly(2)) - ->method('getInternalAttribute') - ->will($this->returnValue('internal')); - $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $contains = new Horde_Kolab_Server_Query_Element_Equals('contains', 'contains'); - $or = new Horde_Kolab_Server_Query_Element_Or(array($equals, $contains)); - $query = new Horde_Kolab_Server_Query_Ldap($or, $this->structure); - $this->assertEquals( - '(|(internal=equals)(internal=contains))', - $query->convertOr($or)->asString() - ); - } - - public function testMethodConvertorThrowsExceptionIfLessThanTwoElementsWereProvided() - { - $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); - $or = new Horde_Kolab_Server_Query_Element_Or(array($equals)); - $query = new Horde_Kolab_Server_Query_Ldap($or, $this->structure); - - /** Hide strict errors from the Net_LDAP2 library */ - $error_reporting = error_reporting(); - error_reporting($error_reporting & ~E_STRICT); - - try { - $query->convertOr($or)->asString(); - $this->fail('No exception!'); - } catch (Horde_Kolab_Server_Exception $e) { - $this->assertEquals(Horde_Kolab_Server_Exception::INVALID_QUERY, $e->getCode()); - } - - /** Reactivate original error reporting */ - error_reporting($error_reporting); - } -} 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