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