fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt SweeneyYUI.add('dom-core-test', function(Y) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var Assert = Y.Assert;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney ArrayAssert = Y.ArrayAssert;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Test.Runner.add(new Y.Test.Case({
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney name: 'Y.DOM.byId',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return element from string': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Assert.areEqual(document.getElementById('test-id'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.byId('test-id'));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return first match when dupe id exists': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-id'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney dupe = document.createElement('div');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney dupe.id = 'test-id';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.body.insertBefore(dupe, node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Assert.areEqual(dupe, Y.DOM.byId('test-id'));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.body.removeChild(dupe);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return null when no match': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Assert.isNull(Y.DOM.byId('fake-id'));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return null when input is null': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Assert.isNull(Y.DOM.byId(null));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return null when input is undefined': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Assert.isNull(Y.DOM.byId());
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should avoid mistaking name for id': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var inputs = document.getElementsByTagName('form')[0]
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney .getElementsByTagName('input');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(inputs[0], Y.DOM.byId('test-name-id1'));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(inputs[1], Y.DOM.byId('test-name-id2'));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should avoid mistaking form id for named input': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var form = document.getElementsByTagName('form')[0];
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(form, Y.DOM.byId('test-names'));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should search the given node': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node.innerHTML = '<span id="test-by-id-root">foo</span><span>bar</span>';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.body.appendChild(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Assert.areEqual(node.childNodes[0],
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.byId('test-by-id-root', node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.body.removeChild(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should restrict search to the given node': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node.id = 'test-by-id-root';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.body.appendChild(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Assert.isNull(Y.DOM.byId('test-by-id-root', node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.body.removeChild(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should search the given node (off document)': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node.innerHTML = '<span id="test-by-id-root">foo</span><span>bar</span>';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Assert.areEqual(node.childNodes[0],
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.byId('test-by-id-root', node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should search the given document (frame)': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Assert.areEqual(document.getElementById('test-id'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.byId('demo', document));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should search the given document (frame)': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var frame = document.getElementById('test-frame'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney doc = frame.contentWindow.document;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Assert.areEqual(doc.getElementById('demo'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.byId('demo', doc));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Test.Runner.add(new Y.Test.Case({
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney name: 'Y.DOM.allById',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return all elements with the given id': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var nodes = document.getElementById('test-dupe-ids')
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney .getElementsByTagName('span');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney ArrayAssert.itemsAreEqual(nodes, Y.DOM.allById('test-dupe-id'));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return all elements with the given id (root element)': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-dupe-root'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney nodes = node.getElementsByTagName('span');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney ArrayAssert.itemsAreEqual(nodes, Y.DOM.allById('test-dupe-id', node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return empty array when no match': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney ArrayAssert.itemsAreEqual([], Y.DOM.allById('fake-id'));
03492fa477ba30a43e50ef260c72731b9b754d91Matt Sweeney },
03492fa477ba30a43e50ef260c72731b9b754d91Matt Sweeney
03492fa477ba30a43e50ef260c72731b9b754d91Matt Sweeney 'should find cloned element': function() {
03492fa477ba30a43e50ef260c72731b9b754d91Matt Sweeney var node = document.getElementById('test-id');
03492fa477ba30a43e50ef260c72731b9b754d91Matt Sweeney var clone = node.cloneNode(true);
03492fa477ba30a43e50ef260c72731b9b754d91Matt Sweeney clone.id = 'cloned-node';
03492fa477ba30a43e50ef260c72731b9b754d91Matt Sweeney
03492fa477ba30a43e50ef260c72731b9b754d91Matt Sweeney document.body.appendChild(clone);
03492fa477ba30a43e50ef260c72731b9b754d91Matt Sweeney ArrayAssert.itemsAreEqual([clone], Y.DOM.allById('cloned-node'));
03492fa477ba30a43e50ef260c72731b9b754d91Matt Sweeney document.body.removeChild(clone);
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney },
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney 'should ignore matches on NAME instead of ID': function() {
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney Assert.areEqual(1, Y.DOM.allById('test-names').length);
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney },
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney 'should find all clones': function() {
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney var node = document.getElementById('test-id'),
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney clone = node.cloneNode(true),
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney clone2 = node.cloneNode(true);
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney clone.id = 'cloned-node';
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney clone2.id = 'cloned-node';
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney document.body.appendChild(clone);
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney document.body.appendChild(clone2);
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney ArrayAssert.itemsAreEqual([clone, clone2], Y.DOM.allById('cloned-node'));
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney document.body.removeChild(clone);
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney document.body.removeChild(clone2);
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney },
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney 'should find all cloned forms': function() {
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney var node = document.getElementById('test-clone-form'),
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney clone = node.cloneNode(true),
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney clone2 = node.cloneNode(true);
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney clone.id = 'cloned-node';
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney clone2.id = 'cloned-node';
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney document.body.appendChild(clone);
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney document.body.appendChild(clone2);
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney ArrayAssert.itemsAreEqual([clone, clone2], Y.DOM.allById('cloned-node'));
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney document.body.removeChild(clone);
db445e900d0225be4de71ea099e90c2a0ad12921Matt Sweeney document.body.removeChild(clone2);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Test.Runner.add(new Y.Test.Case({
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney name: 'Y.DOM.getText',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return the text content of the given node': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-get-text'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney nodes = node.childNodes,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney text = '',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney i = 0,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney child;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney while((child = nodes[i++])) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney text += child.innerHTML || child.nodeValue;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
83bac8606b329c30526704e0950e886c89bfde48Matt Sweeney Assert.areEqual(Y.Lang.trim(text), Y.Lang.trim(Y.DOM.getText(node)));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
c31e28da00e9fe86d7e9aebaa5ff25933fec30b4Matt Sweeney 'should return the text content of the given text node': function() {
c31e28da00e9fe86d7e9aebaa5ff25933fec30b4Matt Sweeney var text = 'foo bar',
c31e28da00e9fe86d7e9aebaa5ff25933fec30b4Matt Sweeney node = document.createTextNode(text);
c31e28da00e9fe86d7e9aebaa5ff25933fec30b4Matt Sweeney
c31e28da00e9fe86d7e9aebaa5ff25933fec30b4Matt Sweeney Assert.areEqual(text, Y.DOM.getText(node));
c31e28da00e9fe86d7e9aebaa5ff25933fec30b4Matt Sweeney },
c31e28da00e9fe86d7e9aebaa5ff25933fec30b4Matt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return empty string when no text found' : function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('', Y.DOM.getText(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return empty string when input is null' : function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('', Y.DOM.getText(null));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return empty string when input is undefined' : function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('', Y.DOM.getText());
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Test.Runner.add(new Y.Test.Case({
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney name: 'Y.DOM.setText',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should set content with the given text': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney content = 'testing text content';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setText(node, content);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(content, Y.DOM.getText(node, content));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should set html content as text': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney content = '<div>testing text content</div>';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setText(node, content);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(content, Y.DOM.getText(node, content));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should preserve spaces': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney content = ' testing text content ';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setText(node, content);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(content, Y.DOM.getText(node, content));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should replace existing content': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney content = 'testing text content';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node.innerHTML = '<em>foo</em>';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
82f3694450ab9870df1b580e54d8cb58968869f9Matt Sweeney Y.DOM.setText(node, content);
82f3694450ab9870df1b580e54d8cb58968869f9Matt Sweeney Assert.areEqual(content, Y.DOM.getText(node, content));
82f3694450ab9870df1b580e54d8cb58968869f9Matt Sweeney },
82f3694450ab9870df1b580e54d8cb58968869f9Matt Sweeney
82f3694450ab9870df1b580e54d8cb58968869f9Matt Sweeney 'should set text for text node': function() {
82f3694450ab9870df1b580e54d8cb58968869f9Matt Sweeney var node = document.createTextNode(''),
82f3694450ab9870df1b580e54d8cb58968869f9Matt Sweeney content = 'testing text content';
82f3694450ab9870df1b580e54d8cb58968869f9Matt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setText(node, content);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(content, Y.DOM.getText(node, content));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Test.Runner.add(new Y.Test.Case({
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney name: 'Y.DOM.elementByAxis',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return the next element': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var root = document.getElementById('test-element-by-axis'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node = root.getElementsByTagName('div')[0];
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(root.getElementsByTagName('span')[0],
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.elementByAxis(node, 'nextSibling'));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return the next node': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var root = document.getElementById('test-element-by-axis'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node = root.getElementsByTagName('div')[0];
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(node.nextSibling,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.elementByAxis(node, 'nextSibling', null, true));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return the next element that passes the test fn': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var root = document.getElementById('test-element-by-axis'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node = root.getElementsByTagName('div')[0],
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney fn = function(node) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney return node.tagName === 'EM';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney };
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(root.getElementsByTagName('em')[0],
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.elementByAxis(node, 'nextSibling', fn));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return the next node that passes the test fn': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var root = document.getElementById('test-element-by-axis'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node = root.getElementsByTagName('div')[0],
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney fn = function(node) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney return node.nodeValue === 'baz';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney };
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(root.getElementsByTagName('span')[0].nextSibling,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.elementByAxis(node, 'nextSibling', fn, true));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return the previous element': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var root = document.getElementById('test-element-by-axis'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node = root.getElementsByTagName('span')[0];
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(root.getElementsByTagName('div')[0],
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.elementByAxis(node, 'previousSibling'));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return the previous node': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var root = document.getElementById('test-element-by-axis'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node = root.getElementsByTagName('span')[0];
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(node.previousSibling,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.elementByAxis(node, 'previousSibling', null, true));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return the previous element that passes the test fn': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var root = document.getElementById('test-element-by-axis'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node = root.getElementsByTagName('EM')[0],
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney fn = function(node) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney return node.tagName === 'DIV';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney };
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(root.getElementsByTagName('div')[0],
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.elementByAxis(node, 'previousSibling', fn));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return the previous node that passes the test fn': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var root = document.getElementById('test-element-by-axis'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node = root.getElementsByTagName('em')[0],
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney fn = function(node) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney return node.nodeValue === 'foo';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney };
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(root.getElementsByTagName('div')[0].previousSibling,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.elementByAxis(node, 'previousSibling', fn, true));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return the parent element': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var root = document.getElementById('test-element-by-axis'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node = root.getElementsByTagName('span')[0];
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(root, Y.DOM.elementByAxis(node, 'parentNode'));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return the ancestor element that passes the test fn': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var root = document.getElementById('test-element-by-axis'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node = root.getElementsByTagName('EM')[0],
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney fn = function(node) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney return node.tagName === 'BODY';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney };
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(document.body,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.elementByAxis(node, 'parentNode', fn));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return null when not found': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var root = document.getElementById('test-element-by-axis'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node = root.firstChild,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney fn = function(node) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney return node.nodeValue === 'foo';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney };
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isNull(Y.DOM.elementByAxis(node, 'previousSibling'));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isNull(Y.DOM.elementByAxis(node, 'previousSibling', fn));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isNull(Y.DOM.elementByAxis(node, 'previousSibling', null, true));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isNull(Y.DOM.elementByAxis(node, 'previousSibling', fn, true));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return null when input is null': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isNull(Y.DOM.elementByAxis(null, 'previousSibling'));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isNull(Y.DOM.elementByAxis(document.body));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return null when input is undefined': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isNull(Y.DOM.elementByAxis());
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney },
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney 'should stop when the stop function returns true': function() {
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney var root = document.getElementById('test-element-by-axis'),
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney node = root.getElementsByTagName('EM')[0],
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney fn = function(node) {
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney return node.tagName === 'BODY';
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney },
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney stopFn = function(node) {
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney return node.id === 'test-ancestor-stop';
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney };
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney Assert.isNull(Y.DOM.elementByAxis(node, 'parentNode', fn, null, stopFn));
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney },
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney 'should find ancestor before stop': function() {
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney var root = document.getElementById('test-element-by-axis'),
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney node = root.getElementsByTagName('EM')[0],
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney fn = function(node) {
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney return node.id === 'test-ancestor-stop';
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney },
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney stopFn = function(node) {
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney return node.tagName === 'BODY';
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney };
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney Assert.areEqual('test-ancestor-stop',
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney Y.DOM.elementByAxis(node, 'parentNode', fn, null, stopFn).id);
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney },
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney 'should find ancestor when both test and stop return true': function() {
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney var root = document.getElementById('test-element-by-axis'),
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney node = root.getElementsByTagName('EM')[0],
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney fn = function(node) {
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney return node.id === 'test-ancestor-stop';
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney },
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney stopFn = function(node) {
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney return node.id === 'test-ancestor-stop';
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney };
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney Assert.areEqual('test-ancestor-stop',
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney Y.DOM.elementByAxis(node, 'parentNode', fn, null, stopFn).id);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Test.Runner.add(new Y.Test.Case({
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney name: 'Y.DOM.ancestor',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return the parent node': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(document.documentElement,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.ancestor(document.body));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return the same node': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(document.body,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.ancestor(document.body, null, true));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return the matching ancestor': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var root = document.getElementById('test-element-by-axis'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node = root.getElementsByTagName('EM')[0],
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney fn = function(node) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney return node.tagName === 'BODY';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney };
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(document.body, Y.DOM.ancestor(node, fn));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return the matching ancestor (test self match)': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var root = document.getElementById('test-element-by-axis'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node = root.getElementsByTagName('EM')[0],
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney fn = function(node) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney return node.tagName === 'EM';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney };
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(node, Y.DOM.ancestor(node, fn, true));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return the matching ancestor (test self not matched)': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var root = document.getElementById('test-element-by-axis'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node = root.getElementsByTagName('EM')[0],
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney fn = function(node) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney return node.tagName === 'BODY';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney };
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(document.body, Y.DOM.ancestor(node, fn, true));
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney },
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney 'should stop when the stop function returns true': function() {
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney var root = document.getElementById('test-element-by-axis'),
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney node = root.getElementsByTagName('EM')[0],
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney fn = function(node) {
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney return node.tagName === 'BODY';
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney },
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney stopFn = function(node) {
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney return node.id === 'test-ancestor-stop';
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney };
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney Assert.isNull(Y.DOM.ancestor(node, fn, null, stopFn));
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney },
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney 'should find ancestor before stop': function() {
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney var root = document.getElementById('test-element-by-axis'),
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney node = root.getElementsByTagName('EM')[0],
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney fn = function(node) {
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney return node.id === 'test-ancestor-stop';
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney },
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney stopFn = function(node) {
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney return node.tagName === 'BODY';
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney };
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney Assert.areEqual('test-ancestor-stop',
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney Y.DOM.ancestor(node, fn, null, stopFn).id);
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney },
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney 'should find ancestor when both test and stop return true': function() {
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney var root = document.getElementById('test-element-by-axis'),
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney node = root.getElementsByTagName('EM')[0],
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney fn = function(node) {
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney return node.id === 'test-ancestor-stop';
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney },
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney stopFn = function(node) {
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney return node.id === 'test-ancestor-stop';
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney };
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney Assert.areEqual('test-ancestor-stop',
80d53e62b2ae5fa5ab6ae4fbcfcbfd8ef5764dd7Matt Sweeney Y.DOM.ancestor(node, fn, null, stopFn).id);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney Y.Test.Runner.add(new Y.Test.Case({
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney name: 'Y.DOM.ancestors',
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney 'should return an array of one (documentElement)': function() {
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney ArrayAssert.itemsAreEqual([document.documentElement],
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney Y.DOM.ancestors(document.body));
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney },
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney 'should include the starting node': function() {
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney var node = document.createElement('div');
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney document.body.appendChild(node);
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney ArrayAssert.itemsAreEqual([document.documentElement, document.body, node],
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney Y.DOM.ancestors(node, null, true));
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney document.body.removeChild(node);
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney },
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney 'should omit the starting node': function() {
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney var node = document.createElement('div');
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney document.body.appendChild(node);
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney ArrayAssert.itemsAreEqual([document.documentElement, document.body],
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney Y.DOM.ancestors(node));
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney document.body.removeChild(node);
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney },
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney 'should return the matching ancestors': function() {
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney var node = document.createElement('div'),
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney fn = function(node) {
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney return node.tagName !== 'HTML';
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney };
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney document.body.appendChild(node);
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney ArrayAssert.itemsAreEqual([document.body], Y.DOM.ancestors(node, fn));
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney document.body.removeChild(node);
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney },
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney 'should return the matching ancestors (test self match)': function() {
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney var root = document.getElementById('test-element-by-axis'),
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney node = root.getElementsByTagName('EM')[0],
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney fn = function(node) {
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney return node.tagName === 'EM';
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney };
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney ArrayAssert.itemsAreEqual([node], Y.DOM.ancestors(node, fn, true));
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney },
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney 'should return the matching ancestors (test self not matched)': function() {
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney var root = document.getElementById('test-element-by-axis'),
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney node = root.getElementsByTagName('EM')[0],
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney fn = function(node) {
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney return node.tagName === 'BODY';
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney };
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney ArrayAssert.itemsAreEqual([document.body], Y.DOM.ancestors(node, fn, true));
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney },
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney 'should stop when the stop function returns true': function() {
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney var root = document.getElementById('test-element-by-axis'),
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney node = root.getElementsByTagName('EM')[0],
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney fn = function(node) {
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney return node.tagName === 'BODY';
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney },
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney stopFn = function(node) {
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney return node.id === 'test-ancestor-stop';
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney };
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney ArrayAssert.itemsAreEqual([], Y.DOM.ancestors(node, fn, null, stopFn));
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney },
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney 'should find ancestor before stop': function() {
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney var root = document.getElementById('test-element-by-axis'),
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney node = root.getElementsByTagName('EM')[0],
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney fn = function(node) {
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney return node.tagName === 'DIV';
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney },
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney stopFn = function(node) {
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney return node.tagName === 'BODY';
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney };
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney ArrayAssert.itemsAreEqual([
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney node.parentNode.parentNode.parentNode,
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney node.parentNode.parentNode,
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney node.parentNode
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney ],
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney Y.DOM.ancestors(node, fn, null, stopFn));
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney },
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney 'should find ancestor when both test and stop return true': function() {
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney var root = document.getElementById('test-element-by-axis'),
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney node = root.getElementsByTagName('EM')[0],
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney fn = function(node) {
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney return node.tagName === 'DIV';
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney },
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney stopFn = function(node) {
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney return node.tagName === 'DIV';
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney };
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney Assert.areEqual(1,
deb3172da8a688abb44a22d5b084c4dd0437df89Matt Sweeney Y.DOM.ancestors(node, fn, null, stopFn).length);
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney }
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney }));
aab1eeae8965892252706bf128f878101c5a01b1Matt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Test.Runner.add(new Y.Test.Case({
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney name: 'Y.DOM.contains',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'html element should contain body element': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isTrue(Y.DOM.contains(document.documentElement, document.body));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'body element should not contain html element': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM.contains(document.body, document.documentElement));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should be true for contained element': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.body.appendChild(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isTrue(Y.DOM.contains(document.body, node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.body.removeChild(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should be false for uncontained element': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM.contains(document.body, node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should be true when element is element': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isTrue(Y.DOM.contains(document.body, document.body));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should be true for contained text node': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createTextNode('foo');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.body.appendChild(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isTrue(Y.DOM.contains(document.documentElement, node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.body.removeChild(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should be false for uncontained text node': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createTextNode('foo');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM.contains(document.body, node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return false for null input': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.body.appendChild(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM.contains(document.body, null));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM.contains(null, node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM.contains(null, null));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.body.removeChild(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return false for undefined input': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM.contains(document.body));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM.contains());
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Test.Runner.add(new Y.Test.Case({
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney name: 'Y.DOM._bruteContains',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'html element should contain body element': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isTrue(Y.DOM._bruteContains(document.documentElement, document.body));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'body element should not contain html element': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM._bruteContains(document.body, document.documentElement));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should be true for contained element': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.body.appendChild(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isTrue(Y.DOM._bruteContains(document.body, node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.body.removeChild(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should be false for uncontained element': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM._bruteContains(document.body, node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should be true when element is element': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isTrue(Y.DOM._bruteContains(document.body, document.body));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should be true for contained text node': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createTextNode('foo');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.body.appendChild(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isTrue(Y.DOM._bruteContains(document.documentElement, node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.body.removeChild(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should be false for uncontained text node': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createTextNode('foo');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM._bruteContains(document.body, node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return false for null input': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.body.appendChild(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM._bruteContains(document.body, null));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM._bruteContains(null, node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM._bruteContains(null, null));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.body.removeChild(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return false for undefined input': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM._bruteContains(document.body));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM._bruteContains());
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Test.Runner.add(new Y.Test.Case({
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney name: 'Y.DOM.inDoc',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return false for off document node': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM.inDoc(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return true for in document node': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isTrue(Y.DOM.inDoc(document.body));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return false for removed node': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.body.appendChild(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.body.removeChild(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM.inDoc(node), 'removed');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should work with duplicate IDs in document': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var nodes = document.getElementById('test-dupe-ids')
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney .getElementsByTagName('span');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isTrue(Y.DOM.inDoc(nodes[2]));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should work with duplicate IDs off document': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node.id = 'test-dupe-id';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM.inDoc(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should work with form that has input name="id" and id="id"': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-names');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isTrue(Y.DOM.inDoc(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return false when input is null': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM.inDoc(null));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return false for cloned node off document': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-id');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node = node.cloneNode(true);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM.inDoc(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return true for cloned node in document (same id)': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-id');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node = node.cloneNode(true);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.body.appendChild(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isTrue(Y.DOM.inDoc(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.body.removeChild(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return true for cloned node in document (new id)': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-id');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node = node.cloneNode(true);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node.id = 'test-id-new';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.body.appendChild(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isTrue(Y.DOM.inDoc(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.body.removeChild(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Test.Runner.add(new Y.Test.Case({
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney name: 'Y.DOM.create',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create empty div': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create(('<div/>'));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('DIV', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('', el.innerHTML);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should trim leading space': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create((' <div/>'));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('DIV', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('', el.innerHTML);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create empty div (self-closed input)': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create(('<div/>'));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('DIV', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('', el.innerHTML);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create div with text': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create(('<div>foo</div>'));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('DIV', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('foo', el.innerHTML);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create div with innerHTML': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create(('<div><em>bar</em></div>'));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('DIV', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('<em>bar</em>', el.innerHTML.toLowerCase());
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create input type submit': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<input name="foo" value="bar" type="submit">');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('INPUT', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('submit', el.type);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('foo', el.name);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('bar', el.value);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create input type radio': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<input name="test-input" type="radio">');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('INPUT', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('radio', el.type);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create form': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<form/>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('FORM', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a form with content': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<form><fieldset><legend>foo</legend>' +
83bac8606b329c30526704e0950e886c89bfde48Matt Sweeney '<label>foo:</label><input name="foo"><input type="submit"></fieldset></form>'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney fieldset = el.firstChild,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney legend = fieldset.firstChild;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney label = legend.nextSibling,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney input = label.nextSibling;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney submit = input.nextSibling;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('FORM', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('FIELDSET', fieldset.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('LEGEND', legend.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('LABEL', label.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('INPUT', input.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('foo', input.name);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('INPUT', submit.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('submit', submit.type);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create legend': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<legend/>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('LEGEND', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create fieldset': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<fieldset/>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('FIELDSET', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create label': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<label/>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('LABEL', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a list item': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<li>fresh</li>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('LI', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('fresh', el.innerHTML);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a one item list': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney el = Y.DOM.create('<ul><li>fresh</li></ul>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(1, el.childNodes.length);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a table': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<table/>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('TABLE', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a table with content': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<table><tr><td>foo</td><td>bar</td></tr></table>'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney tbody = el.firstChild,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney tr = el.firstChild.firstChild,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney td = tr.firstChild;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('TABLE', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('TBODY', tbody.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('TR', tr.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('TD', td.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('TD', td.nextSibling.tagName, 'td 2');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a table head': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<thead></thead>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('THEAD', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
1c8e83505eae7560612e069a40097601f35c7dc0Matt Sweeney 'should create a table head from uppercase': function() {
1c8e83505eae7560612e069a40097601f35c7dc0Matt Sweeney var el = Y.DOM.create('<THEAD></THEAD>');
1c8e83505eae7560612e069a40097601f35c7dc0Matt Sweeney Assert.areEqual('THEAD', el.tagName);
1c8e83505eae7560612e069a40097601f35c7dc0Matt Sweeney },
1c8e83505eae7560612e069a40097601f35c7dc0Matt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a table head with nested table': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<thead><tr><td><table><tbody><tr>' +
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney '<td>fresh</td></tr></tbody></table></td></tr></thead>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('THEAD', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(1, el.getElementsByTagName('table').length);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a table heading cell': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<th>fresh</th>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('TH', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('fresh', el.innerHTML);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a caption': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<caption>fresh</caption>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('CAPTION', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('fresh', el.innerHTML);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a colgroup': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<colgroup/>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('COLGROUP', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a col element': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<col>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('COL', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a colgroup with col elements': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<colgroup><col><col></colgroup>'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney nodes = el.childNodes,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney i = 0,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney cols = [],
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney child;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney // IE inserts a linefeed between cols
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney while((child = nodes[i++])) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney if (child.nodeName === 'COL') {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney cols.push(child);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('COLGROUP', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('COL', cols[0].tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('COL', cols[1].tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a table row': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<tr/>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('TR', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a table row with content': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<tr><td>foo</td><td>bar</td></tr>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('TR', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('TD', el.firstChild.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('TD', el.firstChild.nextSibling.tagName, 'td 2');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a table cell': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<td/>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('TD', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a table cell with content': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<td>fresh</td>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('TD', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('fresh', el.innerHTML);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a button element': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<button>fresh</button>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('BUTTON', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create an optgroup element': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<optgroup></optgroup>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('OPTGROUP', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create an optgroup with an option': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<optgroup><option>foo</option></optgroup>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('OPTGROUP', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('OPTION', el.firstChild.tagName, 'option');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create an optgroup with options': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<optgroup><option>foo</option><option>bar</option></optgroup>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('OPTGROUP', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('OPTION', el.firstChild.tagName, 'option');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('OPTION', el.firstChild.nextSibling.tagName, 'option 2');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a select element': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<select/>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('SELECT', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a select with an option': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<select><option>foo</option></select>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('SELECT', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('OPTION', el.firstChild.tagName, 'option');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a select with options': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<select><option>foo</option><option>bar</option></select>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('SELECT', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('OPTION', el.firstChild.tagName, 'option');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('OPTION', el.firstChild.nextSibling.tagName, 'option 2');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a option element': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<option/>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('OPTION', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a option with content': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<option><foo</option>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('OPTION', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a selected option': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<option selected><foo</option>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('OPTION', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create an iframe (self-closed)': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<iframe/>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('IFRAME', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create an iframe': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<iframe src="http://search.yahoo.com/" id="yui-iframetest"></iframe>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('IFRAME', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create an iframe with attributes': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var html = '<iframe border="0" frameBorder="0" marginWidth="0"' +
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney ' marginHeight="0" leftMargin="0" topMargin="0"' +
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney ' allowTransparency="true" width="100%" height="99%"></iframe>';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney el = Y.DOM.create(html);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('IFRAME', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(0, el.frameBorder);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(document, el.ownerDocument);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a script': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<scr' + 'ipt/>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('SCRIPT', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a script with src': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<scr' + 'ipt src="http://search.yahoo.com/"></scr' + 'ipt>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('SCRIPT', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('http://search.yahoo.com/', el.src);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a link element': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<link/>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('LINK', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a link element with attrs': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('<link href="http://search.yahoo.com/" rel="stylesheet">');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('LINK', el.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('http://search.yahoo.com/', el.href);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(el.rel, 'stylesheet');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should create a textNode': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var el = Y.DOM.create('text');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(3, el.nodeType);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return a fragment when creating a collection': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var html = '<div>foo</div><div id="tmp-bar">bar</div><div>baz</div>',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney el = Y.DOM.create(html);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(11, el.nodeType);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(3, el.childNodes.length);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('tmp-bar', el.childNodes[1].id);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('foo', el.childNodes[0].innerHTML);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return a fragment containing options': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var html = '<option>foo</option><option id="tmp-bar">bar</option><option>baz</option>',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney el = Y.DOM.create(html);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(11, el.nodeType);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(3, el.childNodes.length);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('tmp-bar', el.childNodes[1].id);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return a fragment including text nodes': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var html = 'foo <span>bar</span> baz',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney el = Y.DOM.create(html);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(11, el.nodeType);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(3, el.childNodes[0].nodeType);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(1, el.childNodes[1].nodeType);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(3, el.childNodes[2].nodeType);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return a fragment with the correct selected option': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var html = '<option>foo</option><option selected>bar</option><option>baz</option>';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney el = Y.DOM.create(html);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(11, el.nodeType);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(3, el.childNodes.length);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isTrue(el.childNodes[1].selected);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return a fragment containing table cells': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var html = '<td>foo</td><td id="tmp-bar">bar</td><td>baz</td>',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney el = Y.DOM.create(html);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(11, el.nodeType);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(3, el.childNodes.length);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('tmp-bar', el.childNodes[1].id);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return a fragment containing col elements': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var html = '<col><col>',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney el = Y.DOM.create(html);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(11, el.nodeType);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(2, el.childNodes.length);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('COL', el.childNodes[0].tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('COL', el.childNodes[1].tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return a fragment containing table bodies': function() {
14dc4f889a7b6c39f10aa490ea3c4c69de5e99bbMatt Sweeney var html = '<tbody><tr><td>foo</td></tr></tbody><tbody id="tmp-bar"><tr><td>bar</td></tr></tbody><tbody><tr><td>bar</td></tr></tbody>',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney el = Y.DOM.create(html);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(11, el.nodeType);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(3, el.childNodes.length);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('TBODY', el.childNodes[0].tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('TBODY', el.childNodes[1].tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('tmp-bar', el.childNodes[1].id);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return a fragment containing thead with nested table and tbody': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var html = '<thead><tr><td><table><tbody><tr><td>fresh</td></tr>' +
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney '</tbody></table></td></tr></thead><tbody></tbody>',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney el = Y.DOM.create(html);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(11, el.nodeType);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(2, el.childNodes.length);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('THEAD', el.firstChild.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(1, el.firstChild.getElementsByTagName('table').length);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('TBODY', el.childNodes[1].tagName);
510f536d1be251eaf69272bd5b0b9a1f953683d9Matt Sweeney },
510f536d1be251eaf69272bd5b0b9a1f953683d9Matt Sweeney
510f536d1be251eaf69272bd5b0b9a1f953683d9Matt Sweeney 'should return null when given null input': function() {
510f536d1be251eaf69272bd5b0b9a1f953683d9Matt Sweeney var html = null,
510f536d1be251eaf69272bd5b0b9a1f953683d9Matt Sweeney el = Y.DOM.create(html);
510f536d1be251eaf69272bd5b0b9a1f953683d9Matt Sweeney
510f536d1be251eaf69272bd5b0b9a1f953683d9Matt Sweeney Assert.areEqual(null, el);
510f536d1be251eaf69272bd5b0b9a1f953683d9Matt Sweeney },
510f536d1be251eaf69272bd5b0b9a1f953683d9Matt Sweeney
510f536d1be251eaf69272bd5b0b9a1f953683d9Matt Sweeney 'should return null when given undefined input': function() {
510f536d1be251eaf69272bd5b0b9a1f953683d9Matt Sweeney var html = undefined,
510f536d1be251eaf69272bd5b0b9a1f953683d9Matt Sweeney el = Y.DOM.create(html);
510f536d1be251eaf69272bd5b0b9a1f953683d9Matt Sweeney
510f536d1be251eaf69272bd5b0b9a1f953683d9Matt Sweeney Assert.areEqual(null, el);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Test.Runner.add(new Y.Test.Case({
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney name: 'Y.DOM.getAttribute',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return "className" value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node.className = 'foo';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('foo', Y.DOM.getAttribute(node, 'class'), 'class');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('foo', Y.DOM.getAttribute(node, 'className'), 'className');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return "for" value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('for-id');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('id', Y.DOM.getAttribute(node, 'for'));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('id', Y.DOM.getAttribute(node, 'htmlFor'));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should handle bad input': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.getAttribute(null);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.getAttribute();
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isTrue(true);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Test.Runner.add(new Y.Test.Case({
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney name: 'Y.DOM.setAttribute',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should set className': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setAttribute(node, 'class', 'foo');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('foo', node.className);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setAttribute(node, 'className', 'bar');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('bar', node.className);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should set "for" attribute': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('label');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setAttribute(node, 'for', 'foo');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('foo', node.htmlFor);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setAttribute(node, 'htmlFor', 'bar');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('bar', node.htmlFor);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should handle bad input': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setAttribute(null, 'bar');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setAttribute(node, null);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setAttribute();
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isTrue(true);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Test.Runner.add(new Y.Test.Case({
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney name: 'Y.DOM.getValue',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'input value should match html value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-text-value'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = 'test value';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'input value should match no html value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-text-no-value'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = '';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'input value should match empty html value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-text-empty-value'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = '';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'textarea value should match html value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-textarea-text-value'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = 'textarea test';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'textarea value should match no html value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-textarea-no-value'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = '';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should ignore textarea html value attribute': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-textarea-value');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('', Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'select value should match html value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-select-value');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = 'option value';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'select value should match no html value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-select-no-value'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = '';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'select value should match empty html value with text': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-select-empty-value-text'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = '';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'select value should match empty html value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-select-empty-value'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = '';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'option value should match html value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-option-value');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = 'option value';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'option value should match html content': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-option-value-text');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = 'option text';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'option value should match no html value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-option-no-value'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = '';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'option value should match empty html value with text': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-select-empty-value-text'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = '';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'option value should match empty html value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-select-empty-value'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = '';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'button value should match html value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-button-value');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = 'button value';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'button value should match no html value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-button-no-value'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = '';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'button value should ignore html content': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-button-text-value');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = '';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'button value should match empty value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-button-empty-value');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = '';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Test.Runner.add(new Y.Test.Case({
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney name: 'Y.DOM.setValue',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'input value should match updated value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-text-value'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = 'new value';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setValue(node, val);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setValue(node, 'test value');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'value updated from empty string should be new value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-text-empty-value'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = 'new value';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setValue(node, val);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setValue(node, '');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'value updated from no value should be new value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-text-no-value'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = 'new value';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setValue(node, val);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setValue(node, '');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node.removeAttribute('value')
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'textarea from html value should match new value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-textarea-text-value'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = 'new textarea test';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setValue(node, val);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setValue('textarea test');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'textarea from no value should match new value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-textarea-no-value'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = 'new textarea test';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setValue(node, val);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setValue('');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'button value should match updated value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-button-value'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = 'new value';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setValue(node, val);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setValue(node, 'test value');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'button value updated from empty string should be new value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-button-empty-value'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = 'new value';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setValue(node, val);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setValue(node, '');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'button value updated from no value should be new value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-button-no-value'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = 'new value';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setValue(node, val);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setValue(node, '');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node.removeAttribute('value')
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'option value should match updated value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-option-value'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = 'new value';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setValue(node, val);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setValue(node, 'test value');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'option value updated from text should be new value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-option-value-text'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = 'new value';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setValue(node, val);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setValue(node, '');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'option value updated from empty string should be new value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-option-empty-value'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = 'new value';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setValue(node, val);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setValue(node, '');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'option value updated from no value should be new value': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-option-no-value'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = 'new value';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setValue(node, val);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, Y.DOM.getValue(node));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.setValue(node, '');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node.removeAttribute('value')
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Test.Runner.add(new Y.Test.Case({
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney name: 'Y.DOM._nl2Frag',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return fragment from HTMLCollection': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney frag;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node.innerHTML = '<div>foo</div><div>bar</div><div>baz</div>';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney frag = Y.DOM._nl2frag(node.childNodes);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Assert.areEqual(11, frag.nodeType);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Assert.areEqual(3, frag.childNodes.length);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return fragment from Array of HTML Elements': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var nodes = [
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.createElement('div'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.createElement('div'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney document.createElement('div')
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney ],
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney frag = Y.DOM._nl2frag(nodes);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Assert.areEqual(11, frag.nodeType);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Assert.areEqual(3, frag.childNodes.length);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return null for bad input': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isNull(Y.DOM._nl2frag({}));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isNull(Y.DOM._nl2frag());
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isNull(Y.DOM._nl2frag(''));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isNull(Y.DOM._nl2frag(1));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Test.Runner.add(new Y.Test.Case({
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney name: 'Y.DOM.isWindow',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return true for window object': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isTrue(Y.DOM.isWindow(window));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return true for frame window object': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var frame = document.getElementById('test-frame'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney doc = frame.contentWindow.document,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney win = doc.defaultView || doc.parentWindow;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isTrue(Y.DOM.isWindow(win));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return false for document object': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM.isWindow(document));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return false for non-window input': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM.isWindow());
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM.isWindow(null));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM.isWindow(1));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isFalse(Y.DOM.isWindow(document.body));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Test.Runner.add(new Y.Test.Case({
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney name: 'Y.DOM._removeChildNodes',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should remove all childNodes': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney html = '<em>foo</em><strong>bar</strong><span>baz</span>';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node.innerHTML = html;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM._removeChildNodes(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(0, node.childNodes.length);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Test.Runner.add(new Y.Test.Case({
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney name: 'Y.DOM.addHTML',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should append the given html to the node': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.addHTML(node, '<em>new content</em>');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('EM', node.lastChild.nodeName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should prepend the given html to the node': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node.innerHTML = '<strong>bar</strong>';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.addHTML(node, '<em>new content</em>', node.firstChild);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('EM', node.firstChild.nodeName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should insert the given html after the first child': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node.innerHTML = '<em>foo</em><strong>bar</strong>';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.addHTML(node, '<span>new content</span>', node.childNodes[1]);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('SPAN', node.childNodes[1].nodeName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should append the given node': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.addHTML(node, document.createElement('div'));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('DIV', node.firstChild.nodeName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should add html before the given node': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node.innerHTML = '<em>foo</em><strong>bar</strong>';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.addHTML(node.childNodes[1], '<span>new content</span>', 'before');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('SPAN', node.childNodes[1].nodeName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should add html after the given node': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node.innerHTML = '<em>foo</em><strong>bar</strong>';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM.addHTML(node.childNodes[1], '<span>new content</span>', 'after');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('SPAN', node.childNodes[2].nodeName);
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney },
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney 'should replace the existing content (empty string)': function() {
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney var node = document.createElement('div');
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney node.innerHTML = '<em>foo</em><strong>bar</strong>';
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney Y.DOM.addHTML(node, '', 'replace');
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney Assert.areEqual(0, node.childNodes.length);
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney },
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney 'should replace the existing content (null)': function() {
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney var node = document.createElement('div');
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney node.innerHTML = '<em>foo</em><strong>bar</strong>';
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney Y.DOM.addHTML(node, null, 'replace');
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney Assert.areEqual(0, node.childNodes.length);
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney },
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney 'should replace the existing content (undefined)': function() {
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney var node = document.createElement('div');
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney node.innerHTML = '<em>foo</em><strong>bar</strong>';
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney Y.DOM.addHTML(node, undefined, 'replace');
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney Assert.areEqual(0, node.childNodes.length);
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney },
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney 'should replace the existing content (0)': function() {
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney var node = document.createElement('div');
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney node.innerHTML = '<em>foo</em><strong>bar</strong>';
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney Y.DOM.addHTML(node, 0, 'replace');
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney Assert.areEqual(1, node.childNodes.length);
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney Assert.areEqual(3, node.firstChild.nodeType);
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney },
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney
59f175924390b0e7cf15bcae6f4e894b893259b4Matt Sweeney
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney 'should append the given nodelist': function() {
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney var node = document.createElement('div'),
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney node2 = document.createElement('div'),
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney nodelist;
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney node.innerHTML = '<em>foo</em><strong>bar</strong>';
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney nodelist = node.getElementsByTagName('*');
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney Y.DOM.addHTML(node2, nodelist);
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney Assert.areEqual('EM', node2.childNodes[0].nodeName);
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney },
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney 'should insert the given nodelist before the given node': function() {
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney var node = document.createElement('div'),
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney node2 = document.createElement('div'),
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney nodelist;
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney node.innerHTML = '<em>foo</em><strong>bar</strong>';
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney node2.innerHTML = '<span>baz</span><b>foobar</b>';
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney nodelist = node.getElementsByTagName('*');
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney Y.DOM.addHTML(node2, nodelist, node2.firstChild.nextSibling);
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney Assert.areEqual('EM', node2.childNodes[1].nodeName);
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney },
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney 'should prepend the given nodelist': function() {
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney var node = document.createElement('div'),
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney node2 = document.createElement('div'),
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney nodelist;
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney node.innerHTML = '<em>foo</em><strong>bar</strong>';
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney node2.innerHTML = '<span>baz</span><b>foobar</b>';
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney nodelist = node.getElementsByTagName('*');
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney Y.DOM.addHTML(node2, nodelist, node2.firstChild);
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney
cf44c6be4a920ebd3f8ac3143e387dda03dc7208Matt Sweeney Assert.areEqual('EM', node2.childNodes[0].nodeName);
2291c2a0c5280ce4cee43acf12a9a3df24f253f1Matt Sweeney },
2291c2a0c5280ce4cee43acf12a9a3df24f253f1Matt Sweeney
2291c2a0c5280ce4cee43acf12a9a3df24f253f1Matt Sweeney 'should append the given number': function() {
2291c2a0c5280ce4cee43acf12a9a3df24f253f1Matt Sweeney var node = document.createElement('div');
2291c2a0c5280ce4cee43acf12a9a3df24f253f1Matt Sweeney Y.DOM.addHTML(node, 0);
2291c2a0c5280ce4cee43acf12a9a3df24f253f1Matt Sweeney
2291c2a0c5280ce4cee43acf12a9a3df24f253f1Matt Sweeney Assert.areEqual('0', node.innerHTML);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Test.Runner.add(new Y.Test.Case({
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney name: 'Y.DOM._getRegExp',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return RegExp obj': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var re = Y.DOM._getRegExp('^foo$');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.isTrue(typeof re.test === 'function');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return cached RegExp obj': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var re = Y.DOM._getRegExp('^foo$'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney re2 = Y.DOM._getRegExp('^foo$');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areSame(re, re2);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return new RegExp obj': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var re = Y.DOM._getRegExp('^foo$'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney re2 = Y.DOM._getRegExp('^foos$'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney re3 = Y.DOM._getRegExp('^foo$', 'g');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areNotSame(re, re2);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areNotSame(re, re3);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Test.Runner.add(new Y.Test.Case({
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney name: 'Y.DOM._getDoc',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return document from body': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var doc = Y.DOM._getDoc(document.body);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areSame(document, doc);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return document from new node': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var doc = Y.DOM._getDoc(document.createElement('div'));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areSame(document, doc);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return document from window': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var doc = Y.DOM._getDoc(window);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areSame(document, doc);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return document from document': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var doc = Y.DOM._getDoc(window);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areSame(document, doc);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return iframe document from iframe window': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var win = document.getElementById('test-frame').contentWindow,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney doc = Y.DOM._getDoc(win);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areSame(win.document, doc);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return iframe document from iframe node': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var win = document.getElementById('test-frame').contentWindow,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney doc = Y.DOM._getDoc(win.document.getElementById('demo'));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areSame(win.document, doc);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return iframe document from iframe document': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var win = document.getElementById('test-frame').contentWindow,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney doc = Y.DOM._getDoc(win.document);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areSame(win.document, doc);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Test.Runner.add(new Y.Test.Case({
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney name: 'Y.DOM._getWin',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return window from body': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var win = Y.DOM._getWin(document.body);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areSame(window.window, win.window);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return window from new node': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var win = Y.DOM._getWin(document.createElement('div'));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areSame(window.window, win.window);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return window from window': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var win = Y.DOM._getWin(window);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areSame(window.window, window.window);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return window from document': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var win = Y.DOM._getWin(window);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areSame(window.window, win.window);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return iframe window from iframe window': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.getElementById('test-frame'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney win = Y.DOM._getWin(node.contentWindow);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areSame(node.contentWindow.window, win.window);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return iframe window from iframe node': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var contentWin = document.getElementById('test-frame').contentWindow,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney win = Y.DOM._getWin(contentWin.document.getElementById('demo'));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areSame(contentWin.window, win.window);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should return iframe window from iframe document': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var contentWin = document.getElementById('test-frame').contentWindow,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney win = Y.DOM._getWin(contentWin.document);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areSame(contentWin.window, win.window);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Test.Runner.add(new Y.Test.Case({
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney name: 'Y.DOM._batch',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should append html on all nodes in HTMLCollection': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = '<p>new text</p>';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node.innerHTML = '<span></span><span></span><span></span>';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM._batch(node.childNodes, 'addHTML', val);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('P', node.childNodes[0].firstChild.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('P', node.childNodes[1].firstChild.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual('P', node.childNodes[2].firstChild.tagName);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney 'should setText on all nodes in HTMLCollection': function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var node = document.createElement('div'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney val = 'new text';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node.innerHTML = '<span>foo</span><span>bar</span><span>baz</span>',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.DOM._batch(node.childNodes, 'setText', val);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, node.childNodes[0].innerHTML);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, node.childNodes[1].innerHTML);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Assert.areEqual(val, node.childNodes[2].innerHTML);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Test.Runner.add(new Y.Test.Case({
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney name: 'Y.DOM.siblings',
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney 'should return all sibling nodes (firstChild)': function() {
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney var parent = Y.DOM.byId('test-siblings'),
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney node = parent.getElementsByTagName('em')[0],
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney node2 = parent.getElementsByTagName('span')[0],
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney node3 = parent.getElementsByTagName('strong')[0],
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney siblings = Y.DOM.siblings(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney ArrayAssert.itemsAreEqual(siblings, [node2, node3]);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney 'should return all sibling nodes (lastChild)': function() {
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney var parent = Y.DOM.byId('test-siblings'),
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney node = parent.getElementsByTagName('strong')[0],
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney node2 = parent.getElementsByTagName('em')[0],
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney node3 = parent.getElementsByTagName('span')[0],
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney siblings = Y.DOM.siblings(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney ArrayAssert.itemsAreEqual(siblings, [node2, node3]);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney 'should return all sibling nodes': function() {
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney var parent = Y.DOM.byId('test-siblings'),
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney node = parent.getElementsByTagName('span')[0],
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney node2 = parent.getElementsByTagName('em')[0],
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney node3 = parent.getElementsByTagName('strong')[0],
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney siblings = Y.DOM.siblings(node);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney ArrayAssert.itemsAreEqual(siblings, [node2, node3]);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney 'should return all matching sibling nodes': function() {
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney var parent = Y.DOM.byId('test-siblings'),
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney node = parent.getElementsByTagName('span')[0],
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney node2 = parent.getElementsByTagName('em')[0],
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney node3 = parent.getElementsByTagName('strong')[0],
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney siblings = Y.DOM.siblings(node, function(n) {
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney return n.tagName === 'STRONG';
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney });
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney ArrayAssert.itemsAreEqual(siblings, [node3]);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney Y.Test.Runner.add(new Y.Test.Case({
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney name: 'Y.DOM.wrap',
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney 'should wrap the node with the given html': function() {
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney var node = document.createElement('span');
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney Y.DOM.wrap(node, '<p></p>');
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney Assert.areEqual('P', node.parentNode.tagName);
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney },
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney 'should wrap the node with the given complex html': function() {
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney var node = document.createElement('span');
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney Y.DOM.wrap(node, '<p><em><strong><span></span></strong></em></p>');
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney Assert.areEqual('SPAN', node.parentNode.tagName);
5e366c4598b5b84847ec142b157bae6e29041a4dMatt Sweeney },
5e366c4598b5b84847ec142b157bae6e29041a4dMatt Sweeney
5e366c4598b5b84847ec142b157bae6e29041a4dMatt Sweeney 'should wrap the paragraph with a div': function() {
5e366c4598b5b84847ec142b157bae6e29041a4dMatt Sweeney var node = Y.DOM.create('<p>Hello World</p>');
5e366c4598b5b84847ec142b157bae6e29041a4dMatt Sweeney Y.DOM.wrap(node, '<div/>');
5e366c4598b5b84847ec142b157bae6e29041a4dMatt Sweeney Assert.areEqual('DIV', node.parentNode.tagName);
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney }
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney }));
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney Y.Test.Runner.add(new Y.Test.Case({
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney name: 'Y.DOM.unwrap',
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney 'should remove the node\'s parent': function() {
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney var node = document.createElement('span').appendChild(document.createElement('em'));
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney Y.DOM.unwrap(node);
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney Assert.isTrue(!node.parentNode || node.parentNode.nodeType !== 1);
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney },
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney 'should remove the node\'s parent and replace in DOM': function() {
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney var parent = document.createElement('span'),
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney node = parent.appendChild(document.createElement('strong')).
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney appendChild(document.createElement('em'));
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney document.body.insertBefore(parent, document.body.firstChild);
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney Y.DOM.unwrap(node);
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney Assert.areEqual('SPAN', node.parentNode.tagName);
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney document.body.removeChild(node.parentNode);
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney },
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney 'should remove the node\'s parent and replace in DOM with siblings (node as firstChild)': function() {
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney var parent = document.createElement('div'),
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney node;
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney parent.innerHTML = '<p><em>bar</em><strong>baz</strong><span>foo</span></p>';
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney node = parent.getElementsByTagName('em')[0];
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney Y.DOM.unwrap(node);
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney Assert.areEqual('DIV', node.parentNode.tagName);
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney Assert.isNull(node.previousSibling);
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney Assert.areEqual('STRONG', node.nextSibling.tagName);
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney Assert.areEqual('DIV', node.nextSibling.parentNode.tagName);
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney Assert.areEqual('SPAN', node.nextSibling.nextSibling.tagName);
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney },
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney 'should remove the node\'s parent and replace in DOM with siblings': function() {
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney var parent = document.createElement('div'),
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney node;
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney parent.innerHTML = '<p><span>foo</span><em>bar</em><strong>baz</strong></p>';
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney node = parent.getElementsByTagName('em')[0];
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney Y.DOM.unwrap(node);
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney Assert.areEqual('DIV', node.parentNode.tagName);
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney Assert.areEqual('SPAN', node.previousSibling.tagName);
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney Assert.areEqual('DIV', node.previousSibling.parentNode.tagName);
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney Assert.areEqual('STRONG', node.nextSibling.tagName);
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney Assert.areEqual('DIV', node.nextSibling.parentNode.tagName);
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney }
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney }));
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney Y.Test.Runner.add( new Y.Test.Case({
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney name: 'Y.DOM.getId',
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney 'should get the id from the DIV': function() {
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney var element = document.createElement('div'),
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney id = 'test-id';
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney element.id = id;
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney Assert.areEqual(id, Y.DOM.getId(element));
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney },
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney 'should get the id from the new form element': function() {
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney var element = document.createElement('form'),
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney id = 'test-form-id';
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney element.id = id;
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney Assert.areEqual(id, Y.DOM.getId(element));
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney },
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney 'should get the id from the new form element (setAttribute)': function() {
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney var element = document.createElement('form'),
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney id = 'test-form-id';
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney element.setAttribute('id', id);
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney Assert.areEqual(id, Y.DOM.getId(element));
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney },
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney 'should get the id from the new form element rather than the named input': function() {
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney var element = document.createElement('form'),
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney input = document.createElement('input'),
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney id = 'test-form-id';
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney input.name = 'id';
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney element.id = id;
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney Assert.areEqual(id, Y.DOM.getId(element));
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney },
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney 'should get the id from the new form rather than the named input (setAttribute)': function() {
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney var element = document.createElement('form'),
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney input = document.createElement('input'),
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney id = 'test-form-id';
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney input.name = 'id';
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney element.setAttribute('id', id);
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney Assert.areEqual(id, Y.DOM.getId(element));
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney },
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney 'should get the id from the form rather than the named input': function() {
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney var element = document.getElementsByTagName('form')[0];
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney Assert.areEqual('test-names', Y.DOM.getId(element));
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney }
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney }));
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney Y.Test.Runner.add( new Y.Test.Case({
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney name: 'Y.DOM.setId',
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney 'should set the id on the DIV': function() {
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney var element = document.createElement('div'),
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney id = 'test-id';
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney Y.DOM.setId(element, id);
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney Assert.areEqual(id, element.id);
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney },
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney 'should set the id on the FORM': function() {
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney var element = document.createElement('form'),
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney id = 'test-id';
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney Y.DOM.setId(element, id);
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney Assert.areEqual(id, element.id);
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney },
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney 'should set the id on the FORM with a named INPUT': function() {
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney var element = document.createElement('form'),
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney input = document.createElement('input'),
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney id = 'test-id';
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney input.name = 'id';
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney input.value = 'foo';
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney Y.DOM.setId(element, id);
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney Assert.areEqual(id, element.id);
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney Assert.areEqual(id, Y.DOM.getId(element));
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney },
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney 'should set the id on the FORM with an INPUT id === "id"': function() {
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney var element = document.createElement('form'),
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney input = document.createElement('input'),
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney id = 'test-id';
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney input.id = 'id';
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney Y.DOM.setId(element, id);
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney Assert.areEqual(id, element.id);
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney Assert.areEqual(id, Y.DOM.getId(element));
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney }
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney }));
b563272ca356962156a763b23e4736d0197b9134Matt Sweeney
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney Y.Test.Runner.add( new Y.Test.Case({
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney name: 'Y.DOM.generateID',
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney 'should generate an ID': function() {
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney var node = document.createElement('div'),
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney id = Y.DOM.generateID(node);
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney Assert.isNotNull(id);
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney Assert.areEqual(node.id, id);
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney },
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney 'should return exising ID': function() {
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney var node = document.createElement('div'),
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney id = 'foo';
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney node.id = id;
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney Y.DOM.generateID(node);
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney Assert.areEqual('foo', node.id);
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney Assert.areEqual('foo', id);
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney }
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney }));
3489fc6bb1b5c6100aead509cd90048e4bb61617Matt Sweeney
d84031076fc432d8aae518149d34d0299805466cMatt Sweeney}, '@VERSION@' ,{requires:['dom-core', 'test']});