1+ <?php
2+
3+ namespace PE \Tests \Nodes ;
4+ use PE \Nodes \EncoderNodeChild ;
5+ use PE \Nodes \EncoderNodeChildren ;
6+ use PE \Tests \Samples ;
7+
8+ class EncoderNodeChildrenTest extends Samples {
9+
10+ protected function setUp () {
11+ parent ::setUp ();
12+ $ this ->_peApp = $ this ->nodeChildren ();
13+ }
14+
15+ /**
16+ * @return EncoderNodeChildren
17+ */
18+ protected function nodeChildren () {
19+ return new EncoderNodeChildren ();
20+ }
21+
22+ public function testConstructor () {
23+ $ nodeChildren = $ this ->nodeChildren ();
24+ $ this ->assertNotNull ($ nodeChildren );
25+ $ this ->assertTrue ($ nodeChildren instanceof EncoderNodeChildren);
26+ }
27+
28+ public function testAddChild () {
29+ $ nodeChildren = $ this ->nodeChildren ();
30+ $ child = $ nodeChildren ->addChild (new EncoderNodeChild ('test ' ));
31+ $ this ->assertEquals ($ child , $ nodeChildren ->getChild ('test ' ));
32+
33+ $ this ->assertFalse ($ nodeChildren ->addChild ($ child ));
34+
35+ }
36+
37+ public function testGetChild () {
38+ $ nodeChildren = $ this ->nodeChildren ();
39+ $ child = $ nodeChildren ->addChild (new EncoderNodeChild ('test ' ));
40+ $ this ->assertEquals ($ child , $ nodeChildren ->getChild ('test ' ));
41+ $ this ->assertEquals ($ child , $ nodeChildren ->getChild ('tEsT ' ));
42+ $ this ->assertNull ($ nodeChildren ->getChild ('unknown ' ));
43+ }
44+
45+ public function testGetChildren () {
46+ $ nodeChildren = $ this ->nodeChildren ();
47+ $ this ->assertEquals (array (), $ nodeChildren ->getChildren ());
48+ $ child = $ nodeChildren ->addChild (new EncoderNodeChild ('test ' ));
49+ $ this ->assertEquals (array (
50+ 'test ' => $ child
51+ ), $ nodeChildren ->getChildren ());
52+ }
53+
54+ public function testChildExists () {
55+ $ nodeChildren = $ this ->nodeChildren ();
56+ $ nodeChildren ->addChild (new EncoderNodeChild ('test ' ));
57+ $ this ->assertTrue ($ nodeChildren ->childExists ('test ' ));
58+ $ this ->assertFalse ($ nodeChildren ->childExists ('unknown ' ));
59+ }
60+
61+ public function testAddChildrenToObject () {
62+ $ farmNode = $ this ->addFarmNode ();
63+ $ farm = $ this ->getFarm (false , false );
64+ $ house = $ this ->getBuildingHouse ();
65+ $ farmNode ->addChildrenToObject ('buildings ' , $ farm , array (
66+ $ house
67+ ));
68+ $ this ->assertEquals (array ($ house ), $ farm ->getBuildings ());
69+ }
70+ public function testAddChildrenToObjectWhenChildIsNotFound () {
71+ $ this ->setExpectedException ('\\PE \\Exceptions \\EncoderNodeChildException ' , 'Trying to add children to object, but the child "unknown" could not be found ' );
72+ $ nodeChildren = $ this ->nodeChildren ();
73+ $ nodeChildren ->addChildrenToObject ('unknown ' , null , null );
74+ }
75+ }
0 commit comments