Completed
Pull Request — 3.x (#673)
by
unknown
02:59
created

ListBuilderTest::testAddListActionField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 14
rs 9.4285
c 1
b 1
f 0
cc 1
eloc 10
nc 1
nop 0
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())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...r\TypeGuesserInterface>.

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.

Loading history...
81
            ->method('guessType')
82
            ->willReturn(new TypeGuess(null, [], Guess::LOW_CONFIDENCE));
83
84
        $fieldDescription = new FieldDescription();
85
        $fieldDescription->setName('_action');
86
        $list = $this->listBuilder->getBaseList();
87
        $this->listBuilder->addField($list, null, $fieldDescription, $this->admin);
88
89
        $this->assertEquals(
90
            'actions',
91
            $list->get('_action')->getType(),
92
            'Standard list _action field has "actions" type'
93
        );
94
    }
95
}
96