var getInnerHTML = function(id) { return $(id).innerHTML.toString().toLowerCase().gsub(/[\r\n\t]/, ''); }; var createParagraph = function(text) { var p = document.createElement('p'); p.appendChild(document.createTextNode(text)); return p; } new Test.Unit.Runner({ setup: function() { if (documentViewportProperties) return; // Based on properties check from http://www.quirksmode.org/viewport/compatibility.html documentViewportProperties = { properties : [ 'self.pageXOffset', 'self.pageYOffset', 'self.screenX', 'self.screenY', 'self.innerHeight', 'self.innerWidth', 'self.outerHeight', 'self.outerWidth', 'self.screen.height', 'self.screen.width', 'self.screen.availHeight', 'self.screen.availWidth', 'self.screen.availTop', 'self.screen.availLeft', 'self.screen.Top', 'self.screen.Left', 'self.screenTop', 'self.screenLeft', 'document.body.clientHeight', 'document.body.clientWidth', 'document.body.scrollHeight', 'document.body.scrollWidth', 'document.body.scrollLeft', 'document.body.scrollTop', 'document.body.offsetHeight', 'document.body.offsetWidth', 'document.body.offsetTop', 'document.body.offsetLeft' ].inject([], function(properties, prop) { if (!self.screen && prop.include('self.screen')) return; if (!document.body && prop.include('document.body')) return; properties.push(prop); if (prop.include('.body') && document.documentElement) properties.push(prop.sub('.body', '.documentElement')); return properties; }), inspect : function() { var props = []; this.properties.each(function(prop) { if (eval(prop)) props[prop] = eval(prop); }, this); return props; } }; }, testDollarFunction: function() { this.assertUndefined($()); this.assertNull(document.getElementById('noWayThisIDExists')); this.assertNull($('noWayThisIDExists')); this.assertIdentical(document.getElementById('testdiv'), $('testdiv')); this.assertEnumEqual([ $('testdiv'), $('container') ], $('testdiv', 'container')); this.assertEnumEqual([ $('testdiv'), undefined, $('container') ], $('testdiv', 'noWayThisIDExists', 'container')); var elt = $('testdiv'); this.assertIdentical(elt, $(elt)); this.assertRespondsTo('hide', elt); this.assertRespondsTo('childOf', elt); }, testGetElementsByClassName: function() { if (document.getElementsByClassName.toString().include('[native code]')) { this.info("browser uses native getElementsByClassName; skipping tests"); return; } var div = $('class_names'), list = $('class_names_ul'); this.assertElementsMatch(document.getElementsByClassName('A'), 'p.A', 'ul#class_names_ul.A', 'li.A.C'); if (Prototype.Browser.IE) this.assertUndefined(document.getElementById('unextended').show); this.assertElementsMatch(div.getElementsByClassName('B'), 'ul#class_names_ul.A.B', 'div.B.C.D'); this.assertElementsMatch(div.getElementsByClassName('D C B'), 'div.B.C.D'); this.assertElementsMatch(div.getElementsByClassName(' D\nC\tB '), 'div.B.C.D'); this.assertElementsMatch(div.getElementsByClassName($w('D C B'))); this.assertElementsMatch(list.getElementsByClassName('A'), 'li.A.C'); this.assertElementsMatch(list.getElementsByClassName(' A '), 'li.A.C'); this.assertElementsMatch(list.getElementsByClassName('C A'), 'li.A.C'); this.assertElementsMatch(list.getElementsByClassName("C\nA "), 'li.A.C'); this.assertElementsMatch(list.getElementsByClassName('B')); this.assertElementsMatch(list.getElementsByClassName('1'), 'li.1'); this.assertElementsMatch(list.getElementsByClassName([1]), 'li.1'); this.assertElementsMatch(list.getElementsByClassName(['1 junk'])); this.assertElementsMatch(list.getElementsByClassName('')); this.assertElementsMatch(list.getElementsByClassName(' ')); this.assertElementsMatch(list.getElementsByClassName([''])); this.assertElementsMatch(list.getElementsByClassName([' ', ''])); this.assertElementsMatch(list.getElementsByClassName({})); // those lookups shouldn't have extended all nodes in document if (Prototype.Browser.IE) this.assertUndefined(document.getElementById('unextended')['show']); }, testElementInsertWithHTML: function() { Element.insert('insertions-main', {before:'
before text
more testing
'}); this.assert(getInnerHTML('insertions-container').startsWith('before text
more testing
')); Element.insert('insertions-main', {after:'after text
more testing
'}); this.assert(getInnerHTML('insertions-container').endsWith('after text
more testing
')); Element.insert('insertions-main', {top:'top text.
more testing
'}); this.assert(getInnerHTML('insertions-main').startsWith('top text.
more testing
')); Element.insert('insertions-main', {bottom:'bottom text.
more testing
'}); this.assert(getInnerHTML('insertions-main').endsWith('bottom text.
more testing
')); }, testElementInsertWithDOMNode: function() { Element.insert('insertions-node-main', {before: createParagraph('node before')}); this.assert(getInnerHTML('insertions-node-container').startsWith('node before
')); Element.insert('insertions-node-main', {after: createParagraph('node after')}); this.assert(getInnerHTML('insertions-node-container').endsWith('node after
')); Element.insert('insertions-node-main', {top:createParagraph('node top')}); this.assert(getInnerHTML('insertions-node-main').startsWith('node top
')); Element.insert('insertions-node-main', {bottom:createParagraph('node bottom')}); this.assert(getInnerHTML('insertions-node-main').endsWith('node bottom
')); this.assertEqual($('insertions-node-main'), $('insertions-node-main').insert(document.createElement('p'))); }, testElementInsertWithToElementMethod: function() { Element.insert('insertions-node-main', {toElement: createParagraph.curry('toElement') }); this.assert(getInnerHTML('insertions-node-main').endsWith('toelement
')); Element.insert('insertions-node-main', {bottom: {toElement: createParagraph.curry('bottom toElement') }}); this.assert(getInnerHTML('insertions-node-main').endsWith('bottom toelement
')); }, testElementInsertWithToHTMLMethod: function() { Element.insert('insertions-node-main', {toHTML: function() { return 'toHTML
'} }); this.assert(getInnerHTML('insertions-node-main').endsWith('tohtml
')); Element.insert('insertions-node-main', {bottom: {toHTML: function() { return 'bottom toHTML
'} }}); this.assert(getInnerHTML('insertions-node-main').endsWith('bottom tohtml
')); }, testElementInsertWithNonString: function() { Element.insert('insertions-main', {bottom:3}); this.assert(getInnerHTML('insertions-main').endsWith('3')); }, testElementInsertInTables: function() { Element.insert('second_row', {after:'3
')); this.assert(getInnerHTML('element-insertions-multiple-container').endsWith('4')); $('element-insertions-main').update('test'); $('element-insertions-main').insert(null); $('element-insertions-main').insert({bottom:null}); this.assertEqual('test', getInnerHTML('element-insertions-main')); $('element-insertions-main').insert(1337); this.assertEqual('test1337', getInnerHTML('element-insertions-main')); }, testNewElementInsert: function() { var container = new Element('div'); element = new Element('div'); container.insert(element); element.insert({ before: 'a paragraph
' }); this.assertEqual('a paragraph
', getInnerHTML(container)); element.insert({ after: 'some text' }); this.assertEqual('a paragraph
some text', getInnerHTML(container)); element.insert({ top: 'a paragraph
' }); this.assertEqual('a paragraph
', getInnerHTML(element)); element.insert('some text'); this.assertEqual('a paragraph
some text', getInnerHTML(element)); }, testInsertionBackwardsCompatibility: function() { new Insertion.Before('element-insertions-main', 'some backward-compatibility testing before'); this.assert(getInnerHTML('element-insertions-container').include('some backward-compatibility testing before')); new Insertion.After('element-insertions-main', 'some backward-compatibility testing after'); this.assert(getInnerHTML('element-insertions-container').include('some backward-compatibility testing after')); new Insertion.Top('element-insertions-main', 'some backward-compatibility testing top'); this.assert(getInnerHTML('element-insertions-main').startsWith('some backward-compatibility testing top')); new Insertion.Bottom('element-insertions-main', 'some backward-compatibility testing bottom'); this.assert(getInnerHTML('element-insertions-main').endsWith('some backward-compatibility testing bottom')); }, testElementWrap: function() { var element = $('wrap'), parent = document.createElement('div'); element.wrap(); this.assert(getInnerHTML('wrap-container').startsWith('\ntestVar="hello!";\n'+'script>'); this.assertEqual('hello from div!',$('testdiv').innerHTML); this.wait(100,function(){ this.assertEqual('hello!',testVar); Element.update('testdiv','another hello from div!\n