|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Kunstmaan\NodeBundle\Tests\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use Kunstmaan\NodeBundle\Entity\AbstractPage; |
|
6
|
|
|
use Kunstmaan\NodeBundle\Entity\HasNodeInterface; |
|
7
|
|
|
use Kunstmaan\NodeBundle\Entity\StructureNode; |
|
8
|
|
|
use Kunstmaan\NodeBundle\Form\PageAdminType; |
|
9
|
|
|
use Kunstmaan\NodeBundle\Helper\RenderContext; |
|
10
|
|
|
use PHPUnit\Framework\TestCase; |
|
11
|
|
|
use Symfony\Component\DependencyInjection\Container; |
|
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
13
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
14
|
|
|
|
|
15
|
|
|
class TestStructureNode extends StructureNode |
|
16
|
|
|
{ |
|
17
|
|
|
public function getPossibleChildTypes() |
|
18
|
|
|
{ |
|
19
|
|
|
return []; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function service(ContainerInterface $container, Request $request, RenderContext $context) |
|
23
|
|
|
{ |
|
24
|
|
|
$context['test'] = 'test'; |
|
25
|
|
|
} |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
class TestNode extends AbstractPage |
|
|
|
|
|
|
29
|
|
|
{ |
|
30
|
|
|
public function getPossibleChildTypes() |
|
31
|
|
|
{ |
|
32
|
|
|
return []; |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Class StructureNodeTest |
|
38
|
|
|
*/ |
|
39
|
|
|
class StructureNodeTest extends TestCase |
|
|
|
|
|
|
40
|
|
|
{ |
|
41
|
|
|
public function testIsStructureNode() |
|
42
|
|
|
{ |
|
43
|
|
|
$structureNode = new TestStructureNode(); |
|
44
|
|
|
$this->assertTrue($structureNode->isStructureNode()); |
|
45
|
|
|
|
|
46
|
|
|
$node = new TestNode(); |
|
47
|
|
|
$this->assertFalse($node->isStructureNode()); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testIsOnline() |
|
51
|
|
|
{ |
|
52
|
|
|
$structureNode = new TestStructureNode(); |
|
53
|
|
|
$this->assertFalse($structureNode->isOnline()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testGetSetPageTitle() |
|
57
|
|
|
{ |
|
58
|
|
|
$node = new TestStructureNode(); |
|
59
|
|
|
$node->setTitle('The Title'); |
|
60
|
|
|
$this->assertEquals('The Title', $node->getPageTitle()); |
|
61
|
|
|
$this->assertEquals('The Title', $node->getTitle()); |
|
62
|
|
|
$this->assertEquals('The Title', $node->__toString()); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testGetSetParent() |
|
66
|
|
|
{ |
|
67
|
|
|
$entity = $this->createMock(HasNodeInterface::class); |
|
68
|
|
|
$node = new TestStructureNode(); |
|
69
|
|
|
$node->setParent($entity); |
|
|
|
|
|
|
70
|
|
|
$this->assertInstanceOf(get_class($entity), $node->getParent()); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testGetDefaultAdminType() |
|
74
|
|
|
{ |
|
75
|
|
|
$node = new TestStructureNode(); |
|
76
|
|
|
$this->assertEquals(PageAdminType::class, $node->getDefaultAdminType()); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @group legacy |
|
81
|
|
|
*/ |
|
82
|
|
|
public function testService() |
|
83
|
|
|
{ |
|
84
|
|
|
$renderContext = new RenderContext(); |
|
85
|
|
|
|
|
86
|
|
|
$node = new TestStructureNode(); |
|
87
|
|
|
$node->service(new Container(), new Request(), $renderContext); |
|
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
$this->assertArrayHasKey('test', $renderContext->getArrayCopy()); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.