base.html revision db748fdbe02870b4c78302a13fc95ab765d474c0
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt #console .yui3-console-entry {
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt min-height:0;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt #console .yui3-console-entry-fail .yui3-console-entry-cat {
ea94d370123a5892f6c47a97f21d1b28d44bb168Tinderbox User background-color:red;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt #console .yui3-console-entry-pass .yui3-console-entry-cat {
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt background-color:green;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt #console .yui3-console-entry-perf .yui3-console-entry-cat {
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt background-color:blue;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt position:static;
ec899c963c91c16c393e067996400ae244921110Tinderbox User<div id="testbed" class="yui3-skin-foo"></div>
ec899c963c91c16c393e067996400ae244921110Tinderbox User useBrowserConsole:false,
ec899c963c91c16c393e067996400ae244921110Tinderbox User filter: (window.location.search.match(/[?&]filter=([^&]+)/) || [])[1] || 'min'
ec899c963c91c16c393e067996400ae244921110Tinderbox User}).use('test', 'base', 'console', function (Y) {
ec899c963c91c16c393e067996400ae244921110Tinderbox User // NOTE: Attribute's unit tests cover a large section of Base's functionality when it comes to dealing with attributes.
ec899c963c91c16c393e067996400ae244921110Tinderbox User var suite = new Y.Test.Suite("Base Tests");
ec899c963c91c16c393e067996400ae244921110Tinderbox User name : "BaseBuild",
ec899c963c91c16c393e067996400ae244921110Tinderbox User "test:create-basic": function () {
ec899c963c91c16c393e067996400ae244921110Tinderbox User var expectedMethodCalls = [
ec899c963c91c16c393e067996400ae244921110Tinderbox User "ext1::constructor",
ec899c963c91c16c393e067996400ae244921110Tinderbox User "myClass::initializer",
ec899c963c91c16c393e067996400ae244921110Tinderbox User "ext1::constructor",
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt "myClass::initializer",
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt "myClass::methodOne",
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt "myClass::methodOne",
ec899c963c91c16c393e067996400ae244921110Tinderbox User "ext1::extOne",
ec899c963c91c16c393e067996400ae244921110Tinderbox User "ext1::extOne"],
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt actualMethodCalls = [];
ec899c963c91c16c393e067996400ae244921110Tinderbox User function Ext1() {
ec899c963c91c16c393e067996400ae244921110Tinderbox User actualMethodCalls.push("ext1::constructor");
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt var MyClass = Y.Base.create("myClass", Y.Base, [Ext1], {
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt initializer: function() {
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt actualMethodCalls.push("myClass::initializer");
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt methodOne: function() {
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt actualMethodCalls.push("myClass::methodOne");
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt STATIC_ONE: "static_one"
7ae7246a6339bb3a79ffc9f2f9c486de9a2bf65eAutomatic Updater // using 2 instances, just to make sure nothing static/prototype related gets broken by the 1st instance
2cbb4ab75757fbb656997a82c14ca07db37d481aAutomatic Updater var o1 = new MyClass({foo:true});
7ae7246a6339bb3a79ffc9f2f9c486de9a2bf65eAutomatic Updater var o2 = new MyClass({foo:true});
7ae7246a6339bb3a79ffc9f2f9c486de9a2bf65eAutomatic Updater Y.Assert.isFunction(o1.extOne, "Extension method extOne not found on o1");
7ae7246a6339bb3a79ffc9f2f9c486de9a2bf65eAutomatic Updater Y.Assert.isFunction(o2.extOne, "Extension method extOne not found on o2");
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt Y.Assert.isFunction(o1.methodOne, "Prototype method methodOne not found on o1");
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt Y.Assert.isFunction(o2.methodOne, "Prototype method methodOne not found on o2");
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt Y.Assert.areEqual(o1.constructor.STATIC_ONE, "static_one", "STATIC_ONE not found on o1's constructor");
ec899c963c91c16c393e067996400ae244921110Tinderbox User Y.Assert.areEqual(o2.constructor.STATIC_ONE, "static_one", "STATIC_ONE not found on o2's constructor");
ec899c963c91c16c393e067996400ae244921110Tinderbox User Y.Assert.areEqual(o1.constructor.NAME, "myClass", "NAME not found on o1's constructor");
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt Y.Assert.areEqual(o2.constructor.NAME, "myClass", "NAME not found on o2's constructor");
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt Y.ArrayAssert.itemsAreEqual(expectedMethodCalls, actualMethodCalls, "Unexpected method calls");
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt "test:mix-basic": function() {
7ae7246a6339bb3a79ffc9f2f9c486de9a2bf65eAutomatic Updater var expectedMethodCalls = [
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt "myClass::constructor",
ec899c963c91c16c393e067996400ae244921110Tinderbox User "ext1::constructor",
ec899c963c91c16c393e067996400ae244921110Tinderbox User "myClass::initializer",
ec899c963c91c16c393e067996400ae244921110Tinderbox User "myClass::constructor",
ec899c963c91c16c393e067996400ae244921110Tinderbox User "ext1::constructor",
ec899c963c91c16c393e067996400ae244921110Tinderbox User "myClass::initializer",
ec899c963c91c16c393e067996400ae244921110Tinderbox User "myClass::methodOne",
2cbb4ab75757fbb656997a82c14ca07db37d481aAutomatic Updater "myClass::methodOne",
2cbb4ab75757fbb656997a82c14ca07db37d481aAutomatic Updater "ext1::extOne",
2cbb4ab75757fbb656997a82c14ca07db37d481aAutomatic Updater "ext1::extOne"],
7ae7246a6339bb3a79ffc9f2f9c486de9a2bf65eAutomatic Updater actualMethodCalls = [];
7ae7246a6339bb3a79ffc9f2f9c486de9a2bf65eAutomatic Updater function Ext1() {
ec899c963c91c16c393e067996400ae244921110Tinderbox User actualMethodCalls.push("ext1::constructor");
ec899c963c91c16c393e067996400ae244921110Tinderbox User function MyClass(config) {
2cbb4ab75757fbb656997a82c14ca07db37d481aAutomatic Updater actualMethodCalls.push("myClass::constructor");
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt MyClass.superclass.constructor.apply(this, arguments);
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt initializer: function() {
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt actualMethodCalls.push("myClass::initializer");
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt methodOne: function() {
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt actualMethodCalls.push("myClass::methodOne");
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt STATIC_ONE: "static_one",
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt NAME: "myClass"
Y.Base.mix(MyClass, [Ext1]);
// using 2 instances, just to make sure nothing static/prototype related gets broken by the 1st instance
Y.Assert.areEqual(o1.constructor.STATIC_ONE, "static_one", "STATIC_ONE not found on o1's constructor");
Y.Assert.areEqual(o2.constructor.STATIC_ONE, "static_one", "STATIC_ONE not found on o2's constructor");
o1.methodOne();
o2.methodOne();
o1.extOne();
o2.extOne();
Y.ArrayAssert.itemsAreEqual(expectedMethodCalls, actualMethodCalls, "Unexpected method calls");
actualMethodCalls.push("ext1::constructor");
Y.Assert.isNotUndefined(cfg);
Ext1.prototype.initializer = function(cfg) {
actualMethodCalls.push("ext1::initializer");
Y.Assert.isNotUndefined(cfg);
actualMethodCalls.push("myClass::initializer");
Y.Assert.isNotUndefined(cfg);
// using 2 instances, just to make sure nothing static/prototype related gets broken by the 1st instance
Y.ArrayAssert.itemsAreEqual(expectedMethodCalls, actualMethodCalls, "Unexpected method calls");
Ext1.prototype.destructor = function(cfg) {
actualMethodCalls.push("ext1::destructor");
actualMethodCalls.push("myClass::destructor");
// using 2 instances, just to make sure nothing static/prototype related gets broken by the 1st instance
o1.destroy();
o2.destroy();
Y.ArrayAssert.itemsAreEqual(expectedMethodCalls, actualMethodCalls, "Unexpected method calls");
"ext1::attr2::setter", // once for lazy o1 - This was news to me: we should optimize it as part off Attr performance
Ext1.ATTRS = {
actualMethodCalls.push("ext1::attr2::setter");
// using 2 instances, just to make sure nothing static/prototype related gets broken by the 1st instance
o1.set("attr2", "foo");
o2.set("attr2", "foo");
Y.ArrayAssert.itemsAreEqual(expectedMethodCalls, actualMethodCalls, "Unexpected method calls");
Ext1.HTML_PARSER = {
MyWidget.superclass.constructor.apply(this, arguments);
var MyClass = Y.Base.create("myClass", MyWidget, [Ext1]);
// using 2 instances, just to make sure nothing static/prototype related gets broken by the 1st instance
Y.ObjectAssert.areEqual({a:"aa", b:"bb"}, o1.constructor.HTML_PARSER, "o1 HTML_PARSER not aggregated correctly");
Y.ObjectAssert.areEqual({a:"aa", b:"bb"}, o2.constructor.HTML_PARSER, "o2 HTML_PARSER not aggregated correctly");
Ext1.prototype.methodOne = function() {
actualMethodCalls.push("ext1::methodOne");
Ext1.ATTRS = {
actualMethodCalls.push("ext1::attr2::setter");
MyClass.superclass.constructor.apply(this, arguments);
MyClass.NAME = "myClass";
MyClass.ATTRS = {
actualMethodCalls.push("myClass::attr2::setter");
actualMethodCalls.push("myClass::methodOne");
Y.Base.mix(MyClass, [Ext1]);
// using 2 instances, just to make sure nothing static/prototype related gets broken by the 1st instance
o1.set("attr2", "foo");
o1.methodOne();
o2.methodOne();
Y.ArrayAssert.itemsAreEqual(expectedMethodCalls, actualMethodCalls, "Unexpected method calls");
Ext1.prototype.methodOne = function() {
actualMethodCalls.push("ext1::methodOne");
Ext1.ATTRS = {
actualMethodCalls.push("ext1::attr2::setter");
actualMethodCalls.push("myClass::methodOne");
actualMethodCalls.push("myClass::attr2::setter");
// Using 2 instances, just to make sure nothing static/prototype related gets broken by the 1st instance
o1.set("attr2", "foo");
o1.methodOne();
o2.methodOne();
Y.ArrayAssert.itemsAreEqual(expectedMethodCalls, actualMethodCalls, "Unexpected method calls");
actualMethodCalls.push("ext1::constructor");
Ext1.prototype.initializer = function() {
actualMethodCalls.push("ext1::initializer");
Ext1.prototype.methodTwo = function() {
actualMethodCalls.push("ext1::methodTwo");
Ext1.prototype.methodThree = function() {
actualMethodCalls.push("ext1::methodThree");
Ext1.ATTRS = {
actualMethodCalls.push("ext1::attr3::setter");
actualMethodCalls.push("ext2::constructor");
Ext2.prototype.initializer = function() {
actualMethodCalls.push("ext2::initializer");
Ext2.prototype.methodThree = function() {
actualMethodCalls.push("ext2::methodThree");
Ext2.prototype.methodFour = function() {
actualMethodCalls.push("ext2::methodFour");
Ext2.ATTRS = {
actualMethodCalls.push("ext2::attr3::setter");
actualMethodCalls.push("myClass::initializer");
actualMethodCalls.push("myClass::methodOne");
actualMethodCalls.push("myClass::methodTwo");
actualMethodCalls.push("myClass::methodFive");
o1.methodOne();
o2.methodOne();
o1.methodTwo();
o2.methodTwo();
Y.ArrayAssert.itemsAreEqual(expectedMethodCalls, actualMethodCalls, "Unexpected method calls");
Ext1.prototype.extOne = function() {};
Ext2.prototype.extTwo = function() {};
Y.Assert.isTrue(o1 instanceof MyClassOne, "o1 should be an instanceof MyClassOne");
Y.Assert.isTrue(o2 instanceof MyClassTwo, "o2 should be an instanceof MyClassTwo");
Y.Assert.isFalse(o1 instanceof MyClassTwo, "o1 should NOT be an instanceof MyClassTwo");
Y.Assert.isFalse(o2 instanceof MyClassOne, "o2 should NOT be an instanceof MyClassOne");
Y.Assert.isTrue(MyClassOne.superclass.constructor === Y.Base, "MyClassOne should have superclass set to Base");
Y.Assert.isTrue(MyClassTwo.superclass.constructor === Y.Base, "MyClassTwo should have superclass set to Base");
// Make sure Y.Base was untouched.
var b = new Y.Base();
actualMethodCalls.push("myExt::initializer");
actualMethodCalls.push("myClassOne::initializer");
actualMethodCalls.push("myClassOne::afterInit");
Y.ArrayAssert.itemsAreEqual(expectedMethodCalls, actualMethodCalls, "Unexpected method calls");
actualMethodCalls.push("ext1::constructor");
Ext1.prototype.extOne = function() {
actualMethodCalls.push("ext1::extOne");
Ext1.prototype.initializer = function() {
actualMethodCalls.push("ext1::initializer");
actualMethodCalls.push("ext2::constructor");
Ext2.prototype.extTwo = function() {
actualMethodCalls.push("ext2::extTwo");
Ext2.prototype.initializer = function() {
actualMethodCalls.push("ext2::initializer");
actualMethodCalls.push("myClassOne::initializer");
actualMethodCalls.push("myClassOne::methodOne");
var MyClassTwo = Y.Base.create("myClassTwo", MyClassOne, [Ext2], {
actualMethodCalls.push("myClassTwo::initializer");
actualMethodCalls.push("myClassTwo::methodTwo");
o.methodOne();
o.methodTwo();
o.extOne();
o.extTwo();
Y.ArrayAssert.itemsAreEqual(expectedMethodCalls, actualMethodCalls, "Unexpected method calls");
Ext1.prototype.extOne = function() {};
Ext1.prototype.initializer = function() {};
Ext1.prototype.methodOne = function() {
Ext1.STATIC_ONE = "static_one";
Ext1.STATIC_TWO = "static_two";
Ext1.STATIC_THREE = "static_three";
Y.Assert.isTrue(myclass instanceof MyClass);
Y.Assert.isFunction(myclass.init); // but prototype not switched completely by mistake as part of statics:true
Y.Assert.isFalse("STATIC_THREE" in MyClass);
Ext1.prototype.extOne = function() {};
Ext1.prototype.methodOne = function() {
Ext2.prototype.extTwo = function() {};
Ext2.prototype.methodTwo = function() {
Y.Assert.isTrue(myclass1 instanceof MyClass1);
Y.Assert.isFunction(myclass1.init); // but prototype not switched completely by mistake as part of statics:true
Y.Assert.isFalse(MyClass1.AGGREGATE_ONE === Ext1.AGGREGATE_ONE, "Ext1.AGGREGATE_ONE shouldn't have been copied over");
Y.Assert.isFalse(MyClass1.ATTRS === Ext1.ATTRS, "Ext1.ATTRS shouldn't have been copied over with statics:true");
Y.Assert.isTrue(myclass2 instanceof MyClass2);
Y.Assert.isFalse(MyClass2.AGGREGATE_ONE === Ext1.AGGREGATE_ONE, "Ext1.AGGREGATE_ONE shouldn't have been copied over");
Y.Assert.isFalse(MyClass2.AGGREGATE_ONE === Ext2.AGGREGATE_ONE, "Ext2.AGGREGATE_ONE shouldn't have been copied over");
Ext1.prototype.extOne = function() {};
Ext1.prototype.methodOne = function() {
Ext1.CUST = {
r[p].foo = r[p].foo.concat(s[p].foo);
r[p].bar = r[p].bar.concat(s[p].bar);
Ext2.prototype.extTwo = function() {};
Ext2.prototype.methodTwo = function() {
Ext2.CUST = {
Y.Assert.isTrue(myclass1 instanceof MyClass1);
// ObjectAssert.areEqual doesn't work: values don't == compare
}, MyClass1.CUST, "Class1 - object assert");
Y.Assert.isTrue(myclass2 instanceof MyClass2);
// ObjectAssert.areEqual doesn't work: values don't == compare
}, MyClass2.CUST);
Y.Test.Runner.setName("Base Tests");
Y.Test.Runner.add(suite);
Y.one("#btnRun").set("disabled", false).on("click", function() {
console = new Y.Console({