|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
Prado::using('System.Util.*'); |
|
4
|
|
|
Prado::using('System.Collections.TPriorityList'); |
|
5
|
|
|
Prado::using('System.Collections.TPriorityMap'); |
|
6
|
|
|
|
|
7
|
|
|
class NewComponent extends TComponent { |
|
8
|
|
|
private $_object = null; |
|
9
|
|
|
private $_text = 'default'; |
|
10
|
|
|
private $_eventHandled = false; |
|
11
|
|
|
private $_return = null; |
|
12
|
|
|
private $_colorattribute = null; |
|
13
|
|
|
|
|
14
|
|
|
public function getAutoGlobalListen() { |
|
15
|
|
|
return true; |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function getText() { |
|
19
|
|
|
return $this->_text; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function setText($value) { |
|
23
|
|
|
$this->_text=$value; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function getReadOnlyProperty() { |
|
27
|
|
|
return 'read only'; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function getJsReadOnlyJsProperty() { |
|
31
|
|
|
return 'js read only'; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function getObject() { |
|
35
|
|
|
if(!$this->_object) { |
|
36
|
|
|
$this->_object=new NewComponent; |
|
37
|
|
|
$this->_object->_text='object text'; |
|
38
|
|
|
} |
|
39
|
|
|
return $this->_object; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function onMyEvent($param) { |
|
43
|
|
|
$this->raiseEvent('OnMyEvent',$this,$param); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function myEventHandler($sender,$param) { |
|
47
|
|
|
$this->_eventHandled=true; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function eventReturnValue($sender,$param) { |
|
51
|
|
|
return $param->Return; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function isEventHandled() { |
|
55
|
|
|
return $this->_eventHandled; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function resetEventHandled() { |
|
59
|
|
|
$this->_eventHandled = false; |
|
60
|
|
|
} |
|
61
|
|
|
public function getReturn() { |
|
62
|
|
|
return $this->_return; |
|
63
|
|
|
} |
|
64
|
|
|
public function setReturn($return) { |
|
65
|
|
|
$this->_return = $return; |
|
66
|
|
|
} |
|
67
|
|
|
public function getjsColorAttribute() { |
|
68
|
|
|
return $this->_colorattribute; |
|
69
|
|
|
} |
|
70
|
|
|
public function setjsColorAttribute($colorattribute) { |
|
71
|
|
|
$this->_colorattribute = $colorattribute; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
class NewComponentNoListen extends NewComponent { |
|
77
|
|
|
// this object does _not_ auto install global listeners during construction |
|
78
|
|
|
public function getAutoGlobalListen() { |
|
79
|
|
|
return false; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
class DynamicCatchingComponent extends NewComponentNoListen implements IDynamicMethods { |
|
84
|
|
|
public function __dycall($method, $args) { |
|
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
class GlobalRaiseComponent extends NewComponent implements IDynamicMethods { |
|
91
|
|
|
private $_callorder = array(); |
|
92
|
|
|
|
|
93
|
|
|
public function getCallOrders() |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->_callorder; |
|
96
|
|
|
} |
|
97
|
|
|
public function __dycall($method, $args) { |
|
|
|
|
|
|
98
|
|
|
if(strncasecmp($method,'fx',2)!==0) return; |
|
99
|
|
|
$this->_callorder[] = 'fxcall'; |
|
100
|
|
|
} |
|
101
|
|
|
public function fxGlobalListener($sender,$param,$name) { |
|
102
|
|
|
$this->_callorder[] = 'fxGL'; |
|
103
|
|
|
} |
|
104
|
|
|
public function fxPrimaryGlobalEvent($sender,$param,$name) { |
|
105
|
|
|
$this->_callorder[] = 'primary'; |
|
106
|
|
|
} |
|
107
|
|
|
public function commonRaiseEventListener($sender,$param,$name) { |
|
108
|
|
|
$this->_callorder[] = 'com'; |
|
109
|
|
|
} |
|
110
|
|
|
public function postglobalRaiseEventListener($sender,$param,$name) { |
|
111
|
|
|
$this->_callorder[] = 'postgl'; |
|
112
|
|
|
} |
|
113
|
|
|
public function preglobalRaiseEventListener($sender,$param,$name) { |
|
114
|
|
|
$this->_callorder[] = 'pregl'; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
class FooClassBehavior extends TClassBehavior { |
|
121
|
|
|
private $_baseObject = null; |
|
122
|
|
|
public function faaEverMore($object, $laa, $sol) { |
|
123
|
|
|
$this->_baseObject = $object; |
|
124
|
|
|
return $laa * $sol; |
|
125
|
|
|
} |
|
126
|
|
|
public function getLastClassObject() {return $this->_baseObject;} |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
class FooFooClassBehavior extends FooClassBehavior { |
|
130
|
|
|
public function faafaaEverMore($object, $laa, $sol) { |
|
131
|
|
|
|
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
class BarClassBehavior extends TClassBehavior { |
|
136
|
|
|
public function moreFunction($object, $laa, $sol) { |
|
137
|
|
|
return true; |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
|
|
142
|
|
|
|
|
143
|
|
|
class FooBehavior extends TBehavior { |
|
144
|
|
|
public function faaEverMore($laa, $sol) { |
|
145
|
|
|
return true; |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
class FooFooBehavior extends FooBehavior { |
|
149
|
|
|
|
|
150
|
|
|
public function faafaaEverMore($laa, $sol) { |
|
151
|
|
|
return sqrt($laa * $laa + $sol * $sol); |
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
class FooBarBehavior extends TBehavior { |
|
155
|
|
|
public function moreFunction($laa, $sol) { |
|
156
|
|
|
return $laa * $sol * $sol; |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
class PreBarBehavior extends TBehavior { |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
class BarBehavior extends PreBarBehavior implements IInstanceCheck { |
|
164
|
|
|
private $_instanceReturn = null; |
|
165
|
|
|
|
|
166
|
|
|
public function moreFunction($laa, $sol) { |
|
167
|
|
|
return pow($laa+$sol+1, 2); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
public function isinstanceof($class, $instance=null) { |
|
171
|
|
|
return $this->_instanceReturn; |
|
172
|
|
|
} |
|
173
|
|
|
public function setInstanceReturn($value) { |
|
174
|
|
|
$this->_instanceReturn = $value; |
|
175
|
|
|
} |
|
176
|
|
|
} |
|
177
|
|
|
class DynamicCallComponent extends NewComponent implements IDynamicMethods { |
|
178
|
|
|
public function __dycall($method, $args) { |
|
|
|
|
|
|
179
|
|
|
if($method === 'dyPowerFunction') |
|
180
|
|
|
return pow($args[0], $args[1]); |
|
181
|
|
|
if($method === 'dyDivisionFunction') |
|
182
|
|
|
return $args[0] / $args[1]; |
|
183
|
|
|
if($method === 'fxPowerFunction') |
|
184
|
|
|
return 2*pow($args[0], $args[1]); |
|
185
|
|
|
if($method === 'fxDivisionFunction') |
|
186
|
|
|
return 2*$args[0] / $args[1]; |
|
187
|
|
|
} |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
|
|
191
|
|
|
|
|
192
|
|
|
class BehaviorTestBehavior extends TBehavior { |
|
193
|
|
|
private $excitement = 'faa'; |
|
194
|
|
|
public function getExcitement() { |
|
195
|
|
|
return $this->excitement; |
|
196
|
|
|
} |
|
197
|
|
|
public function setExcitement($value) { |
|
198
|
|
|
$this->excitement = $value; |
|
199
|
|
|
} |
|
200
|
|
|
public function getReadOnly() { |
|
201
|
|
|
return true; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
public function onBehaviorEvent($sender, $param,$responsetype=null,$postfunction=null) { |
|
205
|
|
|
return $this->getOwner()->raiseEvent('onBehaviorEvent',$sender,$param,$responsetype,$postfunction); |
|
206
|
|
|
} |
|
207
|
|
|
public function fxGlobalBehaviorEvent($sender, $param) { |
|
208
|
|
|
} |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
class dy1TextReplace extends TBehavior { |
|
|
|
|
|
|
212
|
|
|
protected $_called = false; |
|
213
|
|
|
public function dyTextFilter($text, $callchain) { |
|
214
|
|
|
$this->_called = true; |
|
215
|
|
|
return str_replace("..", '__', $callchain->dyTextFilter($text)); |
|
216
|
|
|
} |
|
217
|
|
|
public function isCalled() { |
|
218
|
|
|
return $this->_called; |
|
219
|
|
|
} |
|
220
|
|
|
public function dyPowerFunction($x, $y, $callchain) |
|
221
|
|
|
{ |
|
222
|
|
|
return pow($x / $callchain->dyPowerFunction($x, $y), $y); |
|
223
|
|
|
} |
|
224
|
|
|
} |
|
225
|
|
|
class dy2TextReplace extends dy1TextReplace { |
|
|
|
|
|
|
226
|
|
|
public function dyTextFilter($text, $callchain) { |
|
227
|
|
|
$this->_called = true; |
|
228
|
|
|
return str_replace("++", '||', $callchain->dyTextFilter($text)); |
|
229
|
|
|
} |
|
230
|
|
|
} |
|
231
|
|
|
class dy3TextReplace extends dy1TextReplace { |
|
|
|
|
|
|
232
|
|
|
public function dyTextFilter($text, $callchain) { |
|
233
|
|
|
$this->_called = true; |
|
234
|
|
|
return str_replace("!!", '??', $callchain->dyTextFilter($text)); |
|
235
|
|
|
} |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
class dy1ClassTextReplace extends TClassBehavior { |
|
|
|
|
|
|
239
|
|
|
protected $_called = false; |
|
240
|
|
|
public function dyTextFilter($hostobject, $text, $callchain) { |
|
241
|
|
|
$this->_called = true; |
|
242
|
|
|
return str_replace("__", '..', $callchain->dyTextFilter($text)); |
|
243
|
|
|
} |
|
244
|
|
|
public function isCalled() { |
|
245
|
|
|
return $this->_called; |
|
246
|
|
|
} |
|
247
|
|
|
public function dyPowerFunction($hostobject, $x, $y, $callchain) |
|
248
|
|
|
{ |
|
249
|
|
|
return pow($x / $callchain->dyPowerFunction($x, $y), $y); |
|
250
|
|
|
} |
|
251
|
|
|
} |
|
252
|
|
|
class dy2ClassTextReplace extends dy1ClassTextReplace { |
|
|
|
|
|
|
253
|
|
|
public function dyTextFilter($hostobject, $text, $callchain) { |
|
254
|
|
|
$this->_called = true; |
|
255
|
|
|
return str_replace("||", '++', $callchain->dyTextFilter($text)); |
|
256
|
|
|
} |
|
257
|
|
|
} |
|
258
|
|
|
class dy3ClassTextReplace extends dy1ClassTextReplace { |
|
|
|
|
|
|
259
|
|
|
public function dyTextFilter($hostobject, $text, $callchain) { |
|
260
|
|
|
$this->_called = true; |
|
261
|
|
|
return str_replace("??", '^_^', $callchain->dyTextFilter($text)); |
|
262
|
|
|
} |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
|
|
266
|
|
|
class IntraObjectExtenderBehavior extends TBehavior { |
|
267
|
|
|
|
|
268
|
|
|
private $lastCall = null; |
|
269
|
|
|
private $arglist = null; |
|
270
|
|
|
|
|
271
|
|
|
public function getLastCall() { |
|
272
|
|
|
$v = $this->lastCall; |
|
273
|
|
|
$this->lastCall = null; |
|
274
|
|
|
return $v; |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
public function getLastArgumentList() { |
|
278
|
|
|
$v = $this->arglist; |
|
279
|
|
|
$this->arglist = null; |
|
280
|
|
|
return $v; |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
|
|
284
|
|
|
|
|
285
|
|
|
public function dyListen($fx, $chain) { |
|
286
|
|
|
$this->lastCall = 1; |
|
287
|
|
|
$this->arglist = func_get_args(); |
|
288
|
|
|
|
|
289
|
|
|
return $chain->dyListen($fx); // Calls the next event, within a chain |
|
290
|
|
|
} |
|
291
|
|
|
public function dyUnlisten($fx, $chain) { |
|
292
|
|
|
$this->lastCall = 2; |
|
293
|
|
|
$this->arglist = func_get_args(); |
|
294
|
|
|
|
|
295
|
|
|
return $chain->dyUnlisten($fx); |
|
296
|
|
|
} |
|
297
|
|
|
public function dyPreRaiseEvent($name,$sender,$param,$responsetype,$postfunction, $chain) { |
|
298
|
|
|
$this->lastCall = 3; |
|
299
|
|
|
$this->arglist = func_get_args(); |
|
300
|
|
|
|
|
301
|
|
|
return $chain->dyPreRaiseEvent($name);// Calls the next event, within a chain, if parameters are left off, they are filled in with |
|
302
|
|
|
// the original parameters passed to the dynamic event. Parameters can be passed if they are changed. |
|
303
|
|
|
} |
|
304
|
|
|
public function dyIntraRaiseEventTestHandler($handler,$sender,$param,$name, $chain) { |
|
305
|
|
|
$this->lastCall += 4; |
|
306
|
|
|
$this->arglist = func_get_args(); |
|
307
|
|
|
} |
|
308
|
|
|
public function dyIntraRaiseEventPostHandler($name,$sender,$param,$handler, $chain) { |
|
309
|
|
|
$this->lastCall += 5; |
|
310
|
|
|
$this->arglist = func_get_args(); |
|
311
|
|
|
} |
|
312
|
|
|
public function dyPostRaiseEvent($responses,$name,$sender,$param,$responsetype,$postfunction, $chain) { |
|
313
|
|
|
$this->lastCall += 6; |
|
314
|
|
|
$this->arglist = func_get_args(); |
|
315
|
|
|
} |
|
316
|
|
|
public function dyEvaluateExpressionFilter($expression, $chain) { |
|
317
|
|
|
$this->lastCall = 7; |
|
318
|
|
|
$this->arglist = func_get_args(); |
|
319
|
|
|
return $expression; |
|
320
|
|
|
} |
|
321
|
|
|
public function dyEvaluateStatementsFilter($statement, $chain) { |
|
322
|
|
|
$this->lastCall = 8; |
|
323
|
|
|
$this->arglist = func_get_args(); |
|
324
|
|
|
return $statement; |
|
325
|
|
|
} |
|
326
|
|
|
public function dyCreatedOnTemplate($parent, $chain) { |
|
327
|
|
|
$this->lastCall = 9; |
|
328
|
|
|
$this->arglist = func_get_args(); |
|
329
|
|
|
return $parent; |
|
330
|
|
|
} |
|
331
|
|
|
public function dyAddParsedObject($object, $chain) { |
|
332
|
|
|
$this->lastCall = 10; |
|
333
|
|
|
$this->arglist = func_get_args(); |
|
334
|
|
|
} |
|
335
|
|
|
public function dyAttachBehavior($name,$behavior, $chain) { |
|
336
|
|
|
$this->lastCall = 11; |
|
337
|
|
|
$this->arglist = func_get_args(); |
|
338
|
|
|
} |
|
339
|
|
|
public function dyDetachBehavior($name,$behavior, $chain) { |
|
340
|
|
|
$this->lastCall = 12; |
|
341
|
|
|
$this->arglist = func_get_args(); |
|
342
|
|
|
} |
|
343
|
|
|
public function dyEnableBehaviors($chain) { |
|
344
|
|
|
$this->lastCall += 13; |
|
345
|
|
|
$this->arglist = func_get_args(); |
|
346
|
|
|
} |
|
347
|
|
|
public function dyDisableBehaviors($chain) { |
|
348
|
|
|
$this->lastCall = 14; |
|
349
|
|
|
$this->arglist = func_get_args(); |
|
350
|
|
|
} |
|
351
|
|
|
public function dyEnableBehavior($name,$behavior, $chain) { |
|
352
|
|
|
$this->lastCall = 15; |
|
353
|
|
|
$this->arglist = func_get_args(); |
|
354
|
|
|
} |
|
355
|
|
|
public function dyDisableBehavior($name,$behavior, $chain) { |
|
356
|
|
|
$this->lastCall = 16; |
|
357
|
|
|
$this->arglist = func_get_args(); |
|
358
|
|
|
} |
|
359
|
|
|
} |
|
360
|
|
|
|
|
361
|
|
|
|
|
362
|
|
|
class IntraClassObjectExtenderBehavior extends TClassBehavior { |
|
363
|
|
|
} |
|
364
|
|
|
|
|
365
|
|
|
|
|
366
|
|
|
class TDynamicBehavior extends TBehavior implements IDynamicMethods { |
|
367
|
|
|
private $_dyMethod = null; |
|
368
|
|
|
public function getLastBehaviorDynamicMethodCalled() { |
|
369
|
|
|
return $this->_dyMethod; |
|
370
|
|
|
} |
|
371
|
|
|
public function __dycall($method, $args) { |
|
|
|
|
|
|
372
|
|
|
$this->_dyMethod = $method; |
|
373
|
|
|
if($method == 'dyTestDynamicBehaviorMethod') |
|
374
|
|
|
return $args[0] / $args[1]; |
|
375
|
|
|
} |
|
376
|
|
|
public function dyTestIntraEvent($param1, $param2, $chain) { |
|
377
|
|
|
return $chain->dyTestIntraEvent($param1*2*$param2, $param2); |
|
378
|
|
|
} |
|
379
|
|
|
public function TestBehaviorMethod($param1, $param2) { |
|
|
|
|
|
|
380
|
|
|
return $param1 * $param2; |
|
381
|
|
|
} |
|
382
|
|
|
} |
|
383
|
|
|
|
|
384
|
|
|
|
|
385
|
|
|
class TDynamicClassBehavior extends TClassBehavior implements IDynamicMethods { |
|
386
|
|
|
private $_dyMethod = null; |
|
387
|
|
|
public function getLastBehaviorDynamicMethodCalled() { |
|
388
|
|
|
return $this->_dyMethod; |
|
389
|
|
|
} |
|
390
|
|
|
//Dynamic Calls within class behaviors contain the main object as the first parameter within the args |
|
391
|
|
|
public function __dycall($method, $args) { |
|
|
|
|
|
|
392
|
|
|
$this->_dyMethod = $method; |
|
393
|
|
|
$object = array_shift($args); |
|
|
|
|
|
|
394
|
|
|
if($method == 'dyTestDynamicClassBehaviorMethod') |
|
395
|
|
|
return $args[0] / $args[1]; |
|
396
|
|
|
} |
|
397
|
|
|
public function dyTestIntraEvent($object, $param1, $param2, $chain) { |
|
398
|
|
|
return $chain->dyTestIntraEvent($param1*2*$param2, $param2); |
|
399
|
|
|
} |
|
400
|
|
|
public function TestBehaviorMethod($object, $param1, $param2) { |
|
|
|
|
|
|
401
|
|
|
return $param1 * $param2; |
|
402
|
|
|
} |
|
403
|
|
|
} |
|
404
|
|
|
|
|
405
|
|
|
|
|
406
|
|
|
|
|
407
|
|
|
|
|
408
|
|
|
/** |
|
409
|
|
|
* @package System |
|
410
|
|
|
*/ |
|
411
|
|
|
class TComponentTest extends PHPUnit_Framework_TestCase { |
|
412
|
|
|
|
|
413
|
|
|
protected $component; |
|
414
|
|
|
|
|
415
|
|
|
public function setUp() { |
|
416
|
|
|
$this->component = new NewComponent(); |
|
417
|
|
|
} |
|
418
|
|
|
|
|
419
|
|
|
|
|
420
|
|
|
public function tearDown() { |
|
421
|
|
|
// PHP version 5.3.6 doesn't call the __destruct method when unsetting variables; |
|
422
|
|
|
// Thus any object that listens must be explicitly call unlisten in this version of PHP. |
|
423
|
|
|
if($this->component) |
|
424
|
|
|
$this->component->unlisten(); |
|
425
|
|
|
$this->component = null; |
|
426
|
|
|
} |
|
427
|
|
|
|
|
428
|
|
|
|
|
429
|
|
|
public function testGetListeningToGlobalEvents() { |
|
430
|
|
|
$this->assertEquals(true, $this->component->getListeningToGlobalEvents()); |
|
431
|
|
|
$this->component->unlisten(); |
|
432
|
|
|
$this->assertEquals(false, $this->component->getListeningToGlobalEvents()); |
|
433
|
|
|
} |
|
434
|
|
|
|
|
435
|
|
|
|
|
436
|
|
|
public function testConstructorAutoListen() { |
|
437
|
|
|
// the default object auto installs class behavior hooks |
|
438
|
|
|
$this->assertEquals(1, $this->component->getEventHandlers('fxAttachClassBehavior')->getCount()); |
|
439
|
|
|
$this->assertEquals(1, $this->component->getEventHandlers('fxDetachClassBehavior')->getCount()); |
|
440
|
|
|
$this->assertTrue($this->component->getListeningToGlobalEvents()); |
|
441
|
|
|
|
|
442
|
|
|
// this object does not auto install class behavior hooks, thus not changing the global event structure. |
|
443
|
|
|
// Creating a new instance should _not_ influence the fxAttachClassBehavior and fxDetachClassBehavior |
|
444
|
|
|
// count. |
|
445
|
|
|
$component_nolisten = new NewComponentNoListen(); |
|
446
|
|
|
$this->assertEquals(1, $this->component->getEventHandlers('fxAttachClassBehavior')->getCount()); |
|
447
|
|
|
$this->assertEquals(1, $this->component->getEventHandlers('fxDetachClassBehavior')->getCount()); |
|
448
|
|
|
$this->assertEquals(1, $component_nolisten->getEventHandlers('fxAttachClassBehavior')->getCount()); |
|
449
|
|
|
$this->assertEquals(1, $component_nolisten->getEventHandlers('fxDetachClassBehavior')->getCount()); |
|
450
|
|
|
|
|
451
|
|
|
// tests order of class behaviors when a parent and class have class behavior. |
|
452
|
|
|
// The child should override the parent object-oriented programming style |
|
453
|
|
|
$this->component->attachClassBehavior('Bar', 'BarBehavior', 'NewComponentNoListen'); |
|
454
|
|
|
$this->component->attachClassBehavior('FooBar', 'FooBarBehavior', 'NewComponent'); |
|
455
|
|
|
|
|
456
|
|
|
//create new object with new class behaviors built in, defined in the two lines above |
|
457
|
|
|
$component = new NewComponentNoListen; |
|
458
|
|
|
|
|
459
|
|
|
$this->assertEquals(25, $component->moreFunction(2, 2)); |
|
460
|
|
|
|
|
461
|
|
|
$this->assertEquals(25, $component->Bar->moreFunction(2, 2)); |
|
462
|
|
|
$this->assertEquals(8, $component->FooBar->moreFunction(2, 2)); |
|
463
|
|
|
|
|
464
|
|
|
$component->unlisten();// unwind object and class behaviors |
|
465
|
|
|
$this->component->detachClassBehavior('FooBar', 'NewComponent'); |
|
466
|
|
|
$this->component->detachClassBehavior('Bar', 'NewComponentNoListen'); |
|
467
|
|
|
|
|
468
|
|
|
} |
|
469
|
|
|
|
|
470
|
|
|
|
|
471
|
|
|
public function testListenAndUnlisten() { |
|
472
|
|
|
|
|
473
|
|
|
$component = new NewComponentNoListen(); |
|
474
|
|
|
|
|
475
|
|
|
$this->assertEquals(false, $component->getListeningToGlobalEvents()); |
|
476
|
|
|
|
|
477
|
|
|
//This is from $this->component being instanced and listening. $component is accessing the global event structure |
|
478
|
|
|
$this->assertEquals(1, $component->getEventHandlers('fxAttachClassBehavior')->getCount()); |
|
479
|
|
|
|
|
480
|
|
|
$this->assertEquals(2, $component->listen()); |
|
481
|
|
|
|
|
482
|
|
|
$this->assertEquals(true, $component->getListeningToGlobalEvents()); |
|
483
|
|
|
|
|
484
|
|
|
//This is from $this->component being instanced and listening. $component is accessing the global event structure |
|
485
|
|
|
$this->assertEquals(2, $component->getEventHandlers('fxAttachClassBehavior')->getCount()); |
|
486
|
|
|
|
|
487
|
|
|
$this->assertEquals(2, $component->unlisten()); |
|
488
|
|
|
|
|
489
|
|
|
$this->assertEquals(false, $component->getListeningToGlobalEvents()); |
|
490
|
|
|
|
|
491
|
|
|
//This is from $this->component being instanced and listening. $component is accessing the global event structure |
|
492
|
|
|
$this->assertEquals(1, $component->getEventHandlers('fxAttachClassBehavior')->getCount()); |
|
493
|
|
|
} |
|
494
|
|
|
|
|
495
|
|
|
|
|
496
|
|
|
public function testListenAndUnlistenWithDynamicEventCatching() { |
|
497
|
|
|
|
|
498
|
|
|
$component = new DynamicCatchingComponent(); |
|
499
|
|
|
|
|
500
|
|
|
$this->assertEquals(false, $component->getListeningToGlobalEvents()); |
|
501
|
|
|
|
|
502
|
|
|
//This is from $this->component being instanced and listening. $component is accessing the global event structure |
|
503
|
|
|
$this->assertEquals(0, $component->getEventHandlers(TComponent::GLOBAL_RAISE_EVENT_LISTENER)->getCount()); |
|
504
|
|
|
|
|
505
|
|
|
// this adds the fxAttachClassBehavior, fxDetachClassBehavior, and __dycall of the component |
|
506
|
|
|
$this->assertEquals(3, $component->listen()); |
|
507
|
|
|
|
|
508
|
|
|
$this->assertEquals(true, $component->getListeningToGlobalEvents()); |
|
509
|
|
|
|
|
510
|
|
|
//This is from $this->component being instanced and listening. $component is accessing the global event structure |
|
511
|
|
|
$this->assertEquals(1, $component->getEventHandlers(TComponent::GLOBAL_RAISE_EVENT_LISTENER)->getCount()); |
|
512
|
|
|
|
|
513
|
|
|
$this->assertEquals(3, $component->unlisten()); |
|
514
|
|
|
|
|
515
|
|
|
$this->assertEquals(false, $component->getListeningToGlobalEvents()); |
|
516
|
|
|
|
|
517
|
|
|
//This is from $this->component being instanced and listening. $component is accessing the global event structure |
|
518
|
|
|
$this->assertEquals(0, $component->getEventHandlers(TComponent::GLOBAL_RAISE_EVENT_LISTENER)->getCount()); |
|
519
|
|
|
} |
|
520
|
|
|
|
|
521
|
|
|
|
|
522
|
|
|
|
|
523
|
|
|
//Test Class behaviors |
|
524
|
|
|
public function testAttachClassBehavior() { |
|
525
|
|
|
|
|
526
|
|
|
// ensure that the class is listening |
|
527
|
|
|
$this->assertEquals(1, $this->component->getEventHandlers('fxAttachClassBehavior')->getCount()); |
|
528
|
|
|
|
|
529
|
|
|
//Test that the component is not a FooClassBehavior |
|
530
|
|
|
$this->assertNull($this->component->asa('FooClassBehavior'), "Component is already a FooClassBehavior and should not have this behavior"); |
|
531
|
|
|
|
|
532
|
|
|
//Add the FooClassBehavior |
|
533
|
|
|
$this->component->attachClassBehavior('FooClassBehavior', new FooClassBehavior); |
|
534
|
|
|
|
|
535
|
|
|
//Test that the existing listening component can be a FooClassBehavior |
|
536
|
|
|
$this->assertNotNull($this->component->asa('FooClassBehavior'), "Component is does not have the FooClassBehavior and should have this behavior"); |
|
537
|
|
|
|
|
538
|
|
|
// test if the function modifies new instances of the object |
|
539
|
|
|
$anothercomponent = new NewComponent(); |
|
540
|
|
|
|
|
541
|
|
|
//The new component should be a FooClassBehavior |
|
542
|
|
|
$this->assertNotNull($anothercomponent->asa('FooClassBehavior'), "anothercomponent does not have the FooClassBehavior"); |
|
543
|
|
|
|
|
544
|
|
|
// test when overwriting an existing class behavior, it should throw an TInvalidOperationException |
|
545
|
|
|
try { |
|
546
|
|
|
$this->component->attachClassBehavior('FooClassBehavior', new BarClassBehavior); |
|
547
|
|
|
$this->fail('TInvalidOperationException not raised when overwriting an existing behavior'); |
|
548
|
|
|
} catch(TInvalidOperationException $e) { |
|
|
|
|
|
|
549
|
|
|
} |
|
550
|
|
|
|
|
551
|
|
|
|
|
552
|
|
|
// test when overwriting an existing class behavior, it should throw an TInvalidOperationException |
|
553
|
|
|
try { |
|
554
|
|
|
$this->component->attachClassBehavior('FooBarBehavior', 'FooBarBehavior', 'TComponent'); |
|
555
|
|
|
$this->fail('TInvalidOperationException not raised when trying to place a behavior on the root object TComponent'); |
|
556
|
|
|
} catch(TInvalidOperationException $e) { |
|
|
|
|
|
|
557
|
|
|
} |
|
558
|
|
|
|
|
559
|
|
|
|
|
560
|
|
|
// test if the function does not modify any existing objects that are not listening |
|
561
|
|
|
// The FooClassBehavior is already a part of the class behaviors thus the new instance gets the behavior. |
|
562
|
|
|
$nolistencomponent = new NewComponentNoListen(); |
|
563
|
|
|
|
|
564
|
|
|
// test if the function modifies all existing objects that are listening |
|
565
|
|
|
// Adding a behavior to the first object, the second instance should automatically get the class behavior. |
|
566
|
|
|
// This is because the second object is listening to the global events of class behaviors |
|
567
|
|
|
$this->component->attachClassBehavior('BarClassBehavior', new BarClassBehavior); |
|
568
|
|
|
$this->assertNotNull($anothercomponent->asa('BarClassBehavior'), "anothercomponent is does not have the BarClassBehavior"); |
|
569
|
|
|
|
|
570
|
|
|
// The no listen object should not have the BarClassBehavior because it was added as a class behavior after the object was instanced |
|
571
|
|
|
$this->assertNull($nolistencomponent->asa('BarClassBehavior'), "nolistencomponent has the BarClassBehavior and should not"); |
|
572
|
|
|
|
|
573
|
|
|
// But the no listen object should have the FooClassBehavior because the class behavior was installed before the object was instanced |
|
574
|
|
|
$this->assertNotNull($nolistencomponent->asa('FooClassBehavior'), "nolistencomponent is does not have the FooClassBehavior"); |
|
575
|
|
|
|
|
576
|
|
|
//Clear out what was done during this test |
|
577
|
|
|
$anothercomponent->unlisten(); |
|
578
|
|
|
$this->component->detachClassBehavior('FooClassBehavior'); |
|
579
|
|
|
$this->component->detachClassBehavior('BarClassBehavior'); |
|
580
|
|
|
|
|
581
|
|
|
// Test attaching of single object behaviors as class-wide behaviors |
|
582
|
|
|
$this->component->attachClassBehavior('BarBehaviorObject', 'BarBehavior'); |
|
583
|
|
|
$this->assertTrue($this->component->asa('BarBehaviorObject') instanceof BarBehavior); |
|
584
|
|
|
$this->assertEquals($this->component->BarBehaviorObject->Owner, $this->component); |
|
585
|
|
|
$this->component->detachClassBehavior('BarBehaviorObject'); |
|
586
|
|
|
} |
|
587
|
|
|
|
|
588
|
|
|
|
|
589
|
|
|
|
|
590
|
|
|
|
|
591
|
|
|
|
|
592
|
|
|
public function testDetachClassBehavior() { |
|
593
|
|
|
// ensure that the component is listening |
|
594
|
|
|
$this->assertEquals(1, $this->component->getEventHandlers('fxDetachClassBehavior')->getCount()); |
|
595
|
|
|
|
|
596
|
|
|
$prenolistencomponent = new NewComponentNoListen(); |
|
597
|
|
|
|
|
598
|
|
|
//Attach a class behavior |
|
599
|
|
|
$this->component->attachClassBehavior('FooClassBehavior', new FooClassBehavior); |
|
600
|
|
|
|
|
601
|
|
|
//Create new components that listen and don't listen to global events |
|
602
|
|
|
$anothercomponent = new NewComponent(); |
|
603
|
|
|
$postnolistencomponent = new NewComponentNoListen(); |
|
|
|
|
|
|
604
|
|
|
|
|
605
|
|
|
//ensures that all the Components are properly initialized |
|
606
|
|
|
$this->assertEquals(2, $this->component->getEventHandlers('fxDetachClassBehavior')->getCount()); |
|
607
|
|
|
$this->assertNotNull($this->component->asa('FooClassBehavior'), "Component does not have the FooClassBehavior and should have this behavior"); |
|
608
|
|
|
$this->assertNull($prenolistencomponent->asa('FooClassBehavior'), "Component has the FooClassBehavior and should _not_ have this behavior"); |
|
609
|
|
|
$this->assertNotNull($anothercomponent->asa('FooClassBehavior'), "Component does not have the FooClassBehavior and should have this behavior"); |
|
610
|
|
|
$this->assertNotNull($postnolistencomponent->asa('FooClassBehavior'), "Component does not have the FooClassBehavior and should have this behavior"); |
|
611
|
|
|
|
|
612
|
|
|
|
|
613
|
|
|
$this->component->detachClassBehavior('FooClassBehavior'); |
|
614
|
|
|
|
|
615
|
|
|
$this->assertNull($this->component->asa('FooClassBehavior'), "Component has the FooClassBehavior and should _not_ have this behavior"); |
|
616
|
|
|
$this->assertNull($prenolistencomponent->asa('FooClassBehavior'), "Component has the FooClassBehavior and should _not_ have this behavior"); |
|
617
|
|
|
$this->assertNull($anothercomponent->asa('FooClassBehavior'), "Component has the FooClassBehavior and should _not_ have this behavior"); |
|
618
|
|
|
$this->assertNotNull($postnolistencomponent->asa('FooClassBehavior'), "Component does not have the FooClassBehavior and should have this behavior"); |
|
619
|
|
|
|
|
620
|
|
|
|
|
621
|
|
|
//tear down function variables |
|
622
|
|
|
$anothercomponent->unlisten(); |
|
623
|
|
|
} |
|
624
|
|
|
|
|
625
|
|
|
public function testGetClassHierarchy() { |
|
626
|
|
|
$component = new DynamicCatchingComponent; |
|
627
|
|
|
$this->assertEquals(array('TComponent', 'NewComponent', 'NewComponentNoListen', 'DynamicCatchingComponent'), $component->getClassHierarchy()); |
|
628
|
|
|
$this->assertEquals(array('TComponent', 'NewComponent', 'NewComponentNoListen', 'DynamicCatchingComponent'), $component->getClassHierarchy(false)); |
|
629
|
|
|
$this->assertEquals(array('tcomponent', 'newcomponent', 'newcomponentnolisten', 'dynamiccatchingcomponent'), $component->getClassHierarchy(true)); |
|
630
|
|
|
} |
|
631
|
|
|
|
|
632
|
|
|
|
|
633
|
|
|
public function testAsA() { |
|
634
|
|
|
$anothercomponent = new NewComponent(); |
|
635
|
|
|
|
|
636
|
|
|
// ensure the component does not have the FooClassBehavior |
|
637
|
|
|
$this->assertNull($this->component->asa('FooClassBehavior')); |
|
638
|
|
|
$this->assertNull($this->component->asa('FooFooClassBehavior')); |
|
639
|
|
|
$this->assertNull($this->component->asa('BarClassBehavior')); |
|
640
|
|
|
$this->assertNull($this->component->asa('NonExistantClassBehavior')); |
|
641
|
|
|
|
|
642
|
|
|
$this->assertNull($anothercomponent->asa('FooClassBehavior')); |
|
643
|
|
|
$this->assertNull($anothercomponent->asa('FooFooClassBehavior')); |
|
644
|
|
|
$this->assertNull($anothercomponent->asa('BarClassBehavior')); |
|
645
|
|
|
$this->assertNull($anothercomponent->asa('NonExistantClassBehavior')); |
|
646
|
|
|
|
|
647
|
|
|
// add the class behavior |
|
648
|
|
|
$this->component->attachClassBehavior('FooClassBehavior', new FooClassBehavior); |
|
649
|
|
|
|
|
650
|
|
|
//Check that the component has only the class behavior assigned |
|
651
|
|
|
$this->assertNotNull($this->component->asa('FooClassBehavior')); |
|
652
|
|
|
$this->assertNull($this->component->asa('FooFooClassBehavior')); |
|
653
|
|
|
$this->assertNull($this->component->asa('BarClassBehavior')); |
|
654
|
|
|
$this->assertNull($this->component->asa('NonExistantClassBehavior')); |
|
655
|
|
|
|
|
656
|
|
|
//Check that the component has only the class behavior assigned |
|
657
|
|
|
$this->assertNotNull($anothercomponent->asa('FooClassBehavior')); |
|
658
|
|
|
$this->assertNull($anothercomponent->asa('FooFooClassBehavior')); |
|
659
|
|
|
$this->assertNull($anothercomponent->asa('BarClassBehavior')); |
|
660
|
|
|
$this->assertNull($anothercomponent->asa('NonExistantClassBehavior')); |
|
661
|
|
|
|
|
662
|
|
|
// remove the class behavior |
|
663
|
|
|
$this->component->detachClassBehavior('FooClassBehavior'); |
|
664
|
|
|
|
|
665
|
|
|
// Check the function doesn't have the behavior any more |
|
666
|
|
|
$this->assertNull($this->component->asa('FooClassBehavior')); |
|
667
|
|
|
$this->assertNull($this->component->asa('FooFooClassBehavior')); |
|
668
|
|
|
$this->assertNull($this->component->asa('BarClassBehavior')); |
|
669
|
|
|
$this->assertNull($this->component->asa('NonExistantClassBehavior')); |
|
670
|
|
|
|
|
671
|
|
|
$this->assertNull($anothercomponent->asa('FooClassBehavior')); |
|
672
|
|
|
$this->assertNull($anothercomponent->asa('FooFooClassBehavior')); |
|
673
|
|
|
$this->assertNull($anothercomponent->asa('BarClassBehavior')); |
|
674
|
|
|
$this->assertNull($anothercomponent->asa('NonExistantClassBehavior')); |
|
675
|
|
|
|
|
676
|
|
|
|
|
677
|
|
|
|
|
678
|
|
|
|
|
679
|
|
|
$this->component->attachBehavior('BarBehavior', new BarBehavior); |
|
680
|
|
|
|
|
681
|
|
|
//Check that the component has only the object behavior assigned |
|
682
|
|
|
$this->assertNull($this->component->asa('FooBehavior')); |
|
683
|
|
|
$this->assertNull($this->component->asa('FooFooBehavior')); |
|
684
|
|
|
$this->assertNotNull($this->component->asa('BarBehavior')); |
|
685
|
|
|
$this->assertNull($this->component->asa('NonExistantBehavior')); |
|
686
|
|
|
|
|
687
|
|
|
//Check that the component has the behavior assigned |
|
688
|
|
|
$this->assertNull($anothercomponent->asa('FooBehavior')); |
|
689
|
|
|
$this->assertNull($anothercomponent->asa('FooFooBehavior')); |
|
690
|
|
|
$this->assertNull($anothercomponent->asa('BarBehavior')); |
|
691
|
|
|
$this->assertNull($anothercomponent->asa('NonExistantBehavior')); |
|
692
|
|
|
|
|
693
|
|
|
$this->component->detachBehavior('BarBehavior'); |
|
694
|
|
|
|
|
695
|
|
|
//Check that the component has no object behaviors assigned |
|
696
|
|
|
$this->assertNull($this->component->asa('FooBehavior')); |
|
697
|
|
|
$this->assertNull($this->component->asa('FooFooBehavior')); |
|
698
|
|
|
$this->assertNull($this->component->asa('BarBehavior')); |
|
699
|
|
|
$this->assertNull($this->component->asa('NonExistantBehavior')); |
|
700
|
|
|
|
|
701
|
|
|
//Check that the component has no behavior assigned |
|
702
|
|
|
$this->assertNull($anothercomponent->asa('FooBehavior')); |
|
703
|
|
|
$this->assertNull($anothercomponent->asa('FooFooBehavior')); |
|
704
|
|
|
$this->assertNull($anothercomponent->asa('BarBehavior')); |
|
705
|
|
|
$this->assertNull($anothercomponent->asa('NonExistantBehavior')); |
|
706
|
|
|
|
|
707
|
|
|
$anothercomponent->unlisten(); |
|
708
|
|
|
} |
|
709
|
|
|
|
|
710
|
|
|
public function testIsA() { |
|
711
|
|
|
//This doesn't check the IInstanceCheck functionality, separate function |
|
712
|
|
|
|
|
713
|
|
|
$this->assertTrue($this->component->isa('TComponent')); |
|
714
|
|
|
$this->assertTrue($this->component->isa('NewComponent')); |
|
715
|
|
|
$this->assertFalse($this->component->isa(new FooBehavior)); |
|
716
|
|
|
$this->assertFalse($this->component->isa('FooBehavior')); |
|
717
|
|
|
|
|
718
|
|
|
//Ensure there is no BarBehavior |
|
719
|
|
|
$this->assertNull($this->component->asa('FooFooBehavior')); |
|
720
|
|
|
|
|
721
|
|
|
$this->assertFalse($this->component->isa('FooBehavior')); |
|
722
|
|
|
$this->assertFalse($this->component->isa('FooFooBehavior')); |
|
723
|
|
|
|
|
724
|
|
|
$this->component->attachBehavior('FooFooBehavior', new FooFooBehavior); |
|
725
|
|
|
|
|
726
|
|
|
$this->assertNotNull($this->component->asa('FooFooBehavior')); |
|
727
|
|
|
|
|
728
|
|
|
$this->assertTrue($this->component->isa('FooBehavior')); |
|
729
|
|
|
$this->assertTrue($this->component->isa('FooFooBehavior')); |
|
730
|
|
|
|
|
731
|
|
|
$this->component->disableBehaviors(); |
|
732
|
|
|
// It still has the behavior |
|
733
|
|
|
$this->assertNotNull($this->component->asa('FooFooBehavior')); |
|
734
|
|
|
|
|
735
|
|
|
// But it is not expressed |
|
736
|
|
|
$this->assertFalse($this->component->isa('FooBehavior')); |
|
737
|
|
|
$this->assertFalse($this->component->isa('FooFooBehavior')); |
|
738
|
|
|
|
|
739
|
|
|
$this->component->enableBehaviors(); |
|
740
|
|
|
$this->assertNotNull($this->component->asa('FooFooBehavior')); |
|
741
|
|
|
|
|
742
|
|
|
$this->assertTrue($this->component->isa('FooFooBehavior')); |
|
743
|
|
|
|
|
744
|
|
|
|
|
745
|
|
|
|
|
746
|
|
|
$this->component->attachBehavior('FooBarBehavior', new FooBarBehavior); |
|
747
|
|
|
|
|
748
|
|
|
$this->assertTrue($this->component->isa('FooBehavior')); |
|
749
|
|
|
$this->assertTrue($this->component->isa('FooBarBehavior')); |
|
750
|
|
|
|
|
751
|
|
|
$this->component->disableBehavior('FooBarBehavior'); |
|
752
|
|
|
|
|
753
|
|
|
$this->assertTrue($this->component->isa('FooBehavior')); |
|
754
|
|
|
$this->assertFalse($this->component->isa('FooBarBehavior')); |
|
755
|
|
|
|
|
756
|
|
|
$this->component->enableBehavior('FooBarBehavior'); |
|
757
|
|
|
$this->component->disableBehavior('FooFooBehavior'); |
|
758
|
|
|
$this->assertFalse($this->component->isa('FooBehavior')); |
|
759
|
|
|
$this->assertFalse($this->component->isa('FooFooBehavior')); |
|
760
|
|
|
$this->assertTrue($this->component->isa('FooBarBehavior')); |
|
761
|
|
|
|
|
762
|
|
|
$this->component->disableBehavior('FooBarBehavior'); |
|
763
|
|
|
$this->component->disableBehavior('FooFooBehavior'); |
|
764
|
|
|
|
|
765
|
|
|
$this->assertFalse($this->component->isa('FooBehavior')); |
|
766
|
|
|
$this->assertFalse($this->component->isa('FooFooBehavior')); |
|
767
|
|
|
$this->assertFalse($this->component->isa('FooBarBehavior')); |
|
768
|
|
|
|
|
769
|
|
|
$this->component->enableBehavior('FooBarBehavior'); |
|
770
|
|
|
$this->component->enableBehavior('FooFooBehavior'); |
|
771
|
|
|
|
|
772
|
|
|
$this->assertTrue($this->component->isa('FooFooBehavior')); |
|
773
|
|
|
$this->assertTrue($this->component->isa('FooBarBehavior')); |
|
774
|
|
|
|
|
775
|
|
|
|
|
776
|
|
|
$this->component->detachBehavior('FooFooBehavior'); |
|
777
|
|
|
$this->component->detachBehavior('FooBarBehavior'); |
|
778
|
|
|
|
|
779
|
|
|
$this->assertFalse($this->component->isa(new FooBehavior)); |
|
780
|
|
|
$this->assertFalse($this->component->isa('FooBehavior')); |
|
781
|
|
|
$this->assertFalse($this->component->isa(new FooFooBehavior)); |
|
782
|
|
|
$this->assertFalse($this->component->isa('FooFooBehavior')); |
|
783
|
|
|
$this->assertFalse($this->component->isa(new FooBarBehavior)); |
|
784
|
|
|
$this->assertFalse($this->component->isa('FooBarBehavior')); |
|
785
|
|
|
|
|
786
|
|
|
} |
|
787
|
|
|
|
|
788
|
|
|
public function testIsA_with_IInstanceCheck() { |
|
|
|
|
|
|
789
|
|
|
|
|
790
|
|
|
$this->assertTrue($this->component->isa('NewComponent')); |
|
791
|
|
|
$this->assertFalse($this->component->isa('PreBarBehavior')); |
|
792
|
|
|
|
|
793
|
|
|
$this->component->attachBehavior('BarBehavior', $behavior = new BarBehavior); |
|
794
|
|
|
|
|
795
|
|
|
$behavior->setInstanceReturn(null); |
|
796
|
|
|
|
|
797
|
|
|
$this->assertTrue($this->component->isa('NewComponent')); |
|
798
|
|
|
$this->assertTrue($this->component->isa('PreBarBehavior')); |
|
799
|
|
|
$this->assertFalse($this->component->isa('FooBehavior')); |
|
800
|
|
|
|
|
801
|
|
|
// This forces the iso on the BarBehavior to respond to any class with false |
|
802
|
|
|
$behavior->setInstanceReturn(false); |
|
803
|
|
|
$this->assertFalse($this->component->isa('PreBarBehavior')); |
|
804
|
|
|
$this->assertFalse($this->component->isa('FooBehavior')); |
|
805
|
|
|
|
|
806
|
|
|
//This forces the isa on the BarBehavior to respond to any class with true |
|
807
|
|
|
$behavior->setInstanceReturn(true); |
|
808
|
|
|
$this->assertTrue($this->component->isa('FooBehavior')); |
|
809
|
|
|
|
|
810
|
|
|
|
|
811
|
|
|
} |
|
812
|
|
|
|
|
813
|
|
|
public function testAttachDetachBehavior() { |
|
814
|
|
|
|
|
815
|
|
|
try { |
|
816
|
|
|
$this->component->faaEverMore(true, true); |
|
817
|
|
|
$this->fail('TApplicationException not raised trying to execute a undefined class method'); |
|
818
|
|
|
} catch(TApplicationException $e) {} |
|
|
|
|
|
|
819
|
|
|
|
|
820
|
|
|
$this->assertNull($this->component->asa('FooBehavior')); |
|
821
|
|
|
$this->assertFalse($this->component->isa('FooBehavior')); |
|
822
|
|
|
$this->assertNull($this->component->asa('BarBehavior')); |
|
823
|
|
|
$this->assertFalse($this->component->isa('BarBehavior')); |
|
824
|
|
|
|
|
825
|
|
|
try { |
|
826
|
|
|
$this->component->attachBehavior('FooBehavior', new TComponent); |
|
827
|
|
|
$this->fail('TApplicationException not raised trying to execute a undefined class method'); |
|
828
|
|
|
} catch(TInvalidDataTypeException $e) {} |
|
|
|
|
|
|
829
|
|
|
|
|
830
|
|
|
$this->component->attachBehavior('FooBehavior', new FooBehavior); |
|
831
|
|
|
|
|
832
|
|
|
$this->assertNotNull($this->component->asa('FooBehavior')); |
|
833
|
|
|
$this->assertTrue($this->component->isa('FooBehavior')); |
|
834
|
|
|
$this->assertNull($this->component->asa('BarBehavior')); |
|
835
|
|
|
$this->assertFalse($this->component->isa('BarBehavior')); |
|
836
|
|
|
|
|
837
|
|
|
try { |
|
838
|
|
|
$this->assertTrue($this->component->faaEverMore(true, true)); |
|
839
|
|
|
} catch(TApplicationException $e) { |
|
840
|
|
|
$this->fail('TApplicationException raised while trying to execute a behavior class method'); |
|
841
|
|
|
} |
|
842
|
|
|
|
|
843
|
|
|
try { |
|
844
|
|
|
$this->component->noMethodHere(true); |
|
845
|
|
|
$this->fail('TApplicationException not raised trying to execute a undefined class method'); |
|
846
|
|
|
} catch(TApplicationException $e) {} |
|
|
|
|
|
|
847
|
|
|
|
|
848
|
|
|
$this->assertTrue($this->component->disableBehavior('FooBehavior')); |
|
849
|
|
|
|
|
850
|
|
|
//BarBehavior is not a behavior at this time |
|
851
|
|
|
$this->assertNull($this->component->disableBehavior('BarBehavior')); |
|
852
|
|
|
|
|
853
|
|
|
try { |
|
854
|
|
|
$this->component->faaEverMore(true, true); |
|
855
|
|
|
$this->fail('TApplicationException not raised trying to execute a undefined class method'); |
|
856
|
|
|
} catch(TApplicationException $e) {} |
|
|
|
|
|
|
857
|
|
|
|
|
858
|
|
|
$this->assertTrue($this->component->enableBehavior('FooBehavior')); |
|
859
|
|
|
|
|
860
|
|
|
//BarBehavior is not a behavior at this time |
|
861
|
|
|
$this->assertNull($this->component->enableBehavior('BarBehavior')); |
|
862
|
|
|
|
|
863
|
|
|
try { |
|
864
|
|
|
$this->assertTrue($this->component->faaEverMore(true, true)); |
|
865
|
|
|
} catch(TApplicationException $e) { |
|
866
|
|
|
$this->fail('TApplicationException raised while trying to execute a behavior class method'); |
|
867
|
|
|
} |
|
868
|
|
|
|
|
869
|
|
|
$this->component->detachBehavior('FooBehavior'); |
|
870
|
|
|
|
|
871
|
|
|
$this->assertNull($this->component->asa('FooBehavior')); |
|
872
|
|
|
$this->assertFalse($this->component->isa('FooBehavior')); |
|
873
|
|
|
$this->assertNull($this->component->asa('BarBehavior')); |
|
874
|
|
|
$this->assertFalse($this->component->isa('BarBehavior')); |
|
875
|
|
|
|
|
876
|
|
|
} |
|
877
|
|
|
|
|
878
|
|
|
public function testAttachDetachBehaviors() { |
|
879
|
|
|
$this->assertNull($this->component->asa('FooBehavior')); |
|
880
|
|
|
$this->assertNull($this->component->asa('BarBehavior')); |
|
881
|
|
|
$this->assertNull($this->component->asa('FooBarBehavior')); |
|
882
|
|
|
$this->assertNull($this->component->asa('PreBarBehavior')); |
|
883
|
|
|
|
|
884
|
|
|
$this->component->attachBehaviors(array('FooFooBehavior' => new FooFooBehavior, 'BarBehavior' => new BarBehavior, 'PreBarBehavior' => new PreBarBehavior)); |
|
885
|
|
|
|
|
886
|
|
|
$this->assertNull($this->component->asa('FooBehavior')); |
|
887
|
|
|
$this->assertNotNull($this->component->asa('FooFooBehavior')); |
|
888
|
|
|
$this->assertNotNull($this->component->asa('BarBehavior')); |
|
889
|
|
|
$this->assertNull($this->component->asa('FooBarBehavior')); |
|
890
|
|
|
$this->assertNotNull($this->component->asa('PreBarBehavior')); |
|
891
|
|
|
|
|
892
|
|
|
$this->assertTrue($this->component->isa('FooFooBehavior')); |
|
893
|
|
|
$this->assertTrue($this->component->isa('FooBehavior')); |
|
894
|
|
|
$this->assertTrue($this->component->isa('BarBehavior')); |
|
895
|
|
|
$this->assertTrue($this->component->isa('PreBarBehavior')); |
|
896
|
|
|
$this->assertFalse($this->component->isa('FooBarBehavior')); |
|
897
|
|
|
|
|
898
|
|
|
$this->component->detachBehaviors(array('FooFooBehavior' => new FooFooBehavior, 'BarBehavior' => new BarBehavior)); |
|
899
|
|
|
|
|
900
|
|
|
$this->assertNull($this->component->asa('FooBehavior')); |
|
901
|
|
|
$this->assertNull($this->component->asa('FooFooBehavior')); |
|
902
|
|
|
$this->assertNull($this->component->asa('BarBehavior')); |
|
903
|
|
|
$this->assertNull($this->component->asa('FooBarBehavior')); |
|
904
|
|
|
$this->assertNotNull($this->component->asa('PreBarBehavior')); |
|
905
|
|
|
|
|
906
|
|
|
$this->assertFalse($this->component->isa('FooFooBehavior')); |
|
907
|
|
|
$this->assertFalse($this->component->isa('FooBehavior')); |
|
908
|
|
|
$this->assertFalse($this->component->isa('BarBehavior')); |
|
909
|
|
|
$this->assertFalse($this->component->isa('FooBarBehavior')); |
|
910
|
|
|
$this->assertTrue($this->component->isa('PreBarBehavior')); |
|
911
|
|
|
|
|
912
|
|
|
|
|
913
|
|
|
|
|
914
|
|
|
// testing if we can detachBehaviors just by the name of the behavior instead of an array of the behavior |
|
915
|
|
|
$this->component->attachBehaviors(array('FooFooBehavior' => new FooFooBehavior, 'BarBehavior' => new BarBehavior)); |
|
916
|
|
|
|
|
917
|
|
|
$this->assertTrue($this->component->isa('FooBehavior')); |
|
918
|
|
|
$this->assertTrue($this->component->isa('BarBehavior')); |
|
919
|
|
|
|
|
920
|
|
|
$this->component->detachBehaviors(array('FooFooBehavior', 'BarBehavior')); |
|
921
|
|
|
|
|
922
|
|
|
$this->assertNull($this->component->asa('FooBehavior')); |
|
923
|
|
|
$this->assertNull($this->component->asa('FooFooBehavior')); |
|
924
|
|
|
$this->assertNull($this->component->asa('BarBehavior')); |
|
925
|
|
|
$this->assertNull($this->component->asa('FooBarBehavior')); |
|
926
|
|
|
|
|
927
|
|
|
$this->assertFalse($this->component->isa('FooFooBehavior')); |
|
928
|
|
|
$this->assertFalse($this->component->isa('FooBehavior')); |
|
929
|
|
|
$this->assertFalse($this->component->isa('BarBehavior')); |
|
930
|
|
|
$this->assertFalse($this->component->isa('FooBarBehavior')); |
|
931
|
|
|
} |
|
932
|
|
|
|
|
933
|
|
|
|
|
934
|
|
|
public function testClearBehaviors() { |
|
935
|
|
|
|
|
936
|
|
|
$this->assertNull($this->component->asa('FooBehavior')); |
|
937
|
|
|
$this->assertNull($this->component->asa('BarBehavior')); |
|
938
|
|
|
$this->assertNull($this->component->asa('FooBarBehavior')); |
|
939
|
|
|
$this->assertNull($this->component->asa('PreBarBehavior')); |
|
940
|
|
|
|
|
941
|
|
|
$this->component->attachBehaviors(array('FooFooBehavior' => new FooFooBehavior, 'BarBehavior' => new BarBehavior, 'PreBarBehavior' => new PreBarBehavior)); |
|
942
|
|
|
|
|
943
|
|
|
$this->assertNull($this->component->asa('FooBehavior')); |
|
944
|
|
|
$this->assertNotNull($this->component->asa('FooFooBehavior')); |
|
945
|
|
|
$this->assertNotNull($this->component->asa('BarBehavior')); |
|
946
|
|
|
$this->assertNull($this->component->asa('FooBarBehavior')); |
|
947
|
|
|
$this->assertNotNull($this->component->asa('PreBarBehavior')); |
|
948
|
|
|
|
|
949
|
|
|
$this->component->clearBehaviors(); |
|
950
|
|
|
|
|
951
|
|
|
$this->assertNull($this->component->asa('FooBehavior')); |
|
952
|
|
|
$this->assertNull($this->component->asa('BarBehavior')); |
|
953
|
|
|
$this->assertNull($this->component->asa('FooBarBehavior')); |
|
954
|
|
|
$this->assertNull($this->component->asa('PreBarBehavior')); |
|
955
|
|
|
} |
|
956
|
|
|
|
|
957
|
|
|
public function testEnableDisableBehavior() { |
|
958
|
|
|
|
|
959
|
|
|
$this->assertNull($this->component->enableBehavior('FooBehavior')); |
|
960
|
|
|
$this->assertNull($this->component->disableBehavior('FooBehavior')); |
|
961
|
|
|
|
|
962
|
|
|
try { |
|
963
|
|
|
$this->component->faaEverMore(true, true); |
|
964
|
|
|
$this->fail('TApplicationException not raised trying to execute a undefined class method'); |
|
965
|
|
|
} catch(TApplicationException $e) {} |
|
|
|
|
|
|
966
|
|
|
|
|
967
|
|
|
$this->component->attachBehavior('FooBehavior', new FooBehavior); |
|
968
|
|
|
|
|
969
|
|
|
$this->assertTrue($this->component->isa('FooBehavior')); |
|
970
|
|
|
try { |
|
971
|
|
|
$this->assertTrue($this->component->faaEverMore(true, true)); |
|
972
|
|
|
} catch(TApplicationException $e) { |
|
973
|
|
|
$this->fail('TApplicationException raised while trying to execute a behavior class method'); |
|
974
|
|
|
} |
|
975
|
|
|
|
|
976
|
|
|
$this->assertTrue($this->component->disableBehavior('FooBehavior')); |
|
977
|
|
|
|
|
978
|
|
|
$this->assertFalse($this->component->isa('FooBehavior')); |
|
979
|
|
|
|
|
980
|
|
|
try { |
|
981
|
|
|
$this->component->faaEverMore(true, true); |
|
982
|
|
|
$this->fail('TApplicationException not raised trying to execute a undefined class method'); |
|
983
|
|
|
} catch(TApplicationException $e) {} |
|
|
|
|
|
|
984
|
|
|
|
|
985
|
|
|
$this->assertTrue($this->component->enableBehavior('FooBehavior')); |
|
986
|
|
|
|
|
987
|
|
|
$this->assertTrue($this->component->isa('FooBehavior')); |
|
988
|
|
|
try { |
|
989
|
|
|
$this->assertTrue($this->component->faaEverMore(true, true)); |
|
990
|
|
|
} catch(TApplicationException $e) { |
|
991
|
|
|
$this->fail('TApplicationException raised while trying to execute a behavior class method'); |
|
992
|
|
|
} |
|
993
|
|
|
|
|
994
|
|
|
|
|
995
|
|
|
|
|
996
|
|
|
$this->assertNull($this->component->enableBehavior('BarClassBehavior')); |
|
997
|
|
|
$this->assertNull($this->component->disableBehavior('BarClassBehavior')); |
|
998
|
|
|
|
|
999
|
|
|
try { |
|
1000
|
|
|
$this->component->moreFunction(true, true); |
|
1001
|
|
|
$this->fail('TApplicationException not raised trying to execute an undefined class method'); |
|
1002
|
|
|
} catch(TApplicationException $e) {} |
|
|
|
|
|
|
1003
|
|
|
|
|
1004
|
|
|
$this->component->attachClassBehavior('BarClassBehavior', new BarClassBehavior); |
|
1005
|
|
|
|
|
1006
|
|
|
$this->assertFalse($this->component->enableBehavior('BarClassBehavior')); |
|
1007
|
|
|
$this->assertFalse($this->component->disableBehavior('BarClassBehavior')); |
|
1008
|
|
|
|
|
1009
|
|
|
try { |
|
1010
|
|
|
$this->assertTrue($this->component->moreFunction(true, true)); |
|
1011
|
|
|
} catch(TApplicationException $e) { |
|
1012
|
|
|
$this->fail('TApplicationException raised while trying to execute a behavior class method'); |
|
1013
|
|
|
} |
|
1014
|
|
|
|
|
1015
|
|
|
$this->component->detachClassBehavior('BarClassBehavior'); |
|
1016
|
|
|
} |
|
1017
|
|
|
|
|
1018
|
|
|
|
|
1019
|
|
|
public function testBehaviorFunctionCalls() { |
|
1020
|
|
|
|
|
1021
|
|
|
$this->component->attachBehavior('FooBarBehavior', $behavior = new FooBarBehavior); |
|
1022
|
|
|
$this->component->attachClassBehavior('FooClassBehavior', $classbehavior = new FooClassBehavior); |
|
1023
|
|
|
|
|
1024
|
|
|
// Test the Class Methods |
|
1025
|
|
|
$this->assertEquals(12, $this->component->faaEverMore(3, 4)); |
|
1026
|
|
|
|
|
1027
|
|
|
// Check that the called object is shifted in front of the array of a class behavior call |
|
1028
|
|
|
$this->assertEquals($this->component, $this->component->getLastClassObject()); |
|
1029
|
|
|
|
|
1030
|
|
|
|
|
1031
|
|
|
//Test the FooBarBehavior |
|
1032
|
|
|
$this->assertEquals(27, $this->component->moreFunction(3, 3)); |
|
1033
|
|
|
|
|
1034
|
|
|
$this->assertTrue($this->component->disableBehavior('FooBarBehavior')); |
|
1035
|
|
|
try { |
|
1036
|
|
|
$this->assertNull($this->component->moreFunction(3, 4)); |
|
1037
|
|
|
$this->fail('TApplicationException not raised trying to execute a disabled behavior'); |
|
1038
|
|
|
} catch(TApplicationException $e) {} |
|
|
|
|
|
|
1039
|
|
|
$this->assertTrue($this->component->enableBehavior('FooBarBehavior')); |
|
1040
|
|
|
|
|
1041
|
|
|
// Test the global event space, this should work and return false because no function implements these methods |
|
1042
|
|
|
$this->assertNull($this->component->fxSomeUndefinedGlobalEvent()); |
|
1043
|
|
|
$this->assertNull($this->component->dySomeUndefinedIntraObjectEvent()); |
|
1044
|
|
|
|
|
1045
|
|
|
$this->component->detachClassBehavior('FooClassBehavior'); |
|
1046
|
|
|
|
|
1047
|
|
|
|
|
1048
|
|
|
|
|
1049
|
|
|
// test object instance behaviors implemented through class-wide behaviors |
|
1050
|
|
|
$this->component->attachClassBehavior('FooFooBehaviorAsClass', 'FooFooBehavior'); |
|
1051
|
|
|
|
|
1052
|
|
|
$component = new NewComponent; |
|
1053
|
|
|
|
|
1054
|
|
|
$this->assertEquals(5, $this->component->faafaaEverMore(3, 4)); |
|
1055
|
|
|
$this->assertEquals(10, $component->faafaaEverMore(6, 8)); |
|
1056
|
|
|
|
|
1057
|
|
|
$this->component->detachClassBehavior('FooFooBehaviorAsClass'); |
|
1058
|
|
|
$component->unlisten(); |
|
1059
|
|
|
$component = null; |
|
|
|
|
|
|
1060
|
|
|
|
|
1061
|
|
|
try { |
|
1062
|
|
|
$this->component->faafaaEverMore(3, 4); |
|
1063
|
|
|
$this->fail('TApplicationException not raised trying to execute a disabled behavior'); |
|
1064
|
|
|
} catch(TApplicationException $e) {} |
|
|
|
|
|
|
1065
|
|
|
|
|
1066
|
|
|
|
|
1067
|
|
|
|
|
1068
|
|
|
// make a call to an unpatched fx and dy call so that it's passed through to the __dycall function |
|
1069
|
|
|
$dynamicComponent = new DynamicCallComponent; |
|
1070
|
|
|
|
|
1071
|
|
|
$this->assertNull($dynamicComponent->fxUndefinedEvent()); |
|
1072
|
|
|
$this->assertNull($dynamicComponent->dyUndefinedEvent()); |
|
1073
|
|
|
|
|
1074
|
|
|
//This tests the dynamic __dycall function |
|
1075
|
|
|
$this->assertEquals(1024, $dynamicComponent->dyPowerFunction(2, 10)); |
|
1076
|
|
|
$this->assertEquals(5, $dynamicComponent->dyDivisionFunction(10, 2)); |
|
1077
|
|
|
|
|
1078
|
|
|
$this->assertEquals(2048, $dynamicComponent->fxPowerFunction(2, 10)); |
|
1079
|
|
|
$this->assertEquals(10, $dynamicComponent->fxDivisionFunction(10, 2)); |
|
1080
|
|
|
|
|
1081
|
|
|
$dynamicComponent->unlisten(); |
|
1082
|
|
|
|
|
1083
|
|
|
} |
|
1084
|
|
|
|
|
1085
|
|
|
|
|
1086
|
|
|
public function testHasProperty() { |
|
1087
|
|
|
$this->assertTrue($this->component->hasProperty('Text'), "Component hasn't property Text"); |
|
1088
|
|
|
$this->assertTrue($this->component->hasProperty('text'), "Component hasn't property text"); |
|
1089
|
|
|
$this->assertFalse($this->component->hasProperty('Caption'), "Component has property Caption"); |
|
1090
|
|
|
|
|
1091
|
|
|
$this->assertTrue($this->component->hasProperty('ColorAttribute'), "Component hasn't property JsColorAttribute"); |
|
1092
|
|
|
$this->assertTrue($this->component->hasProperty('colorattribute'), "Component hasn't property JsColorAttribute"); |
|
1093
|
|
|
$this->assertFalse($this->component->canGetProperty('PastelAttribute'), "Component has property JsPastelAttribute"); |
|
1094
|
|
|
|
|
1095
|
|
|
$this->assertTrue($this->component->hasProperty('JSColorAttribute'), "Component hasn't property JsColorAttribute"); |
|
1096
|
|
|
$this->assertTrue($this->component->hasProperty('jscolorattribute'), "Component hasn't property JsColorAttribute"); |
|
1097
|
|
|
$this->assertFalse($this->component->hasProperty('jsPastelAttribute'), "Component has property JsPastelAttribute"); |
|
1098
|
|
|
|
|
1099
|
|
|
$this->assertFalse($this->component->hasProperty('Excitement'), "Component has property Excitement"); |
|
1100
|
|
|
$this->component->attachBehavior('ExcitementPropBehavior', new BehaviorTestBehavior); |
|
1101
|
|
|
$this->assertTrue($this->component->hasProperty('Excitement'), "Component hasn't property Excitement"); |
|
1102
|
|
|
$this->component->disableBehaviors(); |
|
1103
|
|
|
$this->assertFalse($this->component->hasProperty('Excitement'), "Component has property Excitement"); |
|
1104
|
|
|
$this->component->enableBehaviors(); |
|
1105
|
|
|
$this->assertTrue($this->component->hasProperty('Excitement'), "Component hasn't property Excitement"); |
|
1106
|
|
|
$this->component->disableBehavior('ExcitementPropBehavior'); |
|
1107
|
|
|
$this->assertFalse($this->component->hasProperty('Excitement'), "Component has property Excitement"); |
|
1108
|
|
|
$this->component->enableBehavior('ExcitementPropBehavior'); |
|
1109
|
|
|
$this->assertTrue($this->component->hasProperty('Excitement'), "Component hasn't property Excitement"); |
|
1110
|
|
|
|
|
1111
|
|
|
$this->component->detachBehavior('ExcitementPropBehavior'); |
|
1112
|
|
|
|
|
1113
|
|
|
$this->assertFalse($this->component->hasProperty('Excitement'), "Component has property Excitement"); |
|
1114
|
|
|
|
|
1115
|
|
|
} |
|
1116
|
|
|
|
|
1117
|
|
|
public function testCanGetProperty() { |
|
1118
|
|
|
$this->assertTrue($this->component->canGetProperty('Text')); |
|
1119
|
|
|
$this->assertTrue($this->component->canGetProperty('text')); |
|
1120
|
|
|
$this->assertFalse($this->component->canGetProperty('Caption')); |
|
1121
|
|
|
|
|
1122
|
|
|
$this->assertTrue($this->component->canGetProperty('ColorAttribute')); |
|
1123
|
|
|
$this->assertTrue($this->component->canGetProperty('colorattribute')); |
|
1124
|
|
|
$this->assertFalse($this->component->canGetProperty('PastelAttribute')); |
|
1125
|
|
|
|
|
1126
|
|
|
$this->assertTrue($this->component->canGetProperty('JSColorAttribute')); |
|
1127
|
|
|
$this->assertTrue($this->component->canGetProperty('jscolorattribute')); |
|
1128
|
|
|
$this->assertFalse($this->component->canGetProperty('jsPastelAttribute')); |
|
1129
|
|
|
|
|
1130
|
|
|
|
|
1131
|
|
|
$this->assertFalse($this->component->canGetProperty('Excitement'), "Component has property Excitement"); |
|
1132
|
|
|
$this->component->attachBehavior('ExcitementPropBehavior', new BehaviorTestBehavior); |
|
1133
|
|
|
$this->assertTrue($this->component->canGetProperty('Excitement'), "Component hasn't property Excitement"); |
|
1134
|
|
|
$this->component->disableBehaviors(); |
|
1135
|
|
|
$this->assertFalse($this->component->canGetProperty('Excitement'), "Component has property Excitement"); |
|
1136
|
|
|
$this->component->enableBehaviors(); |
|
1137
|
|
|
$this->assertTrue($this->component->canGetProperty('Excitement'), "Component hasn't property Excitement"); |
|
1138
|
|
|
$this->component->disableBehavior('ExcitementPropBehavior'); |
|
1139
|
|
|
$this->assertFalse($this->component->canGetProperty('Excitement'), "Component has property Excitement"); |
|
1140
|
|
|
$this->component->enableBehavior('ExcitementPropBehavior'); |
|
1141
|
|
|
$this->assertTrue($this->component->canGetProperty('Excitement'), "Component hasn't property Excitement"); |
|
1142
|
|
|
|
|
1143
|
|
|
$this->component->detachBehavior('ExcitementPropBehavior'); |
|
1144
|
|
|
|
|
1145
|
|
|
$this->assertFalse($this->component->canGetProperty('Excitement'), "Component has property Excitement"); |
|
1146
|
|
|
} |
|
1147
|
|
|
|
|
1148
|
|
|
public function testCanSetProperty() { |
|
1149
|
|
|
$this->assertTrue($this->component->canSetProperty('Text')); |
|
1150
|
|
|
$this->assertTrue($this->component->canSetProperty('text')); |
|
1151
|
|
|
$this->assertFalse($this->component->canSetProperty('Caption')); |
|
1152
|
|
|
|
|
1153
|
|
|
$this->assertTrue($this->component->canSetProperty('ColorAttribute')); |
|
1154
|
|
|
$this->assertTrue($this->component->canSetProperty('colorattribute')); |
|
1155
|
|
|
$this->assertFalse($this->component->canSetProperty('PastelAttribute')); |
|
1156
|
|
|
|
|
1157
|
|
|
$this->assertTrue($this->component->canSetProperty('JSColorAttribute')); |
|
1158
|
|
|
$this->assertTrue($this->component->canSetProperty('jscolorattribute')); |
|
1159
|
|
|
$this->assertFalse($this->component->canSetProperty('jsPastelAttribute')); |
|
1160
|
|
|
|
|
1161
|
|
|
$this->assertFalse($this->component->canSetProperty('Excitement'), "Component has property Excitement"); |
|
1162
|
|
|
$this->component->attachBehavior('ExcitementPropBehavior', new BehaviorTestBehavior); |
|
1163
|
|
|
$this->assertTrue($this->component->canSetProperty('Excitement'), "Component hasn't property Excitement"); |
|
1164
|
|
|
$this->component->disableBehaviors(); |
|
1165
|
|
|
$this->assertFalse($this->component->canSetProperty('Excitement'), "Component has property Excitement"); |
|
1166
|
|
|
$this->component->enableBehaviors(); |
|
1167
|
|
|
$this->assertTrue($this->component->canSetProperty('Excitement'), "Component hasn't property Excitement"); |
|
1168
|
|
|
$this->component->disableBehavior('ExcitementPropBehavior'); |
|
1169
|
|
|
$this->assertFalse($this->component->canSetProperty('Excitement'), "Component has property Excitement"); |
|
1170
|
|
|
$this->component->enableBehavior('ExcitementPropBehavior'); |
|
1171
|
|
|
$this->assertTrue($this->component->canSetProperty('Excitement'), "Component hasn't property Excitement"); |
|
1172
|
|
|
|
|
1173
|
|
|
$this->component->detachBehavior('ExcitementPropBehavior'); |
|
1174
|
|
|
} |
|
1175
|
|
|
|
|
1176
|
|
|
public function testGetProperty() { |
|
1177
|
|
|
$this->assertTrue('default'===$this->component->Text); |
|
1178
|
|
|
try { |
|
1179
|
|
|
$value2=$this->component->Caption; |
|
|
|
|
|
|
1180
|
|
|
$this->fail('exception not raised when getting undefined property'); |
|
1181
|
|
|
} catch(TInvalidOperationException $e) { |
|
|
|
|
|
|
1182
|
|
|
} |
|
1183
|
|
|
|
|
1184
|
|
|
$this->assertTrue($this->component->OnMyEvent instanceof TPriorityList); |
|
1185
|
|
|
try { |
|
1186
|
|
|
$value2=$this->component->onUndefinedEvent; |
|
|
|
|
|
|
1187
|
|
|
$this->fail('exception not raised when getting undefined property'); |
|
1188
|
|
|
} catch(TInvalidOperationException $e) { |
|
|
|
|
|
|
1189
|
|
|
} |
|
1190
|
|
|
|
|
1191
|
|
|
//Without the function parenthesis, the function is _not_ called but the __get |
|
1192
|
|
|
// method is called and the global events (list) are accessed |
|
1193
|
|
|
$this->assertTrue($this->component->fxAttachClassBehavior instanceof TPriorityList); |
|
1194
|
|
|
$this->assertTrue($this->component->fxDetachClassBehavior instanceof TPriorityList); |
|
1195
|
|
|
|
|
1196
|
|
|
// even undefined global events have a list as every object is able to access every event |
|
1197
|
|
|
$this->assertTrue($this->component->fxUndefinedEvent instanceof TPriorityList); |
|
1198
|
|
|
|
|
1199
|
|
|
|
|
1200
|
|
|
// Test the behaviors within the __get function |
|
1201
|
|
|
$this->component->enableBehaviors(); |
|
1202
|
|
|
|
|
1203
|
|
|
try { |
|
1204
|
|
|
$value2=$this->component->Excitement; |
|
|
|
|
|
|
1205
|
|
|
$this->fail('exception not raised when getting undefined property'); |
|
1206
|
|
|
} catch(TInvalidOperationException $e) { |
|
|
|
|
|
|
1207
|
|
|
} |
|
1208
|
|
|
|
|
1209
|
|
|
$this->component->attachBehavior('BehaviorTestBehavior', $behavior = new BehaviorTestBehavior); |
|
1210
|
|
|
$this->assertEquals('faa', $this->component->Excitement); |
|
1211
|
|
|
|
|
1212
|
|
|
$this->component->disableBehaviors(); |
|
1213
|
|
|
|
|
1214
|
|
|
try { |
|
1215
|
|
|
$this->assertEquals('faa', $this->component->Excitement); |
|
1216
|
|
|
$this->fail('exception not raised when getting undefined property'); |
|
1217
|
|
|
} catch(TInvalidOperationException $e) { |
|
|
|
|
|
|
1218
|
|
|
} |
|
1219
|
|
|
|
|
1220
|
|
|
$this->component->enableBehaviors(); |
|
1221
|
|
|
$this->assertEquals('faa', $this->component->getExcitement()); |
|
1222
|
|
|
|
|
1223
|
|
|
$this->component->disableBehavior('BehaviorTestBehavior'); |
|
1224
|
|
|
|
|
1225
|
|
|
$this->assertEquals($behavior, $this->component->BehaviorTestBehavior); |
|
1226
|
|
|
try { |
|
1227
|
|
|
$behavior = $this->component->BehaviorTestBehavior2; |
|
|
|
|
|
|
1228
|
|
|
$this->fail('exception not raised when getting undefined property'); |
|
1229
|
|
|
} catch(TInvalidOperationException $e) { |
|
|
|
|
|
|
1230
|
|
|
} |
|
1231
|
|
|
|
|
1232
|
|
|
try { |
|
1233
|
|
|
$this->assertEquals('faa', $this->component->Excitement); |
|
1234
|
|
|
$this->fail('exception not raised when getting undefined property'); |
|
1235
|
|
|
} catch(TInvalidOperationException $e) { |
|
|
|
|
|
|
1236
|
|
|
} |
|
1237
|
|
|
$this->component->enableBehavior('BehaviorTestBehavior'); |
|
1238
|
|
|
$this->assertEquals('faa', $this->component->getExcitement()); |
|
1239
|
|
|
|
|
1240
|
|
|
|
|
1241
|
|
|
// behaviors allow on and fx events to be passed through. |
|
1242
|
|
|
$this->assertTrue($this->component->onBehaviorEvent instanceof TPriorityList); |
|
1243
|
|
|
|
|
1244
|
|
|
} |
|
1245
|
|
|
|
|
1246
|
|
|
public function testSetProperty() { |
|
1247
|
|
|
$value='new value'; |
|
1248
|
|
|
$this->component->Text=$value; |
|
1249
|
|
|
$text=$this->component->Text; |
|
|
|
|
|
|
1250
|
|
|
$this->assertTrue($value===$this->component->Text); |
|
1251
|
|
|
try { |
|
1252
|
|
|
$this->component->NewMember=$value; |
|
1253
|
|
|
$this->fail('exception not raised when setting undefined property'); |
|
1254
|
|
|
} catch(TInvalidOperationException $e) { |
|
|
|
|
|
|
1255
|
|
|
} |
|
1256
|
|
|
|
|
1257
|
|
|
// Test get only properties is a set function |
|
1258
|
|
|
try { |
|
1259
|
|
|
$this->component->ReadOnlyProperty = 'setting read only'; |
|
1260
|
|
|
$this->fail('a property without a set function was set to a new value without error'); |
|
1261
|
|
|
} catch(TInvalidOperationException $e) { |
|
|
|
|
|
|
1262
|
|
|
} |
|
1263
|
|
|
|
|
1264
|
|
|
try { |
|
1265
|
|
|
$this->component->ReadOnlyJsProperty = 'jssetting read only'; |
|
1266
|
|
|
$this->fail('a js property without a set function was set to a new value without error'); |
|
1267
|
|
|
} catch(TInvalidOperationException $e) { |
|
|
|
|
|
|
1268
|
|
|
} |
|
1269
|
|
|
|
|
1270
|
|
|
try { |
|
1271
|
|
|
$this->component->JsReadOnlyJsProperty = 'jssetting read only'; |
|
1272
|
|
|
$this->fail('a js property without a set function was set to a new value without error'); |
|
1273
|
|
|
} catch(TInvalidOperationException $e) { |
|
|
|
|
|
|
1274
|
|
|
} |
|
1275
|
|
|
|
|
1276
|
|
|
$this->assertEquals(0, $this->component->getEventHandlers('onMyEvent')->getCount()); |
|
1277
|
|
|
$this->component->onMyEvent = array($this->component,'myEventHandler'); |
|
1278
|
|
|
$this->assertEquals(1, $this->component->getEventHandlers('onMyEvent')->getCount()); |
|
1279
|
|
|
$this->component->onMyEvent[] = array($this->component,'Object.myEventHandler'); |
|
1280
|
|
|
$this->assertEquals(2, $this->component->getEventHandlers('onMyEvent')->getCount()); |
|
1281
|
|
|
|
|
1282
|
|
|
$this->component->getEventHandlers('onMyEvent')->clear(); |
|
1283
|
|
|
|
|
1284
|
|
|
// Test the behaviors within the __get function |
|
1285
|
|
|
$this->component->enableBehaviors(); |
|
1286
|
|
|
|
|
1287
|
|
|
try { |
|
1288
|
|
|
$this->component->Excitement = 'laa'; |
|
1289
|
|
|
$this->fail('exception not raised when getting undefined property'); |
|
1290
|
|
|
} catch(TInvalidOperationException $e) { |
|
|
|
|
|
|
1291
|
|
|
} |
|
1292
|
|
|
|
|
1293
|
|
|
$this->component->attachBehavior('BehaviorTestBehavior', $behavior1 = new BehaviorTestBehavior); |
|
1294
|
|
|
$this->component->Excitement = 'laa'; |
|
1295
|
|
|
$this->assertEquals('laa', $this->component->Excitement); |
|
1296
|
|
|
$this->assertEquals('sol', $this->component->Excitement = 'sol'); |
|
1297
|
|
|
|
|
1298
|
|
|
|
|
1299
|
|
|
$this->component->disableBehaviors(); |
|
1300
|
|
|
|
|
1301
|
|
|
try { |
|
1302
|
|
|
$this->component->Excitement = false; |
|
1303
|
|
|
$this->assertEquals(false, $this->component->Excitement); |
|
1304
|
|
|
$this->fail('exception not raised when getting undefined property'); |
|
1305
|
|
|
} catch(TInvalidOperationException $e) { |
|
|
|
|
|
|
1306
|
|
|
} |
|
1307
|
|
|
|
|
1308
|
|
|
$this->component->enableBehaviors(); |
|
1309
|
|
|
$this->component->Excitement = 'faa'; |
|
1310
|
|
|
$this->assertEquals('faa', $this->component->getExcitement()); |
|
1311
|
|
|
|
|
1312
|
|
|
$this->component->disableBehavior('BehaviorTestBehavior'); |
|
1313
|
|
|
|
|
1314
|
|
|
try { |
|
1315
|
|
|
$this->component->Excitement = false; |
|
1316
|
|
|
$this->assertEquals(false, $this->component->Excitement); |
|
1317
|
|
|
$this->fail('exception not raised when getting undefined property'); |
|
1318
|
|
|
} catch(TInvalidOperationException $e) { |
|
|
|
|
|
|
1319
|
|
|
} |
|
1320
|
|
|
$this->component->enableBehavior('BehaviorTestBehavior'); |
|
1321
|
|
|
$this->component->Excitement = 'sol'; |
|
1322
|
|
|
$this->assertEquals('sol', $this->component->Excitement); |
|
1323
|
|
|
|
|
1324
|
|
|
|
|
1325
|
|
|
$this->component->attachBehavior('BehaviorTestBehavior2', $behavior2 = new BehaviorTestBehavior); |
|
1326
|
|
|
|
|
1327
|
|
|
$this->assertEquals('sol', $this->component->Excitement); |
|
1328
|
|
|
$this->assertEquals('faa', $behavior2->Excitement); |
|
|
|
|
|
|
1329
|
|
|
|
|
1330
|
|
|
// this sets Excitement for both because they are not uniquely named |
|
1331
|
|
|
$this->component->Excitement = 'befaad'; |
|
1332
|
|
|
|
|
1333
|
|
|
$this->assertEquals('befaad', $this->component->Excitement); |
|
1334
|
|
|
$this->assertEquals('befaad', $behavior1->Excitement); |
|
|
|
|
|
|
1335
|
|
|
$this->assertEquals('befaad', $behavior2->Excitement); |
|
|
|
|
|
|
1336
|
|
|
|
|
1337
|
|
|
|
|
1338
|
|
|
$this->component->detachBehavior('BehaviorTestBehavior2'); |
|
1339
|
|
|
|
|
1340
|
|
|
// behaviors allow on and fx events to be passed through. |
|
1341
|
|
|
$this->assertTrue($this->component->BehaviorTestBehavior->onBehaviorEvent instanceof TPriorityList); |
|
1342
|
|
|
|
|
1343
|
|
|
$this->assertEquals(0, $this->component->BehaviorTestBehavior->getEventHandlers('onBehaviorEvent')->getCount()); |
|
1344
|
|
|
$this->component->onBehaviorEvent = array($this->component,'myEventHandler'); |
|
1345
|
|
|
$this->assertEquals(1, $this->component->BehaviorTestBehavior->getEventHandlers('onBehaviorEvent')->getCount()); |
|
1346
|
|
|
$this->component->onBehaviorEvent[] = array($this->component,'Object.myEventHandler'); |
|
1347
|
|
|
$this->assertEquals(2, $this->component->BehaviorTestBehavior->getEventHandlers('onBehaviorEvent')->getCount()); |
|
1348
|
|
|
|
|
1349
|
|
|
$this->component->BehaviorTestBehavior->getEventHandlers('onBehaviorEvent')->clear(); |
|
1350
|
|
|
} |
|
1351
|
|
|
|
|
1352
|
|
|
|
|
1353
|
|
|
public function testIsSetFunction() { |
|
1354
|
|
|
$this->assertTrue(isset($this->component->fxAttachClassBehavior)); |
|
1355
|
|
|
$this->component->unlisten(); |
|
1356
|
|
|
|
|
1357
|
|
|
$this->assertFalse(isset($this->component->onMyEvent)); |
|
1358
|
|
|
$this->assertFalse(isset($this->component->undefinedEvent)); |
|
1359
|
|
|
$this->assertFalse(isset($this->component->fxAttachClassBehavior)); |
|
1360
|
|
|
|
|
1361
|
|
|
$this->assertFalse(isset($this->component->BehaviorTestBehavior)); |
|
1362
|
|
|
$this->assertFalse(isset($this->component->onBehaviorEvent)); |
|
1363
|
|
|
|
|
1364
|
|
|
$this->component->attachBehavior('BehaviorTestBehavior', new BehaviorTestBehavior); |
|
1365
|
|
|
|
|
1366
|
|
|
$this->assertTrue(isset($this->component->BehaviorTestBehavior)); |
|
1367
|
|
|
$this->assertFalse(isset($this->component->onBehaviorEvent)); |
|
1368
|
|
|
|
|
1369
|
|
|
$this->component->attachEventHandler('onBehaviorEvent','foo'); |
|
1370
|
|
|
$this->assertTrue(isset($this->component->onBehaviorEvent)); |
|
1371
|
|
|
|
|
1372
|
|
|
$this->component->attachEventHandler('onMyEvent','foo'); |
|
1373
|
|
|
$this->assertTrue(isset($this->component->onMyEvent)); |
|
1374
|
|
|
|
|
1375
|
|
|
$this->assertTrue(isset($this->component->Excitement)); |
|
1376
|
|
|
$this->component->Excitement = null; |
|
1377
|
|
|
$this->assertFalse(isset($this->component->Excitement)); |
|
1378
|
|
|
$this->assertFalse(isset($this->component->UndefinedBehaviorProperty)); |
|
1379
|
|
|
|
|
1380
|
|
|
|
|
1381
|
|
|
} |
|
1382
|
|
|
|
|
1383
|
|
|
|
|
1384
|
|
|
public function testUnsetFunction() { |
|
1385
|
|
|
|
|
1386
|
|
|
$this->assertEquals('default', $this->component->getText()); |
|
1387
|
|
|
unset($this->component->Text); |
|
1388
|
|
|
$this->assertNull($this->component->getText()); |
|
1389
|
|
|
|
|
1390
|
|
|
unset($this->component->UndefinedProperty); |
|
1391
|
|
|
|
|
1392
|
|
|
// object events |
|
1393
|
|
|
$this->assertEquals(0, $this->component->onMyEvent->Count); |
|
1394
|
|
|
$this->component->attachEventHandler('onMyEvent','foo'); |
|
1395
|
|
|
$this->assertEquals(1, $this->component->onMyEvent->Count); |
|
1396
|
|
|
unset($this->component->onMyEvent); |
|
1397
|
|
|
$this->assertEquals(0, $this->component->onMyEvent->Count); |
|
1398
|
|
|
|
|
1399
|
|
|
//global events |
|
1400
|
|
|
$this->assertEquals(1, $this->component->fxAttachClassBehavior->Count); |
|
1401
|
|
|
$component = new NewComponent(); |
|
1402
|
|
|
$this->assertEquals(2, $this->component->fxAttachClassBehavior->Count); |
|
1403
|
|
|
unset($this->component->fxAttachClassBehavior); |
|
1404
|
|
|
// retain the other object event |
|
1405
|
|
|
$this->assertEquals(1, $this->component->fxAttachClassBehavior->Count); |
|
1406
|
|
|
$component->unlisten(); |
|
1407
|
|
|
|
|
1408
|
|
|
try { |
|
1409
|
|
|
unset($this->component->Object); |
|
1410
|
|
|
$this->fail('TInvalidOperationException not raised when unsetting get only property'); |
|
1411
|
|
|
} catch(TInvalidOperationException $e) {} |
|
|
|
|
|
|
1412
|
|
|
|
|
1413
|
|
|
$this->component->attachBehavior('BehaviorTestBehavior', new BehaviorTestBehavior); |
|
1414
|
|
|
$this->assertTrue($this->component->asa('BehaviorTestBehavior') instanceof BehaviorTestBehavior); |
|
1415
|
|
|
$this->assertFalse($this->component->asa('BehaviorTestBehavior2') instanceof BehaviorTestBehavior); |
|
1416
|
|
|
|
|
1417
|
|
|
$this->assertEquals('faa', $this->component->Excitement); |
|
1418
|
|
|
unset($this->component->Excitement); |
|
1419
|
|
|
$this->assertNull($this->component->Excitement); |
|
1420
|
|
|
$this->component->Excitement = 'sol'; |
|
1421
|
|
|
$this->assertEquals('sol', $this->component->Excitement); |
|
1422
|
|
|
|
|
1423
|
|
|
// Test the disabling of unset within behaviors |
|
1424
|
|
|
$this->component->disableBehaviors(); |
|
1425
|
|
|
unset($this->component->Excitement); |
|
1426
|
|
|
$this->component->enableBehaviors(); |
|
1427
|
|
|
// This should still be 'sol' because the unset happened inside behaviors being disabled |
|
1428
|
|
|
$this->assertEquals('sol', $this->component->Excitement); |
|
1429
|
|
|
$this->component->disableBehavior('BehaviorTestBehavior'); |
|
1430
|
|
|
unset($this->component->Excitement); |
|
1431
|
|
|
$this->component->enableBehavior('BehaviorTestBehavior'); |
|
1432
|
|
|
$this->assertEquals('sol', $this->component->Excitement); |
|
1433
|
|
|
|
|
1434
|
|
|
unset($this->component->Excitement); |
|
1435
|
|
|
$this->assertNull($this->component->Excitement); |
|
1436
|
|
|
|
|
1437
|
|
|
try { |
|
1438
|
|
|
unset($this->component->ReadOnly); |
|
1439
|
|
|
$this->fail('TInvalidOperationException not raised when unsetting get only property'); |
|
1440
|
|
|
} catch(TInvalidOperationException $e) {} |
|
|
|
|
|
|
1441
|
|
|
|
|
1442
|
|
|
$this->component->onBehaviorEvent = 'foo'; |
|
1443
|
|
|
$this->assertEquals(1, count($this->component->onBehaviorEvent)); |
|
1444
|
|
|
$this->assertEquals(1, count($this->component->BehaviorTestBehavior->onBehaviorEvent)); |
|
1445
|
|
|
unset($this->component->onBehaviorEvent); |
|
1446
|
|
|
$this->assertEquals(0, count($this->component->onBehaviorEvent)); |
|
1447
|
|
|
$this->assertEquals(0, count($this->component->BehaviorTestBehavior->onBehaviorEvent)); |
|
1448
|
|
|
|
|
1449
|
|
|
// Remove behavior via unset |
|
1450
|
|
|
unset($this->component->BehaviorTestBehavior); |
|
1451
|
|
|
$this->assertFalse($this->component->asa('BehaviorTestBehavior') instanceof BehaviorTestBehavior); |
|
1452
|
|
|
|
|
1453
|
|
|
} |
|
1454
|
|
|
|
|
1455
|
|
|
public function testGetSubProperty() { |
|
1456
|
|
|
$this->assertTrue('object text'===$this->component->getSubProperty('Object.Text')); |
|
1457
|
|
|
} |
|
1458
|
|
|
|
|
1459
|
|
|
public function testSetSubProperty() { |
|
1460
|
|
|
$this->component->setSubProperty('Object.Text','new object text'); |
|
1461
|
|
|
$this->assertEquals('new object text',$this->component->getSubProperty('Object.Text')); |
|
1462
|
|
|
} |
|
1463
|
|
|
|
|
1464
|
|
|
public function testHasEvent() { |
|
1465
|
|
|
$this->assertTrue($this->component->hasEvent('OnMyEvent')); |
|
1466
|
|
|
$this->assertTrue($this->component->hasEvent('onmyevent')); |
|
1467
|
|
|
$this->assertFalse($this->component->hasEvent('onYourEvent')); |
|
1468
|
|
|
|
|
1469
|
|
|
// fx won't throw an error if any of these fx function are called on an object. |
|
1470
|
|
|
// It is a special prefix event designation that every object responds to all events. |
|
1471
|
|
|
$this->assertTrue($this->component->hasEvent('fxAttachClassBehavior')); |
|
1472
|
|
|
$this->assertTrue($this->component->hasEvent('fxattachclassbehavior')); |
|
1473
|
|
|
|
|
1474
|
|
|
$this->assertTrue($this->component->hasEvent('fxNonExistantGlobalEvent')); |
|
1475
|
|
|
$this->assertTrue($this->component->hasEvent('fxnonexistantglobalevent')); |
|
1476
|
|
|
|
|
1477
|
|
|
$this->assertTrue($this->component->hasEvent('dyNonExistantLocalEvent')); |
|
1478
|
|
|
$this->assertTrue($this->component->hasEvent('fxnonexistantlocalevent')); |
|
1479
|
|
|
|
|
1480
|
|
|
|
|
1481
|
|
|
//Test behavior events |
|
1482
|
|
|
$this->assertFalse($this->component->hasEvent('onBehaviorEvent')); |
|
1483
|
|
|
$this->component->attachBehavior('BehaviorTestBehavior', new BehaviorTestBehavior); |
|
1484
|
|
|
$this->assertTrue($this->component->hasEvent('onBehaviorEvent')); |
|
1485
|
|
|
$this->assertTrue($this->component->BehaviorTestBehavior->hasEvent('onBehaviorEvent')); |
|
1486
|
|
|
|
|
1487
|
|
|
$this->component->disableBehavior('BehaviorTestBehavior'); |
|
1488
|
|
|
$this->assertFalse($this->component->hasEvent('onBehaviorEvent')); |
|
1489
|
|
|
$this->component->enableBehavior('BehaviorTestBehavior'); |
|
1490
|
|
|
$this->assertTrue($this->component->hasEvent('onBehaviorEvent')); |
|
1491
|
|
|
} |
|
1492
|
|
|
|
|
1493
|
|
|
public function testHasEventHandler() { |
|
1494
|
|
|
$this->assertFalse($this->component->hasEventHandler('OnMyEvent')); |
|
1495
|
|
|
$this->component->attachEventHandler('OnMyEvent','foo'); |
|
1496
|
|
|
$this->assertTrue($this->component->hasEventHandler('OnMyEvent')); |
|
1497
|
|
|
|
|
1498
|
|
|
$this->assertFalse($this->component->hasEventHandler('fxNonExistantGlobalEvent')); |
|
1499
|
|
|
$this->component->attachEventHandler('fxNonExistantGlobalEvent','foo'); |
|
1500
|
|
|
$this->assertTrue($this->component->hasEventHandler('fxNonExistantGlobalEvent')); |
|
1501
|
|
|
|
|
1502
|
|
|
//Test behavior events |
|
1503
|
|
|
$this->assertFalse($this->component->hasEventHandler('onBehaviorEvent')); |
|
1504
|
|
|
$this->component->attachBehavior('BehaviorTestBehavior', new BehaviorTestBehavior); |
|
1505
|
|
|
$this->assertFalse($this->component->hasEventHandler('onBehaviorEvent')); |
|
1506
|
|
|
$this->assertFalse($this->component->BehaviorTestBehavior->hasEventHandler('onBehaviorEvent')); |
|
1507
|
|
|
|
|
1508
|
|
|
$this->component->attachEventHandler('onBehaviorEvent','foo'); |
|
1509
|
|
|
$this->assertTrue($this->component->hasEventHandler('onBehaviorEvent')); |
|
1510
|
|
|
|
|
1511
|
|
|
$this->component->disableBehavior('BehaviorTestBehavior'); |
|
1512
|
|
|
$this->assertFalse($this->component->hasEvent('onBehaviorEvent')); |
|
1513
|
|
|
$this->assertFalse($this->component->hasEventHandler('onBehaviorEvent')); |
|
1514
|
|
|
$this->component->enableBehavior('BehaviorTestBehavior'); |
|
1515
|
|
|
$this->assertTrue($this->component->hasEvent('onBehaviorEvent')); |
|
1516
|
|
|
$this->assertTrue($this->component->hasEventHandler('onBehaviorEvent')); |
|
1517
|
|
|
} |
|
1518
|
|
|
|
|
1519
|
|
|
public function testGetEventHandlers() { |
|
1520
|
|
|
$list=$this->component->getEventHandlers('OnMyEvent'); |
|
1521
|
|
|
$this->assertTrue(($list instanceof TPriorityList) && ($list->getCount()===0)); |
|
1522
|
|
|
$this->component->attachEventHandler('OnMyEvent','foo'); |
|
1523
|
|
|
$this->assertTrue(($list instanceof TPriorityList) && ($list->getCount()===1)); |
|
1524
|
|
|
try { |
|
1525
|
|
|
$list=$this->component->getEventHandlers('YourEvent'); |
|
|
|
|
|
|
1526
|
|
|
$this->fail('exception not raised when getting event handlers for undefined event'); |
|
1527
|
|
|
} catch(TInvalidOperationException $e) { |
|
|
|
|
|
|
1528
|
|
|
} |
|
1529
|
|
|
|
|
1530
|
|
|
$list=$this->component->getEventHandlers('fxRandomEvent'); |
|
1531
|
|
|
$this->assertTrue(($list instanceof TPriorityList) && ($list->getCount()===0)); |
|
1532
|
|
|
$this->component->attachEventHandler('fxRandomEvent','foo'); |
|
1533
|
|
|
$this->assertTrue(($list instanceof TPriorityList) && ($list->getCount()===1)); |
|
1534
|
|
|
try { |
|
1535
|
|
|
$list=$this->component->getEventHandlers('fxSomeUndefinedGlobalEvent'); |
|
|
|
|
|
|
1536
|
|
|
} catch(TInvalidOperationException $e) { |
|
1537
|
|
|
$this->fail('exception raised when getting event handlers for universal global event'); |
|
1538
|
|
|
} |
|
1539
|
|
|
|
|
1540
|
|
|
|
|
1541
|
|
|
|
|
1542
|
|
|
//Test behavior events |
|
1543
|
|
|
try { |
|
1544
|
|
|
$list=$this->component->getEventHandlers('onBehaviorEvent'); |
|
|
|
|
|
|
1545
|
|
|
$this->fail('exception not raised when getting event handlers for undefined event'); |
|
1546
|
|
|
} catch(TInvalidOperationException $e) { |
|
|
|
|
|
|
1547
|
|
|
} |
|
1548
|
|
|
$this->assertFalse($this->component->hasEventHandler('onBehaviorEvent')); |
|
1549
|
|
|
|
|
1550
|
|
|
$this->component->attachBehavior('BehaviorTestBehavior', new BehaviorTestBehavior); |
|
1551
|
|
|
$list=$this->component->getEventHandlers('onBehaviorEvent'); |
|
1552
|
|
|
$this->assertTrue(($list instanceof TPriorityList) && ($list->getCount()===0)); |
|
1553
|
|
|
$this->component->attachEventHandler('onBehaviorEvent','foo'); |
|
1554
|
|
|
$this->assertTrue(($list instanceof TPriorityList) && ($list->getCount()===1)); |
|
1555
|
|
|
|
|
1556
|
|
|
$this->component->disableBehavior('BehaviorTestBehavior'); |
|
1557
|
|
|
try { |
|
1558
|
|
|
$list=$this->component->getEventHandlers('onBehaviorEvent'); |
|
1559
|
|
|
$this->fail('exception not raised when getting event handlers for undefined event'); |
|
1560
|
|
|
} catch(TInvalidOperationException $e) { |
|
|
|
|
|
|
1561
|
|
|
} |
|
1562
|
|
|
$this->component->enableBehavior('BehaviorTestBehavior'); |
|
1563
|
|
|
$this->assertTrue(($this->component->getEventHandlers('onBehaviorEvent') instanceof TPriorityList) && ($list->getCount()===1)); |
|
1564
|
|
|
|
|
1565
|
|
|
} |
|
1566
|
|
|
|
|
1567
|
|
|
public function testAttachEventHandler() { |
|
1568
|
|
|
|
|
1569
|
|
|
$this->component->attachEventHandler('OnMyEvent','foo'); |
|
1570
|
|
|
$this->assertEquals(1, $this->component->getEventHandlers('OnMyEvent')->getCount()); |
|
1571
|
|
|
try { |
|
1572
|
|
|
$this->component->attachEventHandler('YourEvent','foo'); |
|
1573
|
|
|
$this->fail('exception not raised when attaching event handlers for undefined event'); |
|
1574
|
|
|
} catch(TInvalidOperationException $e) { |
|
|
|
|
|
|
1575
|
|
|
} |
|
1576
|
|
|
|
|
1577
|
|
|
//Testing the priorities of attaching events |
|
1578
|
|
|
$this->component->attachEventHandler('OnMyEvent','foopre', 5); |
|
1579
|
|
|
$this->component->attachEventHandler('OnMyEvent','foopost', 15); |
|
1580
|
|
|
$this->component->attachEventHandler('OnMyEvent','foobar', 10); |
|
1581
|
|
|
$this->assertEquals(4, $this->component->getEventHandlers('OnMyEvent')->getCount()); |
|
1582
|
|
|
$list = $this->component->getEventHandlers('OnMyEvent'); |
|
1583
|
|
|
$this->assertEquals('foopre', $list[0]); |
|
1584
|
|
|
$this->assertEquals('foo', $list[1]); |
|
1585
|
|
|
$this->assertEquals('foobar', $list[2]); |
|
1586
|
|
|
$this->assertEquals('foopost', $list[3]); |
|
1587
|
|
|
|
|
1588
|
|
|
|
|
1589
|
|
|
//Test attaching behavior events |
|
1590
|
|
|
try { |
|
1591
|
|
|
$this->component->attachEventHandler('onBehaviorEvent','foo'); |
|
1592
|
|
|
$this->fail('exception not raised when getting event handlers for undefined event'); |
|
1593
|
|
|
} catch(TInvalidOperationException $e) { |
|
|
|
|
|
|
1594
|
|
|
} |
|
1595
|
|
|
$this->component->attachBehavior('BehaviorTestBehavior', new BehaviorTestBehavior); |
|
1596
|
|
|
|
|
1597
|
|
|
$this->component->attachEventHandler('onBehaviorEvent','foo'); |
|
1598
|
|
|
|
|
1599
|
|
|
//Testing the priorities of attaching behavior events |
|
1600
|
|
|
$this->component->attachEventHandler('onBehaviorEvent','foopre', 5); |
|
1601
|
|
|
$this->component->attachEventHandler('onBehaviorEvent','foopost', 15); |
|
1602
|
|
|
$this->component->attachEventHandler('onBehaviorEvent','foobar', 10); |
|
1603
|
|
|
$this->component->attachEventHandler('onBehaviorEvent','foobarfoobar', 10); |
|
1604
|
|
|
$this->assertEquals(5, $this->component->getEventHandlers('onBehaviorEvent')->getCount()); |
|
1605
|
|
|
$list = $this->component->getEventHandlers('onBehaviorEvent'); |
|
1606
|
|
|
$this->assertEquals('foopre', $list[0]); |
|
1607
|
|
|
$this->assertEquals('foo', $list[1]); |
|
1608
|
|
|
$this->assertEquals('foobar', $list[2]); |
|
1609
|
|
|
$this->assertEquals('foobarfoobar', $list[3]); |
|
1610
|
|
|
$this->assertEquals('foopost', $list[4]); |
|
1611
|
|
|
|
|
1612
|
|
|
$this->component->disableBehavior('BehaviorTestBehavior'); |
|
1613
|
|
|
try { |
|
1614
|
|
|
$this->component->attachEventHandler('onBehaviorEvent','bar'); |
|
1615
|
|
|
$this->fail('exception not raised when getting event handlers for undefined event'); |
|
1616
|
|
|
} catch(TInvalidOperationException $e) { |
|
|
|
|
|
|
1617
|
|
|
} |
|
1618
|
|
|
$this->component->enableBehavior('BehaviorTestBehavior'); |
|
1619
|
|
|
|
|
1620
|
|
|
} |
|
1621
|
|
|
|
|
1622
|
|
|
public function testDetachEventHandler() { |
|
1623
|
|
|
|
|
1624
|
|
|
$this->component->attachEventHandler('OnMyEvent','foo'); |
|
1625
|
|
|
$this->assertEquals(1, $this->component->getEventHandlers('OnMyEvent')->getCount()); |
|
1626
|
|
|
|
|
1627
|
|
|
$this->component->attachEventHandler('OnMyEvent','foopre', 5); |
|
1628
|
|
|
$this->component->attachEventHandler('OnMyEvent','foopost', 15); |
|
1629
|
|
|
$this->component->attachEventHandler('OnMyEvent','foobar', 10); |
|
1630
|
|
|
$this->component->attachEventHandler('OnMyEvent','foobarfoobar', 10); |
|
1631
|
|
|
|
|
1632
|
|
|
|
|
1633
|
|
|
|
|
1634
|
|
|
$this->component->detachEventHandler('OnMyEvent','foo'); |
|
1635
|
|
|
$list = $this->component->getEventHandlers('OnMyEvent'); |
|
1636
|
|
|
$this->assertEquals(4, $list->getCount()); |
|
1637
|
|
|
|
|
1638
|
|
|
$this->assertEquals('foopre', $list[0]); |
|
1639
|
|
|
$this->assertEquals('foobar', $list[1]); |
|
1640
|
|
|
$this->assertEquals('foobarfoobar', $list[2]); |
|
1641
|
|
|
$this->assertEquals('foopost', $list[3]); |
|
1642
|
|
|
|
|
1643
|
|
|
$this->component->detachEventHandler('OnMyEvent','foopre', null); |
|
1644
|
|
|
$this->assertEquals(4, $list->getCount()); |
|
1645
|
|
|
|
|
1646
|
|
|
$this->component->detachEventHandler('OnMyEvent','foopre', 5); |
|
1647
|
|
|
$this->assertEquals(3, $list->getCount()); |
|
1648
|
|
|
|
|
1649
|
|
|
|
|
1650
|
|
|
// Now do detaching of behavior on events |
|
1651
|
|
|
try { |
|
1652
|
|
|
$this->component->attachEventHandler('onBehaviorEvent','foo'); |
|
1653
|
|
|
$this->fail('exception not raised when getting event handlers for undefined event'); |
|
1654
|
|
|
} catch(TInvalidOperationException $e) { |
|
|
|
|
|
|
1655
|
|
|
} |
|
1656
|
|
|
$this->component->attachBehavior('BehaviorTestBehavior', new BehaviorTestBehavior); |
|
1657
|
|
|
|
|
1658
|
|
|
$this->component->attachEventHandler('onBehaviorEvent','foo'); |
|
1659
|
|
|
$this->assertEquals(1, $this->component->getEventHandlers('onBehaviorEvent')->getCount()); |
|
1660
|
|
|
|
|
1661
|
|
|
$this->component->attachEventHandler('onBehaviorEvent','foopre', 5); |
|
1662
|
|
|
$this->component->attachEventHandler('onBehaviorEvent','foopost', 15); |
|
1663
|
|
|
$this->component->attachEventHandler('onBehaviorEvent','foobar', 10); |
|
1664
|
|
|
$this->component->attachEventHandler('onBehaviorEvent','foobarfoobar', 10); |
|
1665
|
|
|
|
|
1666
|
|
|
|
|
1667
|
|
|
|
|
1668
|
|
|
$this->component->detachEventHandler('onBehaviorEvent','foo'); |
|
1669
|
|
|
$list = $this->component->getEventHandlers('onBehaviorEvent'); |
|
1670
|
|
|
$this->assertEquals(4, $list->getCount()); |
|
1671
|
|
|
|
|
1672
|
|
|
$this->assertEquals('foopre', $list[0]); |
|
1673
|
|
|
$this->assertEquals('foobar', $list[1]); |
|
1674
|
|
|
$this->assertEquals('foobarfoobar', $list[2]); |
|
1675
|
|
|
$this->assertEquals('foopost', $list[3]); |
|
1676
|
|
|
|
|
1677
|
|
|
$this->component->detachEventHandler('onBehaviorEvent','foopre', null); |
|
1678
|
|
|
$this->assertEquals(4, $list->getCount()); |
|
1679
|
|
|
|
|
1680
|
|
|
$this->component->detachEventHandler('onBehaviorEvent','foopre', 5); |
|
1681
|
|
|
$this->assertEquals(3, $list->getCount()); |
|
1682
|
|
|
} |
|
1683
|
|
|
|
|
1684
|
|
|
|
|
1685
|
|
|
|
|
1686
|
|
|
|
|
1687
|
|
|
public function testRaiseEvent() { |
|
1688
|
|
|
$this->component->attachEventHandler('OnMyEvent',array($this->component,'myEventHandler')); |
|
1689
|
|
|
$this->assertFalse($this->component->isEventHandled()); |
|
1690
|
|
|
$this->component->raiseEvent('OnMyEvent',$this,null); |
|
1691
|
|
|
$this->assertTrue($this->component->isEventHandled()); |
|
1692
|
|
|
$this->component->attachEventHandler('OnMyEvent',array($this->component,'Object.myEventHandler')); |
|
1693
|
|
|
$this->assertFalse($this->component->Object->isEventHandled()); |
|
|
|
|
|
|
1694
|
|
|
$this->component->raiseEvent('OnMyEvent',$this,null); |
|
1695
|
|
|
$this->assertTrue($this->component->Object->isEventHandled()); |
|
|
|
|
|
|
1696
|
|
|
|
|
1697
|
|
|
$this->component->resetEventHandled(); |
|
1698
|
|
|
$this->component->Object->resetEventHandled(); |
|
|
|
|
|
|
1699
|
|
|
|
|
1700
|
|
|
|
|
1701
|
|
|
// Test a behavior on event |
|
1702
|
|
|
$this->component->attachBehavior('test', new BehaviorTestBehavior); |
|
1703
|
|
|
|
|
1704
|
|
|
$this->component->attachEventHandler('onBehaviorEvent',array($this->component,'myEventHandler')); |
|
1705
|
|
|
$this->assertFalse($this->component->isEventHandled()); |
|
1706
|
|
|
$this->component->raiseEvent('onBehaviorEvent',$this,null); |
|
1707
|
|
|
$this->assertTrue($this->component->isEventHandled()); |
|
1708
|
|
|
$this->component->attachEventHandler('onBehaviorEvent',array($this->component,'Object.myEventHandler')); |
|
1709
|
|
|
$this->assertFalse($this->component->Object->isEventHandled()); |
|
|
|
|
|
|
1710
|
|
|
$this->component->raiseEvent('onBehaviorEvent',$this,null); |
|
1711
|
|
|
$this->assertTrue($this->component->Object->isEventHandled()); |
|
|
|
|
|
|
1712
|
|
|
|
|
1713
|
|
|
//test behavior enabled/disabled events |
|
1714
|
|
|
$this->component->disableBehavior('test'); |
|
1715
|
|
|
|
|
1716
|
|
|
$this->component->resetEventHandled(); |
|
1717
|
|
|
$this->component->Object->resetEventHandled(); |
|
|
|
|
|
|
1718
|
|
|
|
|
1719
|
|
|
try { |
|
1720
|
|
|
$this->component->attachEventHandler('onBehaviorEvent',array($this->component,'myEventHandler')); |
|
1721
|
|
|
$this->fail('exception not raised when getting event handlers for undefined event'); |
|
1722
|
|
|
} catch(TInvalidOperationException $e) {} |
|
|
|
|
|
|
1723
|
|
|
$this->assertFalse($this->component->isEventHandled()); |
|
1724
|
|
|
try { |
|
1725
|
|
|
$this->component->raiseEvent('onBehaviorEvent',$this,null); |
|
1726
|
|
|
$this->fail('exception not raised when getting event handlers for undefined event'); |
|
1727
|
|
|
} catch(TInvalidOperationException $e) {} |
|
|
|
|
|
|
1728
|
|
|
$this->assertFalse($this->component->isEventHandled()); |
|
1729
|
|
|
|
|
1730
|
|
|
$this->component->enableBehavior('test'); |
|
1731
|
|
|
|
|
1732
|
|
|
|
|
1733
|
|
|
|
|
1734
|
|
|
//Test the return types of this function |
|
1735
|
|
|
|
|
1736
|
|
|
$this->assertFalse($this->component->isEventHandled()); |
|
1737
|
|
|
$this->assertFalse($this->component->Object->isEventHandled()); |
|
|
|
|
|
|
1738
|
|
|
$this->assertEquals(array(), $this->component->onBehaviorEvent($this,$this->component)); |
|
1739
|
|
|
$this->assertTrue($this->component->isEventHandled()); |
|
1740
|
|
|
$this->assertTrue($this->component->Object->isEventHandled()); |
|
|
|
|
|
|
1741
|
|
|
|
|
1742
|
|
|
// This accumulates all the responses from each of the events |
|
1743
|
|
|
$arr=$this->component->onBehaviorEvent($this, $this->component, TEventResults::EVENT_RESULT_ALL); |
|
1744
|
|
|
$this->assertEquals($this, $arr[0]['sender']); |
|
1745
|
|
|
$this->assertEquals($this->component, $arr[0]['param']); |
|
1746
|
|
|
$this->assertTrue(null === $arr[0]['response']); |
|
1747
|
|
|
|
|
1748
|
|
|
$this->assertEquals($this, $arr[1]['sender']); |
|
1749
|
|
|
$this->assertEquals($this->component, $arr[1]['param']); |
|
1750
|
|
|
$this->assertTrue(null === $arr[1]['response']); |
|
1751
|
|
|
|
|
1752
|
|
|
$this->assertEquals(2, count($arr)); |
|
1753
|
|
|
|
|
1754
|
|
|
// This tests without the default filtering-out of null |
|
1755
|
|
|
$arr=$this->component->onBehaviorEvent($this, $this->component, false); |
|
1756
|
|
|
$this->assertEquals(array(null, null), $arr); |
|
1757
|
|
|
|
|
1758
|
|
|
|
|
1759
|
|
|
unset($this->component->onBehaviorEvent); |
|
1760
|
|
|
$this->assertEquals(0, $this->component->onBehaviorEvent->Count); |
|
1761
|
|
|
|
|
1762
|
|
|
$this->component->onBehaviorEvent = array($this, 'returnValue4'); |
|
1763
|
|
|
$this->component->onBehaviorEvent = array($this, 'returnValue1'); |
|
1764
|
|
|
|
|
1765
|
|
|
// Test the per event post processing function |
|
1766
|
|
|
$arr=$this->component->onBehaviorEvent($this, $this->component, array($this, 'postEventFunction')); |
|
1767
|
|
|
$this->assertEquals(array(exp(4), exp(1)), $arr); |
|
1768
|
|
|
$arr=$this->component->onBehaviorEvent($this, $this->component, array($this, 'postEventFunction2')); |
|
1769
|
|
|
$this->assertEquals(array(sin(4), sin(1)), $arr); |
|
1770
|
|
|
|
|
1771
|
|
|
|
|
1772
|
|
|
//Testing Feed-forward functionality |
|
1773
|
|
|
unset($this->component->onBehaviorEvent); |
|
1774
|
|
|
|
|
1775
|
|
|
$this->component->onBehaviorEvent = array($this, 'ffValue4'); |
|
1776
|
|
|
$this->component->onBehaviorEvent = array($this, 'ffValue2'); |
|
1777
|
|
|
$arr=$this->component->onBehaviorEvent($this, 5, TEventResults::EVENT_RESULT_FEED_FORWARD); |
|
1778
|
|
|
$this->assertEquals(array(20, 40), $arr); |
|
1779
|
|
|
|
|
1780
|
|
|
|
|
1781
|
|
|
unset($this->component->onBehaviorEvent); |
|
1782
|
|
|
|
|
1783
|
|
|
//Order of these events affects the response order in feed forward |
|
1784
|
|
|
$this->component->onBehaviorEvent = array($this, 'ffValue2'); |
|
1785
|
|
|
$this->component->onBehaviorEvent = array($this, 'ffValue4'); |
|
1786
|
|
|
$arr=$this->component->onBehaviorEvent($this, 5, TEventResults::EVENT_RESULT_FEED_FORWARD); |
|
1787
|
|
|
$this->assertEquals(array(10, 40), $arr); |
|
1788
|
|
|
} |
|
1789
|
|
|
|
|
1790
|
|
|
public function returnValue1(){return 1;} |
|
1791
|
|
|
public function returnValue4(){return 4;} |
|
1792
|
|
|
public function postEventFunction($sender, $param, $caller, $response){return exp($response);} |
|
1793
|
|
|
public function postEventFunction2($sender, $param, $caller, $response){return sin($response);} |
|
1794
|
|
|
public function ffValue2($sender, $param){return $param*2;} |
|
1795
|
|
|
public function ffValue4($sender, $param){return $param*4;} |
|
1796
|
|
|
|
|
1797
|
|
|
|
|
1798
|
|
|
public function testGlobalEventListenerInRaiseEvent() { |
|
1799
|
|
|
//TODO Test the Global Event Listener |
|
|
|
|
|
|
1800
|
|
|
} |
|
1801
|
|
|
|
|
1802
|
|
|
|
|
1803
|
|
|
public function testIDynamicMethodsOnBehavior() { |
|
1804
|
|
|
|
|
1805
|
|
|
//Add Behavior with dynamic call |
|
1806
|
|
|
$this->component->attachBehavior('TDynamicBehavior', new TDynamicBehavior); |
|
1807
|
|
|
|
|
1808
|
|
|
//Check that the behavior is working as it should |
|
1809
|
|
|
$this->assertTrue($this->component->isa('TDynamicBehavior')); |
|
1810
|
|
|
$this->assertNull($this->component->getLastBehaviorDynamicMethodCalled()); |
|
1811
|
|
|
|
|
1812
|
|
|
// call basic behavior implemented method from object (containing behavior) |
|
1813
|
|
|
$this->assertEquals(42, $this->component->TestBehaviorMethod(6, 7)); |
|
1814
|
|
|
|
|
1815
|
|
|
//Test out undefined behavior/host object method |
|
1816
|
|
|
try { |
|
1817
|
|
|
$this->component->objectAndBehaviorUndefinedMethod(); |
|
1818
|
|
|
$this->fail('exception not raised when evaluating an undefined method by the object and behavior'); |
|
1819
|
|
|
} catch(TApplicationException $e) { |
|
|
|
|
|
|
1820
|
|
|
} |
|
1821
|
|
|
|
|
1822
|
|
|
// calling undefined dynamic method, caught by the __dycall method in the behavior and implemented |
|
1823
|
|
|
// this behavior catches undefined dynamic event and divides param1 by param 2 |
|
1824
|
|
|
$this->assertEquals(22, $this->component->dyTestDynamicBehaviorMethod(242, 11)); |
|
1825
|
|
|
$this->assertEquals('dyTestDynamicBehaviorMethod', $this->component->getLastBehaviorDynamicMethodCalled()); |
|
1826
|
|
|
|
|
1827
|
|
|
// calling undefined dynamic method, caught by the __dycall in the behavior and ignored |
|
1828
|
|
|
$this->assertNull($this->component->dyUndefinedIntraEvent(242, 11)); |
|
1829
|
|
|
$this->assertEquals('dyUndefinedIntraEvent', $this->component->getLastBehaviorDynamicMethodCalled()); |
|
1830
|
|
|
|
|
1831
|
|
|
//call behavior defined dynamic event |
|
1832
|
|
|
// param1 * 2 * param2 |
|
1833
|
|
|
$this->assertEquals(2420, $this->component->dyTestIntraEvent(121, 10)); |
|
1834
|
|
|
|
|
1835
|
|
|
$this->component->detachBehavior('TDynamicBehavior'); |
|
1836
|
|
|
$this->assertFalse($this->component->isa('TDynamicBehavior')); |
|
1837
|
|
|
|
|
1838
|
|
|
|
|
1839
|
|
|
|
|
1840
|
|
|
//Add Class Behavior with dynamic call |
|
1841
|
|
|
$this->component->attachBehavior('TDynamicClassBehavior', new TDynamicClassBehavior); |
|
1842
|
|
|
|
|
1843
|
|
|
//Check that the behavior is working as it should |
|
1844
|
|
|
$this->assertTrue($this->component->isa('TDynamicClassBehavior')); |
|
1845
|
|
|
$this->assertNull($this->component->getLastBehaviorDynamicMethodCalled()); |
|
1846
|
|
|
|
|
1847
|
|
|
// call basic behavior implemented method from object (containing behavior) |
|
1848
|
|
|
$this->assertEquals(42, $this->component->TestBehaviorMethod(6, 7)); |
|
1849
|
|
|
|
|
1850
|
|
|
//Test out undefined behavior/host object method |
|
1851
|
|
|
try { |
|
1852
|
|
|
$this->component->objectAndBehaviorUndefinedMethod(); |
|
1853
|
|
|
$this->fail('exception not raised when evaluating an undefined method by the object and behavior'); |
|
1854
|
|
|
} catch(TApplicationException $e) { |
|
|
|
|
|
|
1855
|
|
|
} |
|
1856
|
|
|
|
|
1857
|
|
|
// calling undefined dynamic method, caught by the __dycall method in the behavior and implemented |
|
1858
|
|
|
// this behavior catches undefined dynamic event and divides param1 by param 2 |
|
1859
|
|
|
$this->assertEquals(22, $this->component->dyTestDynamicClassBehaviorMethod(242, 11)); |
|
1860
|
|
|
$this->assertEquals('dyTestDynamicClassBehaviorMethod', $this->component->getLastBehaviorDynamicMethodCalled()); |
|
1861
|
|
|
|
|
1862
|
|
|
// calling undefined dynamic method, caught by the __dycall in the behavior and ignored |
|
1863
|
|
|
$this->assertNull($this->component->dyUndefinedIntraEvent(242, 11)); |
|
1864
|
|
|
$this->assertEquals('dyUndefinedIntraEvent', $this->component->getLastBehaviorDynamicMethodCalled()); |
|
1865
|
|
|
|
|
1866
|
|
|
//call behavior defined dynamic event |
|
1867
|
|
|
// param1 * 2 * param2 |
|
1868
|
|
|
$this->assertEquals(2420, $this->component->dyTestIntraEvent(121, 10)); |
|
1869
|
|
|
|
|
1870
|
|
|
$this->component->detachBehavior('TDynamicClassBehavior'); |
|
1871
|
|
|
$this->assertFalse($this->component->isa('TDynamicClassBehavior')); |
|
1872
|
|
|
|
|
1873
|
|
|
|
|
1874
|
|
|
} |
|
1875
|
|
|
|
|
1876
|
|
|
// This also tests the priority of the common global raiseEvent events |
|
1877
|
|
|
public function testIDynamicMethodsOnBehaviorGlobalEvents() { |
|
1878
|
|
|
$component = new GlobalRaiseComponent(); |
|
1879
|
|
|
|
|
1880
|
|
|
// common function has a default priority of 10 |
|
1881
|
|
|
$component->attachEventHandler(TComponent::GLOBAL_RAISE_EVENT_LISTENER, array($component, 'commonRaiseEventListener')); |
|
1882
|
|
|
$component->attachEventHandler(TComponent::GLOBAL_RAISE_EVENT_LISTENER, array($component, 'postglobalRaiseEventListener'), 1); |
|
1883
|
|
|
$component->attachEventHandler(TComponent::GLOBAL_RAISE_EVENT_LISTENER, array($component, 'preglobalRaiseEventListener'), -1); |
|
1884
|
|
|
|
|
1885
|
|
|
$this->assertEquals(5, $this->component->fxGlobalListener->getCount()); |
|
1886
|
|
|
$this->assertEquals(1, $this->component->fxPrimaryGlobalEvent->getCount()); |
|
1887
|
|
|
$this->assertEquals(1, $this->component->fxPrimaryGlobalEvent->getCount(), 'fxPrimaryGlobalEvent is not installed on test object'); |
|
1888
|
|
|
|
|
1889
|
|
|
// call the global event on a different object than the test object |
|
1890
|
|
|
$res = $this->component->raiseEvent('fxPrimaryGlobalEvent', $this, null, TEventResults::EVENT_RESULT_ALL); |
|
1891
|
|
|
|
|
1892
|
|
|
$this->assertEquals(6, count($res)); |
|
1893
|
|
|
$this->assertEquals(array('pregl', 'primary', 'postgl', 'fxGL', 'fxcall', 'com'), $component->getCallOrders()); |
|
1894
|
|
|
|
|
1895
|
|
|
$component->unlisten(); |
|
1896
|
|
|
} |
|
1897
|
|
|
|
|
1898
|
|
|
|
|
1899
|
|
|
|
|
1900
|
|
|
|
|
1901
|
|
|
public function testEvaluateExpression() { |
|
1902
|
|
|
$expression="1+2"; |
|
1903
|
|
|
$this->assertTrue(3===$this->component->evaluateExpression($expression)); |
|
1904
|
|
|
try { |
|
1905
|
|
|
$button=$this->component->evaluateExpression('$this->button'); |
|
|
|
|
|
|
1906
|
|
|
$this->fail('exception not raised when evaluating an invalid exception'); |
|
1907
|
|
|
} catch(Exception $e) { |
|
|
|
|
|
|
1908
|
|
|
} |
|
1909
|
|
|
} |
|
1910
|
|
|
|
|
1911
|
|
|
|
|
1912
|
|
|
|
|
1913
|
|
|
|
|
1914
|
|
|
public function testEvaluateStatements() { |
|
1915
|
|
|
$statements='$a="test string"; echo $a;'; |
|
1916
|
|
|
$this->assertEquals('test string',$this->component->evaluateStatements($statements)); |
|
1917
|
|
|
try { |
|
1918
|
|
|
$statements='$a=new NewComponent; echo $a->button;'; |
|
1919
|
|
|
$button=$this->component->evaluateStatements($statements); |
|
|
|
|
|
|
1920
|
|
|
$this->fail('exception not raised when evaluating an invalid statement'); |
|
1921
|
|
|
} catch(Exception $e) { |
|
|
|
|
|
|
1922
|
|
|
} |
|
1923
|
|
|
} |
|
1924
|
|
|
|
|
1925
|
|
|
|
|
1926
|
|
|
public function testDynamicFunctionCall() { |
|
1927
|
|
|
|
|
1928
|
|
|
$this->assertEquals(' aa bb cc __ .. ++ || !! ?? ', $this->component->dyTextFilter(' aa bb cc __ .. ++ || !! ?? ')); |
|
1929
|
|
|
|
|
1930
|
|
|
$this->component->attachBehavior('dy1', new dy1TextReplace); |
|
1931
|
|
|
$this->assertFalse($this->component->dy1->isCalled()); |
|
1932
|
|
|
$this->assertEquals(' aa bb cc __ __ ++ || !! ?? ', $this->component->dyTextFilter(' aa bb cc __ .. ++ || !! ?? ')); |
|
1933
|
|
|
$this->assertTrue($this->component->dy1->isCalled()); |
|
1934
|
|
|
|
|
1935
|
|
|
$this->component->attachBehavior('dy2', new dy2TextReplace); |
|
1936
|
|
|
$this->assertFalse($this->component->dy2->isCalled()); |
|
1937
|
|
|
$this->assertEquals(' aa bb cc __ __ || || !! ?? ', $this->component->dyTextFilter(' aa bb cc __ .. ++ || !! ?? ')); |
|
1938
|
|
|
$this->assertTrue($this->component->dy2->isCalled()); |
|
1939
|
|
|
|
|
1940
|
|
|
$this->component->attachBehavior('dy3', new dy3TextReplace); |
|
1941
|
|
|
$this->assertFalse($this->component->dy3->isCalled()); |
|
1942
|
|
|
$this->assertEquals(' aa bb cc __ __ || || ?? ?? ', $this->component->dyTextFilter(' aa bb cc __ .. ++ || !! ?? ')); |
|
1943
|
|
|
$this->assertTrue($this->component->dy3->isCalled()); |
|
1944
|
|
|
|
|
1945
|
|
|
$this->assertEquals(' aa bb cc __ .. ++ || !! ?? ', $this->component->dyUndefinedEvent(' aa bb cc __ .. ++ || !! ?? ')); |
|
1946
|
|
|
|
|
1947
|
|
|
$this->assertEquals(0.25, $this->component->dyPowerFunction(2,2)); |
|
1948
|
|
|
|
|
1949
|
|
|
|
|
1950
|
|
|
$this->component->detachBehavior('dy1'); |
|
1951
|
|
|
$this->component->detachBehavior('dy2'); |
|
1952
|
|
|
$this->component->detachBehavior('dy3'); |
|
1953
|
|
|
|
|
1954
|
|
|
//test class behaviors of dynamic events and the argument list order |
|
1955
|
|
|
|
|
1956
|
|
|
$this->assertEquals(' aa bb cc __ .. ++ || !! ?? ', $this->component->dyTextFilter(' aa bb cc __ .. ++ || !! ?? ')); |
|
1957
|
|
|
|
|
1958
|
|
|
$this->component->attachBehavior('dy1', new dy1ClassTextReplace); |
|
1959
|
|
|
$this->assertFalse($this->component->dy1->isCalled()); |
|
1960
|
|
|
$this->assertEquals(' aa bb cc .. .. ++ || !! ?? ', $this->component->dyTextFilter(' aa bb cc __ .. ++ || !! ?? ')); |
|
1961
|
|
|
$this->assertTrue($this->component->dy1->isCalled()); |
|
1962
|
|
|
|
|
1963
|
|
|
$this->component->attachBehavior('dy2', new dy2ClassTextReplace); |
|
1964
|
|
|
$this->assertFalse($this->component->dy2->isCalled()); |
|
1965
|
|
|
$this->assertEquals(' aa bb cc .. .. ++ ++ !! ?? ', $this->component->dyTextFilter(' aa bb cc __ .. ++ || !! ?? ')); |
|
1966
|
|
|
$this->assertTrue($this->component->dy2->isCalled()); |
|
1967
|
|
|
|
|
1968
|
|
|
$this->component->attachBehavior('dy3', new dy3ClassTextReplace); |
|
1969
|
|
|
$this->assertFalse($this->component->dy3->isCalled()); |
|
1970
|
|
|
$this->assertEquals(' aa bb cc .. .. ++ ++ !! ^_^ ', $this->component->dyTextFilter(' aa bb cc __ .. ++ || !! ?? ')); |
|
1971
|
|
|
$this->assertTrue($this->component->dy3->isCalled()); |
|
1972
|
|
|
|
|
1973
|
|
|
$this->assertEquals(' aa bb cc __ .. ++ || !! ?? ', $this->component->dyUndefinedEvent(' aa bb cc __ .. ++ || !! ?? ')); |
|
1974
|
|
|
|
|
1975
|
|
|
$this->assertEquals(0.25, $this->component->dyPowerFunction(2,2)); |
|
1976
|
|
|
|
|
1977
|
|
|
|
|
1978
|
|
|
} |
|
1979
|
|
|
|
|
1980
|
|
|
|
|
1981
|
|
|
|
|
1982
|
|
|
|
|
1983
|
|
|
public function testDynamicIntraObjectEvents() { |
|
1984
|
|
|
|
|
1985
|
|
|
$this->component->attachBehavior('IntraEvents', new IntraObjectExtenderBehavior); |
|
1986
|
|
|
|
|
1987
|
|
|
$this->assertNull($this->component->IntraEvents->LastCall); |
|
1988
|
|
|
|
|
1989
|
|
|
//unlisten first, this object listens upon instantiation. |
|
1990
|
|
|
$this->component->unlisten(); |
|
1991
|
|
|
$this->assertEquals(2, $this->component->IntraEvents->LastCall); |
|
1992
|
|
|
|
|
1993
|
|
|
// ensures that IntraEvents nulls the last call variable when calling this getter |
|
1994
|
|
|
$this->assertNull($this->component->IntraEvents->LastCall); |
|
1995
|
|
|
|
|
1996
|
|
|
//listen next to undo the unlisten |
|
1997
|
|
|
$this->component->listen(); |
|
1998
|
|
|
$this->assertEquals(1, $this->component->IntraEvents->LastCall); |
|
1999
|
|
|
|
|
2000
|
|
|
|
|
2001
|
|
|
$this->assertEquals(3, $this->component->evaluateExpression('1+2')); |
|
2002
|
|
|
$this->assertEquals(7, $this->component->IntraEvents->LastCall); |
|
2003
|
|
|
|
|
2004
|
|
|
$statements='$a="test string"; echo $a;'; |
|
2005
|
|
|
$this->assertEquals('test string', $this->component->evaluateStatements($statements)); |
|
2006
|
|
|
$this->assertEquals(8, $this->component->IntraEvents->LastCall); |
|
2007
|
|
|
|
|
2008
|
|
|
$component2 = new NewComponentNoListen(); |
|
2009
|
|
|
$this->assertNull($this->component->createdOnTemplate($component2)); |
|
2010
|
|
|
$this->assertEquals(9, $this->component->IntraEvents->LastCall); |
|
2011
|
|
|
|
|
2012
|
|
|
$this->assertNull($this->component->addParsedObject($component2)); |
|
2013
|
|
|
$this->assertEquals(10, $this->component->IntraEvents->LastCall); |
|
2014
|
|
|
|
|
2015
|
|
|
|
|
2016
|
|
|
|
|
2017
|
|
|
$behavior = new BarBehavior; |
|
2018
|
|
|
$this->assertEquals($behavior, $this->component->attachBehavior('BarBehavior', $behavior)); |
|
2019
|
|
|
$this->assertEquals(11, $this->component->IntraEvents->LastCall); |
|
2020
|
|
|
|
|
2021
|
|
|
$this->assertNull($this->component->disableBehaviors()); |
|
2022
|
|
|
$this->assertNull($this->component->enableBehaviors()); |
|
2023
|
|
|
$this->assertEquals(27, $this->component->IntraEvents->LastCall); |
|
2024
|
|
|
|
|
2025
|
|
|
$this->assertTrue($this->component->disableBehavior('BarBehavior')); |
|
2026
|
|
|
$this->assertEquals(16, $this->component->IntraEvents->LastCall); |
|
2027
|
|
|
|
|
2028
|
|
|
$this->assertTrue($this->component->enableBehavior('BarBehavior')); |
|
2029
|
|
|
$this->assertEquals(15, $this->component->IntraEvents->LastCall); |
|
2030
|
|
|
|
|
2031
|
|
|
$this->assertEquals($behavior, $this->component->detachBehavior('BarBehavior')); |
|
2032
|
|
|
$this->assertEquals(12, $this->component->IntraEvents->LastCall); |
|
2033
|
|
|
|
|
2034
|
|
|
|
|
2035
|
|
|
$this->component->attachEventHandler('OnMyEvent',array($this->component,'myEventHandler')); |
|
2036
|
|
|
$this->component->raiseEvent('OnMyEvent',$this,null); |
|
2037
|
|
|
|
|
2038
|
|
|
//3 + 4 + 5 + 6 = 18 (the behavior adds these together when each raiseEvent dynamic intra event is called) |
|
2039
|
|
|
$this->assertEquals(18, $this->component->IntraEvents->LastCall); |
|
2040
|
|
|
} |
|
2041
|
|
|
|
|
2042
|
|
|
|
|
2043
|
|
|
|
|
2044
|
|
|
public function testJavascriptGetterSetter() { |
|
2045
|
|
|
|
|
2046
|
|
|
$this->assertFalse(isset($this->component->ColorAttribute)); |
|
2047
|
|
|
$this->assertFalse(isset($this->component->JsColorAttribute)); |
|
2048
|
|
|
|
|
2049
|
|
|
$this->component->ColorAttribute = "('#556677', '#abcdef', 503987)"; |
|
|
|
|
|
|
2050
|
|
|
$this->assertEquals("('#556677', '#abcdef', 503987)", $this->component->ColorAttribute); |
|
|
|
|
|
|
2051
|
|
|
|
|
2052
|
|
|
$this->assertTrue(isset($this->component->ColorAttribute)); |
|
2053
|
|
|
$this->assertTrue(isset($this->component->JsColorAttribute)); |
|
2054
|
|
|
|
|
2055
|
|
|
$this->component->ColorAttribute = "new Array(1, 2, 3, 4, 5)"; |
|
|
|
|
|
|
2056
|
|
|
$this->assertEquals("new Array(1, 2, 3, 4, 5)", $this->component->JsColorAttribute); |
|
2057
|
|
|
|
|
2058
|
|
|
$this->component->JsColorAttribute = "['#112233', '#fedcba', 22009837]"; |
|
2059
|
|
|
$this->assertEquals("['#112233', '#fedcba', 22009837]", $this->component->ColorAttribute); |
|
|
|
|
|
|
2060
|
|
|
} |
|
2061
|
|
|
|
|
2062
|
|
|
|
|
2063
|
|
|
public function testJavascriptIssetUnset() { |
|
2064
|
|
|
|
|
2065
|
|
|
$this->component->JsColorAttribute = "['#112233', '#fedcba', 22009837]"; |
|
2066
|
|
|
$this->assertEquals("['#112233', '#fedcba', 22009837]", $this->component->ColorAttribute); |
|
|
|
|
|
|
2067
|
|
|
|
|
2068
|
|
|
unset($this->component->ColorAttribute); |
|
2069
|
|
|
|
|
2070
|
|
|
$this->assertFalse(isset($this->component->ColorAttribute)); |
|
2071
|
|
|
$this->assertFalse(isset($this->component->JsColorAttribute)); |
|
2072
|
|
|
|
|
2073
|
|
|
$this->component->JsColorAttribute = "['#112233', '#fedcba', 22009837]"; |
|
2074
|
|
|
|
|
2075
|
|
|
$this->assertTrue(isset($this->component->ColorAttribute)); |
|
2076
|
|
|
$this->assertTrue(isset($this->component->JsColorAttribute)); |
|
2077
|
|
|
|
|
2078
|
|
|
unset($this->component->JsColorAttribute); |
|
2079
|
|
|
|
|
2080
|
|
|
$this->assertFalse(isset($this->component->ColorAttribute)); |
|
2081
|
|
|
$this->assertFalse(isset($this->component->JsColorAttribute)); |
|
2082
|
|
|
|
|
2083
|
|
|
} |
|
2084
|
|
|
|
|
2085
|
|
|
|
|
2086
|
|
|
|
|
2087
|
|
|
} |
|
2088
|
|
|
|