This repository has been archived by the owner on Jul 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented Flow template engine adapter
- Loading branch information
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} | ||
} |