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