Bienvenue sur PostGIS.fr

Bienvenue sur PostGIS.fr , le site de la communauté des utilisateurs francophones de PostGIS.

PostGIS ajoute le support d'objets géographique à la base de données PostgreSQL. En effet, PostGIS "spatialise" le serverur PostgreSQL, ce qui permet de l'utiliser comme une base de données SIG.

Maintenu à jour, en fonction de nos disponibilités et des diverses sorties des outils que nous testons, nous vous proposons l'ensemble de nos travaux publiés en langue française.

source: trunk/workshop-routing-foss4g/web/ext/test/unit/Ext.js @ 81

Revision 76, 39.7 KB checked in by djay, 12 years ago (diff)

Ajout du répertoire web

  • Property svn:executable set to *
Line 
1/*!
2 * Ext JS Library 3.4.0
3 * Copyright(c) 2006-2011 Sencha Inc.
4 * licensing@sencha.com
5 * http://www.sencha.com/license
6 */
7Ext.test.session.addTest('Ext', {
8
9    name: 'core',
10   
11    planned: 355,
12   
13    // addBehaviors
14   
15    // 7
16    test_apply: function(){
17        var o1 = Ext.apply({}, {
18            foo: 1,
19            bar: 2
20        });
21        Y.ObjectAssert.hasKeys(o1, {
22            foo: 1,
23            bar: 2
24        }, 'Test simple apply, with a return value');
25       
26        var o2 = {};
27        Ext.apply(o2, {
28            opt1: 'x',
29            opt2: 'y'
30        });
31        Y.ObjectAssert.hasKeys(o2, {
32            opt1: 'x',
33            opt2: 'y'
34        }, 'Test that the reference is changed');
35       
36        var o3 = Ext.apply({}, {
37            prop1: 1
38        });
39        Y.Assert.isUndefined(o3.prop2, 'Test to ensure no extra properties are copied');
40       
41        var o4 = Ext.apply({
42            foo: 1,
43            baz: 4
44        }, {
45            foo: 2,
46            bar: 3
47        });
48        Y.ObjectAssert.hasKeys(o4, {
49            foo: 2,
50            bar: 3,
51            baz: 4
52        }, 'Ensure that properties get overwritten by defaults');
53       
54        var o5 = {};
55        Ext.apply(o5, {
56            foo: 'new',
57            exist: true
58        }, {
59            foo: 'old',
60            def: true
61        });
62        Y.ObjectAssert.hasKeys(o5, {
63            foo: 'new',
64            def: true,
65            exist: true
66        }, 'Test using defaults');
67       
68        var o6 = Ext.apply({}, {
69            foo: 'foo',
70            bar: 'bar'
71        }, {
72            foo: 'oldFoo',
73            bar: 'oldBar'
74        });
75        Y.ObjectAssert.hasKeys(o6, {
76            foo: 'foo',
77            bar: 'bar'
78        }, 'Test to ensure all defaults get overridden');
79       
80        Y.Assert.isNull(Ext.apply(null, {}), 'Test null first argument');
81    },
82   
83    // 5
84    test_applyIf: function(){
85        var o1 = Ext.applyIf({}, {
86            foo: 'foo',
87            bar: 'bar'
88        });
89        Y.ObjectAssert.hasKeys(o1, {
90            foo: 'foo',
91            bar: 'bar'
92        }, 'Test with an empty destination object');
93       
94        var o2 = Ext.applyIf({
95            foo: 'foo'
96        }, {
97            foo: 'oldFoo'
98        });
99        Y.ObjectAssert.hasKeys(o2, {
100            foo: 'foo'
101        }, 'Ensure existing properties don\'t get overridden');
102       
103        var o3 = Ext.applyIf({
104            foo: 1,
105            bar: 2
106        }, {
107            bar: 3,
108            baz: 4
109        });
110        Y.ObjectAssert.hasKeys(o3, {
111            foo: 1,
112            bar: 2,
113            baz: 4
114        }, 'Test mixing properties to be overridden');
115       
116        var o4 = {};
117        Ext.applyIf(o4, {
118            foo: 2
119        }, {
120            foo: 1
121        });
122        Y.ObjectAssert.hasKeys(o4, {
123            foo: 2
124        }, 'Test that the reference of the object is changed');
125       
126        Y.Assert.isNull(Ext.applyIf(null, {}), 'Test null first argument');
127    },
128   
129    // 6
130    test_clean: function(){
131        Y.ArrayAssert.itemsAreEqual([true, true, true], Ext.clean([true, true, true]), 'Test with all true');
132        Y.ArrayAssert.isEmpty(Ext.clean([]), 'Test with empty');
133        Y.ArrayAssert.isEmpty(Ext.clean([false, false, false]), 'Test with all false');
134        Y.ArrayAssert.isEmpty(Ext.clean(null), 'Test with non array parameter');
135        Y.ArrayAssert.itemsAreEqual([1, 1], Ext.clean([1, 0, 1]), 'Test with non booleans');
136        Y.ArrayAssert.itemsAreEqual([1, 2, 3, 1], Ext.clean([1, 2, false, 0, 3, 1]), 'Ensure order is maintained properly');
137    },
138   
139    // 7
140    test_copyTo: function(){
141        var from = {
142            x: 50,
143            y: 100,
144            width: 'auto',
145            height: 200
146        };
147       
148        var o1 = Ext.copyTo({}, from, 'x,y');
149        Y.ObjectAssert.hasKeys(o1, {
150            x: 50,
151            y: 100
152        }, 'Test simple copy with string');
153       
154        var o2 = Ext.copyTo({}, from, '');
155        Y.Assert.isUndefined(o2.x, 'Test with empty string as properties');
156        Y.Assert.isUndefined(o2.y, 'Test with empty string as properties');
157        Y.Assert.isUndefined(o2.width, 'Test with empty string as properties');
158        Y.Assert.isUndefined(o2.height, 'Test with empty string as properties');
159       
160        var o3 = {};
161        Ext.copyTo(o3, from, 'width');
162        Y.ObjectAssert.hasKeys(o3, {
163            width: 'auto'
164        }, 'Test copy ensuring that the original reference is changed');
165       
166        var o4 = Ext.copyTo({
167            x: 1
168        }, from, ['x', 'y']);
169        Y.ObjectAssert.hasKeys(o4, {
170            x: 50,
171            y: 100
172        }, 'Test with array as properties, also with an existing value in the destination object');
173    },
174   
175    // create
176    // decode
177   
178    // 14
179    test_destroy: function(){
180        var C1 = Ext.extend(Object, {
181            constructor: function(){
182                this.c1destroy = false;
183            },
184            destroy: function(){
185                this.c1destroy = true;
186            }
187        });
188        var C2 = Ext.extend(Object, {
189            constructor: function(){
190                this.c2destroy = false;
191            },
192            destroy: function(){
193                this.c2destroy = true;
194            }
195        });
196        var C3 = Ext.extend(Object, {
197            constructor: function(){
198                this.c3destroy = false;
199            },
200            dest: function(){
201                this.c3destroy = true;
202            }
203        });
204       
205        var o1 = new C1();
206        Ext.destroy(o1);
207        Y.Assert.isTrue(o1.c1destroy, 'Simple destroy test with a single object');
208       
209        var arr1 = [new C1(), new C2(), new C2()];
210        Ext.destroy(arr1);
211        Y.Assert.isTrue(arr1[0].c1destroy, 'Test with an array of items');
212        Y.Assert.isTrue(arr1[1].c2destroy, 'Test with an array of items');
213        Y.Assert.isTrue(arr1[2].c2destroy, 'Test with an array of items');
214       
215        var o2 = new C1(), o3 = new C2(), o4 = new C1();
216       
217        Ext.destroy(o2, o3, o4);
218        Y.Assert.isTrue(o2.c1destroy, 'Test with param array');
219        Y.Assert.isTrue(o3.c2destroy, 'Test with param array');
220        Y.Assert.isTrue(o4.c1destroy, 'Test with param array');
221       
222        var o5 = new C3();
223        Ext.destroy(o5);
224        Y.Assert.isFalse(o5.c3destroy, 'Test item without a destroy method');
225       
226        var arr2 = [new C1(), new C3(), new C2()];
227        Ext.destroy(arr2);
228        Y.Assert.isTrue(arr2[0].c1destroy, 'Test with an array of items, mix of items with and without destroy');
229        Y.Assert.isFalse(arr2[1].c3destroy, 'Test with an array of items, mix of items with and without destroy');
230        Y.Assert.isTrue(arr2[2].c2destroy, 'Test with an array of items, mix of items with and without destroy');
231       
232        var id1 = Ext.id(), el1 = Ext.getBody().createChild({
233            id: id1
234        });
235        Ext.destroy(el1);
236        Y.Assert.isNull(document.getElementById(id1), 'Test with an Ext.Element');
237       
238        var id2 = Ext.id(), el2 = Ext.getBody().createChild({
239            id: id2
240        }), o6 = new C1();
241        Ext.destroy(el2, o6);
242        Y.Assert.isNull(document.getElementById(id2), 'Test with a mix of elements and objects');
243        Y.Assert.isTrue(o6.c1destroy, 'Test with a mix of elements and objects');
244    },
245   
246    // 14
247    test_destroyMembers: function(){
248        var C1 = Ext.extend(Object, {
249            constructor: function(){
250                this.p1 = 1;
251                this.p2 = 2;
252                this.p3 = 3;
253                this.p4 = 4;
254                this.d = false;
255            },
256           
257            destroy: function(){
258                this.d = true;
259            }
260        });
261        var C2 = Ext.extend(Object, {
262            constructor: function(){
263                this.p1 = new C1();
264                this.p2 = new C1();
265                this.p3 = 1;
266            }
267        });
268       
269        var o1 = new C1();
270        Ext.destroyMembers(o1, 'p1', 'p3');
271        Y.Assert.isUndefined(o1.p1, 'Simple test with a mix of properties');
272        Y.Assert.areEqual(2, o1.p2, 'Simple test with a mix of properties');
273        Y.Assert.isUndefined(o1.p3, 'Simple test with a mix of properties');
274        Y.Assert.areEqual(4, o1.p4, 'Simple test with a mix of properties');
275       
276        var o2 = new C2();
277        Ext.destroyMembers(o2);
278        Y.Assert.isNotUndefined(o2.p1, 'Test with empty parameter list, ensure nothing is removed or destroyed');
279        Y.Assert.isNotUndefined(o2.p2, 'Test with empty parameter list, ensure nothing is removed or destroyed');
280        Y.Assert.areEqual(1, o2.p3, 'Test with empty parameter list, ensure nothing is removed or destroyed');
281        Y.Assert.isFalse(o2.p1.d, 'Test with empty parameter list, ensure nothing is removed or destroyed');
282        Y.Assert.isFalse(o2.p2.d, 'Test with empty parameter list, ensure nothing is removed or destroyed');
283       
284        var o3 = new C2(), o4 = o3.p1, o5 = o3.p2;
285        Ext.destroyMembers(o3, 'p1', 'p2');
286        Y.Assert.isUndefined(o3.p1, 'Destroy objects, ensure they are destroyed and removed');
287        Y.Assert.isUndefined(o3.p2, 'Destroy objects, ensure they are destroyed and removed');
288        Y.Assert.areEqual(1, o3.p3, 'Destroy objects, ensure they are destroyed and removed');
289        Y.Assert.isTrue(o4.d, 'Destroy objects, ensure they are destroyed and removed');
290        Y.Assert.isTrue(o5.d, 'Destroy objects, ensure they are destroyed and removed');
291    },
292   
293    // 10
294    test_each: function(){
295        var sum = 0;
296        Ext.each([1, 2, 3, 4], function(val){
297            sum += val;
298        });
299        Y.Assert.areEqual(10, sum, 'Simple each on an array of numbers');
300           
301        var s = '';
302        Ext.each(['T', 'e', 's', 't', 'i', 'n', 'g'], function(c){
303            s += c;
304        });
305        Y.Assert.areEqual('Testing', s, 'Simple each on array of strings');
306           
307        sum = 0;
308        Ext.each(5, function(num){
309            sum += num;
310        });
311        Y.Assert.areEqual(5, sum, 'Test with a non array parameter, number');
312           
313        var hit = false;
314        Ext.each([], function(){
315            hit = true;
316        });
317        Y.Assert.isFalse(hit, 'Test with empty array parameter');
318           
319        hit = false;
320        Ext.each(null, function(){
321            hit = true;
322        });
323        Y.Assert.isFalse(hit, 'Test with null parameter');
324           
325        hit = false;
326        Ext.each(document.getElementsByTagName('body'), function(){
327            hit = true;
328        });
329        Y.Assert.isTrue(hit, 'Test iteration over NodeLists');
330           
331        var arr = [];
332        Ext.each([1, 2, 3, 4, 5, 6], function(val, idx){
333            arr.push(idx);
334        });
335        Y.ArrayAssert.itemsAreEqual([0, 1, 2, 3, 4, 5], arr, 'Test index is passed correctly');
336           
337        sum = 0;
338        Ext.each([1, 2, 3, 4, 5, 6], function(val){
339            if(val > 4){
340                return false;
341            }
342            sum += val;
343        });
344        Y.Assert.areEqual(10, sum, 'Test that returning false stops iteration');
345           
346        sum = 0;
347        var scope = {value: 3};
348        Ext.each([1, 2, 3], function(val){
349            sum += val * this.value;
350        }, scope);
351        Y.Assert.areEqual(18, sum, 'Test scope argument #1');
352           
353        sum = 0;
354        scope = {value: 5};
355        Ext.each([1, 2, 3], function(val){
356            sum += val * this.value; //value should be 5
357        }, scope);
358        Y.Assert.areEqual(30, sum, 'Test scope argument #2');
359    },
360   
361    // encode
362   
363    // 5
364    test_escapeRe: function(){
365        Y.Assert.areEqual('\\-', Ext.escapeRe('-'), 'Test with single char');
366        Y.Assert.areEqual('\\*\\.', Ext.escapeRe('*.'), 'Test with multiple characters next to each other');
367        Y.Assert.areEqual('foo', Ext.escapeRe('foo'), 'Test with no escapeable chars');
368        Y.Assert.areEqual('\\{baz\\}', Ext.escapeRe('{baz}'), 'Test with mixed set');
369        Y.Assert.areEqual('\\-\\.\\*\\+\\?\\^\\$\\{\\}\\(\\)\\|\\[\\]\\/\\\\', Ext.escapeRe('-.*+?^${}()|[]/\\'), 'Test with every character');
370    },
371   
372    // 4
373    test_extend: function(){
374        var Dude = Ext.extend(Object, {
375            constructor: function(config){
376                Ext.apply(this, config);
377                this.isBadass = false;
378            }
379        });
380        var Aweysome = Ext.extend(Dude, {
381            constructor: function(){
382                Aweysome.superclass.constructor.apply(this, arguments);
383                this.isBadass = true;
384            }
385        });
386       
387        var david = new Aweysome({
388            davis: 'isAwesome'
389        });
390        Y.Assert.areEqual('isAwesome', david.davis, 'Test if David is awesome');
391        Y.Assert.isTrue(david.isBadass, 'Test if David is badass');
392        Y.Assert.isFunction(david.override, 'Test if extend added the override method');
393        Y.ObjectAssert.areEqual({
394            isBadass: true,
395            davis: 'isAwesome'
396        }, david, 'Test if David is badass and awesome');
397    },
398   
399    // 9
400    test_flatten: function(){
401        Y.ArrayAssert.isEmpty(Ext.flatten([]), 'Test with empty array');
402        Y.ArrayAssert.isEmpty(Ext.flatten([[], [], []]), 'Test with an array of empty arrays');
403        Y.ArrayAssert.isEmpty(Ext.flatten(null), 'Test with null');
404        Y.ArrayAssert.isEmpty(Ext.flatten(undefined), 'Test with undefined');
405        Y.ArrayAssert.itemsAreEqual([1, 7, 3, 4], Ext.flatten([1, 7, 3, 4]), 'Test with a simple flat array');
406        Y.ArrayAssert.itemsAreEqual([1, 2, 3], Ext.flatten([[1], [2], [3]]), 'Test with an array of arrays with a single item');
407        Y.ArrayAssert.itemsAreEqual([1, 2, 3, 4, 5, 6], Ext.flatten([[1, 2], [3, 4], [5, 6]]), 'Test sub arrays with multiple items');
408        Y.ArrayAssert.itemsAreEqual([1, 2, 3, 4, 5, 6, 7], Ext.flatten([1, 2, [3, 4], 5, [6, 7]]), 'Test a mix of sub arrays and non arrays');
409        Y.ArrayAssert.itemsAreEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], Ext.flatten([[[1, [2, 3], [4, 5]], [6, 7, [8, [9, 10]]]]]), 'Test with multiple levels of nesting');
410    },
411   
412    // 1
413    test_fly: function(){
414        var id = Ext.id();
415        var div = document.createElement('div');
416        div.id = id;
417        Ext.getBody().dom.appendChild(div);
418       
419        var div2 = Ext.fly(id);
420        Y.Assert.areSame(div, div2.dom, 'Test if fly got the correct item');
421        div2.remove();
422    },
423   
424    // 1
425    test_get: function(){
426        var id = Ext.id();
427        var div = document.createElement('div');
428        div.id = id;
429        Ext.getBody().dom.appendChild(div);
430        var div2 = Ext.get(id);
431        Y.Assert.areSame(div, div2.dom, 'Test if "get" got the correct item');
432        div2.remove();
433    },
434   
435    // 1
436    test_getBody: function(){
437        var body = Ext.getBody();
438        Y.Assert.isTrue(body.dom === document.body || body.dom === document.documentElement, 'Test if getBody returns the body');
439    },
440   
441    // getCmp
442   
443    // 1
444    test_getDoc: function(){
445        var doc = Ext.getDoc();
446        Y.Assert.areSame(document, doc.dom, 'Test if getDoc returns document');
447    },
448   
449    // 1
450    test_getDom: function(){
451        var id = Ext.id();
452        var div = document.createElement('div');
453        div.id = id;
454        Ext.getBody().dom.appendChild(div);
455       
456        var div2 = Ext.getDom(id);
457        Y.Assert.areSame(div, div2, 'Test if getDom returns correct element');
458        div2.parentNode.removeChild(div2);
459    },
460   
461    // 1
462    test_getScrollBarWidth: function(){
463        Y.Assert.isNumber(Ext.getScrollBarWidth(), 'Test if getScrollBarWith returns a number');
464    },
465   
466    // 1
467    test_id: function(){
468        var id = Ext.id(document);
469        var id2 = Ext.id(document);
470        Y.Assert.areEqual(id, id2, 'Test if id returns same id for the same element');
471    },
472   
473    // 8
474    test_invoke: function(){
475        var n = 0;
476        var fn = function(a, b){
477            Y.Assert.areEqual('a', a, 'Testing invoke param');
478            Y.Assert.areEqual('b', b, 'Testing invoke param');
479            return ++n;
480        };
481       
482        var arr = [{
483            get: fn
484        }, {
485            get: fn
486        }, {
487            get: fn
488        }];
489        var results = Ext.invoke(arr, 'get', 'a', 'b');
490       
491        Y.ArrayAssert.itemsAreEqual([1, 2, 3], results, 'Test invoke results');
492        Y.Assert.areEqual(n, results.length, 'Number of invocations');
493    },
494   
495    // 12
496    test_isArray: function(){
497        var C = Ext.extend(Object, {
498            length: 1
499        });
500        Y.Assert.isTrue(Ext.isArray([]), 'Test with empty array');
501        Y.Assert.isTrue(Ext.isArray([1, 2, 3, 4]), 'Test with filled array');
502        Y.Assert.isFalse(Ext.isArray(false), 'Test with boolean #1');
503        Y.Assert.isFalse(Ext.isArray(true), 'Test with boolean #2');
504        Y.Assert.isFalse(Ext.isArray('foo'), 'Test with string');
505        Y.Assert.isFalse(Ext.isArray(1), 'Test with number');
506        Y.Assert.isFalse(Ext.isArray(null), 'Test with null');
507        Y.Assert.isFalse(Ext.isArray(new Date()), 'Test with a date');
508        Y.Assert.isFalse(Ext.isArray({}), 'Test with empty object');
509        Y.Assert.isFalse(Ext.isArray(document.getElementsByTagName('body')), 'Test with node list');
510        Y.Assert.isFalse(Ext.isArray(Ext.getBody().dom), 'Test with element');
511        Y.Assert.isFalse(Ext.isArray(new C()), 'Test with custom class that has a length property');
512    },
513   
514    // 11
515    test_isBoolean: function(){
516        Y.Assert.isTrue(Ext.isBoolean(true), 'Test with true');
517        Y.Assert.isTrue(Ext.isBoolean(false), 'Test with false');
518        Y.Assert.isFalse(Ext.isBoolean([]), 'Test with empty array');
519        Y.Assert.isFalse(Ext.isBoolean([1, 2, 3]), 'Test with filled array');
520        Y.Assert.isFalse(Ext.isBoolean(1), 'Test with number');
521        Y.Assert.isFalse(Ext.isBoolean(''), 'Test with empty string');
522        Y.Assert.isFalse(Ext.isBoolean('foo'), 'Test with non empty string');
523        Y.Assert.isFalse(Ext.isBoolean(Ext.getBody().dom), 'Test with element');
524        Y.Assert.isFalse(Ext.isBoolean(null), 'Test with null');
525        Y.Assert.isFalse(Ext.isBoolean({}), 'Test with object');
526        Y.Assert.isFalse(Ext.isBoolean(new Date()), 'Test with date');
527    },
528   
529    // 9
530    test_isDate: function(){
531        Y.Assert.isTrue(Ext.isDate(new Date()), 'Test with simple date');
532        Y.Assert.isTrue(Ext.isDate(Date.parseDate('2000', 'Y')), 'Test with simple date');
533        Y.Assert.isFalse(Ext.isDate(true), 'Test with boolean');
534        Y.Assert.isFalse(Ext.isDate(1), 'Test with number');
535        Y.Assert.isFalse(Ext.isDate('foo'), 'Test with string');
536        Y.Assert.isFalse(Ext.isDate(null), 'Test with null');
537        Y.Assert.isFalse(Ext.isDate([]), 'Test with array');
538        Y.Assert.isFalse(Ext.isDate({}), 'Test with object');
539        Y.Assert.isFalse(Ext.isDate(Ext.getBody().dom), 'Test with element');
540    },
541   
542    // 10
543    test_isDefined: function(){
544        Y.Assert.isFalse(Ext.isDefined(undefined), 'Test with undefined');
545        Y.Assert.isTrue(Ext.isDefined(null), 'Test with null');
546        Y.Assert.isTrue(Ext.isDefined({}), 'Test with object');
547        Y.Assert.isTrue(Ext.isDefined([]), 'Test with array');
548        Y.Assert.isTrue(Ext.isDefined(new Date()), 'Test with date');
549        Y.Assert.isTrue(Ext.isDefined(1), 'Test with number');
550        Y.Assert.isTrue(Ext.isDefined(false), 'Test with boolean');
551        Y.Assert.isTrue(Ext.isDefined(''), 'Test with empty string');
552        Y.Assert.isTrue(Ext.isDefined('foo'), 'Test with non-empty string');
553        Y.Assert.isTrue(Ext.isDefined(Ext.getBody().dom), 'Test with element');
554    },
555   
556    // 5
557    test_isElement: function(){
558        Y.Assert.isTrue(Ext.isElement(Ext.getBody().dom), 'Test with element');
559        Y.Assert.isFalse(Ext.isElement(Ext.getBody()), 'Test with Ext.Element');
560        Y.Assert.isFalse(Ext.isElement(null), 'Test with null');
561        Y.Assert.isFalse(Ext.isElement(1), 'Test with number');
562        Y.Assert.isFalse(Ext.isElement('foo'), 'Test with string');
563    },
564   
565    // 10
566    test_isEmpty: function(){
567        Y.Assert.isTrue(Ext.isEmpty(''), 'Test with empty string');
568        Y.Assert.isTrue(Ext.isEmpty(null), 'Test with null');
569        Y.Assert.isTrue(Ext.isEmpty(undefined), 'Test with undefined');
570        Y.Assert.isTrue(Ext.isEmpty([]), 'Test with empty array');
571        Y.Assert.isFalse(Ext.isEmpty('Foo'), 'Test with simple string');
572        Y.Assert.isFalse(Ext.isEmpty(false), 'Test with boolean false');
573        Y.Assert.isFalse(Ext.isEmpty(1), 'Test with numeric value');
574        Y.Assert.isFalse(Ext.isEmpty({}), 'Test with object with no properties');
575        Y.Assert.isFalse(Ext.isEmpty([1, 2, 3]), 'Test with filled array');
576        Y.Assert.isFalse(Ext.isEmpty('', true), 'Test empty string with allowBlank');
577    },
578   
579    // 12
580    test_isFunction: function(){
581        var c = new Ext.util.Observable(), o = {
582            fn: function(){
583            }
584        };
585        Y.Assert.isTrue(Ext.isFunction(function(){
586        }), 'Test with anonymous function');
587        Y.Assert.isTrue(Ext.isFunction(new Function('return "";')), 'Test with new Function syntax');
588        Y.Assert.isTrue(Ext.isFunction(Ext.emptyFn), 'Test with static function');
589        Y.Assert.isTrue(Ext.isFunction(c.fireEvent), 'Test with instance function');
590        Y.Assert.isTrue(Ext.isFunction(o.fn), 'Test with function on object');
591        Y.Assert.isFalse(Ext.isFunction(Ext.version), 'Test with class property');
592        Y.Assert.isFalse(Ext.isFunction(null), 'Test with null');
593        Y.Assert.isFalse(Ext.isFunction(1), 'Test with number');
594        Y.Assert.isFalse(Ext.isFunction(''), 'Test with string');
595        Y.Assert.isFalse(Ext.isFunction(new Date()), 'Test with date');
596        Y.Assert.isFalse(Ext.isFunction([]), 'Test with array');
597        Y.Assert.isFalse(Ext.isFunction({}), 'Test with object');
598    },
599   
600    // 19
601    test_isNumber: function(){
602        Y.Assert.isTrue(Ext.isNumber(0), 'Test with 0');
603        Y.Assert.isTrue(Ext.isNumber(4), 'Test with non-zero integer');
604        Y.Assert.isTrue(Ext.isNumber(-3), 'Test with negative integer');
605        Y.Assert.isTrue(Ext.isNumber(7.9), 'Test with positive float');
606        Y.Assert.isTrue(Ext.isNumber(-4.3), 'Test with negative float');
607        Y.Assert.isTrue(Ext.isNumber(Number.MAX_VALUE), 'Test with MAX_VALUE');
608        Y.Assert.isTrue(Ext.isNumber(Number.MIN_VALUE), 'Test with MIN_VALUE');
609        Y.Assert.isTrue(Ext.isNumber(Math.PI), 'Test with Math.PI');
610        Y.Assert.isTrue(Ext.isNumber(Number('3.1')), 'Test with Number() constructor');
611        Y.Assert.isFalse(Ext.isNumber(Number.NaN), 'Test with NaN');
612        Y.Assert.isFalse(Ext.isNumber(Number.POSITIVE_INFINITY), 'Test with POSITIVE_INFINITY');
613        Y.Assert.isFalse(Ext.isNumber(Number.NEGATIVE_INFINITY), 'Test with NEGATIVE_INFINITY');
614        Y.Assert.isFalse(Ext.isNumber(true), 'Test with true');
615        Y.Assert.isFalse(Ext.isNumber(''), 'Test with empty string');
616        Y.Assert.isFalse(Ext.isNumber('1.0'), 'Test with string containing a number');
617        Y.Assert.isFalse(Ext.isNumber(null), 'Test with null');
618        Y.Assert.isFalse(Ext.isNumber(undefined), 'Test with undefined');
619        Y.Assert.isFalse(Ext.isNumber([]), 'Test with array');
620        Y.Assert.isFalse(Ext.isNumber({}), 'Test with object');
621    },
622   
623    // 14
624    test_isObject: function(){
625        Y.Assert.isTrue(Ext.isObject({}), 'Test with empty object');
626        Y.Assert.isTrue(Ext.isObject({
627            foo: 1
628        }), 'Test with object with properties');
629        Y.Assert.isTrue(Ext.isObject(new Ext.util.Observable()), 'Test with object instance');
630        Y.Assert.isTrue(Ext.isObject(new Object()), 'Test with new Object(  ) syntax');
631        Y.Assert.isFalse(Ext.isObject(new Date()), 'Test with a date object');
632        Y.Assert.isFalse(Ext.isObject([]), 'Test with array');
633        Y.Assert.isFalse(Ext.isObject(new Array()), 'Test with new Array(  ) syntax');
634        Y.Assert.isFalse(Ext.isObject(1), 'Test with number');
635        Y.Assert.isFalse(Ext.isObject('foo'), 'Test with string');
636        Y.Assert.isFalse(Ext.isObject(false), 'Test with boolean');
637        Y.Assert.isFalse(Ext.isObject(new Number(3)), 'Test with new Number() syntax');
638        Y.Assert.isFalse(Ext.isObject(new String('foo')), 'Test with new String() syntax');
639        Y.Assert.isFalse(Ext.isObject(null), 'Test with null');
640        Y.Assert.isFalse(Ext.isObject(undefined), 'Test with undefined');
641    },
642   
643    // 14
644    test_isPrimitive: function(){
645        Y.Assert.isTrue(Ext.isPrimitive(1), 'Test with integer');
646        Y.Assert.isTrue(Ext.isPrimitive(-3), 'Test with negative integer');
647        Y.Assert.isTrue(Ext.isPrimitive(1.4), 'Test with floating number');
648        Y.Assert.isTrue(Ext.isPrimitive(Number.MAX_VALUE), 'Test with Number.MAX_VALUE');
649        Y.Assert.isTrue(Ext.isPrimitive(Math.PI), 'Test with Math.PI');
650        Y.Assert.isTrue(Ext.isPrimitive(''), 'Test with empty string');
651        Y.Assert.isTrue(Ext.isPrimitive('foo'), 'Test with non empty string');
652        Y.Assert.isTrue(Ext.isPrimitive(true), 'Test with boolean true');
653        Y.Assert.isTrue(Ext.isPrimitive(false), 'Test with boolean false');
654        Y.Assert.isFalse(Ext.isPrimitive(null), 'Test with null');
655        Y.Assert.isFalse(Ext.isPrimitive(undefined), 'Test with undefined');
656        Y.Assert.isFalse(Ext.isPrimitive({}), 'Test with object');
657        Y.Assert.isFalse(Ext.isPrimitive([]), 'Test with array');
658        Y.Assert.isFalse(Ext.isPrimitive(new Ext.util.Observable()), 'Test with object instance');
659    },
660   
661    // 10
662    test_isString: function(){
663        var s = new String('foo');
664        Y.Assert.isTrue(Ext.isString(''), 'Test with empty string');
665        Y.Assert.isTrue(Ext.isString('foo'), 'Test with non empty string');
666        Y.Assert.isTrue(Ext.isString(String('')), 'Test with String() syntax');
667        Y.Assert.isFalse(Ext.isString(new String('')), 'Test with new String() syntax'); //should return an object that wraps the primitive
668        Y.Assert.isFalse(Ext.isString(1), 'Test with number');
669        Y.Assert.isFalse(Ext.isString(true), 'Test with boolean');
670        Y.Assert.isFalse(Ext.isString(null), 'Test with null');
671        Y.Assert.isFalse(Ext.isString(undefined), 'Test with undefined');
672        Y.Assert.isFalse(Ext.isString([]), 'Test with array');
673        Y.Assert.isFalse(Ext.isString({}), 'Test with number');
674    },
675   
676    // 8
677    test_iterate: function(){
678        var n = 0;
679        Ext.iterate({
680            n1: 11,
681            n2: 13,
682            n3: 18
683        }, function(k, v, o){
684            Y.Assert.isNumber(v);
685            n += v;
686        });
687        Y.Assert.areEqual(42, n, 'Test if iterate has called the function the correct number of times (object)');
688        n = 0;
689        Ext.iterate([11, 13, 18], function(x){
690            Y.Assert.isNumber(x);
691            n += x;
692        });
693        Y.Assert.areEqual(42, n, 'Test if iterate has called the function the correct number of times (array)');
694    },
695   
696    // 7
697    test_max: function(){
698        Y.Assert.areEqual(14, Ext.max([14]), 'Test single item');
699        Y.Assert.areEqual(16, Ext.max([1, 4, 16, 3, 8]), 'Test with max in the middle');
700        Y.Assert.areEqual(9, Ext.max([9, 1, 5, 8]), 'Test with max at start');
701        Y.Assert.areEqual(12, Ext.max([1, 9, 0, 4, 12]), 'Test with max at end');
702        Y.Assert.isUndefined(Ext.max([]), 'Test with empty array');
703        Y.Assert.areEqual('j', Ext.max(['a', 'f', 'j', 'c', 'b']), 'Test with strings');
704        Y.Assert.areEqual(7, Ext.max([6, 7, 8], function(a, b){
705            return (a % 8 > b % 8) ? 1 : -1;
706        }), 'Test with custom comparator');
707    },
708   
709    // 4
710    test_mean: function(){
711        Y.Assert.isUndefined(Ext.mean([]), 'Test with an empty list');
712        Y.Assert.areEqual(4, Ext.mean([4]), 'Test with a single item');
713        Y.Assert.areEqual(3, Ext.mean([1, 2, 3, 4, 5]), 'Test with multiple items');
714        Y.Assert.areEqual(1.3, Ext.mean([1.1, 1.2, 1.3, 1.4, 1.5]), 'Test with floats');
715    },
716   
717    // 7
718    test_min: function(){
719        Y.Assert.areEqual(5, Ext.min([5]), 'Test single item');
720        Y.Assert.areEqual(2, Ext.min([3, 7, 2, 4, 8]), 'Test with min in the middle');
721        Y.Assert.areEqual(4, Ext.min([4, 12, 28, 100, 5]), 'Test with min at the start');
722        Y.Assert.areEqual(3, Ext.min([13, 4, 17, 83, 3]), 'Test with min at the end');
723        Y.Assert.isUndefined(Ext.min([]), 'Test with empty array');
724        Y.Assert.areEqual('b', Ext.min(['c', 'm', 'b', 'q', 's']), 'Test with strings');
725        Y.Assert.areEqual(8, Ext.min([6, 7, 8], function(a, b){
726            return (a % 8 > b % 8) ? 1 : -1;
727        }), 'Test with custom comparator');
728    },
729   
730    // 14
731    test_namespace: function(){
732        var w = window;
733       
734        Ext.namespace('FooTest1');
735        Y.Assert.isNotUndefined(w.FooTest1, 'Test creation with a single top-level namespace');
736       
737        Ext.namespace('FooTest2', 'FooTest3', 'FooTest4');
738        Y.Assert.isNotUndefined(w.FooTest2, 'Test creation with multiple top level namespaces');
739        Y.Assert.isNotUndefined(w.FooTest3, 'Test creation with multiple top level namespaces');
740        Y.Assert.isNotUndefined(w.FooTest4, 'Test creation with multiple top level namespaces');
741       
742        Ext.namespace('FooTest5', 'FooTest5.ns1', 'FooTest5.ns1.ns2', 'FooTest5.ns1.ns2.ns3');
743        Y.Assert.isNotUndefined(w.FooTest5, 'Test a chain of namespaces, starting from a top-level');
744        Y.Assert.isNotUndefined(w.FooTest5.ns1, 'Test a chain of namespaces, starting from a top-level');
745        Y.Assert.isNotUndefined(w.FooTest5.ns1.ns2, 'Test a chain of namespaces, starting from a top-level');
746        Y.Assert.isNotUndefined(w.FooTest5.ns1.ns2.ns3, 'Test a chain of namespaces, starting from a top-level');
747       
748        Ext.namespace('FooTest6.ns1', 'FooTest7.ns1');
749        Y.Assert.isNotUndefined(w.FooTest6.ns1, 'Test creating lower level namespaces without first defining the top level');
750        Y.Assert.isNotUndefined(w.FooTest7.ns1, 'Test creating lower level namespaces without first defining the top level');
751       
752        Ext.namespace('FooTest8', 'FooTest8.ns1.ns2');
753        Y.Assert.isNotUndefined(w.FooTest8, 'Test creating a lower level namespace without defining the middle level');
754        Y.Assert.isNotUndefined(w.FooTest8.ns1, 'Test creating a lower level namespace without defining the middle level');
755        Y.Assert.isNotUndefined(w.FooTest8.ns1.ns2, 'Test creating a lower level namespace without defining the middle level');
756       
757        FooTest8.prop1 = 'foo';
758        Ext.namespace('FooTest8');
759        Y.Assert.areEqual('foo', FooTest8.prop1, 'Ensure existing namespaces are not overwritten');
760    },
761   
762    // ns is alias of namespace
763   
764    // 18
765    test_num: function(){
766        Y.Assert.areEqual(3, Ext.num(3), 'Test with an integer');
767        Y.Assert.areEqual(-7, Ext.num(-7), 'Test with a negative integer');
768        Y.Assert.areEqual(5.43, Ext.num(5.43), 'Test with a float');
769        Y.Assert.areEqual(-9.8, Ext.num(-9.8), 'Test with a negative float');
770        Y.Assert.areEqual(Math.PI, Ext.num(Math.PI), 'Test with Math.PI');
771        Y.Assert.isUndefined(Ext.num(null), 'Test with null, no default');
772        Y.Assert.areEqual(3, Ext.num(null, 3), 'Test with null, with default');
773        Y.Assert.isUndefined(Ext.num(undefined), 'Test with undefined, no default');
774        Y.Assert.areEqual(17, Ext.num(undefined, 17), 'Test with undefined, with default');
775        Y.Assert.isUndefined(Ext.num(true), 'Test with boolean, no default');
776        Y.Assert.areEqual(8, Ext.num(true, 8), 'Test with boolean, with default');
777        Y.Assert.isUndefined(Ext.num(''), 'Test with empty string');
778        Y.Assert.areEqual(453, Ext.num('453'), 'Test with a string argument in the form of a number');
779        Y.Assert.isUndefined(Ext.num('    '), 'Test with a string containing only spaces');
780        Y.Assert.isUndefined(Ext.num('foo'), 'Test with non empty string');
781        Y.Assert.isUndefined(Ext.num([]), 'Test with empty array');
782        Y.Assert.isUndefined(Ext.num([1, 2, 3]), 'Test with non empty array');
783        Y.Assert.isUndefined(Ext.num([1]), 'Test with array with a single item');
784    },
785   
786    // onReady
787   
788    test_override: function(){
789   
790    },
791   
792    // 4
793    test_partition: function(){
794        var part = Ext.partition([true, false, true, true, false]);
795        Y.ArrayAssert.itemsAreEqual([true, true, true], part[0], 'Test if partitioned into true values');
796        Y.ArrayAssert.itemsAreEqual([false, false], part[1], 'Test if partitioned into false values');
797        var part2 = Ext.partition([12, 1, 11, 2, 3, 50, 5, 15], function(v){
798            return v > 10
799        });
800        Y.ArrayAssert.itemsAreEqual([12, 11, 50, 15], part2[0], 'Test if partitioned into a list of items less than 10');
801        Y.ArrayAssert.itemsAreEqual([1, 2, 3, 5], part2[1], 'Test if partitioned into a list of items greater than 10');
802    },
803   
804    // 1
805    test_pluck: function(){
806        var results = Ext.pluck([{
807            n: 11
808        }, {
809            n: 13
810        }, {
811            n: 18
812        }], 'n');
813        Y.ArrayAssert.itemsAreEqual([11, 13, 18], results, 'Test pluck results');
814    },
815   
816    // preg
817    // query
818    // reg
819    // removeNode
820    // select
821   
822    // 4
823    test_sum: function(){
824        Y.Assert.areEqual(0, Ext.sum([]), 'Test with an empty list');
825        Y.Assert.areEqual(4, Ext.sum([4]), 'Test with a single item');
826        Y.Assert.areEqual(15, Ext.sum([1, 2, 3, 4, 5]), 'Test with multiple items');
827        Y.Assert.areEqual(6.5, Ext.sum([1.1, 1.2, 1.3, 1.4, 1.5]), 'Test with floats');
828    },
829   
830    // 1
831    test_toArray: function(){
832        Y.Assert.isArray(Ext.toArray(document.getElementsByTagName('body')), 'Test with node list');
833    },
834   
835    // 25
836    test_type: function(){
837        Y.Assert.areEqual('string', Ext.type('foo'), 'Test with string');
838        Y.Assert.areEqual('object', Ext.type(new String('foo')), 'Test with new String() syntax'); //for some reason, isn't a string
839       
840        Y.Assert.areEqual('number', Ext.type(1), 'Test with number');
841        Y.Assert.areEqual('object', Ext.type(new Number(3)), 'Test with new Number() syntax'); //for some reason, isn't a number
842       
843        Y.Assert.areEqual('boolean', Ext.type(false), 'Test with boolean');
844        Y.Assert.areEqual('object', Ext.type(new Boolean(false)), 'Test with new Boolean() syntax'); //for some reason, isn't a boolean
845       
846        Y.Assert.areEqual('date', Ext.type(new Date()), 'Test with a date object');
847        Y.Assert.areEqual('date', Ext.type(Date.parseDate('2000', 'Y')), 'Test with simple date (parsed)');
848       
849        Y.Assert.areEqual('function', Ext.type(function(){
850        }), 'Test with a function');
851        Y.Assert.areEqual('function', Ext.type(Ext.emptyFn), 'Test with Ext.emptyFn');
852        Y.Assert.areEqual('function', Ext.type(new Function()), 'Test with new Function() syntax');
853       
854        Y.Assert.areEqual('object', Ext.type({}), 'Test with empty object');
855        Y.Assert.areEqual('object', Ext.type({
856            foo: 1
857        }), 'Test with object with properties');
858        Y.Assert.areEqual('object', Ext.type(new Ext.util.Observable()), 'Test with object instance');
859        Y.Assert.areEqual('object', Ext.type(new Object()), 'Test with new Object() syntax');
860       
861        Y.Assert.areEqual('array', Ext.type([]), 'Test with array');
862        Y.Assert.areEqual('array', Ext.type(new Array()), 'Test with new Array() syntax');
863       
864        Y.Assert.areEqual('regexp', Ext.type(/asdf/), 'Test with regexp');
865        Y.Assert.areEqual('regexp', Ext.type(new RegExp('asdf')), 'Test with new Regexp() syntax');
866       
867        Y.Assert.areEqual('nodelist', Ext.type(document.getElementsByTagName('body')), 'Test with node list');
868       
869        Y.Assert.areEqual('textnode', Ext.type(document.createTextNode('test')), 'Test with text node');
870       
871        Y.Assert.areEqual('whitespace', Ext.type(document.createTextNode('')), 'Test with empty text node');
872        Y.Assert.areEqual('whitespace', Ext.type(document.createTextNode('     ')), 'Test with whitespace in text node');
873       
874        Y.Assert.areEqual('', Ext.type(null), 'Test with null');
875        Y.Assert.areEqual(false, Ext.type(undefined), 'Test with undefined');
876    },
877   
878    // 7
879    test_unique: function(){
880        var fn = function(){
881        }, obj = {}, arr = [], date = new Date();
882        Y.ArrayAssert.itemsAreEqual([true, false], Ext.unique([true, true, false, true, false, false]), 'Test with all booleans');
883        Y.ArrayAssert.itemsAreEqual([1, 2, 3], Ext.unique([1, 2, 3, 3, 2, 1]), 'Test with all numbers');
884        Y.ArrayAssert.itemsAreEqual([fn], Ext.unique([fn, fn, fn, fn]), 'Test with functions');
885        Y.ArrayAssert.itemsAreEqual([arr], Ext.unique([arr, arr, arr, arr]), 'Test with arrays');
886        Y.ArrayAssert.itemsAreEqual([obj], Ext.unique([obj, obj, obj, obj]), 'Test with objects');
887        Y.ArrayAssert.itemsAreEqual([date], Ext.unique([date, date, date, date]), 'Test with dates');
888        Y.ArrayAssert.itemsAreEqual([obj, fn, arr, date], Ext.unique([obj, obj, fn, obj, arr, obj, fn, arr, date, fn, arr, obj]), 'Test with objects, functions, arrays, and dates');
889    },
890   
891    // 2
892    test_urlAppend: function(){
893        var url = "http://example.com/";
894        Y.Assert.areEqual('http://example.com/?test=1', Ext.urlAppend(url, 'test=1'), 'Test for question mark');
895        Y.Assert.areEqual('http://example.com/?test=1&foo=2', Ext.urlAppend(url + '?test=1', 'foo=2'), 'Test for ampersand');
896    },
897   
898    // 3
899    test_urlDecode: function(){
900        Y.ObjectAssert.hasKeys({
901            foo: 1,
902            bar: 2
903        }, Ext.urlDecode('foo=1&bar=2'), 'Decode 2 keys');
904        Y.ObjectAssert.hasKeys({
905            foo: 1,
906            bar: ['2', '3', '4']
907        }, Ext.urlDecode('foo=1&bar=2&bar=3&bar=4', false), 'Decode 2 keys, one of them an array (overwrite off)');
908        Y.ObjectAssert.hasKeys({
909            foo: 1,
910            bar: 4
911        }, Ext.urlDecode('foo=1&bar=2&bar=3&bar=4', true), 'Decode 2 keys, one of them an array (overwrite on)');
912    },
913   
914    // 3
915    test_urlEncode: function(){
916        Y.Assert.areEqual('foo=1&bar=2', Ext.urlEncode({
917            foo: 1,
918            bar: 2
919        }), 'Decode 2 keys');
920        Y.Assert.areEqual('foo=1&bar=2&bar=3&bar=4', Ext.urlEncode({
921            foo: 1,
922            bar: ['2', '3', '4']
923        }), 'Decode 2 keys, one of them an array');
924        Y.Assert.areEqual('test=1&foo=1&bar=2&bar=3&bar=4', Ext.urlEncode({
925            foo: 1,
926            bar: ['2', '3', '4']
927        }, 'test=1'), 'Decode 2 keys, one of them an array, with pre: test=1');
928    },
929   
930    // 7
931    test_value: function(){
932        Y.Assert.areEqual('test1', Ext.value('test1', 'test2'), 'Testing "test1" string');
933        Y.Assert.areEqual('test2', Ext.value('', 'test2'), 'Testing blank string');
934        Y.Assert.areEqual('test2', Ext.value(undefined, 'test2'), 'Testing undefined value');
935        Y.Assert.areEqual('test2', Ext.value(null, 'test2'), 'Testing null value');
936        Y.Assert.areEqual('', Ext.value('', 'test2', true), 'Testing blank string with allowBlank: true');
937        // it does not consider undef and null as a blank string, so these are OK
938        Y.Assert.areEqual('test2', Ext.value(undefined, 'test2', true), 'Testing undefined value with allowBlank: true');
939        Y.Assert.areEqual('test2', Ext.value(null, 'test2', true), 'Testing null value with allowBlank: true');
940    },
941   
942    // 4
943    test_zip: function(){
944        var arr = Ext.zip([1, 2, 3], [4, 5, 6]);
945        Y.ArrayAssert.itemsAreEqual([1, 4], arr[0], 'Zip two arrays');
946        Y.ArrayAssert.itemsAreEqual([2, 5], arr[1], 'Zip two arrays');
947        Y.ArrayAssert.itemsAreEqual([3, 6], arr[2], 'Zip two arrays');
948        Y.ArrayAssert.itemsAreEqual([['$+12.43'], ['$-10.15'], ['$+22.96']], Ext.zip(['+', '-', '+'], [12, 10, 22], [43, 15, 96], function(a, b, c){
949            return '$' + a + '' + b + '.' + c;
950        }), 'Zip using a function');
951    }
952   
953});
Note: See TracBrowser for help on using the repository browser.