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

NodeBundle/Tests/unit/Entity/NodeTest.php (2 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\NodeBundle\Tests\Entity;
4
5
use Codeception\Stub;
6
use Doctrine\Common\Collections\ArrayCollection;
7
use Kunstmaan\AdminBundle\Entity\AbstractEntity;
8
use Kunstmaan\NodeBundle\Entity\HasNodeInterface;
9
use Kunstmaan\NodeBundle\Entity\Node;
10
use Kunstmaan\NodeBundle\Entity\NodeTranslation;
11
use PHPUnit_Framework_TestCase;
12
use ReflectionClass;
13
14
/**
15
 * Generated by PHPUnit_SkeletonGenerator on 2012-09-14 at 11:09:16.
16
 */
17
class NodeTest extends PHPUnit_Framework_TestCase
18
{
19
    /**
20
     * @var Node
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
        $this->object = new Node();
31
    }
32
33
    public function testIsGetSetHiddenFromNav()
34
    {
35
        $this->assertFalse($this->object->getHiddenFromNav());
36
        $this->object->setHiddenFromNav(true);
37
        $this->assertTrue($this->object->isHiddenFromNav());
38
        $this->assertTrue($this->object->getHiddenFromNav());
39
    }
40
41
    public function testGetSetChildren()
42
    {
43
        $children = new ArrayCollection();
44
        $child = new Node();
45
        $children->add($child);
46
        $this->object->setChildren($children);
47
48
        $this->assertEquals(1, $this->object->getChildren()->count());
49
        $this->assertEquals($children, $this->object->getChildren());
50
        $this->assertTrue($this->object->getChildren()->contains($child));
51
    }
52
53
    public function testGetSetChildrenWithDeletedChildren()
54
    {
55
        $children = new ArrayCollection();
56
        $child = new Node();
57
        $deletedChild = new Node();
58
        $deletedChild->setDeleted(true);
59
        $children->add($child);
60
        $children->add($deletedChild);
61
        $this->object->setChildren($children);
62
63
        $this->assertEquals(1, $this->object->getChildren()->count());
64
        $this->assertTrue($this->object->getChildren()->contains($child));
65
        $this->assertFalse($this->object->getChildren()->contains($deletedChild));
66
    }
67
68
    public function testAddNode()
69
    {
70
        $child = new Node();
71
        $this->object->addNode($child);
72
        $this->assertEquals($this->object, $child->getParent());
73
        $this->assertEquals(1, $this->object->getChildren()->count());
74
    }
75
76 View Code Duplication
    public function testGetSetNodeTranslations()
77
    {
78
        $translations = new ArrayCollection();
79
        $translation = new NodeTranslation();
80
        $translations->add($translation);
81
        $this->object->setNodeTranslations($translations);
82
83
        $this->assertEquals(1, $this->object->getNodeTranslations(true)->count());
84
        $this->assertEquals($translations, $this->object->getNodeTranslations(true));
85
        $this->assertTrue($this->object->getNodeTranslations(true)->contains($translation));
86
    }
87
88 View Code Duplication
    public function testGetNodeTranslationsWithOfflineNodes()
89
    {
90
        $translation1 = new NodeTranslation();
91
        $translation1->setOnline(true);
92
        $this->object->addNodeTranslation($translation1);
93
94
        $translation2 = new NodeTranslation();
95
        $translation2->setOnline(false);
96
        $this->object->addNodeTranslation($translation2);
97
98
        $this->assertEquals(2, $this->object->getNodeTranslations(true)->count());
99
        $this->assertEquals(1, $this->object->getNodeTranslations()->count());
100
    }
101
102
    public function testGetNodeTranslation()
103
    {
104
        $translation1 = new NodeTranslation();
105
        $translation1->setLang('nl');
106
        $translation1->setOnline(true);
107
        $this->object->addNodeTranslation($translation1);
108
109
        $translation2 = new NodeTranslation();
110
        $translation2->setLang('fr');
111
        $translation2->setOnline(true);
112
        $this->object->addNodeTranslation($translation2);
113
114
        $this->assertEquals($translation1, $this->object->getNodeTranslation('nl'));
115
        $this->assertEquals($translation2, $this->object->getNodeTranslation('fr'));
116
        $this->assertNotEquals($translation1, $this->object->getNodeTranslation('fr'));
117
        $this->assertNotEquals($translation2, $this->object->getNodeTranslation('nl'));
118
        $this->assertNull($this->object->getNodeTranslation('en'));
119
    }
120
121
    public function testGetParents()
122
    {
123
        $child = new Node();
124
        $grandChild = new Node();
125
        $child->addNode($grandChild);
126
        $this->object->addNode($child);
127
        $parents = $grandChild->getParents();
128
129
        $this->assertEquals(2, count($parents));
130
        $this->assertEquals($child, $parents[1]);
131
        $this->assertEquals($this->object, $parents[0]);
132
    }
133
134
    public function testIsSetDeleted()
135
    {
136
        $this->assertFalse($this->object->isDeleted());
137
        $this->object->setDeleted(true);
138
        $this->assertTrue($this->object->isDeleted());
139
    }
140
141 View Code Duplication
    public function testSetRefAndGetRefEntityName()
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...
142
    {
143
        /** @var HasNodeInterface $entity */
144
        $entity = Stub::makeEmpty(HasNodeInterface::class);
145
        $this->object->setRef($entity);
146
        $this->assertEquals(get_class($entity), $this->object->getRefEntityName());
147
    }
148
149
    public function testSetInternalName()
150
    {
151
        $this->object->setInternalName('AnInternalName');
152
        $this->assertEquals('AnInternalName', $this->object->getInternalName());
153
    }
154
155
    public function testGetDefaultAdminType()
156
    {
157
        $this->assertEquals('Kunstmaan\NodeBundle\Form\NodeAdminType', $this->object->getDefaultAdminType());
158
    }
159
160 View Code Duplication
    public function testToString()
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...
161
    {
162
        /** @var HasNodeInterface $entity */
163
        $entity = Stub::makeEmpty(HasNodeInterface::class);
164
        $this->object->setId(1);
165
        $this->object->setRef($entity);
166
167
        $this->assertEquals('node 1, refEntityName: '.get_class($entity), $this->object->__toString());
168
    }
169
170
    public function testGetSetLeftRightLevel()
171
    {
172
        $mirror = new ReflectionClass(Node::class);
173
        $property = $mirror->getProperty('lft');
174
        $property->setAccessible(true);
175
        $property->setValue($this->object, 11);
176
        $property = $mirror->getProperty('rgt');
177
        $property->setAccessible(true);
178
        $property->setValue($this->object, 12);
179
        $property = $mirror->getProperty('lvl');
180
        $property->setAccessible(true);
181
        $property->setValue($this->object, 13);
182
183
        $this->assertEquals(11, $this->object->getLeft());
184
        $this->assertEquals(12, $this->object->getRight());
185
        $this->assertEquals(13, $this->object->getLevel());
186
    }
187
}
188