/* Copyright (c) 2010, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.com/yui/license.html version: 3.3.0 build: 3167 */ YUI.add("test",function(b){b.namespace("Test");b.Test.Case=function(c){this._should={};for(var d in c){this[d]=c[d];}if(!b.Lang.isString(this.name)){this.name="testCase"+b.guid();}};b.Test.Case.prototype={resume:function(c){b.Test.Runner.resume(c);},wait:function(e,d){var c=arguments;if(b.Lang.isFunction(c[0])){throw new b.Test.Wait(c[0],c[1]);}else{throw new b.Test.Wait(function(){b.Assert.fail("Timeout: wait() called but resume() never called.");},(b.Lang.isNumber(c[0])?c[0]:10000));}},setUp:function(){},tearDown:function(){}};b.Test.Wait=function(d,c){this.segment=(b.Lang.isFunction(d)?d:null);this.delay=(b.Lang.isNumber(c)?c:0);};b.namespace("Test");b.Test.Suite=function(c){this.name="";this.items=[];if(b.Lang.isString(c)){this.name=c;}else{if(b.Lang.isObject(c)){b.mix(this,c,true);}}if(this.name===""){this.name="testSuite"+b.guid();}};b.Test.Suite.prototype={add:function(c){if(c instanceof b.Test.Suite||c instanceof b.Test.Case){this.items.push(c);}return this;},setUp:function(){},tearDown:function(){}};b.Test.Runner=(function(){function d(e){this.testObject=e;this.firstChild=null;this.lastChild=null;this.parent=null;this.next=null;this.results={passed:0,failed:0,total:0,ignored:0,duration:0};if(e instanceof b.Test.Suite){this.results.type="testsuite";this.results.name=e.name;}else{if(e instanceof b.Test.Case){this.results.type="testcase";this.results.name=e.name;}}}d.prototype={appendChild:function(e){var f=new d(e);if(this.firstChild===null){this.firstChild=this.lastChild=f;}else{this.lastChild.next=f;this.lastChild=f;}f.parent=this;return f;}};function c(){c.superclass.constructor.apply(this,arguments);this.masterSuite=new b.Test.Suite("yuitests"+(new Date()).getTime());this._cur=null;this._root=null;this._log=true;this._waiting=false;this._running=false;this._lastResults=null;var f=[this.TEST_CASE_BEGIN_EVENT,this.TEST_CASE_COMPLETE_EVENT,this.TEST_SUITE_BEGIN_EVENT,this.TEST_SUITE_COMPLETE_EVENT,this.TEST_PASS_EVENT,this.TEST_FAIL_EVENT,this.TEST_IGNORE_EVENT,this.COMPLETE_EVENT,this.BEGIN_EVENT];for(var e=0;e-1&&i.indexOf(" ")>-1))&&b.Lang.isFunction(g[i])){h.appendChild(i);}}},_addTestSuiteToTestTree:function(e,h){var g=e.appendChild(h);for(var f=0;f0){return b.Lang.substitute(d,{message:c});}else{return c;}},_getCount:function(){return this._asserts;},_increment:function(){this._asserts++;},_reset:function(){this._asserts=0;},fail:function(c){throw new b.Assert.Error(b.Assert._formatMessage(c,"Test force-failed."));},areEqual:function(d,e,c){b.Assert._increment();if(d!=e){throw new b.Assert.ComparisonFailure(b.Assert._formatMessage(c,"Values should be equal."),d,e);}},areNotEqual:function(c,e,d){b.Assert._increment();if(c==e){throw new b.Assert.UnexpectedValue(b.Assert._formatMessage(d,"Values should not be equal."),c);}},areNotSame:function(c,e,d){b.Assert._increment();if(c===e){throw new b.Assert.UnexpectedValue(b.Assert._formatMessage(d,"Values should not be the same."),c);}},areSame:function(d,e,c){b.Assert._increment();if(d!==e){throw new b.Assert.ComparisonFailure(b.Assert._formatMessage(c,"Values should be the same."),d,e);}},isFalse:function(d,c){b.Assert._increment();if(false!==d){throw new b.Assert.ComparisonFailure(b.Assert._formatMessage(c,"Value should be false."),false,d);}},isTrue:function(d,c){b.Assert._increment();if(true!==d){throw new b.Assert.ComparisonFailure(b.Assert._formatMessage(c,"Value should be true."),true,d);}},isNaN:function(d,c){b.Assert._increment();if(!isNaN(d)){throw new b.Assert.ComparisonFailure(b.Assert._formatMessage(c,"Value should be NaN."),NaN,d);}},isNotNaN:function(d,c){b.Assert._increment();if(isNaN(d)){throw new b.Assert.UnexpectedValue(b.Assert._formatMessage(c,"Values should not be NaN."),NaN);}},isNotNull:function(d,c){b.Assert._increment();if(b.Lang.isNull(d)){throw new b.Assert.UnexpectedValue(b.Assert._formatMessage(c,"Values should not be null."),null);}},isNotUndefined:function(d,c){b.Assert._increment();if(b.Lang.isUndefined(d)){throw new b.Assert.UnexpectedValue(b.Assert._formatMessage(c,"Value should not be undefined."),undefined);}},isNull:function(d,c){b.Assert._increment();if(!b.Lang.isNull(d)){throw new b.Assert.ComparisonFailure(b.Assert._formatMessage(c,"Value should be null."),null,d);}},isUndefined:function(d,c){b.Assert._increment();if(!b.Lang.isUndefined(d)){throw new b.Assert.ComparisonFailure(b.Assert._formatMessage(c,"Value should be undefined."),undefined,d); }},isArray:function(d,c){b.Assert._increment();if(!b.Lang.isArray(d)){throw new b.Assert.UnexpectedValue(b.Assert._formatMessage(c,"Value should be an array."),d);}},isBoolean:function(d,c){b.Assert._increment();if(!b.Lang.isBoolean(d)){throw new b.Assert.UnexpectedValue(b.Assert._formatMessage(c,"Value should be a Boolean."),d);}},isFunction:function(d,c){b.Assert._increment();if(!b.Lang.isFunction(d)){throw new b.Assert.UnexpectedValue(b.Assert._formatMessage(c,"Value should be a function."),d);}},isInstanceOf:function(d,e,c){b.Assert._increment();if(!(e instanceof d)){throw new b.Assert.ComparisonFailure(b.Assert._formatMessage(c,"Value isn't an instance of expected type."),d,e);}},isNumber:function(d,c){b.Assert._increment();if(!b.Lang.isNumber(d)){throw new b.Assert.UnexpectedValue(b.Assert._formatMessage(c,"Value should be a number."),d);}},isObject:function(d,c){b.Assert._increment();if(!b.Lang.isObject(d)){throw new b.Assert.UnexpectedValue(b.Assert._formatMessage(c,"Value should be an object."),d);}},isString:function(d,c){b.Assert._increment();if(!b.Lang.isString(d)){throw new b.Assert.UnexpectedValue(b.Assert._formatMessage(c,"Value should be a string."),d);}},isTypeOf:function(c,e,d){b.Assert._increment();if(typeof e!=c){throw new b.Assert.ComparisonFailure(b.Assert._formatMessage(d,"Value should be of type "+c+"."),expected,typeof e);}}};b.assert=function(d,c){b.Assert._increment();if(!d){throw new b.Assert.Error(b.Assert._formatMessage(c,"Assertion failed."));}};b.fail=b.Assert.fail;b.Assert.Error=function(c){arguments.callee.superclass.constructor.call(this,c);this.message=c;this.name="Assert Error";};b.extend(b.Assert.Error,Error,{getMessage:function(){return this.message;},toString:function(){return this.name+": "+this.getMessage();},valueOf:function(){return this.toString();}});b.Assert.ComparisonFailure=function(d,c,e){arguments.callee.superclass.constructor.call(this,d);this.expected=c;this.actual=e;this.name="ComparisonFailure";};b.extend(b.Assert.ComparisonFailure,b.Assert.Error,{getMessage:function(){return this.message+"\nExpected: "+this.expected+" ("+(typeof this.expected)+")"+"\nActual: "+this.actual+" ("+(typeof this.actual)+")";}});b.Assert.UnexpectedValue=function(d,c){arguments.callee.superclass.constructor.call(this,d);this.unexpected=c;this.name="UnexpectedValue";};b.extend(b.Assert.UnexpectedValue,b.Assert.Error,{getMessage:function(){return this.message+"\nUnexpected: "+this.unexpected+" ("+(typeof this.unexpected)+") ";}});b.Assert.ShouldFail=function(c){arguments.callee.superclass.constructor.call(this,c||"This test should fail but didn't.");this.name="ShouldFail";};b.extend(b.Assert.ShouldFail,b.Assert.Error);b.Assert.ShouldError=function(c){arguments.callee.superclass.constructor.call(this,c||"This test should have thrown an error but didn't.");this.name="ShouldError";};b.extend(b.Assert.ShouldError,b.Assert.Error);b.Assert.UnexpectedError=function(c){arguments.callee.superclass.constructor.call(this,"Unexpected error: "+c.message);this.cause=c;this.name="UnexpectedError";this.stack=c.stack;};b.extend(b.Assert.UnexpectedError,b.Assert.Error);b.ArrayAssert={contains:function(e,d,c){b.Assert._increment();if(b.Array.indexOf(d,e)==-1){b.Assert.fail(b.Assert._formatMessage(c,"Value "+e+" ("+(typeof e)+") not found in array ["+d+"]."));}},containsItems:function(e,f,d){b.Assert._increment();for(var c=0;c-1){b.Assert.fail(b.Assert._formatMessage(c,"Value found in array ["+d+"]."));}},doesNotContainItems:function(e,f,d){b.Assert._increment();for(var c=0;c-1){b.Assert.fail(b.Assert._formatMessage(d,"Value found in array ["+f+"]."));}}},doesNotContainMatch:function(e,d,c){b.Assert._increment();if(typeof e!="function"){throw new TypeError("ArrayAssert.doesNotContainMatch(): First argument must be a function.");}if(b.Array.some(d,e)){b.Assert.fail(b.Assert._formatMessage(c,"Value found in array ["+d+"]."));}},indexOf:function(g,f,c,e){b.Assert._increment();for(var d=0;d0){b.Assert.fail(b.Assert._formatMessage(c,"Array should be empty."));}},isNotEmpty:function(d,c){b.Assert._increment();if(d.length===0){b.Assert.fail(b.Assert._formatMessage(c,"Array should not be empty."));}},itemsAreSame:function(e,f,d){b.Assert._increment();if(e.length!=f.length){b.Assert.fail(b.Assert._formatMessage(d,"Array should have a length of "+e.length+" but has a length of "+f.length)); }for(var c=0;c=0;d--){if(f[d]===g){if(c!=d){b.Assert.fail(b.Assert._formatMessage(e,"Value exists at index "+d+" but should be at index "+c+"."));}return;}}b.Assert.fail(b.Assert._formatMessage(e,"Value doesn't exist in array."));}};b.ObjectAssert={areEqual:function(d,e,c){b.Assert._increment();b.Object.each(d,function(g,f){if(d[f]!=e[f]){throw new b.Assert.ComparisonFailure(b.Assert._formatMessage(c,"Values should be equal for property "+f),d[f],e[f]);}});},hasKey:function(c,d,e){b.Assert._increment();if(!(c in d)){b.fail(b.Assert._formatMessage(e,"Property '"+c+"' not found on object."));}},hasKeys:function(e,c,f){b.Assert._increment();for(var d=0;d0){b.fail(b.Assert._formatMessage(e,"Object owns "+d.length+" properties but should own none."));}}};b.DateAssert={datesAreEqual:function(d,f,c){b.Assert._increment();if(d instanceof Date&&f instanceof Date){var e="";if(d.getFullYear()!=f.getFullYear()){e="Years should be equal.";}if(d.getMonth()!=f.getMonth()){e="Months should be equal.";}if(d.getDate()!=f.getDate()){e="Days of month should be equal.";}if(e.length){throw new b.Assert.ComparisonFailure(b.Assert._formatMessage(c,e),d,f);}}else{throw new TypeError("Y.Assert.datesAreEqual(): Expected and actual values must be Date objects.");}},timesAreEqual:function(d,f,c){b.Assert._increment();if(d instanceof Date&&f instanceof Date){var e="";if(d.getHours()!=f.getHours()){e="Hours should be equal.";}if(d.getMinutes()!=f.getMinutes()){e="Minutes should be equal.";}if(d.getSeconds()!=f.getSeconds()){e="Seconds should be equal.";}if(e.length){throw new b.Assert.ComparisonFailure(b.Assert._formatMessage(c,e),d,f);}}else{throw new TypeError("DateY.AsserttimesAreEqual(): Expected and actual values must be Date objects.");}}};b.namespace("Test.Format");function a(c){return c.replace(/[<>"'&]/g,function(d){switch(d){case"<":return"<";case">":return">";case'"':return""";case"'":return"'";case"&":return"&";}});}b.Test.Format.JSON=function(c){return b.JSON.stringify(c);};b.Test.Format.XML=function(d){function c(g){var e=b.Lang,f="<"+g.type+' name="'+a(g.name)+'"';if(e.isNumber(g.duration)){f+=' duration="'+g.duration+'"';}if(g.type=="test"){f+=' result="'+g.result+'" message="'+a(g.message)+'">';}else{f+=' passed="'+g.passed+'" failed="'+g.failed+'" ignored="'+g.ignored+'" total="'+g.total+'">';b.Object.each(g,function(h){if(e.isObject(h)&&!e.isArray(h)){f+=c(h);}});}f+="";return f;}return''+c(d);};b.Test.Format.JUnitXML=function(c){function d(g){var e=b.Lang,f="";switch(g.type){case"test":if(g.result!="ignore"){f='';if(g.result=="fail"){f+='";}f+="";}break;case"testcase":f='';b.Object.each(g,function(h){if(e.isObject(h)&&!e.isArray(h)){f+=d(h);}});f+="";break;case"testsuite":b.Object.each(g,function(h){if(e.isObject(h)&&!e.isArray(h)){f+=d(h);}});break;case"report":f="";b.Object.each(g,function(h){if(e.isObject(h)&&!e.isArray(h)){f+=d(h);}});f+="";}return f;}return''+d(c);};b.Test.Format.TAP=function(d){var e=1;function c(g){var f=b.Lang,h="";switch(g.type){case"test":if(g.result!="ignore"){h="ok "+(e++)+" - "+g.name;if(g.result=="fail"){h="not "+h+" - "+g.message;}h+="\n";}else{h="#Ignored test "+g.name+"\n";}break;case"testcase":h="#Begin testcase "+g.name+"("+g.failed+" failed of "+g.total+")\n";b.Object.each(g,function(i){if(f.isObject(i)&&!f.isArray(i)){h+=c(i);}});h+="#End testcase "+g.name+"\n";break;case"testsuite":h="#Begin testsuite "+g.name+"("+g.failed+" failed of "+g.total+")\n";b.Object.each(g,function(i){if(f.isObject(i)&&!f.isArray(i)){h+=c(i);}});h+="#End testsuite "+g.name+"\n";break;case"report":b.Object.each(g,function(i){if(f.isObject(i)&&!f.isArray(i)){h+=c(i);}});}return h;}return"1.."+d.total+"\n"+c(d);};b.namespace("Coverage.Format");b.Coverage.Format.JSON=function(c){return b.JSON.stringify(c);};b.Coverage.Format.XdebugJSON=function(d){var c={};b.Object.each(d,function(f,e){c[e]=d[e].lines;});return b.JSON.stringify(c);};b.namespace("Test");b.Test.Reporter=function(c,d){this.url=c;this.format=d||b.Test.Format.XML;this._fields=new Object();this._form=null;this._iframe=null;};b.Test.Reporter.prototype={constructor:b.Test.Reporter,addField:function(c,d){this._fields[c]=d;},clearFields:function(){this._fields=new Object();},destroy:function(){if(this._form){this._form.parentNode.removeChild(this._form);this._form=null;}if(this._iframe){this._iframe.parentNode.removeChild(this._iframe);this._iframe=null;}this._fields=null;},report:function(d){if(!this._form){this._form=document.createElement("form");this._form.method="post";this._form.style.visibility="hidden";this._form.style.position="absolute";this._form.style.top=0;document.body.appendChild(this._form);var c=document.createElement("div");c.innerHTML='';this._iframe=c.firstChild;this._iframe.src="javascript:false";this._iframe.style.visibility="hidden";this._iframe.style.position="absolute"; this._iframe.style.top=0;document.body.appendChild(this._iframe);this._form.target="yuiTestTarget";}this._form.action=this.url;while(this._form.hasChildNodes()){this._form.removeChild(this._form.lastChild);}this._fields.results=this.format(d);this._fields.useragent=navigator.userAgent;this._fields.timestamp=(new Date()).toLocaleString();b.Object.each(this._fields,function(f,g){if(typeof f!="function"){var e=document.createElement("input");e.type="hidden";e.name=g;e.value=f;this._form.appendChild(e);}},this);delete this._fields.results;delete this._fields.useragent;delete this._fields.timestamp;if(arguments[1]!==false){this._form.submit();}}};b.Mock=function(e){e=e||{};var c=null;try{c=b.Object(e);}catch(d){c={};b.log("Couldn't create mock with prototype.","warn","Mock");}b.Object.each(e,function(f){if(b.Lang.isFunction(e[f])){c[f]=function(){b.Assert.fail("Method "+f+"() was called but was not expected to be.");};}});return c;};b.Mock.expect=function(d,h){if(!d.__expectations){d.__expectations={};}if(h.method){var g=h.method,f=h.args||h.arguments||[],c=h.returns,j=b.Lang.isNumber(h.callCount)?h.callCount:1,e=h.error,i=h.run||function(){};d.__expectations[g]=h;h.callCount=j;h.actualCallCount=0;b.Array.each(f,function(k,l,m){if(!(m[l] instanceof b.Mock.Value)){m[l]=b.Mock.Value(b.Assert.areSame,[k],"Argument "+l+" of "+g+"() is incorrect.");}});if(j>0){d[g]=function(){try{h.actualCallCount++;b.Assert.areEqual(f.length,arguments.length,"Method "+g+"() passed incorrect number of arguments.");for(var m=0,k=f.length;m