Ticket #3019: test-form.patch

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

Updated Functional Test Case

  • _source/tests/plugins/form/form.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>Plugin: form</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
     11function prepareEditor( elementId, mode, config, callback, context )
     12{
     13        CKEDITOR.on( 'instanceReady',
     14                function( evt )
     15                {
     16                        var isMe = mode == CKEDITOR.ELEMENT_MODE_REPLACE ?
     17                                evt.editor.name == elementId
     18                                : evt.editor.element.$ ==
     19                                        document.getElementById( elementId );
     20                        if ( isMe )
     21                        {
     22                                callback.call( context, evt.editor );
     23                        }
     24                }, this );
     25
     26        mode = mode || CKEDITOR.ELEMENT_MODE_REPLACE;
     27        switch( mode )
     28        {
     29                case CKEDITOR.ELEMENT_MODE_REPLACE :
     30                        CKEDITOR.replace( elementId, config );
     31                        break;
     32                case CKEDITOR.ELEMENT_MODE_APPENDTO :
     33                        CKEDITOR.appendTo( elementId, config );
     34                        break;
     35        }
     36}
     37
     38CKEDITOR.test.addTestCase( ( function()
     39        {
     40                /**
     41                 * IE always returning CRLF for linefeed, so remove it when retrieve
     42                 * pre-formated text from text area.
     43                 * @param {Object} id
     44                 */
     45                function getTextAreaValue( id )
     46                {
     47                        return CKEDITOR.document.getById( id ).getValue().replace( /\r/gi, '' );
     48                }
     49               
     50                // In these tests, we may "reset" the writer rules to avoid it formatting
     51                // the output, making the assertion easier to the done. We don't need to
     52                // test formatting features here, so this is ok.
     53                var getDataProcessor = function()
     54                {
     55                        var dataProcessor = new CKEDITOR.htmlDataProcessor();
     56                        dataProcessor.writer._.rules = [];
     57                        return dataProcessor;
     58                };
     59
     60                function assumeDataAreSame( content, textareaId )
     61                {
     62                        var html = getDataProcessor().toHtml( content );
     63                        assert.areSame( getTextAreaValue( textareaId ) , html );
     64                }
     65               
     66                // Local references.
     67                var assert = CKEDITOR.test.assert, doc = CKEDITOR.document;
     68                return  {
     69                       
     70                        /**
     71                         * Test insert a form element with all supported attributes and synchronize with the element.
     72                         */
     73                        test_createFormAndUpdate : function()
     74                        {
     75                                prepareEditor( 'editor1', null, null, function( editor )
     76                                        {
     77                                                this.resume( function()
     78                                                {
     79                                                                        editor.focus();
     80                                                                        // async
     81                                                                        editor.execCommand( 'form' );
     82                                                                        this.wait(
     83                                                                                        function()
     84                                                                                        {
     85                                                                                                var dialog = editor._.storedDialogs[ 'form' ];
     86                                                                                                var name = dialog
     87                                                                                                        .getContentElement( 'info',
     88                                                                                                                'txtName' ), action = dialog
     89                                                                                                        .getContentElement( 'info',
     90                                                                                                                'txtAction' ), formId = dialog
     91                                                                                                        .getContentElement( 'info',
     92                                                                                                                'txtId' ), encoding = dialog
     93                                                                                                        .getContentElement( 'info',
     94                                                                                                                'cmbEncoding' ), target = dialog
     95                                                                                                        .getContentElement( 'info',
     96                                                                                                                'cmbTarget' ), method = dialog
     97                                                                                                        .getContentElement( 'info',
     98                                                                                                                'cmbMethod' );
     99       
     100                                                                                                // Set form fields values
     101                                                                                                name.setValue( 'form-name' );
     102                                                                                                action.setValue( 'http://dev.fckeditor.net/newticket?' );
     103                                                                                                formId.setValue( 'form-id1' );
     104                                                                                                encoding.setValue( 'application/x-www-form-urlencoded' );
     105                                                                                                target.setValue( '_blank' );
     106                                                                                                method.setValue( 'post' );
     107       
     108                                                                                                dialog.fire( 'ok' );
     109                                                                                                dialog.hide();
     110       
     111                                                                                                var result = editor.getData(), expected;
     112                                                                                                if ( CKEDITOR.env.gecko )
     113                                                                                                        assumeDataAreSame( result,  'formResultGecko' );
     114                                                                                                else
     115                                                                                                        assumeDataAreSame( result,  'formResult' );
     116                                                                                               
     117                                                                                                //test modify mode
     118                                                                                                var  element = new CKEDITOR.dom.element(
     119                                                                                                editor.document.$.getElementsByTagName( 'form' )[ 0 ] );
     120                                                                                                editor.getSelection().selectElement( element );
     121                                                                                               
     122                                                                                                //sync
     123                                                                                                editor.execCommand( 'form' );
     124                                                                                               
     125                                                                                                // check form fields values are updated.
     126                                                                                                assert.areSame( 'form-name', name.getValue() );
     127                                                                                                assert.areSame( 'http://dev.fckeditor.net/newticket?', action.getValue() );
     128                                                                                                assert.areSame( 'form-id1', formId.getValue() );
     129                                                                                                assert.areSame( 'application/x-www-form-urlencoded', encoding.getValue() );
     130                                                                                                assert.areSame( '_blank', target.getValue() );
     131                                                                                                assert.areSame( 'post', method.getValue() );
     132       
     133                                                                                        }, 1000 );
     134                                                } );
     135                                        }, this );
     136                                        this.wait();           
     137                        },
     138
     139                        name :document.title
     140                };
     141        } )() );
     142        //]]>
     143        </script>
     144</head>
     145<body>
     146        <textarea id="editor1" name="editor1"></textarea>
     147        <textarea id="formResultGecko"><form action="http://dev.fckeditor.net/newticket?" encoding="application/x-www-form-urlencoded" id="form-id1" method="post" name="form-name" target="_blank"><br /> </form><p><br /> </p></textarea>
     148        <textarea id="formResult"><form action="http://dev.fckeditor.net/newticket?" encoding="application/x-www-form-urlencoded" id="form-id1" method="post" name="form-name" target="_blank"><br /></form></textarea>
     149</form>
     150</textarea>
     151</body>
     152</html>
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy