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\Controller; |
13
|
|
|
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
use Sonata\AdminBundle\Admin\Pool; |
16
|
|
|
use Sonata\AdminBundle\Controller\CoreController; |
17
|
|
|
use Symfony\Component\HttpFoundation\Request; |
18
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
19
|
|
|
|
20
|
|
|
class CoreControllerTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
public function testdashboardActionStandardRequest() |
23
|
|
|
{ |
24
|
|
|
$container = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface'); |
25
|
|
|
|
26
|
|
|
$pool = new Pool($container, 'title', 'logo.png'); |
27
|
|
|
$pool->setTemplates([ |
28
|
|
|
'ajax' => 'ajax.html', |
29
|
|
|
'dashboard' => 'dashboard.html', |
30
|
|
|
]); |
31
|
|
|
|
32
|
|
|
$templating = $this->createMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface'); |
33
|
|
|
$request = new Request(); |
34
|
|
|
|
35
|
|
|
$requestStack = new RequestStack(); |
36
|
|
|
$requestStack->push($request); |
37
|
|
|
|
38
|
|
|
$breadcrumbsBuilder = $this->getMockForAbstractClass('Sonata\AdminBundle\Admin\BreadcrumbsBuilderInterface'); |
39
|
|
|
|
40
|
|
|
$values = [ |
41
|
|
|
'sonata.admin.breadcrumbs_builder' => $breadcrumbsBuilder, |
42
|
|
|
'sonata.admin.pool' => $pool, |
43
|
|
|
'templating' => $templating, |
44
|
|
|
'request_stack' => $requestStack, |
45
|
|
|
]; |
46
|
|
|
|
47
|
|
|
$container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use ($values) { |
48
|
|
|
return $values[$id]; |
49
|
|
|
})); |
50
|
|
|
|
51
|
|
|
$container->expects($this->any()) |
52
|
|
|
->method('has') |
53
|
|
|
->will($this->returnCallback(function ($id) { |
54
|
|
|
if ('templating' == $id) { |
55
|
|
|
return true; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return false; |
59
|
|
|
})); |
60
|
|
|
|
61
|
|
|
$container->expects($this->any())->method('getParameter')->will($this->returnCallback(function ($name) { |
62
|
|
|
if ('sonata.admin.configuration.dashboard_blocks' == $name) { |
63
|
|
|
return []; |
64
|
|
|
} |
65
|
|
|
})); |
66
|
|
|
$container->expects($this->any())->method('has')->will($this->returnCallback(function ($id) { |
67
|
|
|
if ('templating' == $id) { |
68
|
|
|
return true; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return false; |
72
|
|
|
})); |
73
|
|
|
|
74
|
|
|
$controller = new CoreController(); |
75
|
|
|
$controller->setContainer($container); |
76
|
|
|
|
77
|
|
|
$response = $controller->dashboardAction($request); |
|
|
|
|
78
|
|
|
|
79
|
|
|
$this->isInstanceOf('Symfony\Component\HttpFoundation\Response', $response); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testdashboardActionAjaxLayout() |
83
|
|
|
{ |
84
|
|
|
$container = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface'); |
85
|
|
|
|
86
|
|
|
$pool = new Pool($container, 'title', 'logo.png'); |
87
|
|
|
$pool->setTemplates([ |
88
|
|
|
'ajax' => 'ajax.html', |
89
|
|
|
'dashboard' => 'dashboard.html', |
90
|
|
|
]); |
91
|
|
|
|
92
|
|
|
$templating = $this->createMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface'); |
93
|
|
|
$request = new Request(); |
94
|
|
|
$request->headers->set('X-Requested-With', 'XMLHttpRequest'); |
95
|
|
|
|
96
|
|
|
$requestStack = new RequestStack(); |
97
|
|
|
$requestStack->push($request); |
98
|
|
|
|
99
|
|
|
$values = [ |
100
|
|
|
'sonata.admin.pool' => $pool, |
101
|
|
|
'templating' => $templating, |
102
|
|
|
'request_stack' => $requestStack, |
103
|
|
|
]; |
104
|
|
|
|
105
|
|
|
$container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use ($values) { |
106
|
|
|
return $values[$id]; |
107
|
|
|
})); |
108
|
|
|
|
109
|
|
|
$container->expects($this->any()) |
110
|
|
|
->method('has') |
111
|
|
|
->will($this->returnCallback(function ($id) { |
112
|
|
|
if ('templating' == $id) { |
113
|
|
|
return true; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return false; |
117
|
|
|
})); |
118
|
|
|
|
119
|
|
|
$container->expects($this->any())->method('getParameter')->will($this->returnCallback(function ($name) { |
120
|
|
|
if ('sonata.admin.configuration.dashboard_blocks' == $name) { |
121
|
|
|
return []; |
122
|
|
|
} |
123
|
|
|
})); |
124
|
|
|
$container->expects($this->any())->method('has')->will($this->returnCallback(function ($id) { |
125
|
|
|
if ('templating' == $id) { |
126
|
|
|
return true; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
return false; |
130
|
|
|
})); |
131
|
|
|
|
132
|
|
|
$controller = new CoreController(); |
133
|
|
|
$controller->setContainer($container); |
134
|
|
|
|
135
|
|
|
$response = $controller->dashboardAction($request); |
|
|
|
|
136
|
|
|
|
137
|
|
|
$this->isInstanceOf('Symfony\Component\HttpFoundation\Response', $response); |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.