@@ -56,6 +56,10 @@ public function testStaticAddNode() {
5656 $ nodeTypes = EncoderNode::getNodeTypes (self ::DEFAULT_NODE_NAME );
5757 $ this ->assertArrayHasKey (EncoderNode::DEFAULT_TYPE , $ nodeTypes );
5858 $ this ->assertEquals ($ nodeTypes [EncoderNode::DEFAULT_TYPE ], $ node );
59+
60+ $ types = EncoderNode::getNodeTypes ();
61+ $ this ->assertCount (1 , $ types );
62+ $ this ->assertEquals ('default ' , $ node ->getNodeTypeName ());
5963 }
6064
6165 public function testStaticAddNodeWithNonStringNodeName () {
@@ -94,6 +98,9 @@ public function testStaticGetNodeByObject() {
9498 $ things = $ this ->getThings ();
9599 $ this ->assertEquals ($ thingsNode , EncoderNode::getNodeByObject ($ things ));
96100 $ this ->assertNull (EncoderNode::getNodeByObject ($ this ->getThing ()));
101+
102+ // from cache
103+ $ this ->assertEquals ($ thingsNode , EncoderNode::getNodeByObject ($ things ));
97104 }
98105
99106 public function testStaticGetNodes () {
@@ -117,6 +124,19 @@ public function testStaticNodeExists() {
117124 $ this ->assertTrue (EncoderNode::nodeExists (self ::DEFAULT_NODE_NAME_SINGLE ));
118125 $ this ->assertFalse (EncoderNode::nodeExists ('unknown ' ));
119126 }
127+
128+ public function testStaticAddNodeType () {
129+ $ this ->addBuildingNode ();
130+ $ this ->addBuildingHouseNode ();
131+
132+ $ types = EncoderNode::getNodeTypes ();
133+ $ this ->assertCount (2 , $ types );
134+ $ this ->assertArrayHasKey ('buildings:default ' , $ types );
135+ $ this ->assertArrayHasKey ('buildings:house ' , $ types );
136+
137+ $ this ->assertEquals ('PE \\Nodes \\Farm \\BuildingNode ' , get_class ($ types ['buildings:default ' ]));
138+ $ this ->assertEquals ('PE \\Nodes \\Farm \\Buildings\HouseNode ' , get_class ($ types ['buildings:house ' ]));
139+ }
120140 public function testStaticAddNodeTypeTwice () {
121141 $ this ->setExpectedException ('\\PE \\Exceptions \\EncoderNodeException ' , 'Node type with name "buildings" and node type name "house" already exists ' );
122142 $ this ->addBuildingNode ();
@@ -127,4 +147,120 @@ public function testStaticAddNodeTypeWithoutNodeType() {
127147 $ this ->setExpectedException ('\\PE \\Exceptions \\EncoderNodeException ' , 'The node type you \'re trying to add seems to be a regular node because it has a no type name. Make sure you try to add an EncoderNode with a type name ' );
128148 EncoderNode::addNodeType ($ this ->nodeType ());
129149 }
150+
151+ public function testStaticGetNodeTypeByObject () {
152+ $ this ->addBuildingNode ();
153+ $ houseNode = $ this ->addBuildingHouseNode ();
154+ $ house = $ this ->getBuildingHouse ();
155+ $ this ->assertEquals ($ houseNode , EncoderNode::getNodeTypeByObject ($ house ));
156+ $ this ->assertNull (EncoderNode::getNodeTypeByObject ($ this ->getThing ()));
157+
158+ // from cache
159+ $ this ->assertEquals ($ houseNode , EncoderNode::getNodeTypeByObject ($ house ));
160+ }
161+
162+ public function testStaticGetNodeTypesAll () {
163+ $ this ->addBuildingNode ();
164+ $ this ->addBuildingHouseNode ();
165+
166+ $ types = EncoderNode::getNodeTypes ();
167+ $ this ->assertCount (2 , $ types );
168+ $ this ->assertArrayHasKey ('buildings:default ' , $ types );
169+ $ this ->assertArrayHasKey ('buildings:house ' , $ types );
170+
171+ $ this ->assertEquals ('PE \\Nodes \\Farm \\BuildingNode ' , get_class ($ types ['buildings:default ' ]));
172+ $ this ->assertEquals ('PE \\Nodes \\Farm \\Buildings\HouseNode ' , get_class ($ types ['buildings:house ' ]));
173+ }
174+
175+ public function testStaticGetNodeTypesOfType () {
176+ $ this ->addHouseNodes ();
177+
178+ $ types = EncoderNode::getNodeTypes ('buildings ' );
179+ $ this ->assertCount (2 , $ types );
180+ $ this ->assertArrayHasKey ('default ' , $ types );
181+ $ this ->assertArrayHasKey ('house ' , $ types );
182+
183+ $ this ->assertEquals ('PE \\Nodes \\Farm \\BuildingNode ' , get_class ($ types ['default ' ]));
184+ $ this ->assertEquals ('PE \\Nodes \\Farm \\Buildings\HouseNode ' , get_class ($ types ['house ' ]));
185+ }
186+
187+ public function testStaticGetNodeType () {
188+ $ this ->addBuildingNode ();
189+ $ this ->addBuildingHouseNode ();
190+
191+ $ this ->assertEquals ('PE \\Nodes \\Farm \\Buildings\HouseNode ' , get_class (EncoderNode::getNodeType ('buildings ' , 'house ' )));
192+ $ this ->assertNull (EncoderNode::getNodeType ('buildings ' , 'unknown ' ));
193+ $ this ->assertNull (EncoderNode::getNodeType ('unknown ' , 'unknown ' ));
194+ }
195+
196+ public function testStaticNodeTypeExists () {
197+ $ this ->addBuildingNode ();
198+ $ this ->addBuildingHouseNode ();
199+
200+ $ this ->assertTrue (EncoderNode::nodeTypeExists ('buildings ' , 'house ' ));
201+ $ this ->assertFalse (EncoderNode::nodeTypeExists ('buildings ' , 'unknown ' ));
202+ $ this ->assertFalse (EncoderNode::nodeTypeExists ('unknown ' , 'unknown ' ));
203+ }
204+
205+ public function testStaticClean () {
206+ $ this ->addBuildingNode ();
207+ $ this ->addBuildingHouseNode ();
208+
209+ $ this ->assertCount (2 , EncoderNode::getNodeTypes ());
210+ $ this ->assertCount (2 , EncoderNode::getNodes ());
211+
212+ EncoderNode::clean ();
213+
214+ $ this ->assertEmpty (EncoderNode::getNodeTypes ());
215+ $ this ->assertEmpty (EncoderNode::getNodes ());
216+ }
217+
218+
219+
220+
221+ public function testClassPrepend () {
222+ $ buildingNode = $ this ->addBuildingNode ();
223+
224+ $ this ->assertEquals ('\\PE \\Samples \\Farm ' , $ buildingNode ->classPrepend ());
225+ }
226+
227+ public function testGetNodeObjectName () {
228+ $ buildingNode = $ this ->addBuildingNode ();
229+
230+ $ this ->assertEquals ('Building ' , $ buildingNode ->getNodeObjectName ());
231+
232+ // get it from cache
233+ $ this ->assertEquals ('Building ' , $ buildingNode ->getNodeObjectName ());
234+ }
235+
236+ public function testNodeIsObject () {
237+ $ this ->addBuildingNode ();
238+ $ houseNode = $ this ->addBuildingHouseNode ();
239+ $ house = $ this ->getBuildingHouse ();
240+
241+ $ this ->assertFalse ($ houseNode ->nodeIsObject ($ this ->getThing ()));
242+ $ this ->assertTrue ($ houseNode ->nodeIsObject ($ house ));
243+
244+ // get from cache
245+ $ this ->assertTrue ($ houseNode ->nodeIsObject ($ house ));
246+ }
247+
248+ public function testGetNodeName () {
249+ $ this ->addBuildingNode ();
250+ $ houseNode = $ this ->addBuildingHouseNode ();
251+
252+ $ this ->assertEquals ('buildings ' , $ houseNode ->getNodeName ());
253+ }
254+ public function testGetNodeNameSingle () {
255+ $ this ->addBuildingNode ();
256+ $ houseNode = $ this ->addBuildingHouseNode ();
257+
258+ $ this ->assertEquals ('building ' , $ houseNode ->getNodeNameSingle ());
259+ }
260+ public function testGetNodeTypeName () {
261+ $ this ->addBuildingNode ();
262+ $ houseNode = $ this ->addBuildingHouseNode ();
263+
264+ $ this ->assertEquals ('house ' , $ houseNode ->getNodeTypeName ());
265+ }
130266}
0 commit comments