From: Gunnar Wrobel Date: Mon, 31 Aug 2009 06:24:40 +0000 (+0200) Subject: Fixed all tests and cleaned code style. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=223c00ff2d4aa09b2f8f86e3de7e59914fccec10;p=horde.git Fixed all tests and cleaned code style. --- diff --git a/framework/Kolab_Format/doc/Horde/Kolab/Format/usage.txt b/framework/Kolab_Format/doc/Horde/Kolab/Format/usage.txt index e459f6bb0..7d756f8bf 100644 --- a/framework/Kolab_Format/doc/Horde/Kolab/Format/usage.txt +++ b/framework/Kolab_Format/doc/Horde/Kolab/Format/usage.txt @@ -33,15 +33,15 @@ The API provided by the package is very simple. It only provides a In order to have access to these methods it is necessary to create the "Horde_Kolab_Format" object. The call looks like this: - $format = Horde_Kolab_Format::factory('XML', 'event'); + $format = Horde_Kolab_Format::factory('Xml', 'Event'); The function takes three arguments: -# "Format type": Currently only "XML" is supported here. +# "Format type": Currently only "Xml" is supported here. # "Object type": The type of object you want to read/write. The - package currently implements "contact", "distributionslist", - "event", "note", "task" and "hprefs" + package currently implements "Contact", "Distributionslist", + "Event", "Note", "Task" and "Hprefs" The $format variable created above now provides the means to save and load events in Kolab XML format. In order to save an event we @@ -152,20 +152,21 @@ are available within that array. Creating your own Kolab XML format ================================== -Currently the "Horde_Kolab_Format" implements the object types -"contact", "distributionslist", "event", "note", "task" as they are -defined within the Kolab Format specification. In addition the -Horde specific "hprefs" type is available. It is used for storing -Horde user preferences in the IMAP store provided by the Kolab server. +Currently the "Horde_Kolab_Format" package provides handlers for the +object types "Contact", "Distributionslist", "Event", "Note", and +"Task" as they are defined within the Kolab Format specification. In +addition the Horde specific "Hprefs" type is available. It is used for +storing Horde user preferences in the IMAP store provided by the Kolab +server. Depending on the web application you might wish to connect with the Kolab server these object types may not be enough. Do not hesitate to -define your own new type in that case. If you want it to find wider -distribution you should of course discuss it on the Kolab Format +define your own new type in that case. If you want it to be adopted by +more Kolab clients you should of course discuss it on the Kolab Format mailing list (http://kolab.org/pipermail/kolab-format/) to get some feedback on the new type. -The "Horde_Kolab_Format" packages makes the definition of a new object +The "Horde_Kolab_Format" package makes the definition of a new object type rather straight forward. The following will explain the creation of a very simple new object that only saves a single string value. @@ -173,16 +174,16 @@ This time it will be necessary to load the XML format definition, too. Any new object type will extend this XML definition: require_once 'Horde/Kolab/Format.php'; - require_once 'Horde/Kolab/Format/XML.php'; + require_once 'Horde/Kolab/Format/Xml.php'; A new object type is represented by a class that extends -"Horde_Kolab_Format_XML": +"Horde_Kolab_Format_Xml": - class Horde_Kolab_Format_XML_string extends Horde_Kolab_Format_XML { + class Horde_Kolab_Format_Xml_String extends Horde_Kolab_Format_Xml { - var $_fields_specific; + protected $_fields_specific; - function Horde_Kolab_Format_XML_string() + public function __construct() { $this->_root_name = 'string'; @@ -190,12 +191,12 @@ A new object type is represented by a class that extends */ $this->_fields_specific = array( 'string' => array( - 'type' => HORDE_KOLAB_XML_TYPE_STRING, - 'value' => HORDE_KOLAB_XML_VALUE_MAYBE_MISSING, + 'type' => self::TYPE_STRING, + 'value' => self::VALUE_MAYBE_MISSING, ), ); - parent::Horde_Kolab_Format_XML(); + parent::__construct(); } } @@ -207,8 +208,8 @@ type has attributes beyond the basic set required for any Kolab object. So this part may not be missing for a declaration of a new type. -The function creating the class ("Horde_Kolab_Format_XML_string()") -needs to do three things: +The function creating the class ("__construct()") needs to do three +things: * Declaring the XML root name which will be "string" here. It should always match the type name. @@ -219,12 +220,12 @@ needs to do three things: further below. * Calling the parent constructor using - "parent::Horde_Kolab_Format_XML()". + "parent::__construct()". The new format can now be used as demonstrated in the initial event example: - $format = Horde_Kolab_Format::factory('XML', 'string'); + $format = Horde_Kolab_Format::factory('Xml', 'String'); $object = array( 'uid' => 1, 'string' => 'test string', @@ -279,53 +280,53 @@ attributes a new object type may contain. Each entry in the field list will look like this 'attribute_name' => array( - 'type' => HORDE_KOLAB_XML_TYPE_*, - 'value' => HORDE_KOLAB_XML_VALUE_*, + 'type' => self::TYPE_*, + 'value' => self::VALUE_*, ), "attribute_name" should be a short name describing the value that should be stored. "type" must be set to one of the following -"HORDE_KOLAB_XML_TYPE_*" type values: +"self::TYPE_*" type values: -* "HORDE_KOLAB_XML_TYPE_STRING": A string. +* "self::TYPE_STRING": A string. -* "HORDE_KOLAB_XML_TYPE_INTEGER": A number +* "self::TYPE_INTEGER": A number -* "HORDE_KOLAB_XML_TYPE_BOOLEAN": True or false. +* "self::TYPE_BOOLEAN": True or false. -* "HORDE_KOLAB_XML_TYPE_DATE": A date (e.g. 2008/08/08) +* "self::TYPE_DATE": A date (e.g. 2008/08/08) -* "HORDE_KOLAB_XML_TYPE_DATETIME": A time and a date. +* "self::TYPE_DATETIME": A time and a date. -* "HORDE_KOLAB_XML_TYPE_DATE_OR_DATETIME": A date or a time and a +* "self::TYPE_DATE_OR_DATETIME": A date or a time and a date. -* "HORDE_KOLAB_XML_TYPE_COLOR": A color (#00BBFF). +* "self::TYPE_COLOR": A color (#00BBFF). -* "HORDE_KOLAB_XML_TYPE_COMPOSITE": A composite element that combines +* "self::TYPE_COMPOSITE": A composite element that combines several attributes. -* "HORDE_KOLAB_XML_TYPE_MULTIPLE": Wrapper for an element that may +* "self::TYPE_MULTIPLE": Wrapper for an element that may occur several times. -Examples for "HORDE_KOLAB_XML_TYPE_COMPOSITE" and -"HORDE_KOLAB_XML_TYPE_MULTIPLE" can be found in the definitions +Examples for "self::TYPE_COMPOSITE" and +"self::TYPE_MULTIPLE" can be found in the definitions currently provided by the "Horde_Kolab_Format" package. The following "value" settings are allowed: -* "HORDE_KOLAB_XML_VALUE_DEFAULT": An attribute with a default value. +* "self::VALUE_DEFAULT": An attribute with a default value. -* "HORDE_KOLAB_XML_VALUE_MAYBE_MISSING": An attribute that may be left +* "self::VALUE_MAYBE_MISSING": An attribute that may be left undefined. -* "HORDE_KOLAB_XML_VALUE_NOT_EMPTY": An attribute that will cause an +* "self::VALUE_NOT_EMPTY": An attribute that will cause an error if it is left undefined. -* "HORDE_KOLAB_XML_VALUE_CALCULATE": A complex attribute that gets its +* "self::VALUE_CALCULATE": A complex attribute that gets its own function for calculating the correct value. -Examples for "HORDE_KOLAB_XML_VALUE_CALCULATE" can again be found in +Examples for "self::VALUE_CALCULATE" can again be found in the current object types implemented in "Horde_Kolab_Format". diff --git a/framework/Kolab_Format/examples/Horde/Kolab/Format/event.php b/framework/Kolab_Format/examples/Horde/Kolab/Format/event.php index f3bb6cbce..6d8215d5f 100644 --- a/framework/Kolab_Format/examples/Horde/Kolab/Format/event.php +++ b/framework/Kolab_Format/examples/Horde/Kolab/Format/event.php @@ -2,16 +2,24 @@ /** * A sample script for reading/writing an event. * - * $Horde: framework/Kolab_Format/examples/Horde/Kolab/Format/event.php,v 1.3 2008/08/01 07:04:52 wrobel Exp $ + * PHP version 5 * - * @package Kolab_Format + * @category Kolab + * @package Kolab_Format + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server */ -/** We need the Horde_Kolab_Format package */ -require_once 'Horde/Kolab/Format.php'; +/** + * The Autoloader allows us to omit "require/include" statements. + */ +require_once 'Horde/Autoloader.php'; + +Horde_Nls::setCharset('utf-8'); /** Generate the format handler */ -$format = Horde_Kolab_Format::factory('XML', 'event'); +$format = Horde_Kolab_Format::factory('Xml', 'Event'); /** Prepare a test object */ $object = array( diff --git a/framework/Kolab_Format/examples/Horde/Kolab/Format/new_type.php b/framework/Kolab_Format/examples/Horde/Kolab/Format/new_type.php index 1cd2a9f07..8a4c63480 100644 --- a/framework/Kolab_Format/examples/Horde/Kolab/Format/new_type.php +++ b/framework/Kolab_Format/examples/Horde/Kolab/Format/new_type.php @@ -2,31 +2,36 @@ /** * An example of defining a new Kolab format type * - * $Horde: framework/Kolab_Format/examples/Horde/Kolab/Format/new_type.php,v 1.4 2009/01/06 17:49:22 jan Exp $ + * PHP version 5 * - * @package Kolab_Format + * @category Kolab + * @package Kolab_Format + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server */ -/** We need the Horde_Kolab_Format package */ -require_once 'Horde/Kolab/Format.php'; - -/** And we need the XML definition */ -require_once 'Horde/Kolab/Format/XML.php'; +/** + * The Autoloader allows us to omit "require/include" statements. + */ +require_once 'Horde/Autoloader.php'; /** * Kolab XML handler for a string value * - * $Horde: framework/Kolab_Format/examples/Horde/Kolab/Format/new_type.php,v 1.4 2009/01/06 17:49:22 jan Exp $ - * * 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. * - * @author Gunnar Wrobel - * @package Kolab_Format + * @category Kolab + * @package Kolab_Format + * @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_Format_XML_string extends Horde_Kolab_Format_XML { +class Horde_Kolab_Format_Xml_String extends Horde_Kolab_Format_Xml +{ /** * Specific data fields for the prefs object @@ -38,7 +43,7 @@ class Horde_Kolab_Format_XML_string extends Horde_Kolab_Format_XML { /** * Constructor */ - function Horde_Kolab_Format_XML_string() + function __construct() { $this->_root_name = 'string'; @@ -46,17 +51,19 @@ class Horde_Kolab_Format_XML_string extends Horde_Kolab_Format_XML { */ $this->_fields_specific = array( 'string' => array( - 'type' => HORDE_KOLAB_XML_TYPE_STRING, - 'value' => HORDE_KOLAB_XML_VALUE_MAYBE_MISSING, + 'type' => self::TYPE_STRING, + 'value' => self::VALUE_MAYBE_MISSING, ), ); - parent::Horde_Kolab_Format_XML(); + parent::__construct(); } } +Horde_Nls::setCharset('utf-8'); + /** Generate the format handler */ -$format = Horde_Kolab_Format::factory('XML', 'string'); +$format = Horde_Kolab_Format::factory('Xml', 'String'); /** Prepare a test object */ $object = array( diff --git a/framework/Kolab_Format/lib/Horde/Kolab/Format.php b/framework/Kolab_Format/lib/Horde/Kolab/Format.php index 06e422213..bd879cb13 100644 --- a/framework/Kolab_Format/lib/Horde/Kolab/Format.php +++ b/framework/Kolab_Format/lib/Horde/Kolab/Format.php @@ -22,8 +22,9 @@ require_once 'Horde/Autoloader.php'; * * Copyright 2007-2009 Klarälvdalens Datakonsult AB * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. + * See the enclosed file COPYING for license information (LGPL). If you did not + * receive this file, see + * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. * * @category Kolab * @package Kolab_Format diff --git a/framework/Kolab_Format/lib/Horde/Kolab/Format/Date.php b/framework/Kolab_Format/lib/Horde/Kolab/Format/Date.php index a07226cce..20b98f04c 100644 --- a/framework/Kolab_Format/lib/Horde/Kolab/Format/Date.php +++ b/framework/Kolab_Format/lib/Horde/Kolab/Format/Date.php @@ -17,8 +17,9 @@ * * Copyright 2004-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.gnu.org/licenses/old-licenses/lgpl-2.1.html. + * See the enclosed file COPYING for license information (LGPL). If you did not + * receive this file, see + * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. * * @category Kolab * @package Kolab_Format diff --git a/framework/Kolab_Format/lib/Horde/Kolab/Format/Exception.php b/framework/Kolab_Format/lib/Horde/Kolab/Format/Exception.php new file mode 100644 index 000000000..f51f6f9f7 --- /dev/null +++ b/framework/Kolab_Format/lib/Horde/Kolab/Format/Exception.php @@ -0,0 +1,30 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Format + */ + +/** + * This class provides the standard error class for Kolab Format exceptions. + * + * 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_Format + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Format + */ +class Horde_Kolab_Format_Exception extends Horde_Exception +{ +} \ No newline at end of file diff --git a/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml.php b/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml.php index 9650af82e..5c5a3b2c9 100644 --- a/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml.php +++ b/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml.php @@ -20,8 +20,9 @@ * * Copyright 2007-2009 Klarälvdalens Datakonsult AB * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. + * See the enclosed file COPYING for license information (LGPL). If you did not + * receive this file, see + * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. * * @category Kolab * @package Kolab_Format @@ -121,7 +122,7 @@ class Horde_Kolab_Format_Xml /** * The XML document this driver works with. * - * @var Horde_DOM_Document + * @var DOMDocument * * @todo Make protected (fix the XmlTest for that) */ @@ -355,16 +356,16 @@ class Horde_Kolab_Format_Xml * Attempts to return a concrete Horde_Kolab_Format_Xml instance. * based on $object_type. * - * @param string $object_type The object type that should be handled. - * @param array $params Any additional parameters. + * @param string $object_type The object type that should be handled. + * @param array $params Any additional parameters. * * @return Horde_Kolab_Format_Xml The newly created concrete * Horde_Kolab_Format_Xml instance. * - * @throws Horde_Exception If the class for the object type could + * @throws Horde_Kolab_Format_Exception If the class for the object type could * not be loaded. */ - public function &factory($object_type = '', $params = null) + static public function &factory($object_type = '', $params = null) { $object_type = ucfirst(str_replace('-', '', $object_type)); $class = 'Horde_Kolab_Format_Xml_' . $object_type; @@ -372,7 +373,7 @@ class Horde_Kolab_Format_Xml if (class_exists($class)) { $driver = &new $class($params); } else { - throw new Horde_Exception(sprintf(_("Failed to load Kolab XML driver %s"), + throw new Horde_Kolab_Format_Exception(sprintf(_("Failed to load Kolab XML driver %s"), $object_type)); } @@ -412,20 +413,20 @@ class Horde_Kolab_Format_Xml /** * Load an object based on the given XML string. * - * @todo Check encoding of the returned array. It seems to be ISO-8859-1 at - * the moment and UTF-8 would seem more appropriate. - * - * @param string $xmltext The XML of the message as string. + * @param string &$xmltext The XML of the message as string. * * @return array The data array representing the object. * - * @throws Horde_Exception If parsing the XML data failed. + * @throws Horde_Kolab_Format_Exception If parsing the XML data failed. + * + * @todo Check encoding of the returned array. It seems to be ISO-8859-1 at + * the moment and UTF-8 would seem more appropriate. */ public function load(&$xmltext) { try { $this->_parseXml($xmltext); - } catch (DOMException $e) { + } catch (Horde_Kolab_Format_Exception $e) { /** * If the first call does not return successfully this might mean we * got an attachment with broken encoding. There are some Kolab @@ -439,12 +440,8 @@ class Horde_Kolab_Format_Xml } $this->_parseXml($xmltext); } - if (empty($this->_xmldoc)) { - return false; - } - if (!$this->_xmldoc->documentElement->hasChildNodes()) { - throw new Horde_Exception(_("No or unreadable content in Kolab XML object")); + throw new Horde_Kolab_Format_Exception(_("No or unreadable content in Kolab XML object")); } // fresh object data @@ -459,7 +456,7 @@ class Horde_Kolab_Format_Xml // uid is vital if (!isset($object['uid'])) { - throw new Horde_Exception(_("UID not found in Kolab XML object")); + throw new Horde_Kolab_Format_Exception(_("UID not found in Kolab XML object")); } return $object; @@ -468,11 +465,11 @@ class Horde_Kolab_Format_Xml /** * Load the groupware object based on the specifc XML values. * - * @param array $children An array of XML nodes. + * @param array &$children An array of XML nodes. * * @return array The data array representing the object. * - * @throws Horde_Exception If parsing the XML data failed. + * @throws Horde_Kolab_Format_Exception If parsing the XML data failed. */ protected function _load(&$children) { @@ -486,20 +483,19 @@ class Horde_Kolab_Format_Xml /** * Load an array with data from the XML nodes. * - * @param array $object The resulting data array. - * @param array $children An array of XML nodes. - * @param array $fields The fields to populate in the object array. + * @param array &$children An array of XML nodes. + * @param array $fields The fields to populate in the object array. * * @return boolean True on success. * - * @throws Horde_Exception If parsing the XML data failed. + * @throws Horde_Kolab_Format_Exception If parsing the XML data failed. */ protected function _loadArray(&$children, $fields) { $object = array(); // basic fields below the root node - foreach($fields as $field => $params) { + foreach ($fields as $field => $params) { $result = $this->_getXmlData($children, $field, $params); if (isset($result)) { $object[$field] = $result; @@ -519,7 +515,7 @@ class Horde_Kolab_Format_Xml * @return string The content of the specified node or an empty * string. * - * @throws Horde_Exception If parsing the XML data failed. + * @throws Horde_Kolab_Format_Exception If parsing the XML data failed. * * @todo Make protected (fix the XmlTest for that) */ @@ -527,11 +523,11 @@ class Horde_Kolab_Format_Xml { if ($params['type'] == self::TYPE_MULTIPLE) { $result = array(); - foreach($children as $child) { + foreach ($children as $child) { if ($child->nodeType == XML_ELEMENT_NODE && $child->tagName == $name) { - $child_a = array($child); - $value = $this->_getXmlData($child_a, $name, - $params['array']); + $child_a = array($child); + $value = $this->_getXmlData($child_a, $name, + $params['array']); $result[] = $value; } } @@ -551,7 +547,7 @@ class Horde_Kolab_Format_Xml return null; } elseif ($params['value'] == self::VALUE_NOT_EMPTY) { // May not be empty. Return an error - throw new Horde_Exception(sprintf(_("Data value for %s is empty in Kolab XML object!"), + throw new Horde_Kolab_Format_Exception(sprintf(_("Data value for %s is empty in Kolab XML object!"), $name)); } elseif ($params['value'] == self::VALUE_DEFAULT) { // Return the default @@ -567,8 +563,8 @@ class Horde_Kolab_Format_Xml $value = call_user_func(array($this, '_load' . $params['load']), $child, $missing); } else { - throw new Horde_Exception(sprintf("Kolab XML: Missing function %s!", - $params['load'])); + throw new Horde_Kolab_Format_Exception(sprintf("Kolab XML: Missing function %s!", + $params['load'])); } } elseif ($params['type'] == self::TYPE_COMPOSITE) { return $this->_loadArray($child->childNodes, $params['array']); @@ -583,30 +579,36 @@ class Horde_Kolab_Format_Xml /** * Parse the XML string. The root node is returned on success. * - * @param string $xmltext The XML of the message as string. + * @param string &$xmltext The XML of the message as string. * * @return NULL * - * @throws Horde_Exception If parsing the XML data failed. + * @throws Horde_Kolab_Format_Exception If parsing the XML data failed. * * @todo Make protected (fix the XmlTest for that) */ public function _parseXml(&$xmltext) { $this->_xmldoc = new DOMDocument(); + $this->_xmldoc->preserveWhiteSpace = false; - $this->_xmldoc->formatOutput = true; - $this->_xmldoc->loadXML($xmltext); + $this->_xmldoc->formatOutput = true; + + @$this->_xmldoc->loadXML($xmltext); + if (empty($this->_xmldoc->documentElement)) { + throw new Horde_Kolab_Format_Exception(_("No or unreadable content in Kolab XML object")); + } + } /** * Convert the data to a XML string. * - * @param array $attributes The data array representing the note. + * @param array $object The data array representing the note. * * @return string The data as XML string. * - * @throws Horde_Exception If converting the data to XML failed. + * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function save($object) { @@ -622,12 +624,12 @@ class Horde_Kolab_Format_Xml /** * Save the specific XML values. * - * @param array &$root The XML document root. - * @param array $object The resulting data array. + * @param array &$root The XML document root. + * @param array $object The resulting data array. * * @return boolean True on success. * - * @throws Horde_Exception If converting the data to XML failed. + * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ protected function _save(&$root, $object) { @@ -640,42 +642,39 @@ class Horde_Kolab_Format_Xml /** * Creates a new XML document if necessary. * - * @param string $xmltext The XML of the message as string. - * - * @return Horde_DOM_Node The root node of the document. + * @return DOMNode The root node of the document. * * @todo Make protected (fix the XmlTest for that) */ public function &_prepareSave() { - if (empty($this->_xmldoc)) { - // create new XML - $this->_xmldoc = new DOMDocument(); - $this->_xmldoc->preserveWhiteSpace = false; - $this->_xmldoc->formatOutput = true; - $root = $this->_xmldoc->createElement($this->_root_name); - $this->_xmldoc->appendChild($root); - $root->setAttribute('version', $this->_root_version); - } + $this->_xmldoc = new DOMDocument(); + + $this->_xmldoc->preserveWhiteSpace = false; + $this->_xmldoc->formatOutput = true; + + $root = $this->_xmldoc->createElement($this->_root_name); + $this->_xmldoc->appendChild($root); + $root->setAttribute('version', $this->_root_version); return $root; } /** * Save a data array to XML nodes. * - * @param array $root The XML document root. - * @param array $object The data array. - * @param array $fields The fields to write into the XML object. - * @param boolean $append Should the nodes be appended? + * @param array $root The XML document root. + * @param array $object The data array. + * @param array $fields The fields to write into the XML object. + * @param boolean $append Should the nodes be appended? * * @return boolean True on success. * - * @throws Horde_Exception If converting the data to XML failed. + * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ protected function _saveArray($root, $object, $fields, $append = false) { // basic fields below the root node - foreach($fields as $field => $params) { + foreach ($fields as $field => $params) { $this->_updateNode($root, $object, $field, $params, $append); } return true; @@ -684,23 +683,23 @@ class Horde_Kolab_Format_Xml /** * Update the specified node. * - * @param Horde_DOM_Node $parent_node The parent node of the node that - * should be updated. - * @param array $attributes The data array that holds all - * attribute values. - * @param string $name The name of the the attribute - * to be updated. - * @param array $params Parameters for saving the node - * @param boolean $append Should the node be appended? + * @param DOMNode $parent_node The parent node of the node that + * should be updated. + * @param array $attributes The data array that holds all + * attribute values. + * @param string $name The name of the the attribute + * to be updated. + * @param array $params Parameters for saving the node + * @param boolean $append Should the node be appended? * - * @return Horde_DOM_Node The new/updated child node. + * @return DOMNode The new/updated child node. * - * @throws Horde_Exception If converting the data to XML failed. + * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. * * @todo Make protected (fix the XmlTest for that) */ public function _updateNode($parent_node, $attributes, $name, $params, - $append = false) + $append = false) { $value = null; $missing = false; @@ -713,7 +712,7 @@ class Horde_Kolab_Format_Xml $value = $params['default']; } elseif ($params['value'] == self::VALUE_NOT_EMPTY) { // May not be empty. Return an error - throw new Horde_Exception(sprintf(_("Data value for %s is empty in Kolab XML object!"), + throw new Horde_Kolab_Format_Exception(sprintf(_("Data value for %s is empty in Kolab XML object!"), $name)); } elseif ($params['value'] == self::VALUE_MAYBE_MISSING) { /** @@ -735,7 +734,7 @@ class Horde_Kolab_Format_Xml return call_user_func(array($this, '_save' . $params['save']), $parent_node, $name, $value, $missing); } else { - throw new Horde_Exception(sprintf("Kolab XML: Missing function %s!", + throw new Horde_Kolab_Format_Exception(sprintf("Kolab XML: Missing function %s!", $params['save'])); } } elseif ($params['type'] == self::TYPE_COMPOSITE) { @@ -753,7 +752,7 @@ class Horde_Kolab_Format_Xml $this->_removeNodes($parent_node, $name); // Add the new nodes - foreach($value as $add_node) { + foreach ($value as $add_node) { $this->_saveArray($parent_node, array($name => $add_node), array($name => $params['array']), @@ -769,15 +768,16 @@ class Horde_Kolab_Format_Xml /** * Create a text node. * - * @param Horde_DOM_Node $parent The parent of the new node. - * @param string $name The name of the child node to create. - * @param string $value The value of the child node to create. + * @param DOMNode $parent The parent of the new node. + * @param string $name The name of the child node to create. + * @param string $value The value of the child node to create. * - * @return Horde_DOM_Node The new node. + * @return DOMNode The new node. */ protected function _createTextNode($parent, $name, $value) { - $value = Horde_String::convertCharset($value, Horde_Nls::getCharset(), 'utf-8'); + $value = Horde_String::convertCharset($value, Horde_Nls::getCharset(), + 'utf-8'); $node = $this->_xmldoc->createElement($name); @@ -793,14 +793,14 @@ class Horde_Kolab_Format_Xml /** * Return the named node among a list of nodes. * - * @param array %$nodes The list of nodes. + * @param array &$nodes The list of nodes. * @param string $name The name of the node to return. * - * @return mixed The named Horde_DOM_Node or false if no node was found. + * @return mixed The named DOMNode or false if no node was found. */ protected function _findNode(&$nodes, $name) { - foreach($nodes as $node) { + foreach ($nodes as $node) { if ($node->nodeType == XML_ELEMENT_NODE && $node->tagName == $name) { return $node; } @@ -817,21 +817,22 @@ class Horde_Kolab_Format_Xml * @param string $child_name The name of the child node. * @param string $value The value of the child node * - * @return mixed The specified Horde_DOM_Node or false if no node was found. + * @return mixed The specified DOMNode or false if no node was found. */ protected function _findNodeByChildData($nodes, $parent_name, $child_name, $value) { - foreach($nodes as $node) - { - if ($node->nodeType == XML_ELEMENT_NODE && $node->tagName == $parent_name) { + foreach ($nodes as $node) { + if ($node->nodeType == XML_ELEMENT_NODE + && $node->tagName == $parent_name) { $children = $node->childNodes; - foreach ($children as $child) + foreach ($children as $child) { if ($child->nodeType == XML_ELEMENT_NODE && $child->tagName == $child_name && $child->textContent == $value) { return $node; } + } } } @@ -839,9 +840,9 @@ class Horde_Kolab_Format_Xml } /** - * Retrieve the content of a Horde_DOM_Node. + * Retrieve the content of a DOMNode. * - * @param Horde_DOM_Node $nodes The node that should be read. + * @param DOMNode $node The node that should be read. * * @return string The content of the node. */ @@ -854,10 +855,10 @@ class Horde_Kolab_Format_Xml /** * Create a new named node on a parent node. * - * @param Horde_DOM_Node $parent The parent node. - * @param string $name The name of the new child node. + * @param DOMNode $parent The parent node. + * @param string $name The name of the new child node. * - * @return Horde_DOM_Node The new child node. + * @return DOMNode The new child node. */ protected function _createChildNode($parent, $name) { @@ -870,8 +871,10 @@ class Horde_Kolab_Format_Xml /** * Remove named nodes from a parent node. * - * @param Horde_DOM_Node $parent The parent node. - * @param string $name The name of the children to be removed. + * @param DOMNode $parent_node The parent node. + * @param string $name The name of the children to be removed. + * + * @return NULL */ protected function _removeNodes($parent_node, $name) { @@ -884,12 +887,12 @@ class Horde_Kolab_Format_Xml * Create a new named node on a parent node if it is not already * present in the given children. * - * @param Horde_DOM_Node $parent The parent node. - * @param array $children The children that might already - * contain the node. - * @param string $name The name of the new child node. + * @param DOMNode $parent The parent node. + * @param array $children The children that might already + * contain the node. + * @param string $name The name of the new child node. * - * @return Horde_DOM_Node The new or already existing child node. + * @return DOMNode The new or already existing child node. */ protected function _createOrFindChildNode($parent, $children, $name) { @@ -906,12 +909,12 @@ class Horde_Kolab_Format_Xml /** * Load the different XML types. * - * @param string $node The node to load the data from - * @param array $params Parameters for loading the value + * @param string $node The node to load the data from + * @param array $params Parameters for loading the value * * @return string The loaded value. * - * @throws Horde_Exception If converting the data from XML failed. + * @throws Horde_Kolab_Format_Exception If converting the data from XML failed. */ protected function _loadDefault($node, $params) { @@ -942,16 +945,16 @@ class Horde_Kolab_Format_Xml /** * Save a data array as a XML node attached to the given parent node. * - * @param Horde_DOM_Node $parent_node The parent node to attach - * the child to - * @param string $name The name of the node - * @param mixed $value The value to store - * @param boolean $missing Has the value been missing? - * @param boolean $append Should the node be appended? + * @param DOMNode $parent_node The parent node to attach + * the child to + * @param string $name The name of the node + * @param mixed $value The value to store + * @param array $params Field parameters + * @param boolean $append Should the node be appended? * - * @return Horde_DOM_Node The new child node. + * @return DOMNode The new child node. * - * @throws Horde_Exception If converting the data to XML failed. + * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ protected function _saveDefault($parent_node, $name, $value, $params, $append = false) @@ -992,7 +995,7 @@ class Horde_Kolab_Format_Xml * Handle loading of categories. Preserve multiple categories in a hidden * object field. Optionally creates categories unknown to the Horde user. * - * @param array $object Array of strings, containing the 'categories' field. + * @param array &$object Array of strings, containing the 'categories' field. * * @return NULL */ @@ -1016,14 +1019,14 @@ class Horde_Kolab_Format_Xml $horde_categories = null; } - $kolab_categories = explode (',', $object['categories']); + $kolab_categories = explode(',', $object['categories']); $primary_category = ''; foreach ($kolab_categories as $kolab_category) { $kolab_category = trim($kolab_category); $valid_category = true; - if ($cManager && + if ($cManager && array_search($kolab_category, $horde_categories) === false) { // Unknown category -> Add if ($cManager->add($kolab_category) === false) { @@ -1051,7 +1054,7 @@ class Horde_Kolab_Format_Xml * Preserve multiple categories on save if "categories" didn't change. * The name "categories" currently refers to one primary category. * - * @param array $object Array of strings, containing the 'categories' field. + * @param array &$object Array of strings, containing the 'categories' field. * * @return NULL */ @@ -1060,8 +1063,7 @@ class Horde_Kolab_Format_Xml // Check for multiple categories. if (!isset($object['_categories_all']) || !isset($object['_categories_primary']) - || !isset($object['categories'])) - { + || !isset($object['categories'])) { return; } @@ -1074,12 +1076,12 @@ class Horde_Kolab_Format_Xml /** * Load the object creation date. * - * @param Horde_DOM_Node $node The original node if set. - * @param boolean $missing Has the node been missing? + * @param DOMNode $node The original node if set. + * @param boolean $missing Has the node been missing? * * @return string The creation date. * - * @throws Horde_Exception If converting the data from XML failed. + * @throws Horde_Kolab_Format_Exception If converting the data from XML failed. */ protected function _loadCreationDate($node, $missing) { @@ -1094,13 +1096,13 @@ class Horde_Kolab_Format_Xml /** * Save the object creation date. * - * @param Horde_DOM_Node $parent_node The parent node to attach the child - * to. - * @param string $name The name of the node. - * @param mixed $value The value to store. - * @param boolean $missing Has the value been missing? + * @param DOMNode $parent_node The parent node to attach the child + * to. + * @param string $name The name of the node. + * @param mixed $value The value to store. + * @param boolean $missing Has the value been missing? * - * @return Horde_DOM_Node The new child node. + * @return DOMNode The new child node. */ protected function _saveCreationDate($parent_node, $name, $value, $missing) { @@ -1117,8 +1119,8 @@ class Horde_Kolab_Format_Xml /** * Load the object modification date. * - * @param Horde_DOM_Node $node The original node if set. - * @param boolean $missing Has the node been missing? + * @param DOMNode $node The original node if set. + * @param boolean $missing Has the node been missing? * * @return string The last modification date. */ @@ -1135,13 +1137,13 @@ class Horde_Kolab_Format_Xml /** * Save the object modification date. * - * @param Horde_DOM_Node $parent_node The parent node to attach - * the child to. - * @param string $name The name of the node. - * @param mixed $value The value to store. - * @param boolean $missing Has the value been missing? + * @param DOMNode $parent_node The parent node to attach + * the child to. + * @param string $name The name of the node. + * @param mixed $value The value to store. + * @param boolean $missing Has the value been missing? * - * @return Horde_DOM_Node The new child node. + * @return DOMNode The new child node. */ protected function _saveModificationDate($parent_node, $name, $value, $missing) { @@ -1155,8 +1157,8 @@ class Horde_Kolab_Format_Xml /** * Load the name of the last client that modified this object * - * @param Horde_DOM_Node $node The original node if set. - * @param boolean $missing Has the node been missing? + * @param DOMNode $node The original node if set. + * @param boolean $missing Has the node been missing? * * @return string The last modification date. */ @@ -1172,13 +1174,13 @@ class Horde_Kolab_Format_Xml /** * Save the name of the last client that modified this object. * - * @param Horde_DOM_Node $parent_node The parent node to attach - * the child to. - * @param string $name The name of the node. - * @param mixed $value The value to store. - * @param boolean $missing Has the value been missing? + * @param DOMNode $parent_node The parent node to attach + * the child to. + * @param string $name The name of the node. + * @param mixed $value The value to store. + * @param boolean $missing Has the value been missing? * - * @return Horde_DOM_Node The new child node. + * @return DOMNode The new child node. */ protected function _saveProductId($parent_node, $name, $value, $missing) { @@ -1192,12 +1194,12 @@ class Horde_Kolab_Format_Xml /** * Load recurrence information. * - * @param Horde_DOM_Node $node The original node if set. - * @param boolean $missing Has the node been missing? + * @param DOMNode $node The original node if set. + * @param boolean $missing Has the node been missing? * * @return array The recurrence information. * - * @throws Horde_Exception If converting the data from XML failed. + * @throws Horde_Kolab_Format_Exception If converting the data from XML failed. */ protected function _loadRecurrence($node, $missing) { @@ -1218,7 +1220,7 @@ class Horde_Kolab_Format_Xml // Exclusions. if (isset($recurrence['exclusion'])) { $exceptions = array(); - foreach($recurrence['exclusion'] as $exclusion) { + foreach ($recurrence['exclusion'] as $exclusion) { if (!empty($exclusion)) { list($year, $month, $mday) = sscanf($exclusion, '%04d-%02d-%02d'); @@ -1231,7 +1233,7 @@ class Horde_Kolab_Format_Xml // Completed dates. if (isset($recurrence['complete'])) { $completions = array(); - foreach($recurrence['complete'] as $complete) { + foreach ($recurrence['complete'] as $complete) { if (!empty($complete)) { list($year, $month, $mday) = sscanf($complete, '%04d-%02d-%02d'); @@ -1242,9 +1244,9 @@ class Horde_Kolab_Format_Xml } // Range is special - foreach($children as $child) { - if ($child->tagname == 'range') { - $recurrence['range-type'] = $child->get_attribute('type'); + foreach ($children as $child) { + if ($child->tagName == 'range') { + $recurrence['range-type'] = $child->getAttribute('type'); } } @@ -1262,88 +1264,88 @@ class Horde_Kolab_Format_Xml /** * Validate recurrence hash information. * - * @param array $recurrence Recurrence hash loaded from XML. + * @param array &$recurrence Recurrence hash loaded from XML. * * @return boolean True on success. * - * @throws Horde_Exception If the recurrence data is invalid. + * @throws Horde_Kolab_Format_Exception If the recurrence data is invalid. */ protected function _validateRecurrence(&$recurrence) { if (!isset($recurrence['cycle'])) { - throw new Horde_Exception('recurrence tag error: cycle attribute missing'); + throw new Horde_Kolab_Format_Exception('recurrence tag error: cycle attribute missing'); } if (!isset($recurrence['interval'])) { - throw new Horde_Exception('recurrence tag error: interval tag missing'); + throw new Horde_Kolab_Format_Exception('recurrence tag error: interval tag missing'); } $interval = $recurrence['interval']; if ($interval < 0) { - throw new Horde_Exception('recurrence tag error: interval cannot be below zero: ' + throw new Horde_Kolab_Format_Exception('recurrence tag error: interval cannot be below zero: ' . $interval); } if ($recurrence['cycle'] == 'weekly') { // Check for if (!isset($recurrence['day']) || count($recurrence['day']) == 0) { - throw new Horde_Exception('recurrence tag error: day tag missing for weekly recurrence'); + throw new Horde_Kolab_Format_Exception('recurrence tag error: day tag missing for weekly recurrence'); } } // The code below is only for monthly or yearly recurrences if ($recurrence['cycle'] != 'monthly' - && $recurrence['cycle'] != 'yearly') + && $recurrence['cycle'] != 'yearly') { return true; + } if (!isset($recurrence['type'])) { - throw new Horde_Exception('recurrence tag error: type attribute missing'); + throw new Horde_Kolab_Format_Exception('recurrence tag error: type attribute missing'); } if (!isset($recurrence['daynumber'])) { - throw new Horde_Exception('recurrence tag error: daynumber tag missing'); + throw new Horde_Kolab_Format_Exception('recurrence tag error: daynumber tag missing'); } $daynumber = $recurrence['daynumber']; if ($daynumber < 0) { - throw new Horde_Exception('recurrence tag error: daynumber cannot be below zero: ' + throw new Horde_Kolab_Format_Exception('recurrence tag error: daynumber cannot be below zero: ' . $daynumber); } if ($recurrence['type'] == 'daynumber') { if ($recurrence['cycle'] == 'yearly' && $daynumber > 366) { - throw new Horde_Exception('recurrence tag error: daynumber cannot be larger than 366 for yearly recurrences: ' . $daynumber); + throw new Horde_Kolab_Format_Exception('recurrence tag error: daynumber cannot be larger than 366 for yearly recurrences: ' . $daynumber); } else if ($recurrence['cycle'] == 'monthly' && $daynumber > 31) { - throw new Horde_Exception('recurrence tag error: daynumber cannot be larger than 31 for monthly recurrences: ' . $daynumber); + throw new Horde_Kolab_Format_Exception('recurrence tag error: daynumber cannot be larger than 31 for monthly recurrences: ' . $daynumber); } } else if ($recurrence['type'] == 'weekday') { // daynumber is the week of the month if ($daynumber > 5) { - throw new Horde_Exception('recurrence tag error: daynumber cannot be larger than 5 for type weekday: ' . $daynumber); + throw new Horde_Kolab_Format_Exception('recurrence tag error: daynumber cannot be larger than 5 for type weekday: ' . $daynumber); } // Check for if (!isset($recurrence['day']) || count($recurrence['day']) == 0) { - throw new Horde_Exception('recurrence tag error: day tag missing for type weekday'); + throw new Horde_Kolab_Format_Exception('recurrence tag error: day tag missing for type weekday'); } } if (($recurrence['type'] == 'monthday' || $recurrence['type'] == 'yearday') - && $recurrence['cycle'] == 'monthly') - { - throw new Horde_Exception('recurrence tag error: type monthday/yearday is only allowed for yearly recurrences'); + && $recurrence['cycle'] == 'monthly') { + throw new Horde_Kolab_Format_Exception('recurrence tag error: type monthday/yearday is only allowed for yearly recurrences'); } if ($recurrence['cycle'] == 'yearly') { if ($recurrence['type'] == 'monthday') { // daynumber and month if (!isset($recurrence['month'])) { - throw new Horde_Exception('recurrence tag error: month tag missing for type monthday'); + throw new Horde_Kolab_Format_Exception('recurrence tag error: month tag missing for type monthday'); } if ($daynumber > 31) { - throw new Horde_Exception('recurrence tag error: daynumber cannot be larger than 31 for type monthday: ' . $daynumber); + throw new Horde_Kolab_Format_Exception('recurrence tag error: daynumber cannot be larger than 31 for type monthday: ' . $daynumber); } } else if ($recurrence['type'] == 'yearday') { if ($daynumber > 366) { - throw new Horde_Exception('recurrence tag error: daynumber cannot be larger than 366 for type yearday: ' . $daynumber); + throw new Horde_Kolab_Format_Exception('recurrence tag error: daynumber cannot be larger than 366 for type yearday: ' . $daynumber); } } } @@ -1354,13 +1356,13 @@ class Horde_Kolab_Format_Xml /** * Save recurrence information. * - * @param Horde_DOM_Node $parent_node The parent node to attach - * the child to. - * @param string $name The name of the node. - * @param mixed $value The value to store. - * @param boolean $missing Has the value been missing? + * @param DOMNode $parent_node The parent node to attach + * the child to. + * @param string $name The name of the node. + * @param mixed $value The value to store. + * @param boolean $missing Has the value been missing? * - * @return Horde_DOM_Node The new child node. + * @return DOMNode The new child node. */ protected function _saveRecurrence($parent_node, $name, $value, $missing) { @@ -1373,7 +1375,7 @@ class Horde_Kolab_Format_Xml // Exclusions. if (isset($value['exceptions'])) { $exclusions = array(); - foreach($value['exceptions'] as $exclusion) { + foreach ($value['exceptions'] as $exclusion) { if (!empty($exclusion)) { list($year, $month, $mday) = sscanf($exclusion, '%04d%02d%02d'); $exclusions[] = "$year-$month-$mday"; @@ -1385,7 +1387,7 @@ class Horde_Kolab_Format_Xml // Completed dates. if (isset($value['completions'])) { $completions = array(); - foreach($value['completions'] as $complete) { + foreach ($value['completions'] as $complete) { if (!empty($complete)) { list($year, $month, $mday) = sscanf($complete, '%04d%02d%02d'); $completions[] = "$year-$month-$mday"; diff --git a/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Annotation.php b/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Annotation.php index 7604cffcf..d9f5c86a5 100644 --- a/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Annotation.php +++ b/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Annotation.php @@ -16,8 +16,9 @@ * * 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.gnu.org/licenses/old-licenses/lgpl-2.1.html. + * See the enclosed file COPYING for license information (LGPL). If you did not + * receive this file, see + * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. * * @category Kolab * @package Kolab_Format diff --git a/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Contact.php b/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Contact.php index ef66f2f58..ff3dfcf7f 100644 --- a/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Contact.php +++ b/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Contact.php @@ -17,8 +17,9 @@ * * Copyright 2007-2009 Klarälvdalens Datakonsult AB * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. + * See the enclosed file COPYING for license information (LGPL). If you did not + * receive this file, see + * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. * * @category Kolab * @package Kolab_Format @@ -411,7 +412,7 @@ class Horde_Kolab_Format_Xml_Contact extends Horde_Kolab_Format_Xml $emails = explode(',', $object['emails']); } - if (isset($object['email']) && + if (isset($object['email']) && !in_array($object['email'], $emails)) { $emails[] = $object['email']; } diff --git a/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Distributionlist.php b/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Distributionlist.php index e471953e1..3f4938475 100644 --- a/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Distributionlist.php +++ b/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Distributionlist.php @@ -17,8 +17,9 @@ * * Copyright 2007-2009 Klarälvdalens Datakonsult AB * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. + * See the enclosed file COPYING for license information (LGPL). If you did not + * receive this file, see + * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. * * @category Kolab * @package Kolab_Format diff --git a/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Event.php b/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Event.php index 9544ae041..a0569e5f4 100644 --- a/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Event.php +++ b/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Event.php @@ -17,8 +17,9 @@ * * Copyright 2007-2009 Klarälvdalens Datakonsult AB * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. + * See the enclosed file COPYING for license information (LGPL). If you did not + * receive this file, see + * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. * * @category Kolab * @package Kolab_Format diff --git a/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Hprefs.php b/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Hprefs.php index b7a8eebc9..6e84b541a 100644 --- a/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Hprefs.php +++ b/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Hprefs.php @@ -16,8 +16,9 @@ * * Copyright 2007-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.gnu.org/licenses/old-licenses/lgpl-2.1.html. + * See the enclosed file COPYING for license information (LGPL). If you did not + * receive this file, see + * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. * * @category Kolab * @package Kolab_Format diff --git a/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Note.php b/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Note.php index bd12d2116..c25b5a3e7 100644 --- a/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Note.php +++ b/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Note.php @@ -17,8 +17,9 @@ * * Copyright 2007-2009 Klarälvdalens Datakonsult AB * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. + * See the enclosed file COPYING for license information (LGPL). If you did not + * receive this file, see + * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. * * @category Kolab * @package Kolab_Format diff --git a/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Task.php b/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Task.php index 5d37389f2..7b8513887 100644 --- a/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Task.php +++ b/framework/Kolab_Format/lib/Horde/Kolab/Format/Xml/Task.php @@ -17,8 +17,9 @@ * * Copyright 2007-2009 Klarälvdalens Datakonsult AB * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. + * See the enclosed file COPYING for license information (LGPL). If you did not + * receive this file, see + * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. * * @category Kolab * @package Kolab_Format @@ -162,7 +163,8 @@ class Horde_Kolab_Format_Xml_Task extends Horde_Kolab_Format_Xml $object['completed'] = (bool) Kolab::percentageToBoolean($object['completed']); - if (isset($object['organizer']) && isset($object['organizer']['smtp-address'])) { + if (isset($object['organizer']) + && isset($object['organizer']['smtp-address'])) { $object['assignee'] = $object['organizer']['smtp-address']; } diff --git a/framework/Kolab_Format/package.xml b/framework/Kolab_Format/package.xml index df33af729..2a6862b05 100644 --- a/framework/Kolab_Format/package.xml +++ b/framework/Kolab_Format/package.xml @@ -74,6 +74,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + @@ -121,6 +122,10 @@ http://pear.php.net/dtd/package-2.0.xsd"> 1.4.0b1 + Exception + pear.horde.org + + Nls pear.horde.org @@ -147,6 +152,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + diff --git a/framework/Kolab_Format/test/Horde/Kolab/Format/AllTests.php b/framework/Kolab_Format/test/Horde/Kolab/Format/AllTests.php index 2a75a4f02..6c97eded2 100644 --- a/framework/Kolab_Format/test/Horde/Kolab/Format/AllTests.php +++ b/framework/Kolab_Format/test/Horde/Kolab/Format/AllTests.php @@ -2,45 +2,71 @@ /** * All tests for the Horde_Kolab_Format:: package. * - * $Horde: framework/Kolab_Format/test/Horde/Kolab/Format/AllTests.php,v 1.4 2009/01/06 17:49:23 jan Exp $ + * PHP version 5 * - * @package Kolab_Format + * @category Kolab + * @package Kolab_Format + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** - * Define the main method + * Define the main method */ if (!defined('PHPUnit_MAIN_METHOD')) { define('PHPUnit_MAIN_METHOD', 'Horde_Kolab_Format_AllTests::main'); } -require_once 'PHPUnit/Framework/TestSuite.php'; -require_once 'PHPUnit/TextUI/TestRunner.php'; +/** + * The Autoloader allows us to omit "require/include" statements. + */ +require_once 'Horde/Autoloader.php'; /** * Combine the tests for this package. * - * $Horde: framework/Kolab_Format/test/Horde/Kolab/Format/AllTests.php,v 1.4 2009/01/06 17:49:23 jan Exp $ - * * Copyright 2007-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. * - * @package Kolab_Format + * @category Kolab + * @package Kolab_Format + * @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_Format_AllTests { +class Horde_Kolab_Format_AllTests +{ + /** + * Main entry point for running the suite. + * + * @return NULL + */ public static function main() { PHPUnit_TextUI_TestRunner::run(self::suite()); } + /** + * Collect the unit tests of this directory into a new suite. + * + * @return PHPUnit_Framework_TestSuite The test suite. + */ public static function suite() { + // Catch strict standards + // FIXME: This does not work yet, as we still have a number of + // static methods in basic Horde libraries that are not + // declared as such. There are also strict failures for the + // Horde_Date classes. + //error_reporting(E_ALL | E_STRICT); + $suite = new PHPUnit_Framework_TestSuite('Horde Framework - Horde_Kolab_Format'); - $basedir = dirname(__FILE__); + $basedir = dirname(__FILE__); $baseregexp = preg_quote($basedir . DIRECTORY_SEPARATOR, '/'); foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($basedir)) as $file) { diff --git a/framework/Kolab_Format/test/Horde/Kolab/Format/ContactTest.php b/framework/Kolab_Format/test/Horde/Kolab/Format/ContactTest.php index 5cd856786..92bb40480 100644 --- a/framework/Kolab_Format/test/Horde/Kolab/Format/ContactTest.php +++ b/framework/Kolab_Format/test/Horde/Kolab/Format/ContactTest.php @@ -2,9 +2,13 @@ /** * Test the contact XML format. * - * $Horde: framework/Kolab_Format/test/Horde/Kolab/Format/ContactTest.php,v 1.4 2009/01/06 17:49:23 jan Exp $ + * PHP version 5 * - * @package Kolab_Format + * @category Kolab + * @package Kolab_Format + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** @@ -12,56 +16,27 @@ */ require_once 'Horde/Autoloader.php'; - -class DummyRegistry { - function get() - { - return 'horde'; - } -} - -class Horde_Kolab_Format_Xml_Contact_dummy extends Horde_Kolab_Format_Xml_Contact -{ - function _saveCreationDate($parent_node, $name, $value, $missing) - { - // Only create the creation date if it has not been set before - if ($missing) { - $value = 0; - } - return $this->_saveDefault($parent_node, - $name, - $value, - array('type' => self::TYPE_DATETIME)); - } - - function _saveModificationDate($parent_node, $name, $value, $missing) - { - // Always store now as modification date - return $this->_saveDefault($parent_node, - $name, - 0, - array('type' => self::TYPE_DATETIME)); - } -} - /** * Test the contact XML format. * - * $Horde: framework/Kolab_Format/test/Horde/Kolab/Format/ContactTest.php,v 1.4 2009/01/06 17:49:23 jan Exp $ - * * Copyright 2007-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. * - * @author Gunnar Wrobel - * @package Kolab_Format + * @category Kolab + * @package Kolab_Format + * @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_Format_ContactTest extends PHPUnit_Framework_TestCase { /** * Set up testing. + * + * @return NULL */ protected function setUp() { @@ -70,52 +45,63 @@ class Horde_Kolab_Format_ContactTest extends PHPUnit_Framework_TestCase /** * Test storing single mail addresses. + * + * @return NULL */ public function testSingleEmail() { - $contact = &new Horde_Kolab_Format_Xml_contact_dummy(); - $object = array('uid' => '1', - 'full-name' => 'User Name', - 'email' => 'user@example.org'); - $xml = $contact->save($object); - $expect = file_get_contents(dirname(__FILE__) . '/fixtures/contact_mail.xml'); + $contact = new Horde_Kolab_Format_Xml_contact_Dummy(); + $object = array('uid' => '1', + 'full-name' => 'User Name', + 'email' => 'user@example.org'); + $xml = $contact->save($object); + $expect = file_get_contents(dirname(__FILE__) + . '/fixtures/contact_mail.xml'); $this->assertEquals($expect, $xml); } /** * Test storing PGP public keys. + * + * @return NULL */ public function testPGP() { - $contact = &new Horde_Kolab_Format_Xml_contact_dummy(); - $object = array('uid' => '1', - 'full-name' => 'User Name', - 'pgp-publickey' => 'PGP Test Key', - 'email' => 'user@example.org'); - $xml = $contact->save($object); - $expect = file_get_contents(dirname(__FILE__) . '/fixtures/contact_pgp.xml'); + $contact = new Horde_Kolab_Format_Xml_contact_Dummy(); + $object = array('uid' => '1', + 'full-name' => 'User Name', + 'pgp-publickey' => 'PGP Test Key', + 'email' => 'user@example.org'); + $xml = $contact->save($object); + $expect = file_get_contents(dirname(__FILE__) + . '/fixtures/contact_pgp.xml'); $this->assertEquals($expect, $xml); } /** * Test loading a contact with a category. + * + * @return NULL */ public function testCategories() { global $prefs; - $contact = &new Horde_Kolab_Format_Xml_contact(); - $xml = file_get_contents(dirname(__FILE__) . '/fixtures/contact_category.xml'); - $object = $contact->load($xml); + $contact = new Horde_Kolab_Format_Xml_contact(); + $xml = file_get_contents(dirname(__FILE__) + . '/fixtures/contact_category.xml'); + $object = $contact->load($xml); $this->assertContains('Test', $object['categories']); - $prefs = 'some string'; + $prefs = 'some string'; $object = $contact->load($xml); $this->assertContains('Test', $object['categories']); } /** * Test loading a contact with a category with preferences. + * + * @return NULL */ public function testCategoriesWithPrefs() { @@ -126,14 +112,15 @@ class Horde_Kolab_Format_ContactTest extends PHPUnit_Framework_TestCase if (class_exists('Prefs')) { $registry = new DummyRegistry(); - $prefs = Prefs::singleton('session'); + $prefs = Prefs::singleton('session'); + /* Monkey patch to allw the value to be set. */ $prefs->_prefs['categories'] = array('v' => ''); - - $contact = &new Horde_Kolab_Format_Xml_contact(); - $xml = file_get_contents(dirname(__FILE__) . '/fixtures/contact_category.xml'); - $object = $contact->load($xml); + $contact = new Horde_Kolab_Format_Xml_contact(); + $xml = file_get_contents(dirname(__FILE__) + . '/fixtures/contact_category.xml'); + $object = $contact->load($xml); $this->assertContains('Test', $object['categories']); $this->assertEquals('Test', $prefs->getValue('categories')); } @@ -141,3 +128,91 @@ class Horde_Kolab_Format_ContactTest extends PHPUnit_Framework_TestCase } + +/** + * A dummy registry. + * + * Copyright 2007-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_Format + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class DummyRegistry +{ + /** + * Returns the application context. + * + * @return string Always "horde". + */ + function get() + { + return 'horde'; + } +} + +/** + * A modification to the original contact handler. This prevents unpredictable + * date entries. + * + * Copyright 2007-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_Format + * @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_Format_Xml_Contact_Dummy extends Horde_Kolab_Format_Xml_Contact +{ + /** + * Save the object creation date. + * + * @param DOMNode $parent_node The parent node to attach the child + * to. + * @param string $name The name of the node. + * @param mixed $value The value to store. + * @param boolean $missing Has the value been missing? + * + * @return DOMNode The new child node. + */ + function _saveCreationDate($parent_node, $name, $value, $missing) + { + // Only create the creation date if it has not been set before + if ($missing) { + $value = 0; + } + return $this->_saveDefault($parent_node, + $name, + $value, + array('type' => self::TYPE_DATETIME)); + } + + /** + * Save the object modification date. + * + * @param DOMNode $parent_node The parent node to attach + * the child to. + * @param string $name The name of the node. + * @param mixed $value The value to store. + * @param boolean $missing Has the value been missing? + * + * @return DOMNode The new child node. + */ + function _saveModificationDate($parent_node, $name, $value, $missing) + { + // Always store now as modification date + return $this->_saveDefault($parent_node, + $name, + 0, + array('type' => self::TYPE_DATETIME)); + } +} \ No newline at end of file diff --git a/framework/Kolab_Format/test/Horde/Kolab/Format/EventTest.php b/framework/Kolab_Format/test/Horde/Kolab/Format/EventTest.php index bec51f6b9..e1279bba5 100644 --- a/framework/Kolab_Format/test/Horde/Kolab/Format/EventTest.php +++ b/framework/Kolab_Format/test/Horde/Kolab/Format/EventTest.php @@ -2,9 +2,13 @@ /** * Test event handling within the Kolab format implementation. * - * $Horde: framework/Kolab_Format/test/Horde/Kolab/Format/EventTest.php,v 1.1 2009/04/02 20:07:26 wrobel Exp $ + * PHP version 5 * - * @package Kolab_Format + * @category Kolab + * @package Kolab_Format + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** @@ -15,21 +19,24 @@ require_once 'Horde/Autoloader.php'; /** * Test event handling. * - * $Horde: framework/Kolab_Format/test/Horde/Kolab/Format/EventTest.php,v 1.1 2009/04/02 20:07:26 wrobel Exp $ - * * Copyright 2007-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. * - * @author Gunnar Wrobel - * @package Kolab_Format + * @category Kolab + * @package Kolab_Format + * @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_Format_EventTest extends PHPUnit_Framework_TestCase { /** * Set up testing. + * + * @return NULL */ protected function setUp() { @@ -39,21 +46,31 @@ class Horde_Kolab_Format_EventTest extends PHPUnit_Framework_TestCase /** * Test for https://www.intevation.de/roundup/kolab/issue3525 + * + * @return NULL */ public function testIssue3525() { $xml = Horde_Kolab_Format::factory('XML', 'event'); // Load XML - $event = file_get_contents(dirname(__FILE__) . '/fixtures/event_umlaut.xml'); + $event = file_get_contents(dirname(__FILE__) + . '/fixtures/event_umlaut.xml'); $result = $xml->load($event); // Check that the xml loads fine - $this->assertEquals(mb_convert_encoding($result['body'], 'UTF-8', 'ISO-8859-1'), '...übbe...'); + $this->assertEquals(mb_convert_encoding($result['body'], 'UTF-8', + 'ISO-8859-1'), '...übbe...'); // Load XML - $event = file_get_contents(dirname(__FILE__) . '/fixtures/event_umlaut_broken.xml'); + $event = file_get_contents(dirname(__FILE__) + . '/fixtures/event_umlaut_broken.xml'); $result = $xml->load($event); - //FIXME: Why does Kolab Format return ISO-8859-1? UTF-8 would seem more appropriate - $this->assertEquals(mb_convert_encoding($result['body'], 'UTF-8', 'ISO-8859-1'), '...übbe...'); + + /** + * FIXME: Why does Kolab Format return ISO-8859-1? UTF-8 would seem more + * appropriate + */ + $this->assertEquals(mb_convert_encoding($result['body'], 'UTF-8', + 'ISO-8859-1'), '...übbe...'); } } diff --git a/framework/Kolab_Format/test/Horde/Kolab/Format/MimeAttrTest.php b/framework/Kolab_Format/test/Horde/Kolab/Format/MimeAttrTest.php index 99733e396..74e9b1bd7 100644 --- a/framework/Kolab_Format/test/Horde/Kolab/Format/MimeAttrTest.php +++ b/framework/Kolab_Format/test/Horde/Kolab/Format/MimeAttrTest.php @@ -2,8 +2,6 @@ /** * Test Kolab Format MIME attributes * - * $Horde: framework/Kolab_Format/test/Horde/Kolab/Format/MimeAttrTest.php,v 1.2 2009/01/06 17:49:23 jan Exp $ - * * PHP version 5 * * @category Kolab @@ -22,8 +20,6 @@ require_once 'Horde/Autoloader.php'; /** * Test Kolab Format MIME attributes * - * $Horde: framework/Kolab_Format/test/Horde/Kolab/Format/MimeAttrTest.php,v 1.2 2009/01/06 17:49:23 jan Exp $ - * * Copyright 2007-2009 The Horde Project (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you diff --git a/framework/Kolab_Format/test/Horde/Kolab/Format/PreferencesTest.php b/framework/Kolab_Format/test/Horde/Kolab/Format/PreferencesTest.php index b752810ec..97d640915 100644 --- a/framework/Kolab_Format/test/Horde/Kolab/Format/PreferencesTest.php +++ b/framework/Kolab_Format/test/Horde/Kolab/Format/PreferencesTest.php @@ -2,9 +2,13 @@ /** * Test the preferences XML format. * - * $Horde: framework/Kolab_Format/test/Horde/Kolab/Format/PreferencesTest.php,v 1.3 2009/01/06 17:49:23 jan Exp $ + * PHP version 5 * - * @package Kolab_Format + * @category Kolab + * @package Kolab_Format + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** @@ -13,49 +17,27 @@ require_once 'Horde/Autoloader.php'; - -class Horde_Kolab_Format_Xml_Hprefs_dummy extends Horde_Kolab_Format_Xml_Hprefs -{ - function _saveCreationDate($parent_node, $name, $value, $missing) - { - // Only create the creation date if it has not been set before - if ($missing) { - $value = 0; - } - return $this->_saveDefault($parent_node, - $name, - $value, - array('type' => self::TYPE_DATETIME)); - } - - function _saveModificationDate($parent_node, $name, $value, $missing) - { - // Always store now as modification date - return $this->_saveDefault($parent_node, - $name, - 0, - array('type' => self::TYPE_DATETIME)); - } -} - /** * Test the preferences XML format. * - * $Horde: framework/Kolab_Format/test/Horde/Kolab/Format/PreferencesTest.php,v 1.3 2009/01/06 17:49:23 jan Exp $ - * * Copyright 2007-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. * - * @author Gunnar Wrobel - * @package Kolab_Format + * @category Kolab + * @package Kolab_Format + * @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_Format_PreferencesTest extends PHPUnit_Framework_TestCase { /** * Set up testing. + * + * @return NULL */ protected function setUp() { @@ -64,12 +46,15 @@ class Horde_Kolab_Format_PreferencesTest extends PHPUnit_Framework_TestCase /** * Test preferences format conversion. + * + * @return NULL */ public function testConversionFromOld() { - $preferences = &new Horde_Kolab_Format_Xml_hprefs_dummy(); + $preferences = new Horde_Kolab_Format_Xml_hprefs_Dummy(); - $xml = file_get_contents(dirname(__FILE__) . '/fixtures/preferences_read_old.xml'); + $xml = file_get_contents(dirname(__FILE__) + . '/fixtures/preferences_read_old.xml'); $object = $preferences->load($xml); $this->assertContains('test', $object['pref']); $this->assertEquals('Test', $object['application']); @@ -77,15 +62,79 @@ class Horde_Kolab_Format_PreferencesTest extends PHPUnit_Framework_TestCase $object = array('uid' => 1, 'pref' => array('test'), 'categories' => 'Test'); - $xml = $preferences->save($object); - $expect = file_get_contents(dirname(__FILE__) . '/fixtures/preferences_write_old.xml'); + $xml = $preferences->save($object); + $expect = file_get_contents(dirname(__FILE__) + . '/fixtures/preferences_write_old.xml'); $this->assertEquals($expect, $xml); $object = array('uid' => 1, 'pref' => array('test'), 'application' => 'Test'); - $xml = $preferences->save($object); - $expect = file_get_contents(dirname(__FILE__) . '/fixtures/preferences_write_old.xml'); + $xml = $preferences->save($object); + $expect = file_get_contents(dirname(__FILE__) + . '/fixtures/preferences_write_old.xml'); $this->assertEquals($expect, $xml); } } + + +/** + * A modification to the original preferences handler. This prevents + * unpredictable date entries. + * + * Copyright 2007-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_Format + * @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_Format_Xml_Hprefs_Dummy extends Horde_Kolab_Format_Xml_Hprefs +{ + /** + * Save the object creation date. + * + * @param DOMNode $parent_node The parent node to attach the child + * to. + * @param string $name The name of the node. + * @param mixed $value The value to store. + * @param boolean $missing Has the value been missing? + * + * @return DOMNode The new child node. + */ + function _saveCreationDate($parent_node, $name, $value, $missing) + { + // Only create the creation date if it has not been set before + if ($missing) { + $value = 0; + } + return $this->_saveDefault($parent_node, + $name, + $value, + array('type' => self::TYPE_DATETIME)); + } + + /** + * Save the object modification date. + * + * @param DOMNode $parent_node The parent node to attach + * the child to. + * @param string $name The name of the node. + * @param mixed $value The value to store. + * @param boolean $missing Has the value been missing? + * + * @return DOMNode The new child node. + */ + function _saveModificationDate($parent_node, $name, $value, $missing) + { + // Always store now as modification date + return $this->_saveDefault($parent_node, + $name, + 0, + array('type' => self::TYPE_DATETIME)); + } +} \ No newline at end of file diff --git a/framework/Kolab_Format/test/Horde/Kolab/Format/RecurrenceTest.php b/framework/Kolab_Format/test/Horde/Kolab/Format/RecurrenceTest.php index cefd966b5..f476b314d 100644 --- a/framework/Kolab_Format/test/Horde/Kolab/Format/RecurrenceTest.php +++ b/framework/Kolab_Format/test/Horde/Kolab/Format/RecurrenceTest.php @@ -2,9 +2,13 @@ /** * Test recurrence handling within the Kolab format implementation. * - * $Horde: framework/Kolab_Format/test/Horde/Kolab/Format/RecurrenceTest.php,v 1.10 2009/01/19 18:10:00 mrubinsk Exp $ + * PHP version 5 * - * @package Kolab_Format + * @category Kolab + * @package Kolab_Format + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** @@ -15,30 +19,31 @@ require_once 'Horde/Autoloader.php'; /** * Test recurrence handling * - * $Horde: framework/Kolab_Format/test/Horde/Kolab/Format/RecurrenceTest.php,v 1.10 2009/01/19 18:10:00 mrubinsk Exp $ - * * Copyright 2007-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. * - * @author Gunnar Wrobel - * @package Kolab_Format + * @category Kolab + * @package Kolab_Format + * @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_Format_RecurrenceTest extends PHPUnit_Framework_TestCase { /** * Set up testing. + * + * @return NULL */ protected function setUp() { @include_once 'Horde/Date/Recurrence.php'; if (!class_exists('Horde_Date_Recurrence')) { - $this->markTestSkipped( - 'The Horde_Date_Recurrence class is missing.' - ); + $this->markTestSkipped('The Horde_Date_Recurrence class is missing.'); } Horde_Nls::setCharset('utf-8'); @@ -47,6 +52,8 @@ class Horde_Kolab_Format_RecurrenceTest extends PHPUnit_Framework_TestCase /** * Test for http://bugs.horde.org/ticket/?id=6388 + * + * @return NULL */ public function testBug6388() { @@ -56,7 +63,7 @@ class Horde_Kolab_Format_RecurrenceTest extends PHPUnit_Framework_TestCase $recur = file_get_contents(dirname(__FILE__) . '/fixtures/recur.xml'); // Load XML - $xml = &Horde_Kolab_Format::factory('XML', 'event'); + $xml = &Horde_Kolab_Format::factory('XML', 'event'); $recur = file_get_contents(dirname(__FILE__) . '/fixtures/recur_fail.xml'); // Check that the xml fails because of a missing interval value @@ -64,13 +71,15 @@ class Horde_Kolab_Format_RecurrenceTest extends PHPUnit_Framework_TestCase $xml->load($recur); $this->assertTrue(false); } catch (Exception $e) { - $this->assertTrue(is_a($e, 'Horde_Exception')); + $this->assertTrue($e instanceOf Horde_Exception); } } /** * Test exception handling. + * + * @return NULL */ public function testExceptions() { @@ -81,34 +90,35 @@ class Horde_Kolab_Format_RecurrenceTest extends PHPUnit_Framework_TestCase $object = $xml->load($recur); - $r = &new Horde_Date_Recurrence($object['start-date']); + $r = new Horde_Date_Recurrence($object['start-date']); $r->fromHash($object['recurrence']); $this->assertTrue($r->hasRecurEnd()); - $this->assertTrue($r->hasException(2006, 8, 16)); + $this->assertTrue($r->hasException(2006, 8, 16)); $this->assertTrue($r->hasException(2006, 10, 18)); $object['recurrence'] = $r->toHash(); - $recur = $xml->save($object); - - $object = $xml->load($recur); + $recur = $xml->save($object); + $object = $xml->load($recur); - $s = &new Horde_Date_Recurrence($object['start-date']); + $s = new Horde_Date_Recurrence($object['start-date']); $s->fromHash($object['recurrence']); $this->assertTrue($s->hasRecurEnd()); - $this->assertTrue($s->hasException(2006, 8, 16)); + $this->assertTrue($s->hasException(2006, 8, 16)); $this->assertTrue($s->hasException(2006, 10, 18)); } /** * Test completion handling. + * + * @return NULL */ public function testCompletions() { $xml = Horde_Kolab_Format::factory('XML', 'event'); - $r = &new Horde_Date_Recurrence(0); + $r = new Horde_Date_Recurrence(0); $r->setRecurType(Horde_Date_Recurrence::RECUR_DAILY); $r->addException(1970, 1, 1); $r->addCompletion(1970, 1, 2); @@ -116,19 +126,20 @@ class Horde_Kolab_Format_RecurrenceTest extends PHPUnit_Framework_TestCase $r->addCompletion(1970, 1, 4); $r->setRecurEnd(new Horde_Date(86400*3)); - $object = array('uid' => 0, 'start-date' => 0, 'end-date' => 60); + $object = array('uid' => 0, 'start-date' => 0, + 'end-date' => 60); $object['recurrence'] = $r->toHash(); - $recur = $xml->save($object); - $object = $xml->load($recur); + $recur = $xml->save($object); + $object = $xml->load($recur); - $s = &new Horde_Date_Recurrence(0); + $s = new Horde_Date_Recurrence(0); $s->fromHash($object['recurrence']); $this->assertTrue($s->hasRecurEnd()); - $this->assertTrue($s->hasException(1970, 1, 1)); - $this->assertTrue($s->hasCompletion(1970, 1, 2)); - $this->assertTrue($s->hasException(1970, 1, 3)); - $this->assertTrue($s->hasCompletion(1970, 1, 4)); + $this->assertTrue($s->hasException(1970, 1, 1)); + $this->assertTrue($s->hasCompletion(1970, 1, 2)); + $this->assertTrue($s->hasException(1970, 1, 3)); + $this->assertTrue($s->hasCompletion(1970, 1, 4)); $this->assertEquals(2, count($s->getCompletions())); $this->assertEquals(2, count($s->getExceptions())); $this->assertFalse($s->hasActiveRecurrence()); diff --git a/framework/Kolab_Format/test/Horde/Kolab/Format/XmlTest.php b/framework/Kolab_Format/test/Horde/Kolab/Format/XmlTest.php index 380c8aca2..fc383115b 100644 --- a/framework/Kolab_Format/test/Horde/Kolab/Format/XmlTest.php +++ b/framework/Kolab_Format/test/Horde/Kolab/Format/XmlTest.php @@ -2,9 +2,13 @@ /** * Test the XML format implementation. * - * $Horde: framework/Kolab_Format/test/Horde/Kolab/Format/XmlTest.php,v 1.5 2009/01/06 17:49:23 jan Exp $ + * PHP version 5 * - * @package Kolab_Format + * @category Kolab + * @package Kolab_Format + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** @@ -15,21 +19,24 @@ require_once 'Horde/Autoloader.php'; /** * Test the XML format. * - * $Horde: framework/Kolab_Format/test/Horde/Kolab/Format/XmlTest.php,v 1.5 2009/01/06 17:49:23 jan Exp $ - * * Copyright 2007-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. * - * @author Gunnar Wrobel - * @package Kolab_Format + * @category Kolab + * @package Kolab_Format + * @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_Format_XmlTest extends PHPUnit_Framework_TestCase { /** * Set up testing. + * + * @return NULL */ protected function setUp() { @@ -39,21 +46,26 @@ class Horde_Kolab_Format_XmlTest extends PHPUnit_Framework_TestCase /** * Check the preparation of the basic XML structure + * + * @return NULL */ public function testBasic() { - $xml = &new Horde_Kolab_Format_XML(); + $xml = new Horde_Kolab_Format_XML(); $xml->_prepareSave(); $base = $xml->_xmldoc->saveXML(); - $this->assertEquals("\n\n", $base); + $this->assertEquals("\n\n", + $base); } /** * The resulting XML string should be readable. + * + * @return NULL */ public function testReadable() { - $xml = &new Horde_Kolab_Format_XML(); + $xml = new Horde_Kolab_Format_XML(); $xml->_prepareSave(); $base = $xml->_xmldoc->saveXML(); $xml->_parseXml($base); @@ -63,10 +75,12 @@ class Horde_Kolab_Format_XmlTest extends PHPUnit_Framework_TestCase /** * Test adding nodes. + * + * @return NULL */ public function testAdd() { - $xml = &new Horde_Kolab_Format_XML(); + $xml = new Horde_Kolab_Format_XML(); $root = $xml->_prepareSave(); $base = $xml->_xmldoc->saveXML(); @@ -87,7 +101,7 @@ class Horde_Kolab_Format_XmlTest extends PHPUnit_Framework_TestCase array('value' => Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY)); $this->assertTrue(false); } catch (Exception $e) { - $this->assertTrue(is_a($e, 'Horde_Exception')); + $this->assertTrue($e instanceOf Horde_Exception); } $xml->_updateNode($root, @@ -95,7 +109,8 @@ class Horde_Kolab_Format_XmlTest extends PHPUnit_Framework_TestCase 'empty1', array('value' => Horde_Kolab_Format_Xml::VALUE_DEFAULT, 'default' => 'empty1', 'type' => 0)); - $this->assertEquals("\n\n empty1\n\n", $xml->_xmldoc->saveXML()); + $this->assertEquals("\n\n empty1\n\n", + $xml->_xmldoc->saveXML()); try { $xml->_updateNode($root, @@ -105,74 +120,80 @@ class Horde_Kolab_Format_XmlTest extends PHPUnit_Framework_TestCase 'save' => '_unknown')); $this->assertTrue(false); } catch (Exception $e) { - $this->assertTrue(is_a($e, 'Horde_Exception')); + $this->assertTrue($e instanceOf Horde_Exception); } } /** * Test node operations + * + * @return NULL */ public function testNodeOps() { - $dxml = new Horde_Kolab_Format_Xml_dummy(); + $dxml = new Horde_Kolab_Format_Xml_Dummy(); $droot = $dxml->_prepareSave(); // Test calculated nodes $dxml->_updateNode($droot, - array(), - 'empty2', - array('value' => Horde_Kolab_Format_Xml::VALUE_CALCULATED, - 'save' => 'Value', 'type' => 0)); + array(), + 'empty2', + array('value' => Horde_Kolab_Format_Xml::VALUE_CALCULATED, + 'save' => 'Value', 'type' => 0)); $dxml->_updateNode($droot, - array('present1' => 'present1'), - 'present1', - array('value' => Horde_Kolab_Format_Xml::VALUE_CALCULATED, - 'save' => 'Value', 'type' => 0)); - $this->assertEquals("\n\n empty2: , missing\n present1: present1\n\n", $dxml->_xmldoc->saveXML()); - - $xml = &new Horde_Kolab_Format_Xml(); + array('present1' => 'present1'), + 'present1', + array('value' => Horde_Kolab_Format_Xml::VALUE_CALCULATED, + 'save' => 'Value', 'type' => 0)); + $this->assertEquals("\n\n empty2: , missing\n present1: present1\n\n", + $dxml->_xmldoc->saveXML()); + + $xml = new Horde_Kolab_Format_Xml(); $root = $xml->_prepareSave(); $xml->_updateNode($root, - array(), - 'empty1', - array('value' => Horde_Kolab_Format_Xml::VALUE_DEFAULT, - 'default' => 'empty1', 'type' => 0)); + array(), + 'empty1', + array('value' => Horde_Kolab_Format_Xml::VALUE_DEFAULT, + 'default' => 'empty1', 'type' => 0)); // Back to the original object: Test saving a normal value $xml->_updateNode($root, - array('present1' => 'present1'), - 'present1', - array('value' => Horde_Kolab_Format_Xml::VALUE_DEFAULT, - 'default' => 'empty1', 'type' => 0)); - $this->assertEquals("\n\n empty1\n present1\n\n", $xml->_xmldoc->saveXML()); + array('present1' => 'present1'), + 'present1', + array('value' => Horde_Kolab_Format_Xml::VALUE_DEFAULT, + 'default' => 'empty1', 'type' => 0)); + $this->assertEquals("\n\n empty1\n present1\n\n", + $xml->_xmldoc->saveXML()); // Test overwriting a value $xml->_updateNode($root, - array('present1' => 'new1'), - 'present1', - array('value' => Horde_Kolab_Format_Xml::VALUE_DEFAULT, - 'default' => 'empty1', 'type' => 0)); - $this->assertEquals("\n\n empty1\n new1\n\n", $xml->_xmldoc->saveXML()); + array('present1' => 'new1'), + 'present1', + array('value' => Horde_Kolab_Format_Xml::VALUE_DEFAULT, + 'default' => 'empty1', 'type' => 0)); + $this->assertEquals("\n\n empty1\n new1\n\n", + $xml->_xmldoc->saveXML()); // Test saving a date $xml->_updateNode($root, - array('date1' => 1175080008), - 'date1', - array('value' => Horde_Kolab_Format_Xml::VALUE_DEFAULT, - 'default' => 'empty1', - 'type' => Horde_Kolab_Format_Xml::TYPE_DATETIME)); - $this->assertEquals("\n\n empty1\n new1\n 2007-03-28T11:06:48Z\n\n", $xml->_xmldoc->saveXML()); + array('date1' => 1175080008), + 'date1', + array('value' => Horde_Kolab_Format_Xml::VALUE_DEFAULT, + 'default' => 'empty1', + 'type' => Horde_Kolab_Format_Xml::TYPE_DATETIME)); + $this->assertEquals("\n\n empty1\n new1\n 2007-03-28T11:06:48Z\n\n", + $xml->_xmldoc->saveXML()); // Now load the data back in $children = $root->childNodes; // Test loading a value that may be empty $this->assertEquals(null, $xml->_getXmlData($children, - 'empty2', - array('value' => Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING, - 'default' => '', - 'type' => Horde_Kolab_Format_Xml::TYPE_STRING))); + 'empty2', + array('value' => Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING, + 'default' => '', + 'type' => Horde_Kolab_Format_Xml::TYPE_STRING))); // Test loading a value that may not be empty try { @@ -183,29 +204,29 @@ class Horde_Kolab_Format_XmlTest extends PHPUnit_Framework_TestCase 'type' => Horde_Kolab_Format_Xml::TYPE_STRING)); $this->assertTrue(false); } catch (Exception $e) { - $this->assertTrue(is_a($e, 'Horde_Exception')); + $this->assertTrue($e instanceOf Horde_Exception); } // Test loading a missing value with a default - $this->assertEquals(0 ,$xml->_getXmlData($children, - 'date2', - array('value' => Horde_Kolab_Format_Xml::VALUE_DEFAULT, - 'default' => 0, - 'type' => Horde_Kolab_Format_Xml::TYPE_DATETIME))); + $this->assertEquals(0, $xml->_getXmlData($children, + 'date2', + array('value' => Horde_Kolab_Format_Xml::VALUE_DEFAULT, + 'default' => 0, + 'type' => Horde_Kolab_Format_Xml::TYPE_DATETIME))); // Test loading a calculated value $this->assertEquals('new1', $dxml->_getXmlData($children, - 'present1', - array('value' => Horde_Kolab_Format_Xml::VALUE_CALCULATED, - 'func' => '_calculate', - 'type' => Horde_Kolab_Format_Xml::TYPE_STRING))); + 'present1', + array('value' => Horde_Kolab_Format_Xml::VALUE_CALCULATED, + 'func' => '_calculate', + 'type' => Horde_Kolab_Format_Xml::TYPE_STRING))); // Test loading a normal value $this->assertEquals('new1', $xml->_getXmlData($children, - 'present1', - array('value' => Horde_Kolab_Format_Xml::VALUE_DEFAULT, - 'default' => 'empty', - 'type' => Horde_Kolab_Format_Xml::TYPE_STRING))); + 'present1', + array('value' => Horde_Kolab_Format_Xml::VALUE_DEFAULT, + 'default' => 'empty', + 'type' => Horde_Kolab_Format_Xml::TYPE_STRING))); // Test loading a date value $this->assertEquals(1175080008, $xml->_getXmlData($children, @@ -218,11 +239,13 @@ class Horde_Kolab_Format_XmlTest extends PHPUnit_Framework_TestCase /** * Test load/save + * + * @return NULL */ public function testReleod() { // Save an object and reload it - $xml = new Horde_Kolab_Format_Xml(); + $xml = new Horde_Kolab_Format_Xml(); $result = $xml->save(array('uid'=>'test', 'body' => 'body', 'dummy' => 'hello', @@ -240,24 +263,30 @@ class Horde_Kolab_Format_XmlTest extends PHPUnit_Framework_TestCase /** * Test complex values + * + * @return NULL */ public function testComplex() { // Continue with complex values - $xml = new Horde_Kolab_Format_Xml(); + $xml = new Horde_Kolab_Format_Xml(); $root = $xml->_prepareSave(); // Test saving a composite value $xml->_updateNode($root, - array('composite1' => array('display-name' => 'test', 'smtp-address' => 'test@example.com')), - 'composite1', $xml->_fields_simple_person); - $this->assertEquals("\n\n \n test\n test@example.com\n \n \n\n", $xml->_xmldoc->saveXML()); + array('composite1' => array('display-name' => 'test', + 'smtp-address' => 'test@example.com')), + 'composite1', $xml->_fields_simple_person); + $this->assertEquals("\n\n \n test\n test@example.com\n \n \n\n", + $xml->_xmldoc->saveXML()); // Test saving multiple values $xml->_updateNode($root, - array('attendee1' => array(array('display-name' => 'test'), array('smtp-address' => 'test@example.com'))), - 'attendee1', $xml->_fields_attendee); - $this->assertEquals("\n\n \n test\n test@example.com\n \n \n \n test\n \n none\n true\n required\n \n \n \n test@example.com\n none\n true\n required\n \n\n", $xml->_xmldoc->saveXML()); + array('attendee1' => array(array('display-name' => 'test'), + array('smtp-address' => 'test@example.com'))), + 'attendee1', $xml->_fields_attendee); + $this->assertEquals("\n\n \n test\n test@example.com\n \n \n \n test\n \n none\n true\n required\n \n \n \n test@example.com\n none\n true\n required\n \n\n", + $xml->_xmldoc->saveXML()); $children = $root->childNodes; @@ -283,24 +312,38 @@ class Horde_Kolab_Format_XmlTest extends PHPUnit_Framework_TestCase /** * A dummy XML type * - * $Horde: framework/Kolab_Format/test/Horde/Kolab/Format/XmlTest.php,v 1.5 2009/01/06 17:49:23 jan Exp $ - * * Copyright 2007-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. * - * @author Gunnar Wrobel - * @package Kolab_Format + * @category Kolab + * @package Kolab_Format + * @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_Format_Xml_dummy extends Horde_Kolab_Format_Xml +class Horde_Kolab_Format_Xml_Dummy extends Horde_Kolab_Format_Xml { + /** + * Save the object creation date. + * + * @param DOMNode $node The parent node to attach the child + * to. + * @param string $name The name of the node. + * @param mixed $value The value to store. + * @param boolean $missing Has the value been missing? + * + * @return DOMNode The new child node. + */ function _saveValue($node, $name, $value, $missing) { - $result=''; + $result =''; $result .= $name . ': '; $result .= $value; - if ($missing) $result .= ', missing'; + if ($missing) { + $result .= ', missing'; + } return $this->_saveDefault($node, $name, diff --git a/framework/Kolab_Format/test/Horde/Kolab/Format/fixtures/preferences_write_old.xml b/framework/Kolab_Format/test/Horde/Kolab/Format/fixtures/preferences_write_old.xml index d255ce27e..9a4f9835b 100644 --- a/framework/Kolab_Format/test/Horde/Kolab/Format/fixtures/preferences_write_old.xml +++ b/framework/Kolab_Format/test/Horde/Kolab/Format/fixtures/preferences_write_old.xml @@ -1,5 +1,5 @@ - + 1 @@ -9,4 +9,4 @@ Horde::Kolab Test test - +