Completed
Push — master ( 3cd231...d48ef1 )
by
unknown
153:58 queued 132:33
created

AdminList/FormPageAdminListConfiguratorTest.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\FormBundle\Tests\AdminList;
4
5
use Doctrine\ORM\QueryBuilder;
6
use Kunstmaan\AdminListBundle\AdminList\ItemAction\SimpleItemAction;
7
use Kunstmaan\FormBundle\AdminList\FormPageAdminListConfigurator;
8
use Kunstmaan\NodeBundle\Tests\Stubs\TestRepository;
9
use Kunstmaan\FormBundle\Tests\Stubs\TestConfiguration;
10
use Kunstmaan\FormBundle\Tests\Entity\FakePage;
11
12
/**
13
 * This test tests the FormPageAdminListConfigurator
14
 */
15
class FormPageAdminListConfiguratorTest extends \PHPUnit_Framework_TestCase
16
{
17
    const PERMISSION_VIEW = 'view';
18
19
    /**
20
     * @var FormPageAdminListConfigurator
21
     */
22
    protected $object;
23
24
    /**
25
     * Sets up the fixture, for example, opens a network connection.
26
     * This method is called before a test is executed.
27
     */
28
    protected function setUp()
29
    {
30
        $em = $this->getMockedEntityManager();
31
        $tokenStorage = $this->createMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
32
        $roleHierarchy = $this->getMockBuilder('Symfony\Component\Security\Core\Role\RoleHierarchyInterface')
33
          ->getMock();
34
        $aclHelper = $this->createMock('Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper', array(), array($em, $tokenStorage, $roleHierarchy));
35
36
        $this->object = new FormPageAdminListConfigurator($em, $aclHelper, self::PERMISSION_VIEW);
37
    }
38
39
    /**
40
     * https://gist.github.com/1331789
41
     *
42
     * @return \Doctrine\ORM\EntityManager
43
     */
44 View Code Duplication
    protected function getMockedEntityManager()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
    {
46
        $emMock  = $this->createMock('\Doctrine\ORM\EntityManager', array('getRepository', 'getConfiguration', 'getClassMetadata', 'persist', 'flush'), array(), '', false);
47
        $emMock->expects($this->any())
48
            ->method('getRepository')
49
            ->will($this->returnValue(new TestRepository()));
50
        $emMock->expects($this->any())
51
            ->method('getConfiguration')
52
            ->will($this->returnValue(new TestConfiguration()));
53
        $emMock->expects($this->any())
54
            ->method('getClassMetadata')
55
            ->will($this->returnValue((object) array('name' => 'aClass')));
56
        $emMock->expects($this->any())
57
            ->method('persist')
58
            ->will($this->returnValue(null));
59
        $emMock->expects($this->any())
60
            ->method('flush')
61
            ->will($this->returnValue(null));
62
63
        return $emMock;  // it tooks 13 lines to achieve mock!
64
    }
65
66
    public function testAdaptQueryBuilder()
67
    {
68
        $queryBuilder = $this->getMockBuilder('Doctrine\ORM\QueryBuilder')
69
            ->disableOriginalConstructor()
70
            ->getMock();
71
72
        $queryBuilder->expects($this->any())
73
            ->method('innerJoin')
74
            ->will($this->returnSelf());
75
76
        $queryBuilder->expects($this->any())
77
            ->method('andWhere')
78
            ->will($this->returnSelf());
79
80
        /* @var $queryBuilder QueryBuilder */
81
        $this->object->adaptQueryBuilder($queryBuilder);
82
    }
83
84
85
86 View Code Duplication
    public function testFixedGetters()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
87
    {
88
        $item = new FakePage();
89
        $item->setId(123);
90
        $this->assertEquals('', $this->object->getAddUrlFor([]));
91
        $this->assertEquals('KunstmaanNodeBundle', $this->object->getBundleName());
92
        $this->assertEquals('NodeTranslation', $this->object->getEntityName());
93
        $this->assertEquals('KunstmaanFormBundle:FormSubmissions', $this->object->getControllerPath());
94
        $this->assertCount(0, $this->object->getDeleteUrlFor($item));
95
        $this->assertCount(1, $this->object->getIndexUrl());
96
        $this->assertCount(2, $this->object->getEditUrlFor($item));
97
        $this->assertFalse($this->object->canAdd());
98
        $this->assertFalse($this->object->canEdit($item));
99
        $this->assertFalse($this->object->canDelete($item));
100
    }
101
102
103
104
    public function testBuildFilters()
105
    {
106
        $this->object->buildFilters();
107
        $filters = $this->object->getFilterBuilder()->getFilterDefinitions();
108
        $this->assertCount(2, $filters);
109
    }
110
111
    public function testBuildFields()
112
    {
113
        $this->object->buildFields();
114
        $fields = $this->object->getFields();
115
        $this->assertCount(3, $fields);
116
    }
117
118 View Code Duplication
    public function testBuildItemActions()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
119
    {
120
        $item = new FakePage();
121
        $item->setId(1);
122
        $this->object->buildItemActions();
123
        $actions = $this->object->getItemActions();
124
        $this->assertCount(1, $actions);
125
        $this->assertInstanceOf(SimpleItemAction::class, $actions[0]);
126
        /** @var SimpleItemAction $action */
127
        $action = $actions[0];
128
        $this->assertCount(2, $action->getUrlFor($item));
129
    }
130
}
131