<?php
$node = new Craur(array(
'animals' => array(
array(
'@name' => 'dog',
'@age' => 6,
'@height' => '50cm'
),
array(
'@name' => 'cat',
'@age' => 2,
'@height' => '30cm'
),
array(
'@name' => 'mouse',
'@age' => 2,
'@height' => '10cm'
)
)
));
function myFilterCallback($value) {
return str_replace('cm', '', $value);
};
/*
* Test to rewrite the value with a filter
*/
$height = $node->getWithFilter('hide@address.com', "myFilterCallback");
assert($height == "50");
/*
* Test default value
*/
$width = $node->getWithFilter('hide@address.com', "myFilterCallback", '100');
assert($width == "100");
/*
* Test with invalid callback
*/
try
{
$node->getWithFilter('hide@address.com', new stdClass());
assert(false);
}
catch (Exception $exception)
{
/*
* This was no callback, so it must fail! Nice!
*/
}
/*
* Test with invalid path and no default value
*/
try
{
$node->getWithFilter('hide@address.com', "myFilterCallback");
assert(false);
}
catch (Exception $exception)
{
/*
* The path was invalid, so it must fail! Nice!
*/
}