Ticket #3075: test-insertHtml.patch

File test-insertHtml.patch, 2.7 KB (added by Garry Yao, 15 years ago)

Unit Test Case

  • _source/tests/core/editor_insertHtml.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>CKEDITOR.editor</title>
     5        <link rel="stylesheet" type="text/css" href="../test.css" />
     6        <script type="text/javascript" src="../../../ckeditor_source.js"></script> <!-- %REMOVE_LINE%
     7        <script type="text/javascript" src="../../ckeditor.js"></script>
     8        %REMOVE_LINE% -->
     9        <script type="text/javascript" src="../test.js"></script>
     10        <script type="text/javascript">
     11        //<![CDATA[
     12
     13CKEDITOR.test.addTestCase( (function()
     14{
     15        // Local reference to the "assert" object.
     16        var assert = CKEDITOR.test.assert;
     17       
     18        /**
     19         * Load the editor and wait for fully interactable.
     20         * @param {Object} elementId
     21         * @parma {Object} mode
     22         * @param {Object} config
     23         * @param {Object} callback Continuation with {@param editor}.
     24         * @param {Object} context
     25         */
     26        function prepareEditor( elementId, mode, config, callback, context )
     27        {
     28                CKEDITOR.on( 'instanceReady',
     29                        function( evt )
     30                        {
     31                                var isMe = mode == CKEDITOR.ELEMENT_MODE_REPLACE ?
     32                                        evt.editor.name == elementId
     33                                        : evt.editor.element.$ ==
     34                                                document.getElementById( elementId );
     35                                if ( isMe )
     36                                {
     37                                        callback.call( context, evt.editor );
     38                                }
     39                        }, this );
     40
     41                mode = mode || CKEDITOR.ELEMENT_MODE_REPLACE;
     42                switch( mode )
     43                {
     44                        case CKEDITOR.ELEMENT_MODE_REPLACE :
     45                                CKEDITOR.replace( elementId, config );
     46                                break;
     47                        case CKEDITOR.ELEMENT_MODE_APPENDTO :
     48                                CKEDITOR.appendTo( elementId, config );
     49                                break;
     50                }
     51        }
     52
     53        return {
     54
     55                /**
     56                 * Test insertHtml on two modes.
     57                 */
     58                test_insertHtml1 : function()
     59                {
     60                        prepareEditor( 'editor4', null, null, function( editor )
     61                        {
     62                                this.resume( function()
     63                                {
     64                                        var htmlData = '<table><tr><td>text</td></tr></table>';
     65                                       
     66                                        // wysiwyg mode
     67                                        editor.focus();
     68                                        editor.insertHtml( htmlData );
     69                                        assert.areSame( '<table><tbody><tr><td>text</td></tr></tbody></table>',
     70                                                editor.getSnapshot() );
     71
     72                                        // source mode
     73                                        // sync
     74                                        editor.setMode( 'source' );
     75                                        editor.setData( '' );
     76                                        editor.insertHtml( htmlData );
     77                                        assert.areSame( '', editor.getSnapshot() );
     78                                } );
     79                        }, this );
     80                        this.wait();
     81                },
     82
     83                name : document.title
     84        };
     85})() );
     86
     87        //]]>
     88        </script>
     89</head>
     90<body>
     91        <textarea id="editor4" name="editor4"></textarea>
     92</body>
     93</html>
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy