|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Sonata Project package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Sonata\AdminBundle\Tests\Block; |
|
15
|
|
|
|
|
16
|
|
|
use Sonata\AdminBundle\Admin\AbstractAdmin; |
|
17
|
|
|
use Sonata\AdminBundle\Admin\Pool; |
|
18
|
|
|
use Sonata\AdminBundle\Block\AdminSearchBlockService; |
|
19
|
|
|
use Sonata\AdminBundle\Search\SearchHandler; |
|
20
|
|
|
use Sonata\BlockBundle\Test\BlockServiceTestCase; |
|
21
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
22
|
|
|
use Twig\Environment; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* NEXT_MAJOR: Remove this class. |
|
26
|
|
|
* |
|
27
|
|
|
* @group legacy |
|
28
|
|
|
* |
|
29
|
|
|
* @author Sullivan Senechal <[email protected]> |
|
30
|
|
|
*/ |
|
31
|
|
|
class DeprecatedAdminSearchBlockServiceTest extends BlockServiceTestCase |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* @var Pool |
|
35
|
|
|
*/ |
|
36
|
|
|
private $pool; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var SearchHandler |
|
40
|
|
|
*/ |
|
41
|
|
|
private $searchHandler; |
|
42
|
|
|
|
|
43
|
|
|
protected function setUp(): void |
|
44
|
|
|
{ |
|
45
|
|
|
parent::setUp(); |
|
46
|
|
|
|
|
47
|
|
|
$this->pool = $this->createMock(Pool::class); |
|
48
|
|
|
$this->searchHandler = $this->createMock(SearchHandler::class); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @expectedDeprecation Passing null as argument 2 to Sonata\AdminBundle\Block\AdminSearchBlockService::__construct() is deprecated since sonata-project/admin-bundle 3.x and will throw a \TypeError in version 4.0. You must pass an instance of Sonata\AdminBundle\Admin\Pool instead. |
|
53
|
|
|
*/ |
|
54
|
|
|
public function testDefaultSettings(): void |
|
55
|
|
|
{ |
|
56
|
|
|
$blockService = new AdminSearchBlockService( |
|
57
|
|
|
$this->createMock(Environment::class), |
|
58
|
|
|
null, |
|
59
|
|
|
$this->pool, |
|
|
|
|
|
|
60
|
|
|
$this->searchHandler |
|
61
|
|
|
); |
|
62
|
|
|
$blockContext = $this->getBlockContext($blockService); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertSettings([ |
|
65
|
|
|
'admin_code' => '', |
|
66
|
|
|
'query' => '', |
|
67
|
|
|
'page' => 0, |
|
68
|
|
|
'per_page' => 10, |
|
69
|
|
|
'icon' => '<i class="fa fa-list"></i>', |
|
70
|
|
|
], $blockContext); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @expectedDeprecation Passing null as argument 2 to Sonata\AdminBundle\Block\AdminSearchBlockService::__construct() is deprecated since sonata-project/admin-bundle 3.x and will throw a \TypeError in version 4.0. You must pass an instance of Sonata\AdminBundle\Admin\Pool instead. |
|
75
|
|
|
*/ |
|
76
|
|
|
public function testGlobalSearchReturnsEmptyWhenFiltersAreDisabled(): void |
|
77
|
|
|
{ |
|
78
|
|
|
$admin = $this->createMock(AbstractAdmin::class); |
|
79
|
|
|
|
|
80
|
|
|
$blockService = new AdminSearchBlockService( |
|
81
|
|
|
$this->createMock(Environment::class), |
|
82
|
|
|
null, |
|
83
|
|
|
$this->pool, |
|
|
|
|
|
|
84
|
|
|
$this->searchHandler |
|
85
|
|
|
); |
|
86
|
|
|
$blockContext = $this->getBlockContext($blockService); |
|
87
|
|
|
|
|
88
|
|
|
$this->searchHandler->expects(self::once())->method('search')->willReturn(false); |
|
|
|
|
|
|
89
|
|
|
$this->pool->expects(self::once())->method('getAdminByAdminCode')->willReturn($admin); |
|
|
|
|
|
|
90
|
|
|
$admin->expects(self::once())->method('checkAccess')->with('list')->willReturn(true); |
|
91
|
|
|
|
|
92
|
|
|
$response = $blockService->execute($blockContext); |
|
93
|
|
|
|
|
94
|
|
|
static::assertSame('', $response->getContent()); |
|
95
|
|
|
static::assertSame(Response::HTTP_NO_CONTENT, $response->getStatusCode()); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: