55use PE \Enums \ActionVariable ;
66use PE \Nodes \EncoderNodeVariable ;
77use PE \Tests \Samples ;
8+ use PE \Variables \Types \NodeAccessor ;
89use PE \Variables \Types \ObjectGetter ;
910use PE \Variables \Types \ObjectSetter ;
11+ use PE \Variables \Types \PostNodeSetter ;
1012
1113class EncoderNodeVariableTest extends Samples {
1214
@@ -113,203 +115,4 @@ public function testProcessValueUnknownTypeException() {
113115 $ variable ->setType ('unknown ' );
114116 $ variable ->getObjectSetter ()->processValue ('string ' );
115117 }
116-
117- public function testCallNodeSetterAction () {
118- $ node = $ this ->getAccessorMethodActionTypeNodeNode ();
119- $ variable = $ node ->getVariable ('node ' );
120-
121- $ this ->assertEquals (array (
122- 'node ' => 'hello world ' ,
123- 'special ' => 'hello world ' ,
124- ), $ variable ->callNodeSetterAction ($ node , array (
125- ActionVariable::GETTER_NODE_DATA => array (
126- 'node ' => 'hello world ' ,
127- ),
128- ActionVariable::GETTER_NAME => 'node '
129- )));
130- }
131-
132- public function testCallNodeSetterActionWithActionTypeNotNode () {
133- $ node = $ this ->getAccessorMethodActionTypeNodeNode ();
134- $ variable = $ node ->getVariable ('node ' );
135- $ setterAction = $ variable ->getSetterAction ();
136- $ setterAction ['type ' ] = 'not-node ' ;
137- $ variable ->setSetterAction ($ setterAction );
138-
139- $ this ->assertNull ($ variable ->callNodeSetterAction ($ node , array (
140- ActionVariable::GETTER_NODE_DATA => array (
141- 'node ' => 'hello world ' ,
142- ),
143- ActionVariable::GETTER_NAME => 'node '
144- )));
145- }
146-
147- public function testCallNodeSetterActionWithMissingVariable () {
148- $ this ->setExpectedException ('\\PE \\Exceptions \\EncoderNodeVariableException ' , 'Action variable "node_data" is not known ' );
149- $ node = $ this ->getAccessorMethodActionTypeNodeNode ();
150- $ this ->getAccessorMethodActionTypeNodeNode ()->getVariable ('node ' )->callNodeSetterAction ($ node , array ());
151- }
152-
153- public function testCallNodeSetterActionWithoutMethod () {
154- $ this ->setExpectedException ('\\PE \\Exceptions \\EncoderNodeVariableException ' , 'Either method must be a string or an array with a "method" key being a string ' );
155- $ node = $ this ->getAccessorMethodActionTypeNodeNode ();
156- $ variable = $ node ->getVariable ('node ' );
157- $ setterAction = $ variable ->getSetterAction ();
158- unset($ setterAction ['method ' ]);
159- $ variable ->setSetterAction ($ setterAction );
160-
161- $ variable ->callNodeSetterAction ($ node , array (
162- ActionVariable::GETTER_NODE_DATA => array (
163- 'node ' => 'hello world ' ,
164- ),
165- ActionVariable::GETTER_NAME => 'node '
166- ));
167- }
168-
169- public function testCallNodeGetterAction () {
170- $ node = $ this ->getAccessorMethodActionTypeNodeNode ();
171- $ variable = $ node ->getVariable ('node ' );
172-
173- $ this ->assertEquals (array (
174- 'node ' => 'hello world ' ,
175- 'special ' => 'hello world getter ' ,
176- ), $ variable ->callNodeGetterAction ($ node , array (
177- ActionVariable::GETTER_NODE_DATA => array (
178- 'node ' => 'hello world ' ,
179- ),
180- ActionVariable::GETTER_NAME => 'node '
181- )));
182- }
183-
184- public function testCallNodeGetterActionWithActionTypeNotNode () {
185- $ node = $ this ->getAccessorMethodActionTypeNodeNode ();
186- $ variable = $ node ->getVariable ('node ' );
187- $ setterAction = $ variable ->getGetterAction ();
188- $ setterAction ['type ' ] = 'not-node ' ;
189- $ variable ->setGetterAction ($ setterAction );
190-
191- $ this ->assertNull ($ variable ->callNodeGetterAction ($ node , array (
192- ActionVariable::GETTER_NODE_DATA => array (
193- 'node ' => 'hello world ' ,
194- ),
195- ActionVariable::GETTER_NAME => 'node '
196- )));
197- }
198-
199-
200- public function testApplyToSetterNodeSimple () {
201- $ node = $ this ->getEncoderNodeVariableApplyToSetterNode ();
202-
203- $ object = $ this ->getEncoderNodeVariableApplyToSetter ();
204- $ var = $ node ->getVariableById ('node-simple ' );
205-
206- $ this ->assertEquals (array (
207- 'node ' => 'test ' ,
208- 'copied ' => 'test ' ,
209- ), $ var ->applyToSetter (array (
210- ActionVariable::SETTER_OBJECT => $ object ,
211- ActionVariable::SETTER_NODE_DATA => array (
212- 'node ' => 'test '
213- ),
214- ActionVariable::SETTER_NODE => $ node ,
215- ActionVariable::SETTER_NAME => 'node ' ,
216- ActionVariable::SETTER_VALUE => 'test '
217- )));
218-
219- $ this ->assertNull ($ object ->getVar ());
220- }
221-
222- public function testApplyToSetterNodeFull () {
223- $ node = $ this ->getEncoderNodeVariableApplyToSetterNode ();
224-
225- $ object = $ this ->getEncoderNodeVariableApplyToSetter ();
226- $ parent = $ this ->getThing ();
227- $ var = $ node ->getVariableById ('node-full ' );
228-
229- $ this ->assertEquals (array (
230- 'node ' => 'test ' ,
231- 'name ' => 'node ' ,
232- 'value ' => 'test ' ,
233- 'object ' => $ object ,
234- 'parent ' => $ parent ,
235- ), $ var ->applyToSetter (array (
236- ActionVariable::SETTER_OBJECT => $ object ,
237- ActionVariable::SETTER_PARENT => $ parent ,
238- ActionVariable::SETTER_NODE_DATA => array (
239- 'node ' => 'test '
240- ),
241- ActionVariable::SETTER_NODE => $ node ,
242- ActionVariable::SETTER_NAME => 'node ' ,
243- ActionVariable::SETTER_VALUE => 'test '
244- )));
245- }
246-
247- public function testApplyToSetterNodeWithoutVariables () {
248- $ this ->_applyToSetterNodeWithoutVariables ('node-without-variables ' );
249- $ this ->_applyToSetterNodeWithoutVariables ('node-without-variables-empty ' );
250- $ this ->_applyToSetterNodeWithoutVariables ('node-without-variables-null ' );
251- }
252- protected function _applyToSetterNodeWithoutVariables ($ variable )
253- {
254- $ node = $ this ->getEncoderNodeVariableApplyToSetterNode ();
255-
256- $ object = $ this ->getEncoderNodeVariableApplyToSetter ();
257- $ var = $ node ->getVariableById ($ variable );
258-
259- $ this ->assertEquals (array (
260- 'test ' => 'altered ' ,
261- ), $ var ->applyToSetter (array (
262- ActionVariable::SETTER_OBJECT => $ object ,
263- ActionVariable::SETTER_NODE_DATA => array (
264- 'test ' => 'test '
265- ),
266- ActionVariable::SETTER_NODE => $ node ,
267- ActionVariable::SETTER_NAME => 'node ' ,
268- ActionVariable::SETTER_VALUE => 'test '
269- )));
270-
271- $ this ->assertNull ($ object ->getVar ());
272- }
273-
274- public function testApplyToSetterNodeUnknownVariable () {
275- $ this ->setExpectedException ('\\PE \\Exceptions \\EncoderNodeVariableException ' , 'Action variable id "unknown_variable" is not known ' );
276- $ node = $ this ->getEncoderNodeVariableApplyToSetterNode ();
277-
278- $ object = $ this ->getEncoderNodeVariableApplyToSetter ();
279- $ var = $ node ->getVariableById ('node-unknown-variable ' );
280-
281- $ var ->applyToSetter (array (
282- ActionVariable::SETTER_OBJECT => $ object ,
283- ActionVariable::SETTER_NODE_DATA => array (
284- 'node ' => 'test '
285- ),
286- ActionVariable::SETTER_NODE => $ node ,
287- ActionVariable::SETTER_NAME => 'node ' ,
288- ActionVariable::SETTER_VALUE => 'test '
289- ));
290- }
291-
292- public function testApplyToSetterObjectWithSetterMethod () {
293- $ this ->_applyToSetterObject ('var ' );
294- $ this ->_applyToSetterObject ('object-using-setter-action ' );
295- $ this ->_applyToSetterObject ('object-using-setter-method ' );
296- }
297-
298- public function testApplyToSetterObjectWithUnknownSetterMethod () {
299- $ this ->setExpectedException ('\\PE \\Exceptions \\EncoderNodeVariableException ' , 'Method "unknownMethod" does not exist for class PE\Samples\Specials\EncoderNodeVariableApplyToSetter does not exist ' );
300- $ this ->_applyToSetterObject ('object-using-unknown-setter-method ' );
301- }
302-
303- protected function _applyToSetterObject ($ variable ) {
304- $ node = $ this ->getEncoderNodeVariableApplyToSetterNode ();
305-
306- $ object = $ this ->getEncoderNodeVariableApplyToSetter ();
307- $ var = $ node ->getVariableById ($ variable );
308-
309- $ this ->assertTrue ($ var ->applyToSetter (array (
310- ActionVariable::SETTER_OBJECT => $ object ,
311- ActionVariable::SETTER_VALUE => 'test '
312- )));
313- $ this ->assertEquals ('test ' , $ object ->getVar ());
314- }
315118}
0 commit comments