dojo.provide("tests.webmap.widget.LayerControl");

dojo.require("doh.runner");
dojo.require("webmap.widget.LayerControl");
dojo.require("tests.Util");
dojo.require("webmap.MapManager");

var div;
function doLayerControlSetup(){
	tests.Util.resetDom();
	div = document.createElement("div");
	document.body.appendChild(div);
}
var MockElem = function(){
	return {
		id: null,
		tagName: null,
		namespace: null,
		getAttribute: function(a){return this[a];},
		setAttribute: function(a,v){this[a] = v;},
		getAttributeNS: function(ns,a){return this[a];},
		setAttributeNS: function(ns,a,v){this.namespace = ns; this[a] = v;},
		firstChild:{},
		innerHTML: "",
		styleSheet: {cssText:""}
	};
};

doh.register("tests.webmap.widget.LayerControl", 
	[
		{
			name: "postCreate",
			setUp: function(){
				doLayerControlSetup();
			},
			runTest: function(){
				var lc = new webmap.widget.LayerControl({}, div);
				tests.assertEqual(3, lc._connections.length);
				// TODO: Sarah - verify which subscriptions
				tests.assertEqual(6, lc._subscriptions.length);
				var url;
				if (dojo.isIE){
					url = lc.imagePath + "identify.cur";
					tests.assertEqual("url('" + url + "')", dojo.style(lc.domNode, "cursor"));
				}else{
					url = tests.Util.getAbsolutePath(lc.imagePath + "/identify.cur");
					tests.assertEqual("url(" + url + "), crosshair", dojo.style(lc.domNode, "cursor"));
				}
				lc.destroy();
			}
		},
		{
			name: "destroy",
			setUp: function(){
				doLayerControlSetup();
			},
			runTest: function(){
				var lc = new webmap.widget.LayerControl({}, div);
				lc._originalSymbols = "not null";
				lc._layerOrder = "not null";
				lc._mapEnvelope = "not null";
				lc.destroy();
				tests.assertEqual(null, lc._originalSymbols);
				tests.assertEqual(null, lc._layerOrder);
				tests.assertEqual(null, lc._mapEnvelope);
				tests.assertEqual(null, lc._connections);
				tests.assertEqual(null, lc._subscriptions);
			}
		},
		{
			name: "_resize_null_viewportOffset_no_resize_arg",
			widget: null,
			subscription: null,
			pubs: 0,
			styles: 0,
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.subscription = dojo.subscribe("webmap.widget.LayerControl.resized", 
					function(){_this.pubs++;});
				this.widget = new webmap.widget.LayerControl({},div);
			},
			runTest: function(){
				var left = dojo.style(this.widget.domNode, "left");
				var top = dojo.style(this.widget.domNode, "top");
				var width = dojo.style(this.widget.domNode, "width");
				var height = dojo.style(this.widget.domNode, "height");
				dojo.publish("webmap.widget.MapControl.resized", [{}]);
				tests.assertEqual(0, this.pubs);
				tests.assertEqual(left, dojo.style(this.widget.domNode, "left"));
				tests.assertEqual(top, dojo.style(this.widget.domNode, "top"));
				tests.assertEqual(width, dojo.style(this.widget.domNode, "width"));
				tests.assertEqual(height, dojo.style(this.widget.domNode, "height"));
			},
			tearDown: function(){
				dojo.unsubscribe(this.subscription);
				this.widget.destroy();
			}
		},
		{
			name: "_resize_null_viewportOffset_has_resize_arg",
			widget: null,
			subscription: null,
			pubs: 0,
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.subscription = dojo.subscribe("webmap.widget.LayerControl.resized", 
					function(a){_this.pubs++;});
				this.widget = new webmap.widget.LayerControl({},div);
			},
			runTest: function(){
				dojo.publish("webmap.widget.MapControl.resized", [{l:0, r:0, w:800, h:600}]);
				tests.assertEqual(0, this.pubs);
				tests.assertEqual(0,dojo.style(this.widget.domNode, "left"));
				tests.assertEqual(0,dojo.style(this.widget.domNode, "top"));
				tests.assertEqual(800,dojo.style(this.widget.domNode, "width"));
				tests.assertEqual(600,dojo.style(this.widget.domNode, "height"));
			},
			tearDown: function(){
				dojo.unsubscribe(this.subscription);
				this.widget.destroy();
			}
		},
		{
			name: "_resize_has_viewportOffset_has_resize_arg",
			widget: null,
			subscription: null,
			pubs: 0,
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.subscription = dojo.subscribe("webmap.widget.LayerControl.resized", 
					function(a){_this.pubs++;});
				this.widget = new webmap.widget.LayerControl({},div);
				this.widget._viewportOffset = {x:-300,y:-200};
			},
			runTest: function(){
				//TODO: is the width and height right... does layerControl have overfow visible?
				dojo.publish("webmap.widget.MapControl.resized", [{l:0, r:0, w:800, h:600}]);
				tests.assertEqual(1, this.pubs);
				tests.assertEqual(-300,dojo.style(this.widget.domNode, "left"));
				tests.assertEqual(-200,dojo.style(this.widget.domNode, "top"));
				tests.assertEqual(800,dojo.style(this.widget.domNode, "width"));
				tests.assertEqual(600,dojo.style(this.widget.domNode, "height"));
			},
			tearDown: function(){
				dojo.unsubscribe(this.subscription);
				this.widget.destroy();
			}
		},
		{
			name: "_doClick",
			setUp: function(){
				doLayerControlSetup();
			},
			runTest: function(){
				var lc = new webmap.widget.LayerControl({}, div);
				var args = null;
				var s = dojo.subscribe("webmap.widget.LayerControl.identified", function(a){args = a;});
				var parent = null;
				var id = null;
				var f = function(a){id = a; return "evtTarget";};
				lc._getClassName = function(a){parent = a; return "locations";};
				lc._doClick({target:{getAttribute:f,parentNode:"parent"}, clientX:1, clientY:2});
				tests.assertEqual("parent", parent);
				tests.assertEqual("locations", args[webmap.config.layerId]);
				tests.assertEqual("evtTarget", args[webmap.config.featureId]);
				tests.assertEqual("id", id);
				tests.assertEqual(new gov.nyc.doitt.gis.service.map.domain.ImagePoint({x:1,y:2}), args[webmap.config.point]);
				lc.destroy();
				dojo.unsubscribe(s);
				console.warn('This method is not complete. Need to identify other layers besides locations.');
			}
		},
		{
			name: "_doHover_isBasemap_true",
			widget: null,
			arg: null,
			svgArg: null,
			vmlArg: null,
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({
					_doHoverSvg:function(a){_this.svgArg = a;},
					_doHoverVml:function(a){_this.vmlArg = a;},
					_isBasemap: function(a){_this.arg = a;return true;}
				},div);
			},
			runTest: function(){
				this.widget._doHover({target:"target"});
				tests.assertEqual("target", this.arg);
				if (dojo.isIE) {
					tests.assertEqual(null, this.vmlArg);
					tests.assertEqual(null, this.svgArg);
				}else{
					tests.assertEqual(null, this.vmlArg);
					tests.assertEqual(null, this.svgArg);
				}
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "_doHover_isBasemap_false",
			widget: null,
			arg: null,
			svgArg: null,
			vmlArg: null,
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({
					_doHoverSvg:function(a){_this.svgArg = a;},
					_doHoverVml:function(a){_this.vmlArg = a;},
					_isBasemap: function(a){_this.arg = a;return false;}
				},div);
			},
			runTest: function(){
				this.widget._doHover({target:"target"});
				tests.assertEqual("target", this.arg);
				if (dojo.isIE) {
					tests.assertEqual("target", this.vmlArg);
					tests.assertEqual(null, this.svgArg);
				}else{
					tests.assertEqual(null, this.vmlArg);
					tests.assertEqual("target", this.svgArg);
				}
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "_doHoverVml_image",
			widget: null,
			element: new MockElem(),
			setUp: function(){
				doLayerControlSetup();
				this.widget = new webmap.widget.LayerControl({},div);
				this.element.tagName = "image";
				this.element.src = "element.gif";
			},
			runTest: function(){
				this.widget._doHoverVml(this.element);
				tests.assertEqual("elementHover.gif", this.element.src);
				//do again to ensure "Hover" is appended only once
				this.widget._doHoverVml(this.element);
				tests.assertEqual("elementHover.gif", this.element.src);
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "_doHoverVml_other",
			widget: null,
			element: new MockElem(),
			storeSymArg: null,
			highlightArgs: null,
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({
					_storeSymbol: function(a){_this.storeSymArg = a;return "sym";},
					_highlightVml: function(a0,a1){_this.highlightArgs = [a0,a1];}
				},div);
				this.element.tagName = "oval";
				this.element.id = "id";
				this.element.parentNode = {tagName:"vml"};
			},
			runTest: function(){
				this.widget._doHoverVml(this.element);
				tests.assertEqual(this.element, this.storeSymArg);
				tests.assertEqual([this.element, "sym"], this.highlightArgs);
				this.storeSymArg = null;
				this.highlightArgs = null;
				this.element.id = "";
				this.widget._doHoverVml(this.element);
				tests.assertEqual(null, this.storeSymArg);
				tests.assertEqual(null, this.highlightArgs);
				this.element.id = null;
				this.widget._doHoverVml(this.element);
				tests.assertEqual(null, this.storeSymArg);
				tests.assertEqual(null, this.highlightArgs);
				this.element.id = "id";
				this.element.parentNode = {tagName:"div"};
				this.widget._doHoverVml(this.element);
				tests.assertEqual(null, this.storeSymArg);
				tests.assertEqual(null, this.highlightArgs);
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "_doHoverSvg_image",
			widget: null,
			element: new MockElem(),
			setUp: function(){
				doLayerControlSetup();
				this.widget = new webmap.widget.LayerControl({},div);
				this.element.tagName = "svg:image";
				this.element.href = "element.gif";
			},
			runTest: function(){
				this.widget._doHoverSvg(this.element);
				tests.assertEqual("elementHover.gif", this.element.href);
				tests.assertEqual("http://www.w3.org/1999/xlink", this.element.namespace);
				//do again to ensure "Hover" is appended only once
				this.widget._doHoverSvg(this.element);
				tests.assertEqual("elementHover.gif", this.element.href);
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "_doHoverSvg_other",
			widget: null,
			element: new MockElem(),
			storeSymArg: null,
			highlightArgs: null,
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({
					_storeSymbol: function(a){_this.storeSymArg = a;return "sym";},
					_highlightSvg: function(a0,a1){_this.highlightArgs = [a0,a1];}
				},div);
				this.element.tagName = "svg:circle";
				this.element.id = "id";
				this.element.parentNode = {tagName:"svg"};
			},
			runTest: function(){
				this.widget._doHoverSvg(this.element);
				tests.assertEqual(this.element, this.storeSymArg);
				tests.assertEqual([this.element, "sym"], this.highlightArgs);
				this.storeSymArg = null;
				this.highlightArgs = null;
				this.element.id = "";
				this.widget._doHoverSvg(this.element);
				tests.assertEqual(null, this.storeSymArg);
				tests.assertEqual(null, this.highlightArgs);
				this.element.id = null;
				this.widget._doHoverSvg(this.element);
				tests.assertEqual(null, this.storeSymArg);
				tests.assertEqual(null, this.highlightArgs);
				this.element.id = "id";
				this.element.parentNode = {tagName:"div"};
				this.widget._doHoverSvg(this.element);
				tests.assertEqual(null, this.storeSymArg);
				tests.assertEqual(null, this.highlightArgs);
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "_doMouseOut_isBasemap_true",
			widget: null,
			arg: null,
			svgArg: null,
			vmlArg: null,
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({
					_doMouseOutSvg:function(a){_this.svgArg = a;},
					_doMouseOutVml:function(a){_this.vmlArg = a;},
					_isBasemap: function(a){_this.arg = a;return true;}
				},div);
			},
			runTest: function(){
				this.widget._doHover({target:"target"});
				tests.assertEqual("target", this.arg);
				if (dojo.isIE) {
					tests.assertEqual(null, this.vmlArg);
					tests.assertEqual(null, this.svgArg);
				}else{
					tests.assertEqual(null, this.vmlArg);
					tests.assertEqual(null, this.svgArg);
				}
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "_doMouseOut_isBasemap_false",
			widget: null,
			arg: null,
			svgArg: null,
			vmlArg: null,
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({
					_doMouseOutSvg:function(a){_this.svgArg = a;},
					_doMouseOutVml:function(a){_this.vmlArg = a;},
					_isBasemap: function(a){_this.arg = a;return false;}
				},div);
			},
			runTest: function(){
				this.widget._doMouseOut({target:"target"});
				tests.assertEqual("target", this.arg);
				if (dojo.isIE) {
					tests.assertEqual("target", this.vmlArg);
					tests.assertEqual(null, this.svgArg);
				}else{
					tests.assertEqual(null, this.vmlArg);
					tests.assertEqual("target", this.svgArg);
				}
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "_doMouseOutVml_image",
			widget: null,
			element: new MockElem(),
			setUp: function(){
				doLayerControlSetup();
				this.widget = new webmap.widget.LayerControl({},div);
				this.element.tagName = "image";
				this.element.src = "elementHover.gif";
			},
			runTest: function(){
				this.widget._doMouseOutVml(this.element);
				tests.assertEqual("element.gif", this.element.src);
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "_doMouseOutVml_other",
			widget: null,
			element: new MockElem(),
			restoreArgs: null,
			classArg: null,
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({
					_getClassName: function(a){_this.classArg = a;return "sym";},
					_restoreVml: function(a0,a1){_this.restoreArgs = [a0,a1];}
				},div);
				this.widget._originalSymbols = {sym:"sym"};
				this.element.tagName = "oval";
				this.element.id = "id";
				this.element.parentNode = {tagName:"vml"};
			},
			runTest: function(){
				this.widget._doMouseOutVml(this.element);
				tests.assertEqual({tagName:"vml"}, this.classArg);
				tests.assertEqual([this.element, "sym"], this.restoreArgs);
				this.classArg = null;
				this.restoreArgs = null;
				this.widget._originalSymbols = null;
				this.widget._doMouseOutVml(this.element);
				tests.assertEqual(null, this.classArg);
				tests.assertEqual(null, this.restoreArgs);
				this.widget._originalSymbols = {sym:"sym"};
				this.element.id = "";
				this.widget._doMouseOutVml(this.element);
				tests.assertEqual(null, this.classArg);
				tests.assertEqual(null, this.restoreArgs);
				this.element.id = null;
				this.widget._doMouseOutVml(this.element);
				tests.assertEqual(null, this.classArg);
				tests.assertEqual(null, this.restoreArgs);
				this.element.id = "id";
				this.element.parentNode = {tagName:"div"};
				this.widget._doMouseOutVml(this.element);
				tests.assertEqual(null, this.classArg);
				tests.assertEqual(null, this.restoreArgs);
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "_doMouseOutSvg_image",
			widget: null,
			element: new MockElem(),
			setUp: function(){
				doLayerControlSetup();
				this.widget = new webmap.widget.LayerControl({},div);
				this.element.tagName = "svg:image";
				this.element.href = "elementHover.gif";
			},
			runTest: function(){
				this.widget._doMouseOutSvg(this.element);
				tests.assertEqual("element.gif", this.element.href);
				tests.assertEqual("http://www.w3.org/1999/xlink", this.element.namespace);
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "_doMouseOutSvg_other",
			widget: null,
			element: new MockElem(),
			restoreArgs: null,
			classArg: null,
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({
					_getClassName: function(a){_this.classArg = a;return "sym";},
					_restoreSvg: function(a0,a1){_this.restoreArgs = [a0,a1];}
				},div);
				this.widget._originalSymbols = {sym:"sym"};
				this.element.tagName = "svg:circle";
				this.element.id = "id";
				this.element.parentNode = {tagName:"svg"};
			},
			runTest: function(){
				this.widget._doMouseOutSvg(this.element);
				tests.assertEqual({tagName:"svg"}, this.classArg);
				tests.assertEqual([this.element, "sym"], this.restoreArgs);
				this.classArg = null;
				this.restoreArgs = null;
				this.widget._originalSymbols = null;
				this.widget._doMouseOutSvg(this.element);
				tests.assertEqual(null, this.classArg);
				tests.assertEqual(null, this.restoreArgs);
				this.widget._originalSymbols = {sym:"sym"};
				this.element.id = "";
				this.widget._doMouseOutSvg(this.element);
				tests.assertEqual(null, this.classArg);
				tests.assertEqual(null, this.restoreArgs);
				this.element.id = null;
				this.widget._doMouseOutSvg(this.element);
				tests.assertEqual(null, this.classArg);
				tests.assertEqual(null, this.restoreArgs);
				this.element.id = "id";
				this.element.parentNode = {tagName:"div"};
				this.widget._doMouseOutSvg(this.element);
				tests.assertEqual(null, this.classArg);
				tests.assertEqual(null, this.restoreArgs);
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "_storeSymbol_vml_no_firstChild",
			setUp: function(){
				doLayerControlSetup();
			},
			runTest: function(){
				if (!dojo.isIE) return;
				var vmlElem = {
					strokeweight: "2", 
					strokecolor:"red", 
					fillcolor:"yellow", 
					parentNode:"parent"
				};
				var lc = new webmap.widget.LayerControl({}, div);
				lc._originalSymbols = {};
				var parent = null;
				lc._getClassName = function(a){parent = a; return "locations";};
				var sym1 = lc._storeSymbol(vmlElem);
				tests.assertEqual(2, sym1.strokeWidth);
				tests.assertEqual("red", sym1.stroke); 
				tests.assertEqual("yellow", sym1.fill);
				tests.assertEqual(undefined, sym1.fillOpacity);
				tests.assertEqual("parent", parent);
				tests.assertEqual({locations:sym1}, lc._originalSymbols);
				var sym2 = lc._storeSymbol(vmlElem);
				tests.assertEqual(2, sym2.strokeWidth);
				tests.assertEqual("red", sym2.stroke); 
				tests.assertEqual("yellow", sym2.fill);
				tests.assertEqual(undefined, sym1.fillOpacity);
				tests.assertEqual("parent", parent);
				tests.assertEqual({locations:sym2}, lc._originalSymbols);
				tests.assertEqual(sym2, sym1);
				lc.destroy();
			}
		},
		{
			name: "_storeSymbol_vml_has_firstChild",
			setUp: function(){
				doLayerControlSetup();
			},
			runTest: function(){
				if (!dojo.isIE) return;
				var vmlElem = {
					strokeweight: "2", 
					strokecolor:"red", 
					fillcolor:"yellow", 
					parentNode:"parent", 
					firstChild:{opacity:".8"}
				};
				var lc = new webmap.widget.LayerControl({}, div);
				lc._originalSymbols = {};
				var parent = null;
				lc._getClassName = function(a){parent = a; return "locations";};
				var sym1 = lc._storeSymbol(vmlElem);
				tests.assertEqual(2, sym1.strokeWidth);
				tests.assertEqual("red", sym1.stroke); 
				tests.assertEqual("yellow", sym1.fill);
				tests.assertEqual(".8", sym1.fillOpacity);
				tests.assertEqual("parent", parent);
				tests.assertEqual({locations:sym1}, lc._originalSymbols);
				var sym2 = lc._storeSymbol(vmlElem);
				tests.assertEqual(2, sym2.strokeWidth);
				tests.assertEqual("red", sym2.stroke); 
				tests.assertEqual("yellow", sym2.fill);
				tests.assertEqual(".8", sym2.fillOpacity);
				tests.assertEqual("parent", parent);
				tests.assertEqual({locations:sym2}, lc._originalSymbols);
				tests.assertEqual(sym2, sym1);
				lc.destroy();
			}
		},
		{
			name: "_storeSymbol_svg",
			setUp: function(){
				doLayerControlSetup();
			},
			runTest: function(){
				if (dojo.isIE) return;
				var gotAttribute = false;
				var svgElem = {
					getAttribute: function(a){
						gotAttribute = true;
						switch (a){
							case "stroke-width": return "2";
							case "stroke": return "red";
							case "stroke-opacity": return ".9";
							case "fill": return "yellow";
							case "fill-opacity": return ".8";
						}
					},
					parentNode: "parent"
				};
				var lc = new webmap.widget.LayerControl({}, div);
				lc._originalSymbols = {};
				var parent = null;
				lc._getClassName = function(a){parent = a; return "locations";};
				var sym1 = lc._storeSymbol(svgElem);
				tests.assertTrue(gotAttribute);
				tests.assertEqual(2, sym1.strokeWidth);
				tests.assertEqual("red", sym1.stroke); 
				tests.assertEqual("yellow", sym1.fill);
				tests.assertEqual(".9", sym1.strokeOpacity);
				tests.assertEqual(".8", sym1.fillOpacity);
				tests.assertEqual("parent", parent);
				tests.assertEqual({locations:sym1}, lc._originalSymbols);
				gotAttribute = false;
				var sym2 = lc._storeSymbol(svgElem);
				tests.assertFalse(gotAttribute);
				tests.assertEqual(2, sym2.strokeWidth);
				tests.assertEqual("red", sym2.stroke); 
				tests.assertEqual("yellow", sym2.fill);
				tests.assertEqual(".9", sym2.strokeOpacity);
				tests.assertEqual(".8", sym2.fillOpacity);
				tests.assertEqual("parent", parent);
				tests.assertEqual({locations:sym2}, lc._originalSymbols);
				tests.assertEqual(sym1, sym2);
				lc.destroy();
			}
		},
		{
			name: "_isPolygon",
			setUp: function(){
				doLayerControlSetup();
			},
			runTest: function(){
				var lc = new webmap.widget.LayerControl({}, div);
				lc._layerOrder = {not_polygon:2};
				var parent = null;
				lc._getClassName = function(a){parent = a;return a == "polygon" ? "polygon" : "not_polygon";};
				tests.assertTrue(lc._isPolygon({parentNode:"polygon"}));
				tests.assertEqual("polygon", parent);
				tests.assertFalse(lc._isPolygon({parentNode:"not_polygon"}));
				tests.assertEqual("not_polygon", parent);
				lc.destroy();
			}
		},
		{
			name: "_getAllParts",
			widget: null,
			node: {parentNode:{childNodes:"childNodes"}},
			arg: null,
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({
					_isPolygon: function(a){_this.arg = a; return true;}
				}, div);
			},
			runTest: function(){
				tests.assertEqual("childNodes", this.widget._getAllParts(this.node));
				tests.assertEqual(this.node, this.arg);
				this.arg = null;
				var _this = this;
				this.widget._isPolygon = function(a){_this.arg = a; return false;};
				tests.assertEqual([this.node], this.widget._getAllParts(this.node));
				tests.assertEqual(this.node, this.arg);
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "_highlightSvg",
			widget: null,
			node: "node",
			arg: null,
			parts: [new MockElem(),new MockElem(),new MockElem()],
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({
					_getAllParts: function(a){_this.arg = a; return _this.parts;}
				}, div);
			},
			runTest: function(){
				this.widget._highlightSvg(this.node, {strokeWidth:1});
				dojo.forEach(this.parts, function(p){
					tests.assertEqual(3, p.getAttribute("stroke-width"));
					tests.assertEqual("red", p.getAttribute("stroke"));
					tests.assertEqual("0.5", p.getAttribute("stroke-opacity"));
					tests.assertEqual("yellow", p.getAttribute("fill"));
					tests.assertEqual("0.5", p.getAttribute("fill-opacity"));
				});
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "_restoreSvg",
			widget: null,
			node: "node",
			arg: null,
			parts: [new MockElem(),new MockElem(),new MockElem()],
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({
					_getAllParts: function(a){_this.arg = a; return _this.parts;}
				}, div);
			},
			runTest: function(){
				this.widget._restoreSvg(this.node, {
					strokeWidth:1,
					stroke:"black",
					strokeOpacity:"0.9",
					fill:"green",
					fillOpacity:"0.7"
				});
				dojo.forEach(this.parts, function(p){
					tests.assertEqual(1, p.getAttribute("stroke-width"));
					tests.assertEqual("black", p.getAttribute("stroke"));
					tests.assertEqual("0.9", p.getAttribute("stroke-opacity"));
					tests.assertEqual("green", p.getAttribute("fill"));
					tests.assertEqual("0.7", p.getAttribute("fill-opacity"));
				});
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "_highlightVml",
			widget: null,
			node: "node",
			arg: null,
			parts: [new MockElem(),new MockElem(),new MockElem()],
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({
					_getAllParts: function(a){_this.arg = a; return _this.parts;}
				}, div);
			},
			runTest: function(){
				this.widget._highlightVml(this.node, {strokeWidth:1});
				dojo.forEach(this.parts, function(p){
					tests.assertEqual(3, p.strokeweight);
					tests.assertEqual("red", p.strokecolor);
					tests.assertEqual("yellow", p.fillcolor);
					tests.assertEqual("0.5", p.firstChild.opacity);
				});
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "_restoreSvg",
			widget: null,
			node: "node",
			arg: null,
			parts: [new MockElem(),new MockElem(),new MockElem()],
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({
					_getAllParts: function(a){_this.arg = a; return _this.parts;}
				}, div);
			},
			runTest: function(){
				this.widget._restoreVml(this.node, {
					strokeWidth:1,
					stroke:"black",
					strokeOpacity:"0.9",
					fill:"green",
					fillOpacity:"0.7"
				});
				dojo.forEach(this.parts, function(p){
					tests.assertEqual(1, p.strokeweight);
					tests.assertEqual("black", p.strokecolor);
					tests.assertEqual("green", p.fillcolor);
					tests.assertEqual("0.7", p.firstChild.opacity);
				});
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "_getClassName",
			widget: null,
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({}, div);
			},
			runTest: function(){
				var node;
				if (dojo.isIE){
					node = {className:"myClass"};
				} else{
					node = new MockElem();
					node.setAttribute("class", "myClass");
				}
				tests.assertEqual("myClass", this.widget._getClassName(node));
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "_drag",
			widget: null,
			isDormant: webmap.isDormant,
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({
					_viewportOffset:{x:-20,y:-40}
				}, div);
				webmap.isDormant = function(){return true;};
			},
			runTest: function(){
				var left = dojo.style(this.widget.domNode, "left");
				var top = dojo.style(this.widget.domNode, "top");
				this.widget._drag({tool:"pan", delta:{x:100,y:50}});
				tests.assertEqual(left, dojo.style(this.widget.domNode, "left"));
				tests.assertEqual(top, dojo.style(this.widget.domNode, "top"));
				webmap.isDormant = function(){return false;};
				this.widget._drag({delta:{x:100,y:50}});
				tests.assertEqual(left, dojo.style(this.widget.domNode, "left"));
				tests.assertEqual(top, dojo.style(this.widget.domNode, "top"));
				this.widget._drag({tool:"zoomIn", delta:{x:100,y:50}});
				tests.assertEqual(left, dojo.style(this.widget.domNode, "left"));
				tests.assertEqual(top, dojo.style(this.widget.domNode, "top"));
				this.widget._drag({tool:"pan", delta:{x:100,y:50}});
				tests.assertEqual(80, dojo.style(this.widget.domNode, "left"));
				tests.assertEqual(10, dojo.style(this.widget.domNode, "top"));
			},
			tearDown: function(){
				webmap.isDormant = this.isDormant;
				this.widget.destroy();
			}
		},
		{
			name: "_createClasses",
			widget: null,
			setUp: function(){
				doLayerControlSetup();
				this.widget = new webmap.widget.LayerControl({}, div);
			},
			runTest: function(){
				console.warn("Write me!"); try{notWritten++;}catch(ignore){}
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "_afterCalloutBox",
			widget: null,
			setUp: function(){
				doLayerControlSetup();
				this.widget = new webmap.widget.LayerControl({
					_viewportOffset: {x:-20,y:-40}
				}, div);
			},
			runTest: function(){
				var left = dojo.style(this.widget.domNode, "left");
				var top = dojo.style(this.widget.domNode, "top");
				dojo.publish("webmap.WindowManager.calloutShown", []);
				if (dojo.isIE){
					tests.assertEqual(-20, dojo.style(this.widget.domNode, "left"));
					tests.assertEqual(-40, dojo.style(this.widget.domNode, "top"));					
				}else{
					tests.assertEqual(left, dojo.style(this.widget.domNode, "left"));
					tests.assertEqual(top, dojo.style(this.widget.domNode, "top"));
				}
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "_update",
			widget: null,
			isDormant: webmap.isDormant,
			mapData: {viewportOffset:{x:-20,y:-40},layers:"layers"},
			args: [],
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({
					_layerOrderCounter: 4,
					_createClasses:function(a){_this.args.push(a);},
					_addMarkup:function(a){_this.args.push(a);}
				}, div);
				webmap.isDormant = function(){return true;};
			},
			runTest: function(){
				var left = dojo.style(this.widget.domNode, "left");
				var top = dojo.style(this.widget.domNode, "top");
				dojo.publish("webmap.MapManager.mapDataChanged", [this.mapData]);
				tests.assertEqual(null, this.widget._originalSymbols);
				tests.assertEqual(null, this.widget._layerOrder);
				tests.assertEqual(4, this.widget._layerOrderCounter);
				tests.assertEqual(null, this.widget._viewportOffset);
				tests.assertFalse(this.widget._classesCreated);
				tests.assertEqual([], this.args);
				tests.assertEqual(left, dojo.style(this.widget.domNode, "left"));
				tests.assertEqual(top, dojo.style(this.widget.domNode, "top"));
				webmap.isDormant = function(){return false;};
				dojo.publish("webmap.MapManager.mapDataChanged", [this.mapData]);
				tests.assertEqual({}, this.widget._originalSymbols);
				tests.assertEqual({locations:100, basemap:0}, this.widget._layerOrder);
				tests.assertEqual(1, this.widget._layerOrderCounter);
				tests.assertEqual(this.mapData.viewportOffset, this.widget._viewportOffset);
				tests.assertTrue(this.widget._classesCreated);
				tests.assertEqual([this.mapData.layers,this.mapData], this.args);
				tests.assertEqual(-20, dojo.style(this.widget.domNode, "left"));
				tests.assertEqual(-40, dojo.style(this.widget.domNode, "top"));					
			},
			tearDown: function(){
				webmap.isDormant = this.isDormant;
				this.widget.destroy();
			}
		},
		{
			name: "_isClearAll",
			widget: null,
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({
					_newTheme:false,
					_mapEnvelope:{minX:1,minY:2,maxX:3,maxY:4}
				}, div);
			},
			runTest: function(){
				tests.assertFalse(
					this.widget._isClearAll({mapEnvelope:{minX:1,minY:2,maxX:3,maxY:4}})
				);
				tests.assertTrue(
					this.widget._isClearAll({mapEnvelope:{minX:1,minY:2,maxX:3,maxY:6}})
				);
				this.widget._newTheme = true;
				tests.assertTrue(
					this.widget._isClearAll({mapEnvelope:{minX:1,minY:2,maxX:3,maxY:4}})
				);
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "_isPolygonTheme",
			widget: null,
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({}, div);
			},
			runTest: function(){
				tests.assertTrue(
					this.widget._isPolygonTheme({clientData:{themeLayerId:""}})
				);
				tests.assertFalse(
					this.widget._isPolygonTheme({clientData:{}})
				);
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "_addMarkup_no_markup",
			widget: null,
			mapData: {clientData:{themeLayerId:"id"},mapEnvelope:"mapEnvelope"},
			clearArg: null,
			sortArg: null,
			markupArg: null,
			appendArg: null,
			removes: 0,
			updates: 0,
			subscription: null,
			onArg: null,
			xmlArg: null,
			polyArg: null,
			loadString: webmap.util.XmlDocumentUtil.loadString,
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({
					_isClearAll: function(a){_this.clearArg = a;},
					_removeAll: function(a){_this.removes++;},
					_sortLayers: function(a){_this.sortArg = a;},
					_newMarkup: function(a){_this.markupArg = a;},
					_appendMarkup: function(a){_this.appendArg = a;},
					_isPolygonTheme: function(a){_this.polyArg = a;return false;},
					_turnOn: function(a){_this.onArg = a;},
					_newTheme: true
				}, div);
				this.subscription = dojo.subscribe("webmap.widget.LayerControl.layersUpdated",
					function(){_this.updates++;}
				);
				webmap.util.XmlDocumentUtil.loadString = function(a){
					_this.xmlArg = a;
					return {documentElement:"documentElement"}
				};
			},
			runTest: function(){
				this.widget._addMarkup(this.mapData);
				tests.assertEqual(null, this.xmlArg);
				tests.assertEqual(null, this.clearArg);
				tests.assertEqual(0, this.removes);
				tests.assertEqual(null, this.sortArg);
				tests.assertEqual(null, this.markupArg);
				tests.assertEqual(null, this.polyArg);
				tests.assertEqual(null, this.onArg);
				tests.assertEqual(null, this.appendArg);
				tests.assertEqual(this.mapData.mapEnvelope, this.widget._mapEnvelope);
				tests.assertEqual(1, this.updates);
				tests.assertTrue(this.widget._newTheme);
				this.mapData.markup = "";
				this.widget._mapEnvelope = null;
				this.widget._addMarkup(this.mapData);
				tests.assertEqual(null, this.xmlArg);
				tests.assertEqual(null, this.clearArg);
				tests.assertEqual(0, this.removes);
				tests.assertEqual(null, this.sortArg);
				tests.assertEqual(null, this.markupArg);
				tests.assertEqual(null, this.polyArg);
				tests.assertEqual(null, this.onArg);
				tests.assertEqual(null, this.appendArg);
				tests.assertEqual(this.mapData.mapEnvelope, this.widget._mapEnvelope);
				tests.assertEqual(2, this.updates);
				tests.assertTrue(this.widget._newTheme);
			},
			tearDown: function(){
				this.widget.destroy();
				dojo.unsubscribe(this.subscription);
				webmap.util.XmlDocumentUtil.loadString = this.loadString;
			}
		},
		{
			name: "_addMarkup_has_markup_isClearAll_true_isPolygonTheme_false",
			widget: null,
			mapData: {clientData:{themeLayerId:"id"},mapEnvelope:"mapEnvelope",
				markup: "markup"
			},
			clearArg: null,
			sortArg: null,
			markupArg: null,
			appendArg: null,
			removes: 0,
			updates: 0,
			subscription: null,
			onArg: null,
			xmlArg: null,
			polyArg: null,
			loadString: webmap.util.XmlDocumentUtil.loadString,
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({
					_isClearAll: function(a){_this.clearArg = a;return true;},
					_removeAll: function(a){_this.removes++;},
					_sortLayers: function(a){_this.sortArg = a;},
					_newMarkup: function(a){_this.markupArg = a;},
					_appendMarkup: function(a){_this.appendArg = a;},
					_isPolygonTheme: function(a){_this.polyArg = a;return false;},
					_turnOn: function(a){_this.onArg = a;},
					_newTheme: true
				}, div);
				this.subscription = dojo.subscribe("webmap.widget.LayerControl.layersUpdated",
					function(){_this.updates++;}
				);
				webmap.util.XmlDocumentUtil.loadString = function(a){
					_this.xmlArg = a;
					return {documentElement:"documentElement"}
				};
			},
			runTest: function(){
				this.widget._addMarkup(this.mapData);
				tests.assertEqual(this.mapData.markup, this.xmlArg);
				tests.assertEqual(this.mapData, this.clearArg);
				tests.assertEqual(1, this.removes);
				tests.assertEqual("documentElement", this.sortArg);
				tests.assertEqual("documentElement", this.markupArg);
				tests.assertEqual(this.mapData, this.polyArg);
				tests.assertEqual(null, this.onArg);
				tests.assertEqual(null, this.appendArg);
				tests.assertEqual(this.mapData.mapEnvelope, this.widget._mapEnvelope);
				tests.assertEqual(1, this.updates);
				tests.assertFalse(this.widget._newTheme);
			},
			tearDown: function(){
				this.widget.destroy();
				dojo.unsubscribe(this.subscription);
				webmap.util.XmlDocumentUtil.loadString = this.loadString;
			}
		},
		{
			name: "_addMarkup_has_markup_isClearAll_true_isPolygonTheme_true",
			widget: null,
			mapData: {clientData:{themeLayerId:"id"},mapEnvelope:"mapEnvelope",
				markup: "markup"
			},
			clearArg: null,
			sortArg: null,
			markupArg: null,
			appendArg: null,
			removes: 0,
			updates: 0,
			subscription: null,
			onArg: null,
			xmlArg: null,
			polyArg: null,
			loadString: webmap.util.XmlDocumentUtil.loadString,
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({
					_isClearAll: function(a){_this.clearArg = a;return true;},
					_removeAll: function(a){_this.removes++;},
					_sortLayers: function(a){_this.sortArg = a;},
					_newMarkup: function(a){_this.markupArg = a;},
					_appendMarkup: function(a){_this.appendArg = a;},
					_isPolygonTheme: function(a){_this.polyArg = a;return true;},
					_turnOn: function(a){_this.onArg = a;},
					_newTheme: true
				}, div);
				this.subscription = dojo.subscribe("webmap.widget.LayerControl.layersUpdated",
					function(){_this.updates++;}
				);
				webmap.util.XmlDocumentUtil.loadString = function(a){
					_this.xmlArg = a;
					return {documentElement:"documentElement"}
				};
			},
			runTest: function(){
				this.widget._addMarkup(this.mapData);
				tests.assertEqual(this.mapData.markup, this.xmlArg);
				tests.assertEqual(this.mapData, this.clearArg);
				tests.assertEqual(1, this.removes);
				tests.assertEqual("documentElement", this.sortArg);
				tests.assertEqual("documentElement", this.markupArg);
				tests.assertEqual(this.mapData, this.polyArg);
				tests.assertEqual(this.mapData.clientData.themeLayerId, this.onArg);
				tests.assertEqual(null, this.appendArg);
				tests.assertEqual(this.mapData.mapEnvelope, this.widget._mapEnvelope);
				tests.assertEqual(1, this.updates);
				tests.assertFalse(this.widget._newTheme);
			},
			tearDown: function(){
				this.widget.destroy();
				dojo.unsubscribe(this.subscription);
				webmap.util.XmlDocumentUtil.loadString = this.loadString;
			}
		},
		{
			name: "_addMarkup_has_markup_isClearAll_false",
			widget: null,
			mapData: {clientData:{themeLayerId:"id"},mapEnvelope:"mapEnvelope",
				markup: "markup"
			},
			clearArg: null,
			sortArg: null,
			markupArg: null,
			appendArg: null,
			removes: 0,
			updates: 0,
			subscription: null,
			onArg: null,
			xmlArg: null,
			polyArg: null,
			loadString: webmap.util.XmlDocumentUtil.loadString,
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({
					_isClearAll: function(a){_this.clearArg = a;return false;},
					_removeAll: function(a){_this.removes++;},
					_sortLayers: function(a){_this.sortArg = a;},
					_newMarkup: function(a){_this.markupArg = a;},
					_appendMarkup: function(a){_this.appendArg = a;},
					_isPolygonTheme: function(a){_this.polyArg = a;return false;},
					_turnOn: function(a){_this.onArg = a;},
					_newTheme: true
				}, div);
				this.subscription = dojo.subscribe("webmap.widget.LayerControl.layersUpdated",
					function(){_this.updates++;}
				);
				webmap.util.XmlDocumentUtil.loadString = function(a){
					_this.xmlArg = a;
					return {documentElement:"documentElement"}
				};
			},
			runTest: function(){
				this.widget._addMarkup(this.mapData);
				tests.assertEqual(this.mapData.markup, this.xmlArg);
				tests.assertEqual(this.mapData, this.clearArg);
				tests.assertEqual(0, this.removes);
				tests.assertEqual(null, this.sortArg);
				tests.assertEqual(null, this.markupArg);
				tests.assertEqual(null, this.polyArg);
				tests.assertEqual(null, this.onArg);
				tests.assertEqual("documentElement", this.appendArg);
				tests.assertEqual(this.mapData.mapEnvelope, this.widget._mapEnvelope);
				tests.assertEqual(1, this.updates);
				tests.assertTrue(this.widget._newTheme);
			},
			tearDown: function(){
				this.widget.destroy();
				dojo.unsubscribe(this.subscription);
				webmap.util.XmlDocumentUtil.loadString = this.loadString;
			}
		},
		{
			name: "_newMarkup",
			widget: null,
			fix: webmap.util.SvgImageFix.fix,
			docToString: webmap.util.XmlDocumentUtil.docToString,
			markup: null,
			vmlArg: null,
			svgArg: null,
			setUp: function(){
				doLayerControlSetup();
				this.widget = new webmap.widget.LayerControl({}, div);
				this.markup = document.createElement("div");
				this.markup.innerHTML = "test";
				document.body.appendChild(this.markup);
				var _this = this;
				webmap.util.XmlDocumentUtil.docToString = function(a){_this.vmlArg = a;};
				webmap.util.SvgImageFix.fix = function(a){_this.svgArg = a;};
			},
			runTest: function(){
				this.widget._newMarkup(this.markup);
				if (dojo.isIE){
					tests.assertEqual(this.markup, this.vmlArg);
					tests.assertEqual(this.markup.innerHTML, this.widget.domNode.innerHTML);
				}else{
					tests.assertEqual(this.markup, this.svgArg);
					tests.assertEqual(this.markup, this.widget.domNode.firstChild);
				}
			},
			tearDown: function(){
				this.widget.destroy();
				webmap.util.SvgImageFix.fix = this.fix;
				webmap.util.XmlDocumentUtil.docToString = this.docToString;
			}
		},
		{
			name: "_sortLayers",
			widget: null,
			markup: null,
			setUp: function(){
				doLayerControlSetup();
				this.widget = new webmap.widget.LayerControl({
					_layerOrder: {layer0:0,layer1:1,layer2:2,layer3:3}
				}, div);
				this.markup = document.createElement("div");
				document.body.appendChild(this.markup);
				this.markup.appendChild(document.createElement("div"));
				this.markup.lastChild.className = "layer1";
				this.markup.appendChild(document.createElement("div"));
				this.markup.lastChild.className = "layer3";
				this.markup.appendChild(document.createElement("div"));
				this.markup.lastChild.className = "layer0";
				this.markup.appendChild(document.createElement("div"));
				this.markup.lastChild.className = "layer2";
			},
			runTest: function(){
				this.widget._sortLayers(this.markup);
				var layers = this.markup.childNodes
				tests.assertEqual("layer0", layers[0].className);
				tests.assertEqual("layer1", layers[1].className);
				tests.assertEqual("layer2", layers[2].className);
				tests.assertEqual("layer3", layers[3].className);
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "_insertLayer",
			widget: null,
			markup: null,
			svg: null,
			fix: webmap.util.SvgImageFix.fix,
			setUp: function(){
				doLayerControlSetup();
				this.widget = new webmap.widget.LayerControl({
					_layerOrder: {layer0:0,layer1:1,layer2:2,layer3:3,layer9:9,layer100:100}
				}, div);
				var _this = this;
				webmap.util.SvgImageFix.fix = function(a){_this.svg = a;};
				this.markup = document.createElement("div");
				document.body.appendChild(this.markup);
				this.markup.appendChild(document.createElement("div"));
				this.markup.lastChild.className = "layer0";
				this.markup.appendChild(document.createElement("div"));
				this.markup.lastChild.className = "layer1";
				this.markup.appendChild(document.createElement("div"));
				this.markup.lastChild.className = "layer3";
				this.markup.appendChild(document.createElement("div"));
				this.markup.lastChild.className = "layer100";
			},
			runTest: function(){
				var layer = document.createElement("div");
				layer.className = "layer2";
				this.widget._insertLayer(this.markup, layer);
				var layers = this.markup.childNodes;
				tests.assertEqual("layer0", layers[0].className);
				tests.assertEqual("layer1", layers[1].className);
				tests.assertEqual("layer2", layers[2].className);
				tests.assertEqual("layer3", layers[3].className);
				tests.assertEqual("layer100", layers[4].className);
				if (dojo.isIE)
					tests.assertEqual(null, this.svg);
				else
					tests.assertEqual(layer, this.svg);
				layer = document.createElement("div");
				var layer = document.createElement("div");
				layer.className = "layer9";
				this.widget._insertLayer(this.markup, layer);
				var layers = this.markup.childNodes;
				tests.assertEqual("layer0", layers[0].className);
				tests.assertEqual("layer1", layers[1].className);
				tests.assertEqual("layer2", layers[2].className);
				tests.assertEqual("layer3", layers[3].className);
				tests.assertEqual("layer9", layers[4].className);
				tests.assertEqual("layer100", layers[5].className);
				if (dojo.isIE)
					tests.assertEqual(null, this.svg);
				else
					tests.assertEqual(layer, this.svg);
				layer = document.createElement("div");
			},
			tearDown: function(){
				this.widget.destroy();
				webmap.util.SvgImageFix.fix = this.fix;
			}
		},
		{
			name: "_appendMarkup",
			widget: null,
			markup: null,
			container: null,
			args: [],
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({
					_insertLayer: function(a0,a1){
						_this.args.push([a0,a1]);
					}
				}, div);
				this.container = document.createElement("div");
				this.widget.domNode.appendChild(this.container);
				this.markup = document.createElement("div");
				document.body.appendChild(this.markup);
				this.markup.appendChild(document.createElement("div"));
				this.markup.lastChild.className = "layer3";
				this.markup.appendChild(document.createElement("div"));
				this.markup.lastChild.className = "layer100";
				this.markup.appendChild(document.createElement("div"));
				this.markup.lastChild.className = "layer0";
				this.markup.appendChild(document.createElement("div"));
				this.markup.lastChild.className = "layer1";
			},
			runTest: function(){
				this.widget._appendMarkup(this.markup);
				tests.assertEqual([this.container, this.markup.childNodes[0]], this.args[0]);
				tests.assertEqual([this.container, this.markup.childNodes[1]], this.args[1]);
				tests.assertEqual([this.container, this.markup.childNodes[2]], this.args[2]);
				tests.assertEqual([this.container, this.markup.childNodes[3]], this.args[3]);
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "_removeAll",
			widget: null,
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({}, div);
				var markup = document.createElement("div");
				this.widget.domNode.appendChild(markup);
				markup.appendChild(document.createElement("div"));
				markup.appendChild(document.createElement("div"));
				markup.appendChild(document.createElement("div"));
				markup.appendChild(document.createElement("div"));
			},
			runTest: function(){
				this.widget._removeAll();
				tests.assertEqual(0, this.widget.domNode.childNodes.length);
				tests.assertEqual("", this.widget.domNode.innerHTML);
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "_toggleVisibility",
			widget: null,
			isDormant: webmap.isDormant,
			layers: null,
			onArgs: [],
			offArgs: [],
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({
					_turnOn: function(a){_this.onArgs.push(a);},
					_turnOff: function(a){_this.offArgs.push(a);}
				}, div);
				this.layers = [
					{layerId:"layer0", visible:true, diabled:false},
					{layerId:"layer1", visible:true, diabled:true},
					{layerId:"layer2", visible:false, diabled:false},
					{layerId:"layer3", visible:false, diabled:true}
				];
				webmap.isDormant = function(){return true;};
			},
			runTest: function(){
				this.widget._toggleVisibility(this.layers);
				tests.assertEqual([], this.onArgs);
				tests.assertEqual([], this.offArgs);
				webmap.isDormant = function(){return false;};
				this.widget._toggleVisibility(this.layers);
				tests.assertEqual(["layer0"], this.onArgs);
			},
			tearDown: function(){
				this.widget.destroy();
				webmap.isDormant = this.isDormant;
			}
		},
		{
			name: "_turnOn_layer_does_not_exists",
			widget: null,
			style: new MockElem(),
			subscription: null,
			queryArgs: [],
			pubArgs: [],
			query: dojo.query,
			setUp: function(){
				doLayerControlSetup();
				this.widget = new webmap.widget.LayerControl({}, div);
				if (dojo.isIE)
					this.style.styleSheet.cssText = "{display:none;}";
				else
					this.style.innerHTML = "{display:none;}";
				var _this = this;
				this.subscription = dojo.subscribe("webmap.widget.LayerControl.layerNeeded",
					function(a){_this.pubArgs.push(a)}
				);
				dojo.query = function(a){
					_this.queryArgs.push(a); 
					return a.substr(0,1) == "." ? [] : [_this.style];
				 };
			},
			runTest: function(){
				this.widget._turnOn("layer4");
				tests.assertEqual(["head style#layer4Style",".layer4"], this.queryArgs);
				tests.assertEqual(["layer4"], this.pubArgs);
				if (dojo.isIE)
					tests.assertEqual("{display:block;}", this.style.styleSheet.cssText);
				else
					tests.assertEqual("{display:block;}", this.style.innerHTML);
			},
			tearDown: function(){
				dojo.query = this.query;
				this.widget.destroy();
			}
		},
		{
			name: "_turnOn_layer_exists",
			widget: null,
			style: new MockElem(),
			subscription: null,
			queryArgs: [],
			pubArgs: [],
			query: dojo.query,
			setUp: function(){
				doLayerControlSetup();
				this.widget = new webmap.widget.LayerControl({}, div);
				if (dojo.isIE)
					this.style.styleSheet.cssText = "{display:none;}";
				else
					this.style.innerHTML = "{display:none;}";
				var _this = this;
				this.subscription = dojo.subscribe("webmap.widget.LayerControl.layerNeeded",
					function(a){_this.pubArgs.push(a)}
				);
				dojo.query = function(a){
					_this.queryArgs.push(a);
					return a.substr(0,1) == "." ? ["layer markup"] : [_this.style];
				 };
			},
			runTest: function(){
				this.widget._turnOn("layer4");
				tests.assertEqual(["head style#layer4Style",".layer4"], this.queryArgs);
				tests.assertEqual([], this.pubArgs);
				if (dojo.isIE)
					tests.assertEqual("{display:block;}", this.style.styleSheet.cssText);
				else
					tests.assertEqual("{display:block;}", this.style.innerHTML);
			},
			tearDown: function(){
				dojo.query = this.query;
				this.widget.destroy();
			}
		},
		{
			name: "_turnOff",
			widget: null,
			style: new MockElem(),
			subscription: null,
			queryArgs: [],
			pubArgs: [],
			query: dojo.query,
			setUp: function(){
				doLayerControlSetup();
				this.widget = new webmap.widget.LayerControl({}, div);
				if (dojo.isIE)
					this.style.styleSheet.cssText = "{display:block;}";
				else
					this.style.innerHTML = "{display:block;}";
				var _this = this;
				this.subscription = dojo.subscribe("webmap.widget.LayerControl.layerOff",
					function(a){_this.pubArgs.push(a)}
				);
				dojo.query = function(a){
					_this.queryArgs.push(a);
					return a.substr(0,1) == "." ? ["layer markup"] : [_this.style];
				 };
			},
			runTest: function(){
				this.widget._turnOff("layer4");
				tests.assertEqual(["head style#layer4Style"], this.queryArgs);
				tests.assertEqual(["layer4"], this.pubArgs);
				if (dojo.isIE)
					tests.assertEqual("{display:none;}", this.style.styleSheet.cssText);
				else
					tests.assertEqual("{display:none;}", this.style.innerHTML);
			},
			tearDown: function(){
				dojo.query = this.query;
				this.widget.destroy();
			}
		},
		{
			name: "_isBasemap",
			widget: null,
			arg: null,
			setUp: function(){
				doLayerControlSetup();
				var _this = this;
				this.widget = new webmap.widget.LayerControl({
					_getClassName: function(a){_this.arg = a; return "";}
				}, div);
			},
			runTest: function(){
				tests.assertFalse(this.widget._isBasemap({parentNode:"parentNode1"}));
				tests.assertEqual("parentNode1", this.arg);
				var _this = this;
				this.widget._getClassName = function(a){_this.arg = a; return webmap.config.baseMapLayerId;};
				tests.assertTrue(this.widget._isBasemap({parentNode:"parentNode2"}));
				tests.assertEqual("parentNode2", this.arg);
			},
			tearDown: function(){
				this.widget.destroy();
			}
		}
	]
);