Completed
Push — master ( 6e92d2...d7f3a5 )
by
unknown
109:07 queued 86:32
created

AdminList/FormPageAdminListConfiguratorTest.php (1 issue)

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\Configuration;
6
use Codeception\Stub;
7
use Doctrine\ORM\EntityManager;
8
use Doctrine\ORM\EntityRepository;
9
use Doctrine\ORM\QueryBuilder;
10
use Kunstmaan\AdminListBundle\AdminList\ItemAction\SimpleItemAction;
11
use Kunstmaan\FormBundle\AdminList\FormPageAdminListConfigurator;
12
use Kunstmaan\NodeBundle\Entity\AbstractPage;
13
14
/**
15
 * This test tests the FormPageAdminListConfigurator
16
 */
17
class FormPageAdminListConfiguratorTest extends \PHPUnit_Framework_TestCase
18
{
19
    const PERMISSION_VIEW = 'view';
20
21
    /**
22
     * @var FormPageAdminListConfigurator
23
     */
24
    protected $object;
25
26
    /**
27
     * Sets up the fixture, for example, opens a network connection.
28
     * This method is called before a test is executed.
29
     */
30
    protected function setUp()
31
    {
32
        $em = $this->getMockedEntityManager();
33
        $tokenStorage = $this->createMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
34
        $roleHierarchy = $this->getMockBuilder('Symfony\Component\Security\Core\Role\RoleHierarchyInterface')
35
          ->getMock();
36
        $aclHelper = $this->createMock('Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper', array(), array($em, $tokenStorage, $roleHierarchy));
37
38
        $this->object = new FormPageAdminListConfigurator($em, $aclHelper, self::PERMISSION_VIEW);
39
    }
40
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
        $configuration = Stub::make(Configuration::class, [
47
            'getQuoteStrategy' => null
48
        ]);
49
50
        $repository = Stub::make(EntityRepository::class, [
51
            'find' => null,
52
            'findBy' => null,
53
            'findOneBy' => null,
54
        ]);
55
        /** @var \Doctrine\ORM\EntityManager $emMock */
56
        $emMock = Stub::make(EntityManager::class, [
57
            'getRepository' => $repository,
58
            'getClassMetaData' => (object)['name' => 'aClass'],
59
            'getConfiguration' => $configuration,
60
            'persist' => null,
61
            'flush' => null
62
        ]);
63
64
        return $emMock;
65
    }
66
67
    public function testAdaptQueryBuilder()
68
    {
69
        $queryBuilder = $this->getMockBuilder('Doctrine\ORM\QueryBuilder')
70
            ->disableOriginalConstructor()
71
            ->getMock();
72
73
        $queryBuilder->expects($this->any())
74
            ->method('innerJoin')
75
            ->will($this->returnSelf());
76
77
        $queryBuilder->expects($this->any())
78
            ->method('andWhere')
79
            ->will($this->returnSelf());
80
81
        /* @var $queryBuilder QueryBuilder */
82
        $this->object->adaptQueryBuilder($queryBuilder);
83
    }
84
85 View Code Duplication
    public function testFixedGetters()
86
    {
87
        $item = Stub::makeEmpty(AbstractPage::class, ['getId' => 123]);
88
        $this->assertEquals('', $this->object->getAddUrlFor([]));
89
        $this->assertEquals('KunstmaanNodeBundle', $this->object->getBundleName());
90
        $this->assertEquals('NodeTranslation', $this->object->getEntityName());
91
        $this->assertEquals('KunstmaanFormBundle:FormSubmissions', $this->object->getControllerPath());
92
        $this->assertCount(0, $this->object->getDeleteUrlFor($item));
93
        $this->assertCount(1, $this->object->getIndexUrl());
94
        $this->assertCount(2, $this->object->getEditUrlFor($item));
95
        $this->assertFalse($this->object->canAdd());
96
        $this->assertFalse($this->object->canEdit($item));
97
        $this->assertFalse($this->object->canDelete($item));
98
    }
99
100
    public function testBuildFilters()
101
    {
102
        $this->object->buildFilters();
103
        $filters = $this->object->getFilterBuilder()->getFilterDefinitions();
104
        $this->assertCount(2, $filters);
105
    }
106
107
    public function testBuildFields()
108
    {
109
        $this->object->buildFields();
110
        $fields = $this->object->getFields();
111
        $this->assertCount(3, $fields);
112
    }
113
114 View Code Duplication
    public function testBuildItemActions()
115
    {
116
        $item = Stub::makeEmpty(AbstractPage::class, ['getId' => 123]);
117
        $this->object->buildItemActions();
118
        $actions = $this->object->getItemActions();
119
        $this->assertCount(1, $actions);
120
        $this->assertInstanceOf(SimpleItemAction::class, $actions[0]);
121
        /** @var SimpleItemAction $action */
122
        $action = $actions[0];
123
        $this->assertCount(2, $action->getUrlFor($item));
124
    }
125
}
126