File: textfield.js

package info (click to toggle)
ckeditor 4.16.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 258,804 kB
  • sloc: javascript: 239,590; sh: 184; makefile: 64; python: 37; php: 15; xml: 5
file content (159 lines) | stat: -rw-r--r-- 4,621 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/* bender-tags: editor,dialog */
/* bender-ckeditor-plugins: dialog,button,forms,toolbar */
/* bender-include: _helpers/tools.js */
/* global formsTools */

var assertRequiredAttribute = formsTools.assertRequiredAttribute;

bender.editor = {
	config: {
		autoParagraph: false
	}
};

bender.test( {

	tearDown: function() {
		var dialog = CKEDITOR.dialog.getCurrent();

		if ( dialog ) {
			dialog.hide();
		}
	},

	// (#2423)
	'test dialog model during text field creation': function() {
		var bot = this.editorBot,
			editor = this.editor;

		bot.setData( '', function() {
			bot.dialog( 'textfield', function( dialog ) {
				assert.isNull( dialog.getModel( editor ) );
				assert.areEqual( CKEDITOR.dialog.CREATION_MODE, dialog.getMode( editor ) );
			} );
		} );
	},

	// (#2423)
	'test dialog model with existing button': function() {
		// (#3700)
		if ( CKEDITOR.env.ie && CKEDITOR.env.version === 8 ) {
			assert.ignore();
		}

		var bot = this.editorBot,
			editor = this.editor;

		bot.setData( '<input type="text" value="test" name="test"/ >', function() {
			bot.dialog( 'textfield', function( dialog ) {
				var txtField = editor.editable().findOne( 'input' );

				editor.getSelection().selectElement( txtField );

				assert.areEqual( txtField, dialog.getModel( editor ) );
				assert.areEqual( CKEDITOR.dialog.EDITING_MODE, dialog.getMode( editor ) );
			} );
		} );
	},

	'test fill fields (text) ': function() {
		var bot = this.editorBot;

		bot.setData( '', function() {
			bot.dialog( 'textfield', function( dialog ) {
				dialog.setValueOf( 'info', '_cke_saved_name', 'name' );
				dialog.setValueOf( 'info', 'value', 'value' );
				dialog.setValueOf( 'info', 'required', 'checked' );

				dialog.getButton( 'ok' ).click();

				assert.areSame( '<input name="name" required="required" type="text" value="value" />', bot.getData( true ) );
			} );
		} );
	},

	'test fill fields (password)': function() {
		var bot = this.editorBot;

		bot.setData( '', function() {
			bot.dialog( 'textfield', function( dialog ) {
				dialog.setValueOf( 'info', 'type', 'password' );
				dialog.setValueOf( 'info', '_cke_saved_name', 'name' );
				dialog.setValueOf( 'info', 'value', 'value' );
				dialog.setValueOf( 'info', 'required', 'checked' );

				dialog.getButton( 'ok' ).click();

				assert.areSame( '<input name="name" required="required" type="password" value="value" />', bot.getData( true ) );
			} );
		} );
	},

	'test empty fields': function() {
		var bot = this.editorBot;

		bot.setHtmlWithSelection( '[<input name="name" type="text" value="value" required="required" />]' );

		bot.dialog( 'textfield', function( dialog ) {
			assert.areSame( 'name', dialog.getValueOf( 'info', '_cke_saved_name' ) );
			assert.areSame( 'value', dialog.getValueOf( 'info', 'value' ) );
			assert.areSame( true, dialog.getValueOf( 'info', 'required' ) );

			dialog.setValueOf( 'info', '_cke_saved_name', '' );
			dialog.setValueOf( 'info', 'value', '' );
			dialog.setValueOf( 'info', 'required', '' );

			dialog.getButton( 'ok' ).click();

			assert.areSame( '<input type="text" />', bot.getData( false, true ) );
		} );
	},

	'test read attributes (email)': function() {
		var bot = this.editorBot;

		bot.setHtmlWithSelection( '[<input name="name" type="email" value="test@host.com" />]' );

		bot.dialog( 'textfield', function( dialog ) {
			assert.areSame( 'name', dialog.getValueOf( 'info', '_cke_saved_name' ) );
			assert.areSame( 'email', dialog.getValueOf( 'info', 'type' ) );
			assert.areSame( 'test@host.com', dialog.getValueOf( 'info', 'value' ) );

			dialog.setValueOf( 'info', 'type', 'text' );

			dialog.getButton( 'ok' ).click();

			assert.areSame( '<input name="name" type="text" value="test@host.com" />', bot.getData( true ) );
		} );
	},

	'test required attribute collapsed': assertRequiredAttribute( {
		html: '[<input type="text" required />]',
		type: 'textfield',
		expected: true
	} ),

	'test required attribute without value': assertRequiredAttribute( {
		html: '[<input type="text" required="" />]',
		type: 'textfield',
		expected: true
	} ),

	'test required attribute with value `required`': assertRequiredAttribute( {
		html: '[<input type="text" required="required" />]',
		type: 'textfield',
		expected: true
	} ),

	'test required attribute absent': assertRequiredAttribute( {
		html: '[<input type="text" />]',
		type: 'textfield',
		expected: false
	} ),

	'test required attribute with invalid value': assertRequiredAttribute( {
		html: '[<input type="text" required="any value other than empty string or required" />]',
		type: 'textfield',
		expected: true
	} )
} );