3 <title>Parser Unit Test</title>
4 <style type="text/css">
5 @import "../resources/dojo.css";
7 <script type="text/javascript"
9 djConfig="isDebug: true, parseOnLoad: true"></script>
10 <script type="text/javascript">
11 dojo.require("dojo.parser");
12 dojo.require("doh.runner");
14 dojo.declare("tests.parser.Class1", null, {
15 constructor: function(args, node){ dojo.mixin(this, args); },
18 this.preambleTestProp++;
21 callCount: 0, // for connect testing
22 callInc: function(){ this.callCount++; },
23 callCount2: 0, // for assignment testing
24 strProp1: "original1",
25 strProp2: "original2",
31 dateProp1: dojo.date.stamp.fromISOString('2007-01-01'),
32 dateProp2: dojo.date.stamp.fromISOString('2007-01-01'),
33 dateProp3: dojo.date.stamp.fromISOString('2007-01-01'),
34 funcProp: function(){},
35 funcProp2: function(){},
36 funcProp3: function(){},
37 onclick: function(){ this.prototypeOnclick=true; }
38 // FIXME: have to test dates!!
39 // FIXME: need to test the args property!!
42 dojo.declare("tests.parser.Class2", null, {
43 constructor: function(){
44 this.fromMarkup = false;
47 markupFactory: function(args, node, classCtor){
48 var i = new tests.parser.Class2();
55 dojo.declare("tests.parser.Class3", tests.parser.Class2, {
57 markupFactory: function(args, node, classCtor){
58 var i = new classCtor();
59 i.classCtor = classCtor;
64 dojo.declare("tests.parser.inputClass", null, {
65 constructor: function(args, node){ dojo.mixin(this, args); },
66 // these attributes are special in HTML, they don't have a value specified
77 dojo.addOnLoad(function(){
81 // console.debug(obj);
82 t.t(typeof obj == "object");
85 // Attribute parsing tests
86 function testStrProp(t){
87 // normal string parameter
88 t.t(dojo.isString(obj.strProp1));
89 t.is("text", obj.strProp1);
91 // make sure that you override a string value like "foo" to a blank value
92 t.t(dojo.isString(obj.strProp2));
93 t.is("", obj.strProp2);
95 function testIntProp(t){
96 t.is("number", (typeof obj.intProp));
99 function testArrProp(t){
100 t.is(3, obj.arrProp.length);
101 t.is(3, obj.arrProp[1].length);
102 t.is(["foo", "bar", "baz"], obj.arrProp);
104 function testBoolProp(t){
105 // make sure that both true and false get read correctly,
106 // and that unspecified attributes' values don't change
108 // boolProp1 specified at true
109 t.is("boolean", (typeof obj.boolProp1));
112 // boolProp2 specified as false
113 t.is("boolean", (typeof obj.boolProp2));
116 // boolProp3 not specified (prototype says false)
117 t.is("boolean", (typeof obj.boolProp3));
120 // boolProp4 not specified (prototype says true)
121 t.is("boolean", (typeof obj.boolProp4));
124 function testDateProp(t){
125 // dateProp1 specified as 2006-1-1
126 t.is("2006-01-01", dojo.date.stamp.toISOString(obj.dateProp1, {selector: 'date'}));
128 // dateProp2="", should map to NaN (a blank value on DateTextBox)
129 t.t(isNaN(obj.dateProp2));
131 // dateProp3="now", should map to current date
132 t.is(dojo.date.stamp.toISOString(new Date(), {selector: 'date'}),
133 dojo.date.stamp.toISOString(obj.dateProp3, {selector: 'date'}));
135 function testDisabledFlag(t){
136 t.is("boolean", (typeof disabledObj.disabled));
137 t.t(disabledObj.disabled);
138 t.f(disabledObj.checked);
140 function testCheckedFlag(t){
141 t.is("boolean", (typeof checkedObj.checked));
142 t.f(checkedObj.disabled);
143 t.t(checkedObj.checked);
145 function testFunctionProp(t){
146 // make sure that unspecified functions (even with common names)
147 // don't get overridden (bug #3074)
149 t.t(obj.prototypeOnclick);
155 // funcProp3="this.func3Called=true;"
157 t.t(obj.func3Called);
160 // test <script> tags inside innerHTML of source node
161 "t.is(4, obj.preambleTestProp);",
162 "t.is(deepTestProp, obj.deepProp);",
163 function testConnect(t){
165 t.is(2, obj.callCount);
167 function testFunctionAssignment(t){
169 t.is(1, obj.callCount2);
171 function testSubNodeParse(t){
172 t.f(dojo.exists("obj2"));
173 var toParse = dojo.byId("toParse");
174 toParse.setAttribute("dojoType", toParse.getAttribute("type"));
175 dojo.parser.parse(toParse.parentNode);
176 t.t(dojo.exists("obj2"));
177 t.is("tests.parser.Class1", obj2.declaredClass);
179 function testMarkupFactory(t){
180 t.t(dojo.exists("obj3"));
181 t.t(obj3.fromMarkup);
183 function testMarkupFactoryClass(t){
184 t.t(dojo.exists("obj4"));
185 t.is(obj4.classCtor, tests.parser.Class3);
186 t.t(obj4 instanceof tests.parser.Class3);
187 t.t(obj4 instanceof tests.parser.Class2);
189 function testDisabledFlag(t){
190 t.t(disabledObj.disabled);
191 t.f(disabledObj.checked);
193 function testCheckedFlag(t){
194 t.f(checkedObj.disabled);
195 t.t(checkedObj.checked);
204 <h1>Parser Unit Test</h1>
206 function foo(){ this.fooCalled=true; }
208 <div dojoType="tests.parser.Class1" jsId="obj"
209 strProp1="text" strProp2=""
211 arrProp="foo, bar, baz"
212 boolProp1="true" boolProp2="false"
213 dateProp1="2006-01-01" dateProp2="" dateProp3="now"
214 funcProp2="foo" funcProp3="this.func3Called=true;"
216 <script type="dojo/method" event="preamble">
217 this.preambleTestProp = 3;
219 <script type="dojo/method">
220 // this should be run immediately
221 this.deepProp = deepTestProp;
223 <script type="dojo/connect" event="callInc">
226 <script type="dojo/method" event="callInc2">
231 <div type="tests.parser.Class1" jsId="obj2" id="toParse">
234 <div dojoType="tests.parser.Class2" jsId="obj3">
236 <div dojoType="tests.parser.Class3" jsId="obj4">
238 <input dojoType="tests.parser.inputClass" jsId="checkedObj" checked type="checkbox">
239 <button dojoType="tests.parser.inputClass" jsId="disabledObj" disabled>hi</button>