Skip to content

Commit

Permalink
[EZP-28180] Adding function "create" to simplify the creation of a ez…
Browse files Browse the repository at this point in the history
…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 fc42f72
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
25 changes: 24 additions & 1 deletion kernel/classes/ezsitedata.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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 )
{
Expand Down
16 changes: 16 additions & 0 deletions tests/tests/kernel/classes/ezsitedata_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.