Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

Commit

Permalink
Implemented Flow template engine adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
aimeos committed Jan 21, 2017
1 parent cc06f91 commit 4fbb133
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
55 changes: 55 additions & 0 deletions lib/custom/src/MW/View/Engine/Flow.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/**
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
* @copyright Aimeos (aimeos.org), 2017
* @package MW
* @subpackage View
*/


namespace Aimeos\MW\View\Engine;


/**
* Flow view engine implementation
*
* @package MW
* @subpackage View
*/
class Flow implements Iface
{
private $view;


/**
* Initializes the view object
*
* @param \TYPO3\Fluid\View\StandaloneView $view Flow template view object
*/
public function __construct( \TYPO3\Fluid\View\StandaloneView $view )
{
$this->view = $view;
}


/**
* Renders the output based on the given template file name and the key/value pairs
*
* @param \Aimeos\MW\View\Iface $view View object
* @param string $filename File name of the view template
* @param array $values Associative list of key/value pairs
* @return string Output generated by the template
* @throws \Aimeos\MW\View\Exception If the template isn't found
*/
public function render( \Aimeos\MW\View\Iface $view, $filename, array $values )
{
$fluid = clone $this->view;

$fluid->setTemplatePathAndFilename( $filename );
$fluid->assign( '_aimeos_view', $view );
$fluid->assignMultiple( $values );

return $fluid->render();
}
}
47 changes: 47 additions & 0 deletions lib/custom/tests/MW/View/Engine/FlowTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
* @copyright Aimeos (aimeos.org), 2017
*/

namespace Aimeos\MW\View\Engine;


class Typo3Test extends \PHPUnit_Framework_TestCase
{
private $object;
private $mock;


protected function setUp()
{
$this->mock = $this->getMockBuilder( '\TYPO3\Fluid\View\StandaloneView' )
->setMethods( array( 'assign', 'assignMultiple', 'render', 'setTemplatePathAndFilename' ) )
->disableOriginalConstructor()
->getMock();

$this->object = new \Aimeos\MW\View\Engine\Flow( $this->mock );
}


protected function tearDown()
{
unset( $this->object, $this->mock );
}


public function testRender()
{
$v = new \Aimeos\MW\View\Standard( array() );

$this->mock->expects( $this->once() )->method( 'setTemplatePathAndFilename' );
$this->mock->expects( $this->once() )->method( 'assignMultiple' );
$this->mock->expects( $this->once() )->method( 'assign' );
$this->mock->expects( $this->once() )->method( 'render' )
->will( $this->returnValue( 'test' ) );

$result = $this->object->render( $v, 'filepath', array( 'key' => 'value' ) );
$this->assertEquals( 'test', $result );
}
}

0 comments on commit 4fbb133

Please sign in to comment.