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\Route; |
13
|
|
|
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
use Sonata\AdminBundle\Admin\AdminInterface; |
16
|
|
|
use Sonata\AdminBundle\Admin\Pool; |
17
|
|
|
use Sonata\AdminBundle\Route\AdminPoolLoader; |
18
|
|
|
use Sonata\AdminBundle\Route\RouteCollection; |
19
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
20
|
|
|
use Symfony\Component\Routing\Route as SymfonyRoute; |
21
|
|
|
use Symfony\Component\Routing\RouteCollection as SymfonyRouteCollection; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @author Andrej Hudec <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class AdminPoolLoaderTest extends TestCase |
27
|
|
|
{ |
28
|
|
|
public function testSupports() |
29
|
|
|
{ |
30
|
|
|
$container = $this->getMockForAbstractClass(ContainerInterface::class); |
31
|
|
|
$pool = $this->getMockBuilder(Pool::class) |
32
|
|
|
->setMethods([]) |
33
|
|
|
->setConstructorArgs([$container, 'title', 'logoTitle']) |
34
|
|
|
->getMock(); |
35
|
|
|
|
36
|
|
|
$adminPoolLoader = new AdminPoolLoader($pool, ['foo_admin', 'bar_admin'], $container); |
37
|
|
|
|
38
|
|
|
$this->assertTrue($adminPoolLoader->supports('foo', 'sonata_admin')); |
39
|
|
|
$this->assertFalse($adminPoolLoader->supports('foo', 'bar')); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testLoad() |
43
|
|
|
{ |
44
|
|
|
$container = $this->getMockForAbstractClass(ContainerInterface::class); |
45
|
|
|
$pool = $this->getMockBuilder(Pool::class) |
46
|
|
|
->setMethods([]) |
47
|
|
|
->setConstructorArgs([$container, 'title', 'logoTitle']) |
48
|
|
|
->getMock(); |
49
|
|
|
|
50
|
|
|
$adminPoolLoader = new AdminPoolLoader($pool, ['foo_admin', 'bar_admin'], $container); |
51
|
|
|
|
52
|
|
|
$routeCollection1 = new RouteCollection('base.Code.Route.foo', 'baseRouteNameFoo', 'baseRoutePatternFoo', 'baseControllerNameFoo'); |
53
|
|
|
$routeCollection2 = new RouteCollection('base.Code.Route.bar', 'baseRouteNameBar', 'baseRoutePatternBar', 'baseControllerNameBar'); |
54
|
|
|
|
55
|
|
|
$routeCollection1->add('foo'); |
56
|
|
|
$routeCollection2->add('bar'); |
57
|
|
|
$routeCollection2->add('baz'); |
58
|
|
|
|
59
|
|
|
$admin1 = $this->getMockForAbstractClass(AdminInterface::class); |
60
|
|
|
$admin1->expects($this->once()) |
61
|
|
|
->method('getRoutes') |
62
|
|
|
->will($this->returnValue($routeCollection1)); |
63
|
|
|
|
64
|
|
|
$admin2 = $this->getMockForAbstractClass(AdminInterface::class); |
65
|
|
|
$admin2->expects($this->once()) |
66
|
|
|
->method('getRoutes') |
67
|
|
|
->will($this->returnValue($routeCollection2)); |
68
|
|
|
|
69
|
|
|
$pool->expects($this->any()) |
70
|
|
|
->method('getInstance') |
71
|
|
|
->will($this->returnCallback(function ($id) use ($admin1, $admin2) { |
72
|
|
|
switch ($id) { |
73
|
|
|
case 'foo_admin': |
74
|
|
|
return $admin1; |
75
|
|
|
case 'bar_admin': |
76
|
|
|
return $admin2; |
77
|
|
|
} |
78
|
|
|
})); |
79
|
|
|
|
80
|
|
|
$collection = $adminPoolLoader->load('foo', 'sonata_admin'); |
81
|
|
|
|
82
|
|
|
$this->assertInstanceOf(SymfonyRouteCollection::class, $collection); |
83
|
|
|
$this->assertInstanceOf(SymfonyRoute::class, $collection->get('baseRouteNameFoo_foo')); |
84
|
|
|
$this->assertInstanceOf(SymfonyRoute::class, $collection->get('baseRouteNameBar_bar')); |
85
|
|
|
$this->assertInstanceOf(SymfonyRoute::class, $collection->get('baseRouteNameBar_bar')); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|