1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sonata Project package. |
5
|
|
|
* |
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sonata\AdminBundle\Tests\Twig\Extension; |
13
|
|
|
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
use Sonata\AdminBundle\Admin\AdminInterface; |
16
|
|
|
use Sonata\AdminBundle\Admin\Pool; |
17
|
|
|
use Sonata\AdminBundle\Twig\Extension\TemplateRegistryExtension; |
18
|
|
|
use Symfony\Component\HttpFoundation\Request; |
19
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class TemplateRegistryExtensionTest. |
23
|
|
|
*/ |
24
|
|
|
class TemplateRegistryExtensionTest extends TestCase |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var TemplateRegistryExtension |
28
|
|
|
*/ |
29
|
|
|
private $extension; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var Pool |
33
|
|
|
*/ |
34
|
|
|
private $pool; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var RequestStack |
38
|
|
|
*/ |
39
|
|
|
private $requestStack; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var Request |
43
|
|
|
*/ |
44
|
|
|
private $request; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var AdminInterface |
48
|
|
|
*/ |
49
|
|
|
private $admin; |
50
|
|
|
|
51
|
|
|
protected function setUp() |
52
|
|
|
{ |
53
|
|
|
$this->request = $this->prophesize(Request::class); |
54
|
|
|
$this->pool = $this->prophesize(Pool::class); |
55
|
|
|
$this->requestStack = $this->prophesize(RequestStack::class); |
56
|
|
|
$this->admin = $this->prophesize(AdminInterface::class); |
57
|
|
|
|
58
|
|
|
$this->requestStack->getCurrentRequest()->willReturn($this->request); |
59
|
|
|
$this->request->get('_sonata_admin')->willReturn('admin.post'); |
60
|
|
|
$this->pool->getAdminByAdminCode('admin.post')->willReturn($this->admin); |
61
|
|
|
|
62
|
|
|
$this->extension = new TemplateRegistryExtension( |
63
|
|
|
$this->pool->reveal(), |
64
|
|
|
$this->requestStack->reveal() |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testGetTemplate() |
69
|
|
|
{ |
70
|
|
|
$this->admin->getTemplate('edit')->willReturn('@SonataAdmin/CRUD/edit.html.twig'); |
|
|
|
|
71
|
|
|
|
72
|
|
|
$this->assertEquals( |
73
|
|
|
'@SonataAdmin/CRUD/edit.html.twig', |
74
|
|
|
$this->extension->getTemplate('edit') |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testGetPoolTemplate() |
79
|
|
|
{ |
80
|
|
|
$this->pool->getTemplate('edit')->willReturn('@SonataAdmin/CRUD/edit.html.twig'); |
|
|
|
|
81
|
|
|
|
82
|
|
|
$this->assertEquals( |
83
|
|
|
'@SonataAdmin/CRUD/edit.html.twig', |
84
|
|
|
$this->extension->getPoolTemplate('edit') |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.