Permalink
Browse files

[EZP-28180] Adding function "create" to simplify the creation of a ez…

…sitedata entry (#1273)

* Adding function "createNew" to simplify the creation of a ezsitedata entry

* Revert to ugly array definition ;)

* Code makeup - tab to spaces
  • Loading branch information...
pkamps authored and andrerom committed Nov 27, 2017
1 parent f7dff9e commit fc42f72eec6cbbc188d39bccfb0e31314d8373be
Showing with 40 additions and 1 deletion.
  1. +24 −1 kernel/classes/ezsitedata.php
  2. +16 −0 tests/tests/kernel/classes/ezsitedata_test.php
@@ -8,11 +8,16 @@
* @package kernel
*/
/**
* eZPersistentObject implementation for ezsite_data table.
* Enables you to store and fetch key/value pairs
*
* Class eZSiteData
*/
class eZSiteData extends eZPersistentObject
{
/**
* Schema definition
* eZPersistentObject implementation for ezsite_data table
* @see kernel/classes/ezpersistentobject.php
* @return array
*/
@@ -37,9 +42,27 @@ public static function definition()
);
}
/**
* Constructs a new eZSiteData instance. You need to call 'store()'
* in order to store it into the DB.
*
* @param string $key
* @param string $value
* @return eZSiteData
*/
public static function create( $name, $value )
{
return new eZSiteData( array(
'name' => $name,
'value' => $value
) );
}
/**
* Fetches a site data by name
*
* @param string $name
* @return eZPersistentObject
*/
public static function fetchByName( $name )
{
@@ -53,6 +53,22 @@ public function testFetchByName()
$res->remove();
}
/**
* Unit test for testCreate() method
*/
public function testCreate()
{
$obj = eZSiteData::create( 'foo', 'bar' );
$obj->store();
unset( $obj );
$res = eZSiteData::fetchByName( 'foo' );
$this->assertInstanceOf( 'eZSiteData', $res );
$res->remove();
}
}
?>

0 comments on commit fc42f72

Please sign in to comment.