Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start extracting a better representation of the Kolab data object.
- Loading branch information
Showing
4 changed files
with
216 additions
and
6 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Data/Exception.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
/** | ||
* The exception marker for data specific Horde_Kolab_Storage errors. | ||
* | ||
* PHP version 5 | ||
* | ||
* @category Kolab | ||
* @package Kolab_Storage | ||
* @author Gunnar Wrobel <wrobel@pardus.de> | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @link http://pear.horde.org/index.php?package=Kolab_Storage | ||
*/ | ||
|
||
/** | ||
* The exception marker for data specific Horde_Kolab_Storage errors. | ||
* | ||
* Copyright 2012 Horde LLC (http://www.horde.org/) | ||
* | ||
* See the enclosed file COPYING for license information (LGPL). If you | ||
* did not receive this file, see http://www.horde.org/licenses/lgpl21. | ||
* | ||
* @category Kolab | ||
* @package Kolab_Storage | ||
* @author Gunnar Wrobel <wrobel@pardus.de> | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @link http://pear.horde.org/index.php?package=Kolab_Storage | ||
*/ | ||
class Horde_Kolab_Storage_Data_Exception extends Horde_Exception_Wrapped | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Data/Object/Content.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
/** | ||
* Generates the core Kolab content. | ||
* | ||
* PHP version 5 | ||
* | ||
* @category Kolab | ||
* @package Kolab_Storage | ||
* @author Gunnar Wrobel <wrobel@pardus.de> | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @link http://pear.horde.org/index.php?package=Kolab_Storage | ||
*/ | ||
|
||
/** | ||
* Generates the core Kolab content. | ||
* | ||
* Copyright 2011-2012 Horde LLC (http://www.horde.org/) | ||
* | ||
* See the enclosed file COPYING for license information (LGPL). If you | ||
* did not receive this file, see http://www.horde.org/licenses/lgpl21. | ||
* | ||
* @category Kolab | ||
* @package Kolab_Storage | ||
* @author Gunnar Wrobel <wrobel@pardus.de> | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @link http://pear.horde.org/index.php?package=Kolab_Storage | ||
*/ | ||
class Horde_Kolab_Storage_Data_Object_Content | ||
{ | ||
/** | ||
* Kolab format handler. | ||
* | ||
* @var Horde_Kolab_Format | ||
*/ | ||
private $_format; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param Horde_Kolab_Format $format The Kolab format handler. | ||
*/ | ||
public function __construct(Horde_Kolab_Format $format) | ||
{ | ||
$this->_format = $format; | ||
} | ||
|
||
/** | ||
* Create the Kolab content as a string. | ||
* | ||
* @param array $object The object data. | ||
* | ||
* @return string The Kolab content. | ||
*/ | ||
public function create(array $object) | ||
{ | ||
try { | ||
return $this->_format->save($object); | ||
} catch (Horde_Kolab_Format_Exception $e) { | ||
throw new Horde_Kolab_Storage_Data_Exception( | ||
'Failed saving Kolab object!', 0, $e | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Modify a previous Kolab object. | ||
* | ||
* @param array $object The new object data. | ||
* @param string $previous The previous data. | ||
* | ||
* @return string The new Kolab content. | ||
*/ | ||
public function modify(array $object, $previous) | ||
{ | ||
try { | ||
return $this->_format->save( | ||
$object, array('previous' => $previous) | ||
); | ||
} catch (Horde_Kolab_Format_Exception $e) { | ||
throw new Horde_Kolab_Storage_Data_Exception( | ||
'Failed saving Kolab object!', 0, $e | ||
); | ||
} | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Data/Object/ContentTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
/** | ||
* Test the Kolab content handler. | ||
* | ||
* PHP version 5 | ||
* | ||
* @category Kolab | ||
* @package Kolab_Storage | ||
* @subpackage UnitTests | ||
* @author Gunnar Wrobel <wrobel@pardus.de> | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @link http://pear.horde.org/index.php?package=Kolab_Storage | ||
*/ | ||
|
||
/** | ||
* Prepare the test setup. | ||
*/ | ||
require_once __DIR__ . '/../../../Autoload.php'; | ||
|
||
/** | ||
* Test the Kolab content handler. | ||
* | ||
* Copyright 2011-2012 Horde LLC (http://www.horde.org/) | ||
* | ||
* See the enclosed file COPYING for license information (LGPL). If you | ||
* did not receive this file, see http://www.horde.org/licenses/lgpl21. | ||
* | ||
* @category Kolab | ||
* @package Kolab_Storage | ||
* @subpackage UnitTests | ||
* @author Gunnar Wrobel <wrobel@pardus.de> | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @link http://pear.horde.org/index.php?package=Kolab_Storage | ||
*/ | ||
class Horde_Kolab_Storage_Unit_Data_Object_ContentTest | ||
extends PHPUnit_Framework_TestCase | ||
{ | ||
public function testCreate() | ||
{ | ||
$format = $this->getMock('Horde_Kolab_Format'); | ||
$format->expects($this->once()) | ||
->method('save') | ||
->with(array('foo' => 'foo')) | ||
->will($this->returnValue('<event/>')); | ||
$content = new Horde_Kolab_Storage_Data_Object_Content($format); | ||
$this->assertEquals( | ||
'<event/>', $content->create(array('foo' => 'foo')) | ||
); | ||
} | ||
|
||
/** | ||
* @expectedException Horde_Kolab_Storage_Data_Exception | ||
*/ | ||
public function testCreateWithException() | ||
{ | ||
$format = $this->getMock('Horde_Kolab_Format'); | ||
$format->expects($this->once()) | ||
->method('save') | ||
->with(array('foo' => 'foo')) | ||
->will($this->throwException(new Horde_Kolab_Format_Exception())); | ||
$content = new Horde_Kolab_Storage_Data_Object_Content($format); | ||
$content->create(array('foo' => 'foo')); | ||
} | ||
|
||
public function testModify() | ||
{ | ||
$format = $this->getMock('Horde_Kolab_Format'); | ||
$format->expects($this->once()) | ||
->method('save') | ||
->with(array('foo' => 'foo'), array('previous' => '<event/>')) | ||
->will($this->returnValue('<event><modified/></event>')); | ||
$content = new Horde_Kolab_Storage_Data_Object_Content($format); | ||
$this->assertEquals( | ||
'<event><modified/></event>', | ||
$content->modify(array('foo' => 'foo'), '<event/>') | ||
); | ||
} | ||
|
||
/** | ||
* @expectedException Horde_Kolab_Storage_Data_Exception | ||
*/ | ||
public function testModifyWithException() | ||
{ | ||
$format = $this->getMock('Horde_Kolab_Format'); | ||
$format->expects($this->once()) | ||
->method('save') | ||
->with(array('foo' => 'foo'), array('previous' => '<event/>')) | ||
->will($this->throwException(new Horde_Kolab_Format_Exception())); | ||
$content = new Horde_Kolab_Storage_Data_Object_Content($format); | ||
$content->modify(array('foo' => 'foo'), '<event/>'); | ||
} | ||
|
||
} |