Ticket #3009: 3009.patch

File 3009.patch, 3.9 KB (added by Garry Yao, 15 years ago)
  • _source/tests/core/test.html

     
     1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2<html xmlns="http://www.w3.org/1999/xhtml">
     3<head>
     4        <title>Test</title>
     5        <link rel="stylesheet" type="text/css" href="../test.css" />
     6        <script type="text/javascript" src="../../../ckeditor_source.js"></script>
     7        <script type="text/javascript" src="../test.js"></script>
     8        <script type="text/javascript">
     9        //<![CDATA[
     10
     11/**
     12 *  Testing {@link CKEDITOR.test.InteractiveEditorTestCase}
     13 */
     14CKEDITOR.test.addTestCase( ( function()
     15        {
     16               
     17                // Local references.
     18                var assert = CKEDITOR.test.assert;
     19                       
     20                function _assumeInitialState()
     21                {
     22                        assert.areSame( this.editor.name, 'test_editor' );
     23                        assert.areSame( this.defaultEditorData, this.editor.getData() );
     24                        assert.isTrue( this.editor.focusManager.hasFocus );
     25                }
     26               
     27                return  new CKEDITOR.test.InteractiveEditorTestCase({
     28                       
     29                        /**
     30                         *  Test editor fully interactive and intial state correctness.
     31                         */
     32                        test_editorReady : function()
     33                        {
     34                                this.waitForEditor( _assumeInitialState );
     35                        },
     36                       
     37                        /**
     38                         *  Test second testcase ( editor loaded ) has same result as first one. 
     39                         */
     40                        test_editorReady2 : function()
     41                        {
     42                                this.waitForEditor( _assumeInitialState );
     43                        },
     44                       
     45                        defaultEditorData: '<p>\n\tThis is some <strong>sample text</strong>. You are using <a href="http://www.fckeditor.net/">FCKeditor</a>.</p>\n',
     46                        name : document.title
     47                } );
     48               
     49        } )() );
     50        //]]>
     51        </script>
     52</head>
     53<body>
     54</body>
     55</html>
  • _source/core/test.js

     
    114114                return html;
    115115        }
    116116};
     117
     118/**
     119 *  All tests in this case share a fully interacted 'playground' editor instance.
     120 */
     121CKEDITOR.test.InteractiveEditorTestCase = function( template ) {
     122        CKEDITOR.test.InteractiveEditorTestCase.superclass.constructor.call( this, template );
     123        // The editor instance shared by all tests.
     124        this.editor = null;
     125};
     126
     127YAHOO.lang.extend( CKEDITOR.test.InteractiveEditorTestCase, YAHOO.tool.TestCase, {
     128       
     129        /**
     130         * Load the editor and wait for fully interactable, the editor is created by replacement mode.
     131         * @param {CKEDITOR.config} config The config options for the shared editor instance. 
     132         * @param {Functoin} callback The callback continuation function.
     133         */
     134        waitForEditor :function ( callback, config )
     135        {
     136                if ( this.editor )
     137                        callback.call( this );
     138                else
     139                {
     140                        var editorName = this.editorName || 'test_editor';
     141                        CKEDITOR.on( 'instanceReady', function( evt )
     142                        {
     143                                if ( evt.editor.name == editorName )
     144                                {
     145                                        window.setTimeout( CKEDITOR.tools.bind( function()
     146                                        {
     147                                       
     148                                                this.editor = evt.editor;
     149                                                this.editor.focus();
     150                                                this.resume( CKEDITOR.tools.bind( callback, this ) );
     151                                               
     152                                        }, this ), 0 );
     153                                }
     154                        }, this );
     155                       
     156                        var element = CKEDITOR.document.getBody().append(
     157                                CKEDITOR.dom.element.createFromHtml(
     158                                '<textarea id="' + editorName + '"></textarea>') );
     159                        element.setValue( this.defaultEditorData );
     160                       
     161                        CKEDITOR.replace( element.getAttribute( 'id' ), config );
     162                       
     163                        // First load, async
     164                        this.wait();
     165                }
     166        },
     167
     168        setUp : function() {
     169                if(this.editor)
     170                {
     171                        this.editor.loadSnapshot( this.defaultEditorData );
     172                        this.editor.focus();
     173                }
     174        },
     175
     176        /**
     177         * Clear up the editor data for each test.
     178         */
     179        tearDown : function() {
     180                if( this.editor )
     181                {
     182                        this.editor.loadSnapshot('');
     183                }
     184        }
     185});
     186 No newline at end of file
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy