|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Kunstmaan\AdminBundle\Tests\Helper\Menu; |
|
4
|
|
|
|
|
5
|
|
|
use Kunstmaan\AdminBundle\Helper\Menu\MenuAdaptorInterface; |
|
6
|
|
|
use Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder; |
|
7
|
|
|
use Kunstmaan\AdminBundle\Helper\Menu\SimpleMenuAdaptor; |
|
8
|
|
|
use Kunstmaan\AdminBundle\Helper\Menu\TopMenuItem; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
11
|
|
|
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; |
|
12
|
|
|
|
|
13
|
|
|
class SimpleMenuAdaptorTest extends TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
/** @var AuthorizationCheckerInterface (mock) */ |
|
16
|
|
|
private $authorizationCheckerInterface; |
|
17
|
|
|
|
|
18
|
|
|
/** @var array */ |
|
19
|
|
|
private $menuItems; |
|
20
|
|
|
|
|
21
|
|
|
public function setUp() |
|
22
|
|
|
{ |
|
23
|
|
|
$this->authorizationCheckerInterface = $this->createMock(AuthorizationCheckerInterface::class); |
|
|
|
|
|
|
24
|
|
|
$this->menuItems = []; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @return \PHPUnit\Framework\MockObject\MockObject|SimpleMenuAdaptor |
|
29
|
|
|
*/ |
|
30
|
|
|
public function setUpSimpleMenuAdaptorMock() |
|
31
|
|
|
{ |
|
32
|
|
|
$simpleMenuAdaptorMock = $this->getMockBuilder(SimpleMenuAdaptor::class) |
|
33
|
|
|
->setConstructorArgs([$this->authorizationCheckerInterface, $this->menuItems]) |
|
34
|
|
|
->setMethods(null) |
|
35
|
|
|
->getMock() |
|
36
|
|
|
; |
|
37
|
|
|
|
|
38
|
|
|
return $simpleMenuAdaptorMock; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @dataProvider provider |
|
43
|
|
|
* |
|
44
|
|
|
* @param TopMenuItem|null $parent |
|
45
|
|
|
*/ |
|
46
|
|
|
public function testAdaptChildren(?TopMenuItem $parent, ?string $itemParent) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->menuItems[] = ['parent' => 'not_test_route']; |
|
49
|
|
|
|
|
50
|
|
|
$this->menuItems[] = [ |
|
51
|
|
|
'role' => 'some_role', |
|
52
|
|
|
'parent' => $itemParent, |
|
53
|
|
|
]; |
|
54
|
|
|
|
|
55
|
|
|
$this->menuItems[] = [ |
|
56
|
|
|
'role' => 'some_role', |
|
57
|
|
|
'parent' => $itemParent, |
|
58
|
|
|
'route' => 'KunstmaanAdminBundle_menu_item', |
|
59
|
|
|
'params' => [], |
|
60
|
|
|
'label' => 'menu_item', |
|
61
|
|
|
]; |
|
62
|
|
|
|
|
63
|
|
|
$children = []; |
|
64
|
|
|
|
|
65
|
|
|
/** @var MenuBuilder $menuBuilderMock */ |
|
66
|
|
|
$menuBuilderMock = $this->createMock(MenuBuilder::class); |
|
67
|
|
|
|
|
68
|
|
|
/** @var Request $request */ |
|
69
|
|
|
$request = new Request([], [], ['_route' => 'KunstmaanAdminBundle_menu_item']); |
|
70
|
|
|
|
|
71
|
|
|
$this->authorizationCheckerInterface |
|
|
|
|
|
|
72
|
|
|
->expects($this->exactly(2)) |
|
73
|
|
|
->method('isGranted') |
|
74
|
|
|
->will($this->onConsecutiveCalls(false, true)) |
|
75
|
|
|
; |
|
76
|
|
|
$simpleMenuAdaptorMock = $this->setUpSimpleMenuAdaptorMock(); |
|
77
|
|
|
$simpleMenuAdaptorMock->adaptChildren($menuBuilderMock, $children, $parent, $request); |
|
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
$this->assertCount(1, $children); |
|
|
|
|
|
|
80
|
|
|
$this->assertContainsOnlyInstancesOf(TopMenuItem::class, $children); |
|
81
|
|
|
$this->assertEquals('menu_item', $children[0]->getLabel()); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function testHasInterface() |
|
85
|
|
|
{ |
|
86
|
|
|
$simpleMenuAdaptorMock = $this->setUpSimpleMenuAdaptorMock(); |
|
87
|
|
|
$this->assertInstanceOf(MenuAdaptorInterface::class, $simpleMenuAdaptorMock); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function provider() |
|
91
|
|
|
{ |
|
92
|
|
|
/** @var TopMenuItem $parent */ |
|
93
|
|
|
$parent = $this->createMock(TopMenuItem::class); |
|
94
|
|
|
$parent |
|
|
|
|
|
|
95
|
|
|
->expects($this->any()) |
|
96
|
|
|
->method('getRoute') |
|
97
|
|
|
->willReturn('test_route') |
|
98
|
|
|
; |
|
99
|
|
|
|
|
100
|
|
|
return [ |
|
101
|
|
|
'with no parent' => [null, null], |
|
102
|
|
|
'with parent' => [$parent, 'test_route'], |
|
103
|
|
|
]; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..