1 /* 2 Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. 3 For licensing, see LICENSE.html or http://ckeditor.com/license 4 */ 5 6 /** 7 * @fileOverview Defines the {@link CKEDITOR.test} object, which contains 8 * functions used at our testing environment. 9 */ 10 11 /*jsl:import ../tests/yuitest.js*/ 12 13 /** 14 * Contains functions used at our testing environment. Currently, 15 * our testing system is based on the 16 * <a href="http://developer.yahoo.com/yui/yuitest/">YUI Test</a>. 17 * @namespace 18 * @example 19 */ 20 CKEDITOR.test = 21 { 22 /** 23 * The assertion namespace, containing all assertion functions. Currently, 24 * this is an alias for 25 * <a href="http://developer.yahoo.com/yui/docs/YAHOO.util.Assert.html">YAHOO.util.Assert</a>. 26 * @example 27 * <b>CKEDITOR.test.assert</b>.areEqual( '10', 10 ); // "true" 28 * <b>CKEDITOR.test.assert</b>.areSame( '10', 10 ); // "false" 29 * <b>CKEDITOR.test.assert</b>.isUndefined( window.test ); // "true" 30 */ 31 assert : YAHOO.util.Assert, 32 33 /** 34 * Adds a test case to the test runner. 35 * @param {Object} testCase The test case object. See other tests for 36 * examples. 37 * @example 38 * <b>CKEDITOR.test.addTestCase</b>((function() 39 * { 40 * // Local reference to the "assert" object. 41 * var assert = CKEDITOR.test.assert; 42 * 43 * return { 44 * test_example : function() 45 * { 46 * assert.areSame( '10', 10 ); // FAIL 47 * } 48 * }; 49 * })()); 50 */ 51 addTestCase : function( testCase ) 52 { 53 YAHOO.tool.TestRunner.add( new YAHOO.tool.TestCase( testCase ) ); 54 }, 55 56 /** 57 * Gets the inner HTML of an element, for testing purposes. 58 */ 59 getInnerHtml : function( elementOrId ) 60 { 61 var html; 62 63 if ( typeof elementOrId == 'string' ) 64 html = document.getElementById( elementOrId ).innerHTML; 65 else if ( elementOrId.getHtml ) 66 html = elementOrId.getHtml(); 67 else 68 html = elementOrId.innerHTML || ''; 69 70 html = html.toLowerCase(); 71 html = html.replace( /[\n\r]/g, '' ); 72 73 html = html.replace( /<\w[^>]*/g, function( match ) 74 { 75 var attribs = []; 76 var hasClass; 77 78 match = match.replace( /\s([^\s=]+)=((?:"[^"]*")|(?:'[^']*')|(?:[^\s]+))/g, function( match, attName, attValue ) 79 { 80 if ( attName == 'style' ) 81 { 82 // Safari adds some extra space to the end. 83 attValue = attValue.replace( /\s+/g, '' ); 84 85 // IE doesn't add the final ";" 86 attValue = attValue.replace( /([^"';\s])\s*(["']?)$/, '$1;$2' ); 87 } 88 89 // IE may have 'class' more than once. 90 if ( attName == 'class' ) 91 { 92 if ( hasClass ) 93 return ''; 94 95 hasClass = true; 96 } 97 98 if ( attName != '_cke_expando' ) 99 attribs.push( [ attName, attValue ] ); 100 101 return ''; 102 } ); 103 104 attribs.sort( function( a, b ) 105 { 106 var nameA = a[ 0 ]; 107 var nameB = b[ 0 ]; 108 return nameA < nameB ? -1 : nameA > nameB ? 1 : 0; 109 } ); 110 111 var ret = match.replace( /\s{2,}/g, ' ' ); 112 113 for ( var i = 0 ; i < attribs.length ; i++ ) 114 { 115 ret += ' ' + attribs[i][0] + '='; 116 ret += (/^["']/).test( attribs[i][1] ) ? attribs[i][1] : '"' + attribs[i][1] + '"'; 117 } 118 119 return ret; 120 } ); 121 122 return html; 123 } 124 }; 125