You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

953 lines
40 KiB

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