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