// test.js
/*jslint  browser:  true,
          eqeqeq:   true,
          immed:    false,
          newcap:   true,
          nomen:    false,
          onevar:   true,
          plusplus: false,
          undef:    false,
          white:    false */
/*jshint  browser:  true,
          eqeqeq:   true,
          immed:    false,
          newcap:   true,
          nomen:    false,
          onevar:   true,
          plusplus: false,
          undef:    false,
          white:    false */
/*global  window, jQuery, $, QUnit, PXHLR */

/* namespace */
module('namespace check');
test('Is PXHLR a global variable?', function(){
    expect(1);
    ok( window.PXHLR, 'PXHLR namespace is present');
});

// /*
module('Setup modules and subclasses', {
    setup: function() {
		PXHLR.modules = new PXHLR.Module();
		PXHLR.modules.init();
		PXHLR.modules.defaults = { context : "#qunit-fixture" };
		// extend module object
		PXHLR.modules.subclass = PXHLR.modules.extend({
			beforeBinding : function (subclassObj) {
				this.debug("subclass beforeBinding");
				this._parent.beforeBinding(subclassObj);
			},
			onBinding : function (subclassObj) {
				this.debug("subclass onBinding");
				this._parent.onBinding(subclassObj);
			},
			afterBinding : function (subclassObj) {
				this.debug("subclass afterBinding");
				this._parent.afterBinding(subclassObj);
			}
		});
		PXHLR.modules.subclass.init();
    },
    teardown: function() {
        delete PXHLR.modules;
    }
});
test('Module should create new instances', function (){
	expect(4);

    ok(PXHLR.modules, "PXHLR.modules is defined");
	deepEqual(PXHLR.Module.prototype, Object.getPrototypeOf(PXHLR.modules), "subclass has modules as its prototype");
	
	ok(PXHLR.modules.subclass, "PXHLR.modules.subclass is defined");
	deepEqual(PXHLR.modules, Object.getPrototypeOf(PXHLR.modules.subclass), "subclass has modules as its prototype");
});
test('Setup a couple more module subclasses', function (){
	expect(6);
	
	// instantiate base module object
	PXHLR.modules.subclass.childclass = PXHLR.modules.subclass.extend({
		beforeBinding : function () {
			this.debug("childclass beforeBinding");
			this._parent.onBinding(this);
		},
		afterBinding : function () {
			this.debug("childclass afterBinding");
			this.childclassHandler("childclass beforeBinding");
			this._parent.afterBinding(this);
		},
		childclassHandler : function (who) {
			this.debug("childclass method childclassHandler called from " + who);
		}
	});
	PXHLR.modules.subclass.childclass.init();

	ok(PXHLR.modules.subclass.childclass, "PXHLR.modules.subclass.childclass is defined");
	ok(PXHLR.modules.subclass.childclass instanceof PXHLR.Module, "New instance");
	deepEqual(PXHLR.modules.subclass, Object.getPrototypeOf(PXHLR.modules.subclass.childclass), "childclass has subclass as its prototype");
	
	PXHLR.modules.subclass.childclass.grandBaby = PXHLR.modules.subclass.childclass.extend({
		init : function () {
			this.debug("grandBaby - init");
			this.grandBabyHandler('grandBaby.init');
		},
		beforeBinding : function () {
			this.debug("grandBaby - beforeBinding");
			this.grandBabyHandler("grandBaby - beforeBinding");
			this._parent.beforeBinding(this);
		},
		grandBabyHandler : function (who) {
			this.debug("grandBaby method grandBabyHandler called from " + who);
			this.childclassHandler('grandBabyHandler');
		}
	});
	PXHLR.modules.subclass.childclass.grandBaby.init();

	ok(PXHLR.modules.subclass.childclass.grandBaby, "PXHLR.modules.subclass.childclass.grandBaby is defined");
	ok(PXHLR.modules.subclass.childclass.grandBaby instanceof PXHLR.Module, "New instance");
	deepEqual(PXHLR.modules.subclass.childclass, Object.getPrototypeOf(PXHLR.modules.subclass.childclass.grandBaby), "grandBaby has childclass as its prototype");
});
// */