1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Devmachine\Bundle\FormBundle\Tests\Twig; |
4
|
|
|
|
5
|
|
|
use Devmachine\Bundle\FormBundle\Twig\GenemuFormExtension; |
6
|
|
|
use Symfony\Component\Form\FormView; |
7
|
|
|
|
8
|
|
|
class GenemuFormExtensionTest extends \PHPUnit_Framework_TestCase |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @test |
12
|
|
|
*/ |
13
|
|
|
public function it_registers_functions() |
14
|
|
|
{ |
15
|
|
|
$twig = new \Twig_Environment(new \Twig_Loader_Array()); |
16
|
|
|
$twig->addExtension(new GenemuFormExtension($this->makeMock('Symfony\Component\Form\FormRendererInterface'))); |
17
|
|
|
|
18
|
|
|
$f1 = $twig->getFunction('form_javascript'); |
19
|
|
|
$f2 = $twig->getFunction('form_stylesheet'); |
20
|
|
|
|
21
|
|
|
$this->assertInstanceOf('Twig_SimpleFunction', $f1); |
22
|
|
|
$this->assertInstanceOf('Twig_SimpleFunction', $f2); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @test |
27
|
|
|
*/ |
28
|
|
|
public function it_proxies_to_form_renderer() |
29
|
|
|
{ |
30
|
|
|
$view = new FormView(); |
31
|
|
|
|
32
|
|
|
$renderer = $this->makeMock('Symfony\Component\Form\FormRendererInterface'); |
33
|
|
|
$renderer |
34
|
|
|
->expects($this->exactly(3)) |
35
|
|
|
->method('searchAndRenderBlock') |
36
|
|
|
->withConsecutive( |
37
|
|
|
[$this->equalTo($view), 'javascript'], |
38
|
|
|
[$this->equalTo($view), 'javascript_prototype'], |
39
|
|
|
[$this->equalTo($view), 'stylesheet'] |
40
|
|
|
) |
41
|
|
|
; |
42
|
|
|
|
43
|
|
|
$twig = new \Twig_Environment(new \Twig_Loader_Array()); |
44
|
|
|
$twig->addExtension(new GenemuFormExtension($renderer)); |
45
|
|
|
|
46
|
|
|
call_user_func($twig->getFunction('form_javascript')->getCallable(), $view); |
47
|
|
|
call_user_func($twig->getFunction('form_javascript')->getCallable(), $view, true); |
48
|
|
|
call_user_func($twig->getFunction('form_stylesheet')->getCallable(), $view); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
private function makeMock($originalClassName) |
52
|
|
|
{ |
53
|
|
|
if (method_exists($this, 'createMock')) { |
54
|
|
|
return $this->createMock($originalClassName); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return $this->getMock($originalClassName); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.