Test function for TwigReferenceFunctions class
function testTwigReferenceFunctions() {
// Create wrapper
$content =& $this->variables;
// Use twig nomenclature
$context['content'] = $content;
// Twig converts {{ hide(content.baz) }} to the following code
// This will have failed, because getAttribute returns a value and not a reference
try {
if (isset($context["content"])) {
$_content_ = $context["content"];
}
else {
$_content_ = NULL;
}
TwigReferenceFunctions::hide($this
->getAttribute($_content_, "baz"));
} catch (Exception $e) {
// Catch the critical warning that a value was passed by reference
}
$this
->assertFalse(isset($content['baz']['#printed']), 'baz is not hidden in content after hide() via value');
// Now lets do the same with some TwigReference magic!
$content_wrapper = new TwigReference();
$content_wrapper
->setReference($content);
$context['content'] = $content_wrapper;
// Twig converts {{ hide(content.baz) }} to the following code
// This will succeed, because getAttribute returns a value, but it is an object
if (isset($context["content"])) {
$_content_ = $context["content"];
}
else {
$_content_ = NULL;
}
TwigReferenceFunctions::hide($this
->getAttribute($_content_, "baz"));
$this
->assertTrue(isset($content['baz']['#printed']), 'baz is hidden in content after hide() via TwigReference object');
$type = TwigReferenceFunctions::gettype($this
->getAttribute($_content_, "baz"));
$this
->assertEqual($type, 'array', 'Type returned via TwigReferenceFunctions:: is an array.');
$type = gettype($this
->getAttribute($_content_, "baz"));
$this
->assertEqual($type, 'object', 'Type returned without TwigReferenceFunctions:: is an object.');
}