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