oop.html revision e275a18d7f6fd57baf841eb4c8f82d790c1ef6bd
<html>
<head>
<title>YUI OOP Tests</title>
</head>
<body class="yui-skin-sam">
<h1>OOP Tests</h1>
<p><input type="button" value="Run Tests" id="btnRun" disabled="true" /></p>
<script type="text/javascript">
(function() {
YUI({
base: "/build/",
filter: "debug",
useConsole: true,
// logInclude: ['event', 'test']
//logExclude: ['Dom', 'Selector', 'Node', 'attribute']
logExclude: {Dom:true, Selector:true, Node:true, attribute:true, event:true, base:true}
}).use("dump", "test", "console", "event-custom", function(Y) {
var button = Y.get('#btnRun'),
Assert = Y.Assert,
ObjectAssert = Y.ObjectAssert;
// Set up the page
button.set("disabled", false);
Y.on("click", function() {
}, button);
var myConsole = new Y.Console().render();
var testOOP= new Y.Test.Case({
name: "OOP tests",
testExtend: function() {
var firedbase = false;
var firedextended = false;
var Base = function() {
Y.log('Base constructor executed');
arguments.callee.superclass.constructor.apply(this, arguments);
// bind by string in order to allow the subclass
};
Y.extend(Base, Y.EventTarget, {
base: function() {
Y.log('base function');
firedbase = true;
}
});
var Extended = function() {
Y.log('Extended constructor executed');
arguments.callee.superclass.constructor.apply(this, arguments);
};
Y.extend(Extended, Base, {
base: function() {
Y.log('extended function');
firedextended = true;
}
});
var b = new Extended();
b.fire('testStringFn', 1, 2);
Y.Assert.isFalse(firedbase);
Y.Assert.isTrue(firedextended);
},
test_merge: function() {
var o1 = { one: "one" },
o2 = { two: "two" },
o3 = { two: "twofromthree", three: "three" },
o4 = { one: "one", two: "twofromthree", three: "three" },
o123 = Y.merge(o1, o2, o3);
ObjectAssert.areEqual(o123, o4);
},
test_mix: function() {
var a = {
'bool' : false,
'num' : 0,
'nul' : null,
'undef': undefined,
'T' : 'blabber'
};
var b = {
'bool' : 'oops',
'num' : 'oops',
'nul' : 'oops',
'undef': 'oops',
'T' : 'oops'
};
Y.mix(a, b, false);
Assert.isFalse((a.bool === 'oops'));
Assert.isFalse((a.num === 'oops'));
Assert.isFalse((a.nul === 'oops'));
Assert.isFalse((a.undef === 'oops'));
Y.mix(a, b, true);
Assert.isTrue((a.bool === 'oops'));
Assert.isTrue((a.num === 'oops'));
Assert.isTrue((a.nul === 'oops'));
Assert.isTrue((a.undef === 'oops'));
},
test_clone: function() {
var a = {
'bool' : false,
'num' : 0,
'nul' : null,
'undef': undefined,
'T' : 'blabber'
};
var b = Y.clone(a);
var c = function() {
var _c = 3;
return {
a: 1,
b: 2,
c: function() {
return _c;
}
}
}();
var d = Y.clone(c);
Assert.isTrue((d.a === 1));
Assert.isTrue((d.c() === 3));
}
});
Y.Test.Runner.add(testOOP);
});
})();
</script>
</body>
</html>