From a1f5cae4e84cfa8c5637a96a60a913290ac6e7ac Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel
Date: Mon, 29 Jun 2009 07:55:55 +0200 Subject: [PATCH] Error handling. --- framework/Kolab_Format/lib/Horde/Kolab/Format.php | 3 +-- .../Kolab_Format/lib/Horde/Kolab/Format/XML.php | 10 ++++++---- .../lib/Horde/Kolab/Format/XML/Annotation.php | 3 --- .../lib/Horde/Kolab/Format/XML/Contact.php | 3 --- .../Horde/Kolab/Format/XML/Distributionlist.php | 3 --- .../lib/Horde/Kolab/Format/XML/Event.php | 3 --- .../lib/Horde/Kolab/Format/XML/Hprefs.php | 4 ++-- .../lib/Horde/Kolab/Format/XML/Note.php | 3 --- .../lib/Horde/Kolab/Format/XML/Task.php | 3 --- .../test/Horde/Kolab/Format/ContactTest.php | 15 -------------- .../test/Horde/Kolab/Format/EventTest.php | 6 ------ .../test/Horde/Kolab/Format/PreferencesTest.php | 9 --------- .../test/Horde/Kolab/Format/RecurrenceTest.php | 23 +--------------------- 13 files changed, 10 insertions(+), 78 deletions(-) diff --git a/framework/Kolab_Format/lib/Horde/Kolab/Format.php b/framework/Kolab_Format/lib/Horde/Kolab/Format.php index 98fc90d44..37dc3f47b 100644 --- a/framework/Kolab_Format/lib/Horde/Kolab/Format.php +++ b/framework/Kolab_Format/lib/Horde/Kolab/Format.php @@ -47,8 +47,7 @@ abstract class Horde_Kolab_Format * * 'version' - The format version. * - * @return mixed The newly created concrete Horde_Kolab_Format_XML instance, or - * a PEAR error. + * @return mixed The newly created concrete Horde_Kolab_Format_XML instance * * @throws Horde_Exception If the specified driver could not be loaded. */ diff --git a/framework/Kolab_Format/lib/Horde/Kolab/Format/XML.php b/framework/Kolab_Format/lib/Horde/Kolab/Format/XML.php index 080d161f5..5297eae82 100644 --- a/framework/Kolab_Format/lib/Horde/Kolab/Format/XML.php +++ b/framework/Kolab_Format/lib/Horde/Kolab/Format/XML.php @@ -364,9 +364,11 @@ class Horde_Kolab_Format_XML * @param string $object_type The object type that should be handled. * @param array $params Any additional parameters. * - * @return Horde_Kolab_Format_XML|PEAR_Error The newly created concrete - * Horde_Kolab_Format_XML - * instance. + * @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 + * not be loaded. */ public function &factory($object_type = '', $params = null) { @@ -476,7 +478,7 @@ class Horde_Kolab_Format_XML * * @param array $children An array of XML nodes. * - * @return array|PEAR_Error The data array representing the object. + * @return array The data array representing the object. * * @throws Horde_Exception If parsing the XML data failed. */ diff --git a/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Annotation.php b/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Annotation.php index ced6102e5..61a14b522 100644 --- a/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Annotation.php +++ b/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Annotation.php @@ -71,9 +71,6 @@ class Horde_Kolab_Format_XML_Annotation extends Horde_Kolab_Format_XML protected function _load(&$children) { $object = $this->_loadArray($children, $this->_fields_specific); - if (is_a($object, 'PEAR_Error')) { - return $object; - } $result = array(); foreach ($object['annotation'] as $annotation) { diff --git a/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Contact.php b/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Contact.php index 6be0db1ea..44f4783a7 100644 --- a/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Contact.php +++ b/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Contact.php @@ -313,9 +313,6 @@ class Horde_Kolab_Format_XML_Contact extends Horde_Kolab_Format_XML protected function _load(&$children) { $object = $this->_loadArray($children, $this->_fields_specific); - if (is_a($object, 'PEAR_Error')) { - return $object; - } // Handle name fields if (isset($object['name'])) { diff --git a/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Distributionlist.php b/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Distributionlist.php index 47c60ab32..0e784687e 100644 --- a/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Distributionlist.php +++ b/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Distributionlist.php @@ -73,9 +73,6 @@ class Horde_Kolab_Format_XML_Distributionlist extends Horde_Kolab_Format_XML protected function _load(&$children) { $object = $this->_loadArray($children, $this->_fields_specific); - if (is_a($object, 'PEAR_Error')) { - return $object; - } // Map the display-name of a kolab dist list to horde's lastname attribute if (isset($object['display-name'])) { 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 ab6261d17..63b5df70c 100644 --- a/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Event.php +++ b/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Event.php @@ -100,9 +100,6 @@ class Horde_Kolab_Format_XML_Event extends Horde_Kolab_Format_XML protected function _load(&$children) { $object = parent::_load($children); - if (is_a($object, 'PEAR_Error')) { - return $object; - } // Translate start/end date including full day events if (strlen($object['start-date']) == 10) { diff --git a/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Hprefs.php b/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Hprefs.php index d51f79599..8f63c715f 100644 --- a/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Hprefs.php +++ b/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Hprefs.php @@ -87,7 +87,7 @@ class Horde_Kolab_Format_XML_Hprefs extends Horde_Kolab_Format_XML $object['application'] = $object['categories']; unset($object['categories']); } else { - return PEAR::raiseError('Preferences XML object is missing an application setting.'); + throw new Horde_Exception('Preferences XML object is missing an application setting.'); } } @@ -110,7 +110,7 @@ class Horde_Kolab_Format_XML_Hprefs extends Horde_Kolab_Format_XML $object['application'] = $object['categories']; unset($object['categories']); } else { - return PEAR::raiseError('Preferences XML object is missing an application setting.'); + throw new Horde_Exception('Preferences XML object is missing an application setting.'); } } diff --git a/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Note.php b/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Note.php index a8e986d82..c15bb6420 100644 --- a/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Note.php +++ b/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Note.php @@ -79,9 +79,6 @@ class Horde_Kolab_Format_XML_Note extends Horde_Kolab_Format_XML protected function _load(&$children) { $object = $this->_loadArray($children, $this->_fields_specific); - if (is_a($object, 'PEAR_Error')) { - return $object; - } $object['desc'] = $object['summary']; unset($object['summary']); diff --git a/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Task.php b/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Task.php index 748167e99..48bb5bf95 100644 --- a/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Task.php +++ b/framework/Kolab_Format/lib/Horde/Kolab/Format/XML/Task.php @@ -124,9 +124,6 @@ class Horde_Kolab_Format_XML_Task extends Horde_Kolab_Format_XML protected function _load(&$children) { $object = $this->_loadArray($children, $this->_fields_specific); - if (is_a($object, 'PEAR_Error')) { - return $object; - } $object['name'] = $object['summary']; unset($object['summary']); diff --git a/framework/Kolab_Format/test/Horde/Kolab/Format/ContactTest.php b/framework/Kolab_Format/test/Horde/Kolab/Format/ContactTest.php index a1ac2291a..3ebde17bd 100644 --- a/framework/Kolab_Format/test/Horde/Kolab/Format/ContactTest.php +++ b/framework/Kolab_Format/test/Horde/Kolab/Format/ContactTest.php @@ -82,9 +82,6 @@ class Horde_Kolab_Format_ContactTest extends PHPUnit_Framework_TestCase 'full-name' => 'User Name', 'email' => 'user@example.org'); $xml = $contact->save($object); - if (is_a($xml, 'PEAR_Error')) { - $this->assertEquals('', $xml->getMessage()); - } $expect = file_get_contents(dirname(__FILE__) . '/fixtures/contact_mail.xml'); $this->assertEquals($expect, $xml); } @@ -100,9 +97,6 @@ class Horde_Kolab_Format_ContactTest extends PHPUnit_Framework_TestCase 'pgp-publickey' => 'PGP Test Key', 'email' => 'user@example.org'); $xml = $contact->save($object); - if (is_a($xml, 'PEAR_Error')) { - $this->assertEquals('', $xml->getMessage()); - } $expect = file_get_contents(dirname(__FILE__) . '/fixtures/contact_pgp.xml'); $this->assertEquals($expect, $xml); } @@ -117,16 +111,10 @@ class Horde_Kolab_Format_ContactTest extends PHPUnit_Framework_TestCase $contact = &new Horde_Kolab_Format_XML_contact(); $xml = file_get_contents(dirname(__FILE__) . '/fixtures/contact_category.xml'); $object = $contact->load($xml); - if (is_a($object, 'PEAR_Error')) { - $this->assertEquals('', $object->getMessage()); - } $this->assertContains('Test', $object['categories']); $prefs = 'some string'; $object = $contact->load($xml); - if (is_a($object, 'PEAR_Error')) { - $this->assertEquals('', $object->getMessage()); - } $this->assertContains('Test', $object['categories']); } @@ -150,9 +138,6 @@ class Horde_Kolab_Format_ContactTest extends PHPUnit_Framework_TestCase $xml = file_get_contents(dirname(__FILE__) . '/fixtures/contact_category.xml'); $object = $contact->load($xml); - if (is_a($object, 'PEAR_Error')) { - $this->assertEquals('', $object->getMessage()); - } $this->assertContains('Test', $object['categories']); $this->assertEquals('Test', $prefs->getValue('categories')); } diff --git a/framework/Kolab_Format/test/Horde/Kolab/Format/EventTest.php b/framework/Kolab_Format/test/Horde/Kolab/Format/EventTest.php index 03ddb8dd1..019bd2425 100644 --- a/framework/Kolab_Format/test/Horde/Kolab/Format/EventTest.php +++ b/framework/Kolab_Format/test/Horde/Kolab/Format/EventTest.php @@ -46,22 +46,16 @@ class Horde_Kolab_Format_EventTest extends PHPUnit_Framework_TestCase public function testIssue3525() { $xml = Horde_Kolab_Format::factory('XML', 'event'); - if (is_a($xml, 'PEAR_Error')) { - $this->assertEquals('', $xml->getMessage()); - } // Load XML $event = file_get_contents(dirname(__FILE__) . '/fixtures/event_umlaut.xml'); $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...'); // Load XML $event = file_get_contents(dirname(__FILE__) . '/fixtures/event_umlaut_broken.xml'); $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...'); } diff --git a/framework/Kolab_Format/test/Horde/Kolab/Format/PreferencesTest.php b/framework/Kolab_Format/test/Horde/Kolab/Format/PreferencesTest.php index c3c6b94b9..7884cb448 100644 --- a/framework/Kolab_Format/test/Horde/Kolab/Format/PreferencesTest.php +++ b/framework/Kolab_Format/test/Horde/Kolab/Format/PreferencesTest.php @@ -75,9 +75,6 @@ class Horde_Kolab_Format_PreferencesTest extends PHPUnit_Framework_TestCase $xml = file_get_contents(dirname(__FILE__) . '/fixtures/preferences_read_old.xml'); $object = $preferences->load($xml); - if (is_a($object, 'PEAR_Error')) { - $this->assertEquals('', $object->getMessage()); - } $this->assertContains('test', $object['pref']); $this->assertEquals('Test', $object['application']); @@ -85,9 +82,6 @@ class Horde_Kolab_Format_PreferencesTest extends PHPUnit_Framework_TestCase 'pref' => array('test'), 'categories' => 'Test'); $xml = $preferences->save($object); - if (is_a($xml, 'PEAR_Error')) { - $this->assertEquals('', $xml->getMessage()); - } $expect = file_get_contents(dirname(__FILE__) . '/fixtures/preferences_write_old.xml'); $this->assertEquals($expect, $xml); @@ -95,9 +89,6 @@ class Horde_Kolab_Format_PreferencesTest extends PHPUnit_Framework_TestCase 'pref' => array('test'), 'application' => 'Test'); $xml = $preferences->save($object); - if (is_a($xml, 'PEAR_Error')) { - $this->assertEquals('', $xml->getMessage()); - } $expect = file_get_contents(dirname(__FILE__) . '/fixtures/preferences_write_old.xml'); $this->assertEquals($expect, $xml); } diff --git a/framework/Kolab_Format/test/Horde/Kolab/Format/RecurrenceTest.php b/framework/Kolab_Format/test/Horde/Kolab/Format/RecurrenceTest.php index c2db3d8a9..54b49cc8d 100644 --- a/framework/Kolab_Format/test/Horde/Kolab/Format/RecurrenceTest.php +++ b/framework/Kolab_Format/test/Horde/Kolab/Format/RecurrenceTest.php @@ -54,23 +54,17 @@ class Horde_Kolab_Format_RecurrenceTest extends PHPUnit_Framework_TestCase public function testBug6388() { $xml = Horde_Kolab_Format::factory('XML', 'event'); - if (is_a($xml, 'PEAR_Error')) { - $this->assertEquals('', $xml->getMessage()); - } // Load XML $recur = file_get_contents(dirname(__FILE__) . '/fixtures/recur.xml'); - // Check that the xml loads fine - $this->assertFalse(is_a($xml->load($recur), 'PEAR_Error')); - // Load XML $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 try { - $this->assertTrue(is_a($xml->load($recur), 'PEAR_Error')); + $xml->load($recur); $this->assertTrue(false); } catch (Exception $e) { $this->assertTrue(is_a($e, 'Horde_Exception')); @@ -84,17 +78,11 @@ class Horde_Kolab_Format_RecurrenceTest extends PHPUnit_Framework_TestCase public function testExceptions() { $xml = Horde_Kolab_Format::factory('XML', 'event'); - if (is_a($xml, 'PEAR_Error')) { - $this->assertEquals('', $xml->getMessage()); - } // Load XML $recur = file_get_contents(dirname(__FILE__) . '/fixtures/recur.xml'); $object = $xml->load($recur); - if (is_a($object, 'PEAR_Error')) { - $this->ensureEquals('', $object->getMessage()); - } $r = &new Horde_Date_Recurrence($object['start-date']); $r->fromHash($object['recurrence']); @@ -107,9 +95,6 @@ class Horde_Kolab_Format_RecurrenceTest extends PHPUnit_Framework_TestCase $recur = $xml->save($object); $object = $xml->load($recur); - if (is_a($object, 'PEAR_Error')) { - $this->ensureEquals('', $object->getMessage()); - } $s = &new Horde_Date_Recurrence($object['start-date']); $s->fromHash($object['recurrence']); @@ -125,9 +110,6 @@ class Horde_Kolab_Format_RecurrenceTest extends PHPUnit_Framework_TestCase public function testCompletions() { $xml = Horde_Kolab_Format::factory('XML', 'event'); - if (is_a($xml, 'PEAR_Error')) { - $this->assertEquals('', $xml->getMessage()); - } $r = &new Horde_Date_Recurrence(0); $r->setRecurType(Horde_Date_Recurrence::RECUR_DAILY); @@ -141,9 +123,6 @@ class Horde_Kolab_Format_RecurrenceTest extends PHPUnit_Framework_TestCase $object['recurrence'] = $r->toHash(); $recur = $xml->save($object); $object = $xml->load($recur); - if (is_a($object, 'PEAR_Error')) { - $this->ensureEquals('', $object->getMessage()); - } $s = &new Horde_Date_Recurrence(0); $s->fromHash($object['recurrence']); -- 2.11.0