1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\NodeBundle\Tests\Entity; |
4
|
|
|
|
5
|
|
|
use Codeception\Stub; |
6
|
|
|
use Kunstmaan\NodeBundle\Entity\AbstractPage; |
7
|
|
|
use Kunstmaan\NodeBundle\Entity\HasNodeInterface; |
8
|
|
|
use Kunstmaan\NodeBundle\Entity\AbstractStructurePage; |
9
|
|
|
use Kunstmaan\NodeBundle\Form\PageAdminType; |
10
|
|
|
use Kunstmaan\NodeBundle\Helper\RenderContext; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
use Symfony\Component\DependencyInjection\Container; |
13
|
|
|
use Symfony\Component\HttpFoundation\Request; |
14
|
|
|
|
15
|
|
|
class TestAbstractStructurePage extends AbstractStructurePage |
16
|
|
|
{ |
17
|
|
|
public function getPossibleChildTypes() |
18
|
|
|
{ |
19
|
|
|
return []; |
20
|
|
|
} |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
class TestNode extends AbstractPage |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
public function getPossibleChildTypes() |
26
|
|
|
{ |
27
|
|
|
return []; |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Class AbstractStructurePageTest |
33
|
|
|
*/ |
34
|
|
|
class AbstractStructurePageTest extends TestCase |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
public function testIsAbstractStructurePage() |
37
|
|
|
{ |
38
|
|
|
$structurePage = new TestAbstractStructurePage(); |
39
|
|
|
$this->assertTrue($structurePage->isStructurePage()); |
40
|
|
|
|
41
|
|
|
$node = new TestNode(); |
42
|
|
|
$this->assertFalse($node->isStructurePage()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testIsOnline() |
46
|
|
|
{ |
47
|
|
|
$structurePage = new TestAbstractStructurePage(); |
48
|
|
|
$this->assertFalse($structurePage->isOnline()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testGetSetPageTitle() |
52
|
|
|
{ |
53
|
|
|
$page = new TestAbstractStructurePage(); |
54
|
|
|
$page->setTitle('The Title'); |
55
|
|
|
$this->assertEquals('The Title', $page->getPageTitle()); |
56
|
|
|
$this->assertEquals('The Title', $page->getTitle()); |
57
|
|
|
$this->assertEquals('The Title', $page->__toString()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testGetSetParent() |
61
|
|
|
{ |
62
|
|
|
/** @var HasNodeInterface $entity */ |
63
|
|
|
$entity = Stub::makeEmpty(HasNodeInterface::class); |
64
|
|
|
$page = new TestAbstractStructurePage(); |
65
|
|
|
$page->setParent($entity); |
66
|
|
|
$this->assertInstanceOf(get_class($entity), $page->getParent()); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testGetDefaultAdminType() |
70
|
|
|
{ |
71
|
|
|
$page = new TestAbstractStructurePage(); |
72
|
|
|
$this->assertEquals(PageAdminType::class, $page->getDefaultAdminType()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testService() |
76
|
|
|
{ |
77
|
|
|
// this method does nothing - is it required? |
78
|
|
|
$page = new TestAbstractStructurePage(); |
79
|
|
|
$page->service(new Container(), new Request(), new RenderContext()); |
|
|
|
|
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
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.