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 <tt>$format</tt> variable created above now provides the means to
save and load events in Kolab XML format. In order to save an event we
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.
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';
*/
$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();
}
}
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.
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',
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".
/**
* 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 <wrobel@pardus.de>
+ * @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(
/**
* 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 <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
- * @package Kolab_Format
+ * @category Kolab
+ * @package Kolab_Format
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @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
/**
* Constructor
*/
- function Horde_Kolab_Format_XML_string()
+ function __construct()
{
$this->_root_name = 'string';
*/
$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(
*
* 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
*
* 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
--- /dev/null
+<?php
+/**
+ * Kolab Format error handling.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package Kolab_Format
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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
*
* 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
/**
* The XML document this driver works with.
*
- * @var Horde_DOM_Document
+ * @var DOMDocument
*
* @todo Make protected (fix the XmlTest for that)
*/
* 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;
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));
}
/**
* 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
}
$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
// 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;
/**
* 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)
{
/**
* 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;
* @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)
*/
{
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;
}
}
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
$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']);
/**
* 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)
{
/**
* 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)
{
/**
* 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;
/**
* 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;
$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) {
/**
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) {
$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']),
/**
* 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);
/**
* 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;
}
* @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;
}
+ }
}
}
}
/**
- * 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.
*/
/**
* 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)
{
/**
* 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)
{
* 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)
{
/**
* 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)
{
/**
* 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)
* 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
*/
$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) {
* 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
*/
// Check for multiple categories.
if (!isset($object['_categories_all'])
|| !isset($object['_categories_primary'])
- || !isset($object['categories']))
- {
+ || !isset($object['categories'])) {
return;
}
/**
* 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)
{
/**
* 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)
{
/**
* 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.
*/
/**
* 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)
{
/**
* 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.
*/
/**
* 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)
{
/**
* 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)
{
// 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');
// 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');
}
// 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');
}
}
/**
* 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 <day>
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 <day>
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);
}
}
}
/**
* 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)
{
// 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";
// 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";
*
* 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
*
* 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
$emails = explode(',', $object['emails']);
}
- if (isset($object['email']) &&
+ if (isset($object['email']) &&
!in_array($object['email'], $emails)) {
$emails[] = $object['email'];
}
*
* 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
*
* 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
*
* 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
*
* 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
*
* 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
$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'];
}
<file name="Format.php" role="php" />
<dir name="Format">
<file name="Date.php" role="php" />
+ <file name="Exception.php" role="php" />
<file name="Xml.php" role="php" />
<dir name="Xml">
<file name="Annotation.php" role="php" />
<min>1.4.0b1</min>
</pearinstaller>
<package>
+ <name>Exception</name>
+ <channel>pear.horde.org</channel>
+ </package>
+ <package>
<name>Nls</name>
<channel>pear.horde.org</channel>
</package>
<install name="examples/Horde/Kolab/Format/new_type.php" as="Horde/Kolab/Format/new_type.php" />
<install name="lib/Horde/Kolab/Format.php" as="Horde/Kolab/Format.php" />
<install name="lib/Horde/Kolab/Format/Date.php" as="Horde/Kolab/Format/Date.php" />
+ <install name="lib/Horde/Kolab/Format/Exception.php" as="Horde/Kolab/Format/Exception.php" />
<install name="lib/Horde/Kolab/Format/Xml.php" as="Horde/Kolab/Format/Xml.php" />
<install name="lib/Horde/Kolab/Format/Xml/Annotation.php" as="Horde/Kolab/Format/Xml/Annotation.php" />
<install name="lib/Horde/Kolab/Format/Xml/Contact.php" as="Horde/Kolab/Format/Xml/Contact.php" />
/**
* 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 <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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) {
/**
* 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 <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Server
*/
/**
*/
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 <wrobel@pardus.de>
- * @package Kolab_Format
+ * @category Kolab
+ * @package Kolab_Format
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @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()
{
/**
* 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()
{
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'));
}
}
+
+/**
+ * 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 <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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
/**
* 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 <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Server
*/
/**
/**
* 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 <wrobel@pardus.de>
- * @package Kolab_Format
+ * @category Kolab
+ * @package Kolab_Format
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @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()
{
/**
* 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...');
}
}
/**
* 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
/**
* 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
/**
* 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 <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Server
*/
/**
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 <wrobel@pardus.de>
- * @package Kolab_Format
+ * @category Kolab
+ * @package Kolab_Format
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @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()
{
/**
* 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']);
$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 <wrobel@pardus.de>
+ * @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
/**
* 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 <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Server
*/
/**
/**
* 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 <wrobel@pardus.de>
- * @package Kolab_Format
+ * @category Kolab
+ * @package Kolab_Format
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @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');
/**
* Test for http://bugs.horde.org/ticket/?id=6388
+ *
+ * @return NULL
*/
public function testBug6388()
{
$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
$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()
{
$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);
$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());
/**
* 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 <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Server
*/
/**
/**
* 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 <wrobel@pardus.de>
- * @package Kolab_Format
+ * @category Kolab
+ * @package Kolab_Format
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @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()
{
/**
* 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("<?xml version=\"1.0\"?>\n<kolab version=\"1.0\"/>\n", $base);
+ $this->assertEquals("<?xml version=\"1.0\"?>\n<kolab version=\"1.0\"/>\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);
/**
* 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();
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,
'empty1',
array('value' => Horde_Kolab_Format_Xml::VALUE_DEFAULT,
'default' => 'empty1', 'type' => 0));
- $this->assertEquals("<?xml version=\"1.0\"?>\n<kolab version=\"1.0\">\n <empty1>empty1</empty1>\n</kolab>\n", $xml->_xmldoc->saveXML());
+ $this->assertEquals("<?xml version=\"1.0\"?>\n<kolab version=\"1.0\">\n <empty1>empty1</empty1>\n</kolab>\n",
+ $xml->_xmldoc->saveXML());
try {
$xml->_updateNode($root,
'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("<?xml version=\"1.0\"?>\n<kolab version=\"1.0\">\n <empty2>empty2: , missing</empty2>\n <present1>present1: present1</present1>\n</kolab>\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("<?xml version=\"1.0\"?>\n<kolab version=\"1.0\">\n <empty2>empty2: , missing</empty2>\n <present1>present1: present1</present1>\n</kolab>\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("<?xml version=\"1.0\"?>\n<kolab version=\"1.0\">\n <empty1>empty1</empty1>\n <present1>present1</present1>\n</kolab>\n", $xml->_xmldoc->saveXML());
+ array('present1' => 'present1'),
+ 'present1',
+ array('value' => Horde_Kolab_Format_Xml::VALUE_DEFAULT,
+ 'default' => 'empty1', 'type' => 0));
+ $this->assertEquals("<?xml version=\"1.0\"?>\n<kolab version=\"1.0\">\n <empty1>empty1</empty1>\n <present1>present1</present1>\n</kolab>\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("<?xml version=\"1.0\"?>\n<kolab version=\"1.0\">\n <empty1>empty1</empty1>\n <present1>new1</present1>\n</kolab>\n", $xml->_xmldoc->saveXML());
+ array('present1' => 'new1'),
+ 'present1',
+ array('value' => Horde_Kolab_Format_Xml::VALUE_DEFAULT,
+ 'default' => 'empty1', 'type' => 0));
+ $this->assertEquals("<?xml version=\"1.0\"?>\n<kolab version=\"1.0\">\n <empty1>empty1</empty1>\n <present1>new1</present1>\n</kolab>\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("<?xml version=\"1.0\"?>\n<kolab version=\"1.0\">\n <empty1>empty1</empty1>\n <present1>new1</present1>\n <date1>2007-03-28T11:06:48Z</date1>\n</kolab>\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("<?xml version=\"1.0\"?>\n<kolab version=\"1.0\">\n <empty1>empty1</empty1>\n <present1>new1</present1>\n <date1>2007-03-28T11:06:48Z</date1>\n</kolab>\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 {
'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,
/**
* 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',
/**
* 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("<?xml version=\"1.0\"?>\n<kolab version=\"1.0\">\n <composite1>\n <display-name>test</display-name>\n <smtp-address>test@example.com</smtp-address>\n <uid></uid>\n </composite1>\n</kolab>\n", $xml->_xmldoc->saveXML());
+ array('composite1' => array('display-name' => 'test',
+ 'smtp-address' => 'test@example.com')),
+ 'composite1', $xml->_fields_simple_person);
+ $this->assertEquals("<?xml version=\"1.0\"?>\n<kolab version=\"1.0\">\n <composite1>\n <display-name>test</display-name>\n <smtp-address>test@example.com</smtp-address>\n <uid></uid>\n </composite1>\n</kolab>\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("<?xml version=\"1.0\"?>\n<kolab version=\"1.0\">\n <composite1>\n <display-name>test</display-name>\n <smtp-address>test@example.com</smtp-address>\n <uid></uid>\n </composite1>\n <attendee1>\n <display-name>test</display-name>\n <smtp-address></smtp-address>\n <status>none</status>\n <request-response>true</request-response>\n <role>required</role>\n </attendee1>\n <attendee1>\n <display-name></display-name>\n <smtp-address>test@example.com</smtp-address>\n <status>none</status>\n <request-response>true</request-response>\n <role>required</role>\n </attendee1>\n</kolab>\n", $xml->_xmldoc->saveXML());
+ array('attendee1' => array(array('display-name' => 'test'),
+ array('smtp-address' => 'test@example.com'))),
+ 'attendee1', $xml->_fields_attendee);
+ $this->assertEquals("<?xml version=\"1.0\"?>\n<kolab version=\"1.0\">\n <composite1>\n <display-name>test</display-name>\n <smtp-address>test@example.com</smtp-address>\n <uid></uid>\n </composite1>\n <attendee1>\n <display-name>test</display-name>\n <smtp-address></smtp-address>\n <status>none</status>\n <request-response>true</request-response>\n <role>required</role>\n </attendee1>\n <attendee1>\n <display-name></display-name>\n <smtp-address>test@example.com</smtp-address>\n <status>none</status>\n <request-response>true</request-response>\n <role>required</role>\n </attendee1>\n</kolab>\n",
+ $xml->_xmldoc->saveXML());
$children = $root->childNodes;
/**
* 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 <wrobel@pardus.de>
- * @package Kolab_Format
+ * @category Kolab
+ * @package Kolab_Format
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @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,
<?xml version="1.0"?>
-<contact version="1.0">
+<h-prefs version="1.0">
<uid>1</uid>
<body></body>
<categories></categories>
<product-id>Horde::Kolab</product-id>
<application>Test</application>
<pref>test</pref>
-</contact>
+</h-prefs>