|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2023 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Aimeos\Base\View\Engine; |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class TwigTest extends \PHPUnit\Framework\TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
private $object; |
|
14
|
|
|
private $mock; |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
protected function setUp() : void |
|
18
|
|
|
{ |
|
19
|
|
|
if( !class_exists( '\Twig\Environment' ) ) { |
|
20
|
|
|
$this->markTestSkipped( 'Twig\Environment is not available' ); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
$this->mock = $this->getMockBuilder( '\Twig\Environment' ) |
|
24
|
|
|
->onlyMethods( array( 'getExtensions', 'getLoader', 'loadTemplate' ) ) |
|
25
|
|
|
->disableOriginalConstructor() |
|
26
|
|
|
->getMock(); |
|
27
|
|
|
|
|
28
|
|
|
$this->object = new \Aimeos\Base\View\Engine\Twig( $this->mock ); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
protected function tearDown() : void |
|
33
|
|
|
{ |
|
34
|
|
|
unset( $this->object, $this->mock ); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
public function testRender() |
|
39
|
|
|
{ |
|
40
|
|
|
$v = new \Aimeos\Base\View\Standard( [] ); |
|
41
|
|
|
|
|
42
|
|
|
$this->mock->expects( $this->any() )->method( 'getExtensions' ) |
|
43
|
|
|
->will( $this->returnValue( array( [] ) ) ); |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
$view = $this->getMockBuilder( '\Twig\Template' ) |
|
47
|
|
|
->setConstructorArgs( array( $this->mock ) ) |
|
48
|
|
|
->onlyMethods( array( 'getBlockNames', 'render', 'renderBlock' ) ) |
|
49
|
|
|
->getMockForAbstractClass(); |
|
50
|
|
|
|
|
51
|
|
|
$view->expects( $this->once() )->method( 'getBlockNames' ) |
|
52
|
|
|
->will( $this->returnValue( array( 'testblock' ) ) ); |
|
53
|
|
|
|
|
54
|
|
|
$view->expects( $this->once() )->method( 'renderBlock' ) |
|
55
|
|
|
->will( $this->returnValue( 'block content' ) ); |
|
56
|
|
|
|
|
57
|
|
|
$view->expects( $this->once() )->method( 'render' ) |
|
58
|
|
|
->will( $this->returnValue( 'test' ) ); |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
$loader = $this->getMockBuilder( '\Twig\Loader\LoaderInterface' ) |
|
62
|
|
|
->disableOriginalConstructor() |
|
63
|
|
|
->getMockForAbstractClass(); |
|
64
|
|
|
|
|
65
|
|
|
$this->mock->expects( $this->exactly( 2 ) )->method( 'getLoader' ) |
|
66
|
|
|
->will( $this->returnValue( $loader ) ); |
|
67
|
|
|
|
|
68
|
|
|
$this->mock->expects( $this->once() )->method( 'loadTemplate' ) |
|
69
|
|
|
->will( $this->returnValue( $view ) ); |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
$result = $this->object->render( $v, __FILE__, array( 'key' => 'value' ) ); |
|
73
|
|
|
$this->assertEquals( 'test', $result ); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|