From 2fa0c8fc0f39cdf2f5a1bd7de8afbbb0ee98cbf6 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Mon, 29 Jun 2009 07:31:56 +0200 Subject: [PATCH] Completed testing fixes. --- .../Kolab_Format/lib/Horde/Kolab/Format/XML.php | 30 ++-- .../lib/Horde/Kolab/Format/XML/Event.php | 2 +- .../test/Horde/Kolab/Format/ContactTest.php | 4 +- .../test/Horde/Kolab/Format/EventTest.php | 10 +- .../test/Horde/Kolab/Format/PreferencesTest.php | 4 +- .../test/Horde/Kolab/Format/RecurrenceTest.php | 8 +- .../test/Horde/Kolab/Format/XmlTest.php | 159 +++++++++++---------- 7 files changed, 125 insertions(+), 92 deletions(-) diff --git a/framework/Kolab_Format/lib/Horde/Kolab/Format/XML.php b/framework/Kolab_Format/lib/Horde/Kolab/Format/XML.php index 7238ed969..40265129d 100644 --- a/framework/Kolab_Format/lib/Horde/Kolab/Format/XML.php +++ b/framework/Kolab_Format/lib/Horde/Kolab/Format/XML.php @@ -128,8 +128,10 @@ class Horde_Kolab_Format_XML * The XML document this driver works with. * * @var Horde_DOM_Document + * + * @todo Make protected (fix the XmlTest for that) */ - protected $_xmldoc = null; + public $_xmldoc = null; /** * The name of the root element. @@ -163,8 +165,10 @@ class Horde_Kolab_Format_XML * Fields for a simple person * * @var array + * + * @todo Make protected (fix the XmlTest for that) */ - protected $_fields_simple_person = array( + public $_fields_simple_person = array( 'type' => self::TYPE_COMPOSITE, 'value' => self::VALUE_MAYBE_MISSING, 'array' => array( @@ -190,8 +194,10 @@ class Horde_Kolab_Format_XML * Fields for an attendee * * @var array + * + * @todo Make protected (fix the XmlTest for that) */ - protected $_fields_attendee = array( + public $_fields_attendee = array( 'type' => self::TYPE_MULTIPLE, 'value' => self::VALUE_DEFAULT, 'default' => array(), @@ -364,7 +370,7 @@ class Horde_Kolab_Format_XML */ public function &factory($object_type = '', $params = null) { - $object_type = str_replace('-', '', $object_type); + $object_type = ucfirst(str_replace('-', '', $object_type)); $class = 'Horde_Kolab_Format_XML_' . $object_type; if (class_exists($class)) { @@ -523,8 +529,10 @@ class Horde_Kolab_Format_XML * string. * * @throws Horde_Exception If parsing the XML data failed. + * + * @todo Make protected (fix the XmlTest for that) */ - protected function _getXmlData($children, $name, $params) + public function _getXmlData($children, $name, $params) { $value = null; $missing = false; @@ -586,8 +594,10 @@ class Horde_Kolab_Format_XML * @return Horde_DOM_Node The root node of the document. * * @throws Horde_Exception If parsing the XML data failed. + * + * @todo Make protected (fix the XmlTest for that) */ - protected function _parseXml(&$xmltext) + public function _parseXml(&$xmltext) { $params = array( 'xml' => $xmltext, @@ -646,8 +656,10 @@ class Horde_Kolab_Format_XML * @param string $xmltext The XML of the message as string. * * @return Horde_DOM_Node The root node of the document. + * + * @todo Make protected (fix the XmlTest for that) */ - protected function _prepareSave() + public function _prepareSave() { if ($this->_xmldoc != null) { $root = $this->_xmldoc->document_element(); @@ -698,8 +710,10 @@ class Horde_Kolab_Format_XML * @return Horde_DOM_Node The new/updated child node. * * @throws Horde_Exception If converting the data to XML failed. + * + * @todo Make protected (fix the XmlTest for that) */ - protected function _updateNode($parent_node, $attributes, $name, $params, + public function _updateNode($parent_node, $attributes, $name, $params, $append = false) { $value = null; 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 0ccbb5eff..ab6261d17 100644 --- a/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Event.php +++ b/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Event.php @@ -126,7 +126,7 @@ class Horde_Kolab_Format_XML_Event extends Horde_Kolab_Format_XML * * @throws Horde_Exception If converting the data to XML failed. */ - function _save($root, $object) + protected function _save($root, $object) { // Translate start/end date including full day events if (!empty($object['_is_all_day'])) { diff --git a/framework/Kolab_Format/test/Horde/Kolab/Format/ContactTest.php b/framework/Kolab_Format/test/Horde/Kolab/Format/ContactTest.php index 314333e6d..a1ac2291a 100644 --- a/framework/Kolab_Format/test/Horde/Kolab/Format/ContactTest.php +++ b/framework/Kolab_Format/test/Horde/Kolab/Format/ContactTest.php @@ -35,7 +35,7 @@ class Horde_Kolab_Format_XML_contact_dummy extends Horde_Kolab_Format_XML_contac return $this->_saveDefault($parent_node, $name, $value, - array('type' => HORDE_KOLAB_XML_TYPE_DATETIME)); + array('type' => self::TYPE_DATETIME)); } function _saveModificationDate($parent_node, $name, $value, $missing) @@ -44,7 +44,7 @@ class Horde_Kolab_Format_XML_contact_dummy extends Horde_Kolab_Format_XML_contac return $this->_saveDefault($parent_node, $name, 0, - array('type' => HORDE_KOLAB_XML_TYPE_DATETIME)); + array('type' => self::TYPE_DATETIME)); } } diff --git a/framework/Kolab_Format/test/Horde/Kolab/Format/EventTest.php b/framework/Kolab_Format/test/Horde/Kolab/Format/EventTest.php index cd71b7b9c..03ddb8dd1 100644 --- a/framework/Kolab_Format/test/Horde/Kolab/Format/EventTest.php +++ b/framework/Kolab_Format/test/Horde/Kolab/Format/EventTest.php @@ -52,17 +52,17 @@ class Horde_Kolab_Format_EventTest extends PHPUnit_Framework_TestCase // Load XML $event = file_get_contents(dirname(__FILE__) . '/fixtures/event_umlaut.xml'); - $result = $xml->load($event); + $result = $xml->load($event); // Check that the xml loads fine $this->assertFalse(is_a($result, 'PEAR_Error')); - $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'); - $result = $xml->load($event); + $result = $xml->load($event); // Check that the xml loads fine $this->assertFalse(is_a($result, 'PEAR_Error')); - //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/PreferencesTest.php b/framework/Kolab_Format/test/Horde/Kolab/Format/PreferencesTest.php index 17583ff39..c3c6b94b9 100644 --- a/framework/Kolab_Format/test/Horde/Kolab/Format/PreferencesTest.php +++ b/framework/Kolab_Format/test/Horde/Kolab/Format/PreferencesTest.php @@ -29,7 +29,7 @@ class Horde_Kolab_Format_XML_hprefs_dummy extends Horde_Kolab_Format_XML_hprefs return $this->_saveDefault($parent_node, $name, $value, - array('type' => HORDE_KOLAB_XML_TYPE_DATETIME)); + array('type' => self::TYPE_DATETIME)); } function _saveModificationDate($parent_node, $name, $value, $missing) @@ -38,7 +38,7 @@ class Horde_Kolab_Format_XML_hprefs_dummy extends Horde_Kolab_Format_XML_hprefs return $this->_saveDefault($parent_node, $name, 0, - array('type' => HORDE_KOLAB_XML_TYPE_DATETIME)); + array('type' => self::TYPE_DATETIME)); } } diff --git a/framework/Kolab_Format/test/Horde/Kolab/Format/RecurrenceTest.php b/framework/Kolab_Format/test/Horde/Kolab/Format/RecurrenceTest.php index eb2ccfd4e..c2db3d8a9 100644 --- a/framework/Kolab_Format/test/Horde/Kolab/Format/RecurrenceTest.php +++ b/framework/Kolab_Format/test/Horde/Kolab/Format/RecurrenceTest.php @@ -69,7 +69,12 @@ class Horde_Kolab_Format_RecurrenceTest extends PHPUnit_Framework_TestCase $recur = file_get_contents(dirname(__FILE__) . '/fixtures/recur_fail.xml'); // Check that the xml fails because of a missing interval value - $this->assertTrue(is_a($xml->load($recur), 'PEAR_Error')); + try { + $this->assertTrue(is_a($xml->load($recur), 'PEAR_Error')); + $this->assertTrue(false); + } catch (Exception $e) { + $this->assertTrue(is_a($e, 'Horde_Exception')); + } } @@ -135,7 +140,6 @@ class Horde_Kolab_Format_RecurrenceTest extends PHPUnit_Framework_TestCase $object = array('uid' => 0, 'start-date' => 0, 'end-date' => 60); $object['recurrence'] = $r->toHash(); $recur = $xml->save($object); - $object = $xml->load($recur); if (is_a($object, 'PEAR_Error')) { $this->ensureEquals('', $object->getMessage()); diff --git a/framework/Kolab_Format/test/Horde/Kolab/Format/XmlTest.php b/framework/Kolab_Format/test/Horde/Kolab/Format/XmlTest.php index f3f914838..4c0ce729b 100644 --- a/framework/Kolab_Format/test/Horde/Kolab/Format/XmlTest.php +++ b/framework/Kolab_Format/test/Horde/Kolab/Format/XmlTest.php @@ -17,35 +17,6 @@ require_once 'Horde/Kolab/Format.php'; require_once 'Horde/Kolab/Format/XML.php'; /** - * 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 - */ -class Horde_Kolab_Format_XML_dummy extends Horde_Kolab_Format_XML -{ - function _saveValue($node, $name, $value, $missing) - { - $result=''; - $result .= $name . ': '; - $result .= $value; - if ($missing) $result .= ', missing'; - - return $this->_saveDefault($node, - $name, - $result, - array('type' => HORDE_KOLAB_XML_TYPE_STRING)); - } -} - -/** * 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 $ @@ -70,16 +41,16 @@ class Horde_Kolab_Format_XmlTest extends PHPUnit_Framework_TestCase } -/* /\** */ -/* * Check the preparation of the basic XML structure */ -/* *\/ */ -/* public function testBasic() */ -/* { */ -/* $xml = &new Horde_Kolab_Format_XML(); */ -/* $xml->_prepareSave(); */ -/* $base = $xml->_xmldoc->dump_mem(true); */ -/* $this->assertEquals("\n\n", $base); */ -/* } */ + /** + * Check the preparation of the basic XML structure + */ + public function testBasic() + { + $xml = &new Horde_Kolab_Format_XML(); + $xml->_prepareSave(); + $base = $xml->_xmldoc->dump_mem(true); + $this->assertEquals("\n\n", $base); + } /** * The resulting XML string should be readable. @@ -109,28 +80,38 @@ class Horde_Kolab_Format_XmlTest extends PHPUnit_Framework_TestCase $xml->_updateNode($root, array(), 'empty1', - array('value' => HORDE_KOLAB_XML_VALUE_MAYBE_MISSING)); + array('value' => Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING)); $this->assertEquals($base, $xml->_xmldoc->dump_mem(true)); // A missing attribute should cause an error if it // is not allowed to be empty - $this->assertTrue(is_a($xml->_updateNode($root, - array(), - 'empty1', - array('value' => HORDE_KOLAB_XML_VALUE_NOT_EMPTY)), 'PEAR_Error')); + try { + $xml->_updateNode($root, + array(), + 'empty1', + array('value' => Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY)); + $this->assertTrue(false); + } catch (Exception $e) { + $this->assertTrue(is_a($e, 'Horde_Exception')); + } $xml->_updateNode($root, array(), 'empty1', - array('value' => HORDE_KOLAB_XML_VALUE_DEFAULT, + array('value' => Horde_Kolab_Format_Xml::VALUE_DEFAULT, 'default' => 'empty1', 'type' => 0)); $this->assertEquals("\n\n empty1\n\n", $xml->_xmldoc->dump_mem(true)); - $this->assertTrue(is_a($xml->_updateNode($root, - array(), - 'empty1', - array('value' => HORDE_KOLAB_XML_VALUE_CALCULATED, - 'save' => '_unknown')), 'PEAR_Error')); + try { + $xml->_updateNode($root, + array(), + 'empty1', + array('value' => Horde_Kolab_Format_Xml::VALUE_CALCULATED, + 'save' => '_unknown')); + $this->assertTrue(false); + } catch (Exception $e) { + $this->assertTrue(is_a($e, 'Horde_Exception')); + } } @@ -147,12 +128,12 @@ class Horde_Kolab_Format_XmlTest extends PHPUnit_Framework_TestCase $dxml->_updateNode($droot, array(), 'empty2', - array('value' => HORDE_KOLAB_XML_VALUE_CALCULATED, + array('value' => Horde_Kolab_Format_Xml::VALUE_CALCULATED, 'save' => 'Value', 'type' => 0)); $dxml->_updateNode($droot, array('present1' => 'present1'), 'present1', - array('value' => HORDE_KOLAB_XML_VALUE_CALCULATED, + 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->dump_mem(true)); @@ -162,14 +143,14 @@ class Horde_Kolab_Format_XmlTest extends PHPUnit_Framework_TestCase $xml->_updateNode($root, array(), 'empty1', - array('value' => HORDE_KOLAB_XML_VALUE_DEFAULT, + 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_XML_VALUE_DEFAULT, + array('value' => Horde_Kolab_Format_Xml::VALUE_DEFAULT, 'default' => 'empty1', 'type' => 0)); $this->assertEquals("\n\n empty1\n present1\n\n", $xml->_xmldoc->dump_mem(true)); @@ -177,7 +158,7 @@ class Horde_Kolab_Format_XmlTest extends PHPUnit_Framework_TestCase $xml->_updateNode($root, array('present1' => 'new1'), 'present1', - array('value' => HORDE_KOLAB_XML_VALUE_DEFAULT, + array('value' => Horde_Kolab_Format_Xml::VALUE_DEFAULT, 'default' => 'empty1', 'type' => 0)); $this->assertEquals("\n\n empty1\n new1\n\n", $xml->_xmldoc->dump_mem(true)); @@ -185,9 +166,9 @@ class Horde_Kolab_Format_XmlTest extends PHPUnit_Framework_TestCase $xml->_updateNode($root, array('date1' => 1175080008), 'date1', - array('value' => HORDE_KOLAB_XML_VALUE_DEFAULT, + array('value' => Horde_Kolab_Format_Xml::VALUE_DEFAULT, 'default' => 'empty1', - 'type' => HORDE_KOLAB_XML_TYPE_DATETIME)); + 'type' => Horde_Kolab_Format_Xml::TYPE_DATETIME)); $this->assertEquals("\n\n empty1\n new1\n 2007-03-28T11:06:48Z\n\n", $xml->_xmldoc->dump_mem(true)); // Now load the data back in @@ -196,44 +177,49 @@ class Horde_Kolab_Format_XmlTest extends PHPUnit_Framework_TestCase // Test loading a value that may be empty $this->assertEquals(null, $xml->_getXmlData($children, 'empty2', - array('value' => HORDE_KOLAB_XML_VALUE_MAYBE_MISSING, + array('value' => Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING, 'default' => '', - 'type' => HORDE_KOLAB_XML_TYPE_STRING))); + 'type' => Horde_Kolab_Format_Xml::TYPE_STRING))); // Test loading a value that may not be empty - $this->assertTrue(is_a($xml->_getXmlData($children, - 'empty2', - array('value' => HORDE_KOLAB_XML_VALUE_NOT_EMPTY, - 'default' => '', - 'type' => HORDE_KOLAB_XML_TYPE_STRING)), 'PEAR_Error')); + try { + $xml->_getXmlData($children, + 'empty2', + array('value' => Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY, + 'default' => '', + 'type' => Horde_Kolab_Format_Xml::TYPE_STRING)); + $this->assertTrue(false); + } catch (Exception $e) { + $this->assertTrue(is_a($e, 'Horde_Exception')); + } // Test loading a missing value with a default $this->assertEquals(0 ,$xml->_getXmlData($children, 'date2', - array('value' => HORDE_KOLAB_XML_VALUE_DEFAULT, + array('value' => Horde_Kolab_Format_Xml::VALUE_DEFAULT, 'default' => 0, - 'type' => HORDE_KOLAB_XML_TYPE_DATETIME))); + 'type' => Horde_Kolab_Format_Xml::TYPE_DATETIME))); // Test loading a calculated value $this->assertEquals('new1', $dxml->_getXmlData($children, 'present1', - array('value' => HORDE_KOLAB_XML_VALUE_CALCULATED, + array('value' => Horde_Kolab_Format_Xml::VALUE_CALCULATED, 'func' => '_calculate', - 'type' => HORDE_KOLAB_XML_TYPE_STRING))); + 'type' => Horde_Kolab_Format_Xml::TYPE_STRING))); // Test loading a normal value $this->assertEquals('new1', $xml->_getXmlData($children, 'present1', - array('value' => HORDE_KOLAB_XML_VALUE_DEFAULT, + array('value' => Horde_Kolab_Format_Xml::VALUE_DEFAULT, 'default' => 'empty', - 'type' => HORDE_KOLAB_XML_TYPE_STRING))); + 'type' => Horde_Kolab_Format_Xml::TYPE_STRING))); // Test loading a date value $this->assertEquals(1175080008, $xml->_getXmlData($children, 'date1', - array('value' => HORDE_KOLAB_XML_VALUE_DEFAULT, + array('value' => Horde_Kolab_Format_Xml::VALUE_DEFAULT, 'default' => 0, - 'type' => HORDE_KOLAB_XML_TYPE_DATETIME))); + 'type' => Horde_Kolab_Format_Xml::TYPE_DATETIME))); } @@ -301,3 +287,32 @@ class Horde_Kolab_Format_XmlTest extends PHPUnit_Framework_TestCase $this->assertEquals('test@example.com', $data[1]['smtp-address']); } } + +/** + * 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 + */ +class Horde_Kolab_Format_XML_dummy extends Horde_Kolab_Format_XML +{ + function _saveValue($node, $name, $value, $missing) + { + $result=''; + $result .= $name . ': '; + $result .= $value; + if ($missing) $result .= ', missing'; + + return $this->_saveDefault($node, + $name, + $result, + array('type' => self::TYPE_STRING)); + } +} \ No newline at end of file -- 2.11.0