Location: PHPKode > scripts > Craur > Craur-1.7.4/tests/filters_with_class_test.php
<?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'
        )
    ) 
));

class FiltersWithClassTest
{
    static public function myFilterCallback($value) {
        return str_replace('cm', '', $value);
    }
}

/*
 * Test to rewrite the value with a filter
 */
$height = $node->getWithFilter('hide@address.com', "FiltersWithClassTest::myFilterCallback");

assert($height == "50");

/*
 * Test default value
 */
$width = $node->getWithFilter('hide@address.com', "FiltersWithClassTest::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!
     */
}
Return current item: Craur