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\DoctrineORMAdminBundle\Tests\Builder; |
15
|
|
|
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
17
|
|
|
use Prophecy\Argument; |
18
|
|
|
use Sonata\AdminBundle\Admin\AdminInterface; |
19
|
|
|
use Sonata\AdminBundle\Guesser\TypeGuesserInterface; |
20
|
|
|
use Sonata\DoctrineMongoDBAdminBundle\Admin\FieldDescription; |
21
|
|
|
use Sonata\DoctrineMongoDBAdminBundle\Builder\ListBuilder; |
22
|
|
|
use Sonata\DoctrineMongoDBAdminBundle\Model\ModelManager; |
23
|
|
|
use Symfony\Component\Form\Guess\Guess; |
24
|
|
|
use Symfony\Component\Form\Guess\TypeGuess; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @author Andrew Mor-Yaroslavtsev <[email protected]> |
28
|
|
|
*/ |
29
|
|
|
class ListBuilderTest extends TestCase |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @var TypeGuesserInterface|\Prophecy\Prophecy\ObjectProphecy |
33
|
|
|
*/ |
34
|
|
|
protected $typeGuesser; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var ListBuilder |
38
|
|
|
*/ |
39
|
|
|
protected $listBuilder; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var AdminInterface|\Prophecy\Prophecy\ObjectProphecy |
43
|
|
|
*/ |
44
|
|
|
protected $admin; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var ModelManager|\Prophecy\Prophecy\ObjectProphecy |
48
|
|
|
*/ |
49
|
|
|
protected $modelManager; |
50
|
|
|
|
51
|
|
|
protected function setUp(): void |
52
|
|
|
{ |
53
|
|
|
$this->typeGuesser = $this->prophesize('Sonata\AdminBundle\Guesser\TypeGuesserInterface'); |
54
|
|
|
|
55
|
|
|
$this->modelManager = $this->prophesize('Sonata\DoctrineMongoDBAdminBundle\Model\ModelManager'); |
56
|
|
|
$this->modelManager->hasMetadata(Argument::any())->willReturn(false); |
57
|
|
|
|
58
|
|
|
$this->admin = $this->prophesize('Sonata\AdminBundle\Admin\AbstractAdmin'); |
59
|
|
|
$this->admin->getClass()->willReturn('Foo'); |
60
|
|
|
$this->admin->getModelManager()->willReturn($this->modelManager); |
61
|
|
|
$this->admin->addListFieldDescription(Argument::any(), Argument::any()) |
62
|
|
|
->willReturn(); |
63
|
|
|
|
64
|
|
|
$this->listBuilder = new ListBuilder($this->typeGuesser->reveal()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testAddListActionField(): void |
68
|
|
|
{ |
69
|
|
|
$fieldDescription = new FieldDescription(); |
70
|
|
|
$fieldDescription->setName('foo'); |
71
|
|
|
$list = $this->listBuilder->getBaseList(); |
72
|
|
|
$this->listBuilder |
73
|
|
|
->addField($list, 'actions', $fieldDescription, $this->admin->reveal()); |
|
|
|
|
74
|
|
|
|
75
|
|
|
$this->assertSame( |
76
|
|
|
'@SonataAdmin/CRUD/list__action.html.twig', |
77
|
|
|
$list->get('foo')->getTemplate(), |
78
|
|
|
'Custom list action field has a default list action template assigned' |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testCorrectFixedActionsFieldType(): void |
83
|
|
|
{ |
84
|
|
|
$this->typeGuesser->guessType( |
|
|
|
|
85
|
|
|
Argument::any(), Argument::any(), Argument::any() |
|
|
|
|
86
|
|
|
)->willReturn( |
87
|
|
|
new TypeGuess('actions', [], Guess::LOW_CONFIDENCE) |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
$fieldDescription = new FieldDescription(); |
91
|
|
|
$fieldDescription->setName('_action'); |
92
|
|
|
$list = $this->listBuilder->getBaseList(); |
93
|
|
|
$this->listBuilder->addField($list, null, $fieldDescription, $this->admin->reveal()); |
|
|
|
|
94
|
|
|
|
95
|
|
|
$this->assertSame( |
96
|
|
|
'actions', |
97
|
|
|
$list->get('_action')->getType(), |
98
|
|
|
'Standard list _action field has "actions" type' |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: