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\AdminBundle\Templating\TemplateRegistryInterface; |
21
|
|
|
use Sonata\BlockBundle\Test\BlockServiceTestCase; |
22
|
|
|
use Symfony\Component\HttpFoundation\Response; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @author Sullivan Senechal <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class AdminSearchBlockServiceTest extends BlockServiceTestCase |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var Pool |
31
|
|
|
*/ |
32
|
|
|
private $pool; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var SearchHandler |
36
|
|
|
*/ |
37
|
|
|
private $searchHandler; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var TemplateRegistryInterface |
41
|
|
|
*/ |
42
|
|
|
private $templateRegistry; |
43
|
|
|
|
44
|
|
|
protected function setUp(): void |
45
|
|
|
{ |
46
|
|
|
parent::setUp(); |
47
|
|
|
|
48
|
|
|
$this->pool = $this->createMock(Pool::class); |
49
|
|
|
$this->searchHandler = $this->createMock(SearchHandler::class); |
50
|
|
|
$this->templateRegistry = $this->createMock(TemplateRegistryInterface::class); |
51
|
|
|
$this->templateRegistry->method('getTemplate')->willReturn('@SonataAdmin/Block/block_search_result.html.twig'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testDefaultSettings(): void |
55
|
|
|
{ |
56
|
|
|
$blockService = new AdminSearchBlockService($this->twig, $this->pool, $this->searchHandler); |
57
|
|
|
$blockContext = $this->getBlockContext($blockService); |
58
|
|
|
|
59
|
|
|
$this->assertSettings([ |
60
|
|
|
'admin_code' => '', |
61
|
|
|
'query' => '', |
62
|
|
|
'page' => 0, |
63
|
|
|
'per_page' => 10, |
64
|
|
|
'icon' => '<i class="fa fa-list"></i>', |
65
|
|
|
], $blockContext); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testGlobalSearchReturnsResponse(): void |
69
|
|
|
{ |
70
|
|
|
$admin = $this->createMock(AbstractAdmin::class); |
71
|
|
|
|
72
|
|
|
$blockService = new AdminSearchBlockService($this->twig, $this->pool, $this->searchHandler, $this->templateRegistry); |
73
|
|
|
$blockContext = $this->getBlockContext($blockService); |
74
|
|
|
|
75
|
|
|
$this->searchHandler->expects(self::once())->method('search')->willReturn(true); |
|
|
|
|
76
|
|
|
$this->pool->expects(self::once())->method('getAdminByAdminCode')->willReturn($admin); |
|
|
|
|
77
|
|
|
$admin->expects(self::once())->method('checkAccess')->with('list'); |
78
|
|
|
|
79
|
|
|
$response = $blockService->execute($blockContext); |
80
|
|
|
|
81
|
|
|
static::assertSame('', $response->getContent()); |
82
|
|
|
static::assertSame(Response::HTTP_OK, $response->getStatusCode()); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testGlobalSearchReturnsEmptyWhenFiltersAreDisabled(): void |
86
|
|
|
{ |
87
|
|
|
$admin = $this->createMock(AbstractAdmin::class); |
88
|
|
|
|
89
|
|
|
$blockService = new AdminSearchBlockService($this->twig, $this->pool, $this->searchHandler); |
90
|
|
|
$blockContext = $this->getBlockContext($blockService); |
91
|
|
|
|
92
|
|
|
$this->searchHandler->expects(self::once())->method('search')->willReturn(false); |
|
|
|
|
93
|
|
|
$this->pool->expects(self::once())->method('getAdminByAdminCode')->willReturn($admin); |
|
|
|
|
94
|
|
|
$admin->expects(self::once())->method('checkAccess')->with('list'); |
95
|
|
|
|
96
|
|
|
$this->twig->expects(self::never())->method('render'); |
|
|
|
|
97
|
|
|
|
98
|
|
|
$response = $blockService->execute($blockContext); |
99
|
|
|
|
100
|
|
|
static::assertSame('', $response->getContent()); |
101
|
|
|
static::assertSame(Response::HTTP_NO_CONTENT, $response->getStatusCode()); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.