My outlook is a bit different - assuming all Views share the same basic features, then we need Zend_View - helpers, filters, etc. Also it's an expansive interface even if the actual Interface file seems to have been condensed to a few basics. It's not that hard to integrate into (and well, adding another View/Renderer calls for more workI think my idea was, let's build the render tree and give the nodes the basic capabilities that we want first. Then we can look at the classes and if they are similar to Zend_View we can have multiple extended Zend_Views (Zps_View). If they are not similar then we can hang them off of a Zend_View. But let's determine what we want and build it before we think about integration.
Anyways, I took the basic interfaces, did some subclassing, added the Composites and lumped it all together with some unit tests. So there's a tested method - enough to talk about at least. Because of Zend_View's render interface, the composite methods was switched to renderAll(). Can't use the render() method since it's definition differs from what the unit tests called for.
Hopefully the Unit Tests speak for themselves.
http://w3style.co.uk/devnet-projects/pe ... tends/Zps/ for those seeking the Subversion url to read the classes. Need to run off so no time to post them all here. All the View files are in there.
Code: Select all
<?php
/**
* @package Zps_View
* @subpackage UnitTests
*/
/** Zps_View */
require_once 'Zps/View.php';
/** Zps_View_Composite */
require_once 'Zps/View/Composite.php';
/** PHPUnit_Framework_TestCase */
require_once 'PHPUnit/Framework/TestCase.php';
/**
* @package Zps_View
* @subpackage UnitTests
*/
class Zps_View_CompositeTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->errorReporting = error_reporting();
$this->displayErrors = ini_get('display_errors');
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', true);
}
public function tearDown()
{
error_reporting($this->errorReporting);
ini_set('display_errors', $this->displayErrors);
}
/**
* 'filename' is a simple stand in for a real template name which feeds
* into each composite or leaf for rendering. We're missing a method
* for sharing the scriptpath across all elements though...
*/
public function testCompositeInstantiationAndInterfaceType()
{
$composite = new Zps_View_Composite('filename');
$this->assertTrue($composite instanceof Zend_View_Interface);
$this->assertTrue($composite instanceof Zps_View_Composite_Interface);
}
public function testCompositeAddView()
{
$composite = new Zps_View_Composite('filename');
$composite->add('header', new Zps_View_Composite('filename'));
$this->assertTrue($composite->hasChildren());
}
public function testCompositeGetView()
{
$composite = new Zps_View_Composite('filename');
$composite->add('header', new Zps_View_Composite('filename'));
$this->assertTrue($composite->getChild('header') instanceof Zps_View_Composite_Interface);
}
public function testCompositeRemoveView()
{
$composite = new Zps_View_Composite('filename');
$composite->add('header', new Zps_View_Composite('filename'));
$composite->remove('header');
$this->assertFalse($composite->hasChildren());
}
public function testCompositeHasView()
{
$composite = new Zps_View_Composite('filename');
$composite->add('header', new Zps_View_Composite('filename'));
$this->assertTrue($composite->has('header'));
}
public function testCompositeTraverseViews()
{
$composite = new Zps_View_Composite('layout.phtml', array('basePath'=>realpath('./Zps/View/_files')));
$composite->add('header', new Zps_View_Composite('header.phtml'));
$composite->add('body', new Zps_View_Composite('body.phtml'));
$composite->add('footer', new Zps_View_Composite('footer.phtml'));
$response = $composite->renderAll();
$expectedResponse = file_get_contents(realpath('./Zps/View/_files/scripts/header.phtml'));
$expectedResponse .= file_get_contents(realpath('./Zps/View/_files/scripts/body.phtml'));
$expectedResponse .= file_get_contents(realpath('./Zps/View/_files/scripts/footer.phtml'));
$this->assertEquals($expectedResponse, $response);
}
}