|
0
|
1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
|
|
2 |
<html> |
|
|
3 |
<head> |
|
|
4 |
<title>YUI OOP Tests</title> |
|
|
5 |
</head> |
|
|
6 |
|
|
|
7 |
<body class="yui-skin-sam"> |
|
|
8 |
<h1 id="header1">OOP Tests</h1> |
|
|
9 |
<p><input type="button" value="Run Tests" id="btnRun" disabled="true" /></p> |
|
|
10 |
|
|
|
11 |
<script type="text/javascript" src="../../../build/yui/yui.js"></script> |
|
|
12 |
<script type="text/javascript"> |
|
|
13 |
|
|
|
14 |
(function() { |
|
|
15 |
YUI({ |
|
|
16 |
base: "../../../build/", |
|
|
17 |
filter: "debug", |
|
|
18 |
useConsole: true, |
|
|
19 |
// logInclude: ['event', 'test'] |
|
|
20 |
//logExclude: ['Dom', 'Selector', 'Node', 'attribute'] |
|
|
21 |
logExclude: {Dom:true, Selector:true, Node:true, attribute:true, event:true, base:true} |
|
|
22 |
}).use("dump", "test", "console", function(Y) { |
|
|
23 |
|
|
|
24 |
var button = Y.get('#btnRun'), |
|
|
25 |
Assert = Y.Assert, |
|
|
26 |
ObjectAssert = Y.ObjectAssert; |
|
|
27 |
|
|
|
28 |
// Set up the page |
|
|
29 |
button.set("disabled", false); |
|
|
30 |
Y.on("click", function() { |
|
|
31 |
Y.Test.Runner.run(); |
|
|
32 |
}, button); |
|
|
33 |
|
|
|
34 |
// var myConsole = new Y.Console().render(); |
|
|
35 |
|
|
|
36 |
var testOOP= new Y.Test.Case({ |
|
|
37 |
name: "OOP tests", |
|
|
38 |
|
|
|
39 |
|
|
|
40 |
testExtend: function() { |
|
|
41 |
|
|
|
42 |
var firedbase = false; |
|
|
43 |
var firedextended = false; |
|
|
44 |
|
|
|
45 |
var Base = function() { |
|
|
46 |
Y.log('Base constructor executed'); |
|
|
47 |
arguments.callee.superclass.constructor.apply(this, arguments); |
|
|
48 |
|
|
|
49 |
// bind by string in order to allow the subclass |
|
|
50 |
this.on('testStringFn', Y.bind('base', this)); |
|
|
51 |
}; |
|
|
52 |
|
|
|
53 |
Y.extend(Base, Y.EventTarget, { |
|
|
54 |
base: function() { |
|
|
55 |
Y.log('base function'); |
|
|
56 |
firedbase = true; |
|
|
57 |
} |
|
|
58 |
}); |
|
|
59 |
|
|
|
60 |
var Extended = function() { |
|
|
61 |
Y.log('Extended constructor executed'); |
|
|
62 |
arguments.callee.superclass.constructor.apply(this, arguments); |
|
|
63 |
}; |
|
|
64 |
|
|
|
65 |
Y.extend(Extended, Base, { |
|
|
66 |
base: function() { |
|
|
67 |
Y.log('extended function'); |
|
|
68 |
firedextended = true; |
|
|
69 |
} |
|
|
70 |
}); |
|
|
71 |
|
|
|
72 |
var b = new Extended(); |
|
|
73 |
b.fire('testStringFn', 1, 2); |
|
|
74 |
|
|
|
75 |
Y.Assert.isFalse(firedbase); |
|
|
76 |
Y.Assert.isTrue(firedextended); |
|
|
77 |
}, |
|
|
78 |
|
|
|
79 |
test_merge: function() { |
|
|
80 |
var o1 = { one: "one" }, |
|
|
81 |
o2 = { two: "two" }, |
|
|
82 |
o3 = { two: "twofromthree", three: "three" }, |
|
|
83 |
o4 = { one: "one", two: "twofromthree", three: "three" }, |
|
|
84 |
o123 = Y.merge(o1, o2, o3); |
|
|
85 |
|
|
|
86 |
ObjectAssert.areEqual(o123, o4); |
|
|
87 |
Assert.areEqual(o123.two, o4.two); |
|
|
88 |
}, |
|
|
89 |
|
|
|
90 |
test_mix: function() { |
|
|
91 |
|
|
|
92 |
var a = { |
|
|
93 |
'bool' : false, |
|
|
94 |
'num' : 0, |
|
|
95 |
'nul' : null, |
|
|
96 |
'undef': undefined, |
|
|
97 |
'T' : 'blabber' |
|
|
98 |
}; |
|
|
99 |
|
|
|
100 |
var b = { |
|
|
101 |
'bool' : 'oops', |
|
|
102 |
'num' : 'oops', |
|
|
103 |
'nul' : 'oops', |
|
|
104 |
'undef': 'oops', |
|
|
105 |
'T' : 'oops' |
|
|
106 |
}; |
|
|
107 |
|
|
|
108 |
Y.mix(a, b, false); |
|
|
109 |
|
|
|
110 |
Assert.isFalse((a.bool === 'oops')); |
|
|
111 |
Assert.isFalse((a.num === 'oops')); |
|
|
112 |
Assert.isFalse((a.nul === 'oops')); |
|
|
113 |
Assert.isFalse((a.undef === 'oops')); |
|
|
114 |
Assert.isFalse((a.T === 'oops')); |
|
|
115 |
|
|
|
116 |
Y.mix(a, b, true); |
|
|
117 |
Assert.isTrue((a.bool === 'oops')); |
|
|
118 |
Assert.isTrue((a.num === 'oops')); |
|
|
119 |
Assert.isTrue((a.nul === 'oops')); |
|
|
120 |
Assert.isTrue((a.undef === 'oops')); |
|
|
121 |
Assert.isTrue((a.T === 'oops')); |
|
|
122 |
|
|
|
123 |
}, |
|
|
124 |
|
|
|
125 |
test_clone: function() { |
|
|
126 |
|
|
|
127 |
var a = { |
|
|
128 |
'bool' : false, |
|
|
129 |
'num' : 0, |
|
|
130 |
'nul' : null, |
|
|
131 |
'undef': undefined, |
|
|
132 |
'T' : 'blabber' |
|
|
133 |
}; |
|
|
134 |
|
|
|
135 |
Assert.isTrue((a.T === 'blabber')); |
|
|
136 |
|
|
|
137 |
var b = Y.clone(a); |
|
|
138 |
|
|
|
139 |
var c = function() { |
|
|
140 |
|
|
|
141 |
var _c = 3; |
|
|
142 |
|
|
|
143 |
return { |
|
|
144 |
a: 1, |
|
|
145 |
b: 2, |
|
|
146 |
c: function() { |
|
|
147 |
return _c; |
|
|
148 |
} |
|
|
149 |
} |
|
|
150 |
}(); |
|
|
151 |
|
|
|
152 |
var d = Y.clone(c); |
|
|
153 |
|
|
|
154 |
Assert.isTrue((d.a === 1)); |
|
|
155 |
Assert.isTrue((d.c() === 3)); |
|
|
156 |
|
|
|
157 |
}, |
|
|
158 |
|
|
|
159 |
test_clone_node: function() { |
|
|
160 |
|
|
|
161 |
var a = { |
|
|
162 |
node: Y.one('#header1'), |
|
|
163 |
y: Y, |
|
|
164 |
el: document.getElementById('header1') |
|
|
165 |
}; |
|
|
166 |
|
|
|
167 |
var b = Y.clone(a); |
|
|
168 |
b.node.foo = 'bar'; |
|
|
169 |
|
|
|
170 |
Assert.isFalse(b.node.foo === a.node.foo); |
|
|
171 |
|
|
|
172 |
} |
|
|
173 |
|
|
|
174 |
}); |
|
|
175 |
|
|
|
176 |
|
|
|
177 |
Y.Test.Runner.add(testOOP); |
|
|
178 |
Y.Test.Runner.run(); |
|
|
179 |
}); |
|
|
180 |
})(); |
|
|
181 |
</script> |
|
|
182 |
</body> |
|
|
183 |
</html> |