basePlugins.html revision b4e59b5d4777b2fc949d0b8da063b6ea1f2d43a1
<html>
<head>
#console .yui-console-entry-fail .yui-console-entry-cat {
background-color:red;
}
#console .yui-console-entry-pass .yui-console-entry-cat {
background-color:green;
}
#console .yui-console-entry-perf .yui-console-entry-cat {
background-color:blue;
}
#console {
position:static;
}
html, body {
height:100%;
}
</style>
</head>
<body class="yui-skin-sam">
<div id="console"></div>
<script type="text/javascript">
YUI({base:"/build/", filter:"raw"}).use("base", "console", "plugin", "test", function(Y) {
function PluginOne() {
PluginOne.superclass.constructor.apply(this, arguments);
}
PluginOne.NS = "one";
PluginOne.NAME = "pluginOne";
PluginOne.ATTRS = {
a: {
value:1
}
};
Y.extend(PluginOne, Y.Plugin.Base, {
initializer: function() {
},
method : function() {
}
});
function PluginTwo() {
PluginTwo.superclass.constructor.apply(this, arguments);
}
PluginTwo.NS = "two";
PluginTwo.NAME = "pluginTwo";
PluginTwo.ATTRS = {
b: {
value:2
}
};
Y.extend(PluginTwo, Y.Plugin.Base, {
initializer: function() {
},
method : function() {
}
});
function PluginThree() {
PluginThree.superclass.constructor.apply(this, arguments);
}
PluginThree.NS = "three";
PluginThree.NAME = "pluginThree";
c: {
value:3
}
};
Y.extend(PluginThree, Y.Plugin.Base, {
initializer: function() {
},
method : function() {
}
});
function Host(config) {
Host.superclass.constructor.apply(this, arguments);
}
Host.NAME = "host";
Host.ATTRS = {
mainA : {
value: "mainA"
},
mainB : {
value: "mainB"
}
};
methodA : function() {
},
methodB : function() {
},
initializer : function() {
}
});
function ExtendedHost() {
ExtendedHost.superclass.constructor.apply(this, arguments);
}
Y.extend(ExtendedHost, Host, {
methodC : function() {},
initializer : function() {}
});
var basicTemplate = {
testInstanceBasedPluginsSetDuringConstruction : function() {
var h1 = new Host({
plugins:[PluginOne, {fn:PluginTwo, cfg:{two:4}}, {fn:PluginThree, cfg:{three:6}}]
});
Y.ObjectAssert.ownsKey("one", h1);
Y.ObjectAssert.ownsKey("two", h1);
Y.ObjectAssert.ownsKey("three", h1);
var h2 = new Host({
plugins:[PluginOne, PluginTwo]
});
Y.ObjectAssert.ownsKey("one", h2);
Y.ObjectAssert.ownsKey("two", h2);
},
testInstanceBasedPluginsSetAfterConstruction : function() {
var h1 = new Host();
h1.plug(PluginOne);
h1.plug(PluginTwo, {two:4});
h1.plug({fn:PluginThree, cfg:{three:6}});
Y.ObjectAssert.ownsKey("one", h1);
Y.ObjectAssert.ownsKey("two", h1);
Y.ObjectAssert.ownsKey("three", h1);
var h2 = new Host();
h2.plug([PluginOne, {fn:PluginTwo, cfg:{two:8}}]);
Y.ObjectAssert.ownsKey("one", h2);
Y.ObjectAssert.ownsKey("two", h2);
},
testClassBasedPlugins : function() {
Y.Base.plug(Host, PluginOne);
Y.Base.plug(Host, [{fn:PluginTwo, cfg:{}}, PluginThree]);
var h1 = new Host();
Y.ObjectAssert.ownsKey("one", h1);
Y.ObjectAssert.ownsKey("two", h1);
Y.ObjectAssert.ownsKey("three", h1);
Y.Base.unplug(Host, PluginThree);
// ---
Y.Base.plug(ExtendedHost, PluginThree);
Y.Base.unplug(ExtendedHost, PluginOne);
var h2 = new Host();
Y.ObjectAssert.ownsKey("one", h2);
Y.ObjectAssert.ownsKey("two", h2);
var h3 = new ExtendedHost();
Y.ObjectAssert.ownsKey("two", h3);
Y.ObjectAssert.ownsKey("three", h3);
}
};
new Y.Console({
width:"100%",
height:"95%",
boundingBox:"#console",
verbose : false,
printTimeout: 0,
newestOnTop : false,
entryTemplate: '<pre class="{entry_class} {cat_class} {src_class}">'+
'<span class="{entry_cat_class}">{label}</span>'+
'<span class="{entry_content_class}">{message}</span>'+
'</pre>'
}).render();
Y.Test.Runner.add(new Y.Test.Case(basicTemplate));
});
</script>
</body>
</html>