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

FormSubmissionAdminListConfiguratorTest.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 Codeception\Stub;
6
use Doctrine\ORM\Configuration;
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\FormSubmissionAdminListConfigurator;
12
use Kunstmaan\NodeBundle\Entity\AbstractPage;
13
use Kunstmaan\NodeBundle\Entity\Node;
14
use Kunstmaan\NodeBundle\Entity\NodeTranslation;
15
16
/**
17
 * This test tests the FormPageAdminListConfigurator
18
 */
19
class FormSubmissionAdminListConfiguratorTest extends \PHPUnit_Framework_TestCase
20
{
21
    /**
22
     * @var FormSubmissionAdminListConfigurator
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 View Code Duplication
    protected function setUp()
31
    {
32
        $em = $this->getMockedEntityManager();
33
        $node = new Node();
34
        $node->setId(666);
35
        $nt = new NodeTranslation();
36
        $nt->setNode($node);
37
        $this->object = new FormSubmissionAdminListConfigurator($em, $nt);
38
    }
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
56
        /** @var \Doctrine\ORM\EntityManager $emMock */
57
        $emMock = Stub::make(EntityManager::class, [
58
            'getRepository' => $repository,
59
            'getConfiguration' => $configuration,
60
            'getClassMetaData' => (object)['name' => 'aClass'],
61
            'persist' => null,
62
            'flush' => null
63
        ]);
64
65
        return $emMock;
66
    }
67
68
    public function testAdaptQueryBuilder()
69
    {
70
        $queryBuilder = $this->getMockBuilder('Doctrine\ORM\QueryBuilder')
71
            ->disableOriginalConstructor()
72
            ->getMock();
73
74
        $queryBuilder->expects($this->any())
75
            ->method('innerJoin')
76
            ->will($this->returnSelf());
77
78
        $queryBuilder->expects($this->any())
79
            ->method('andWhere')
80
            ->will($this->returnSelf());
81
82
        $queryBuilder->expects($this->any())
83
            ->method('setParameter')
84
            ->will($this->returnSelf());
85
86
        /* @var $queryBuilder QueryBuilder */
87
        $this->object->adaptQueryBuilder($queryBuilder);
88
    }
89
90 View Code Duplication
    public function testFixedGetters()
91
    {
92
        $item = Stub::makeEmpty(AbstractPage::class, ['getId' => 123]);
93
        $this->assertEquals('', $this->object->getAddUrlFor([]));
94
        $this->assertEquals('KunstmaanFormBundle', $this->object->getBundleName());
95
        $this->assertEquals('FormSubmission', $this->object->getEntityName());
96
        $this->assertCount(0, $this->object->getDeleteUrlFor($item));
97
        $this->assertCount(2, $this->object->getIndexUrl());
98
        $this->assertCount(2, $this->object->getEditUrlFor($item));
99
        $this->assertCount(2, $this->object->getExportUrl());
100
        $this->assertFalse($this->object->canAdd());
101
        $this->assertFalse($this->object->canEdit($item));
102
        $this->assertFalse($this->object->canDelete($item));
103
        $this->assertTrue($this->object->canExport());
104
    }
105
106
    public function testBuildFilters()
107
    {
108
        $this->object->buildFilters();
109
        $filters = $this->object->getFilterBuilder()->getFilterDefinitions();
110
        $this->assertCount(3, $filters);
111
    }
112
113
    public function testBuildFields()
114
    {
115
        $this->object->buildFields();
116
        $fields = $this->object->getFields();
117
        $this->assertCount(3, $fields);
118
    }
119
120 View Code Duplication
    public function testBuildItemActions()
121
    {
122
        $item = Stub::makeEmpty(AbstractPage::class, ['getId' => 123]);
123
        $this->object->buildItemActions();
124
        $actions = $this->object->getItemActions();
125
        $this->assertCount(1, $actions);
126
        $this->assertInstanceOf(SimpleItemAction::class, $actions[0]);
127
        /** @var SimpleItemAction $action */
128
        $action = $actions[0];
129
        $this->assertCount(2, $action->getUrlFor($item));
130
    }
131
}
132