|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Mouf\Html\Renderer; |
|
4
|
|
|
|
|
5
|
|
|
use Mouf\Html\Renderer\Fixtures\Foo; |
|
6
|
|
|
use Mouf\Html\Renderer\Fixtures\MyImplementation; |
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use Simplex\Container; |
|
9
|
|
|
use Symfony\Component\Cache\Simple\ArrayCache; |
|
10
|
|
|
|
|
11
|
|
|
class ChainRendererTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function testFind() |
|
14
|
|
|
{ |
|
15
|
|
|
$container = new Container(); |
|
16
|
|
|
|
|
17
|
|
|
$container->set('customRenderer1', function() use ($container) { |
|
18
|
|
|
return new FileBasedRenderer( |
|
19
|
|
|
'tests/customTemplates', |
|
20
|
|
|
new ArrayCache(), |
|
21
|
|
|
$container |
|
22
|
|
|
); |
|
23
|
|
|
}); |
|
24
|
|
|
$container->set('packageRenderer1', function() use ($container) { |
|
25
|
|
|
return new FileBasedRenderer( |
|
26
|
|
|
'tests/templates', |
|
27
|
|
|
new ArrayCache(), |
|
28
|
|
|
$container |
|
29
|
|
|
); |
|
30
|
|
|
}); |
|
31
|
|
|
$container->set('templateRenderer', function() use ($container) { |
|
32
|
|
|
return new FileBasedRenderer( |
|
33
|
|
|
'tests/templateTemplates', |
|
34
|
|
|
new ArrayCache(), |
|
35
|
|
|
$container |
|
36
|
|
|
); |
|
37
|
|
|
}); |
|
38
|
|
|
|
|
39
|
|
|
$chainRenderer = new ChainRenderer($container, ['customRenderer1'], ['packageRenderer1'], new ArrayCache(), 'uniqueName'); |
|
40
|
|
|
|
|
41
|
|
|
ob_start(); |
|
42
|
|
|
$chainRenderer->render(new Foo()); |
|
43
|
|
|
$html = ob_get_clean(); |
|
44
|
|
|
$this->assertSame('Foo', $html); |
|
45
|
|
|
|
|
46
|
|
|
// Same test, for cache testing |
|
47
|
|
|
ob_start(); |
|
48
|
|
|
$chainRenderer->render(new Foo()); |
|
49
|
|
|
$html = ob_get_clean(); |
|
50
|
|
|
$this->assertSame('Foo', $html); |
|
51
|
|
|
|
|
52
|
|
|
$chainRenderer->setTemplateRendererInstanceName('templateRenderer'); |
|
53
|
|
|
|
|
54
|
|
|
ob_start(); |
|
55
|
|
|
$chainRenderer->render(new Foo()); |
|
56
|
|
|
$html = ob_get_clean(); |
|
57
|
|
|
$this->assertSame('FooTemplate', $html); |
|
58
|
|
|
|
|
59
|
|
|
$this->expectException(NoRendererFoundException::class); |
|
60
|
|
|
$this->expectExceptionMessage('Renderer not found. Unable to find renderer for object of class \'stdClass\'. Path tested: Testing renderer for directory \'tests/customTemplates\' |
|
61
|
|
|
Tested file: tests/customTemplates/stdClass__context.twig |
|
62
|
|
|
Tested file: tests/customTemplates/stdClass__context.php |
|
63
|
|
|
Tested file: tests/customTemplates/stdClass.twig |
|
64
|
|
|
Tested file: tests/customTemplates/stdClass.php |
|
65
|
|
|
Testing renderer for directory \'tests/templateTemplates\' |
|
66
|
|
|
Tested file: tests/templateTemplates/stdClass__context.twig |
|
67
|
|
|
Tested file: tests/templateTemplates/stdClass__context.php |
|
68
|
|
|
Tested file: tests/templateTemplates/stdClass.twig |
|
69
|
|
|
Tested file: tests/templateTemplates/stdClass.php |
|
70
|
|
|
Testing renderer for directory \'tests/templates\' |
|
71
|
|
|
Tested file: tests/templates/stdClass__context.twig |
|
72
|
|
|
Tested file: tests/templates/stdClass__context.php |
|
73
|
|
|
Tested file: tests/templates/stdClass.twig |
|
74
|
|
|
Tested file: tests/templates/stdClass.php |
|
75
|
|
|
'); |
|
76
|
|
|
$chainRenderer->render(new \stdClass(), 'context'); |
|
77
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|