File: validators.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 (92 lines) | stat: -rw-r--r-- 3,449 bytes parent folder | download
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
/* bender-tags: editor, dialog */
/* bender-ckeditor-plugins: dialog */

bender.test( {
	setUp: function() {
		this.inlineStyleValidator = CKEDITOR.dialog.validate.inlineStyle( 'Invalid inline styles!' );
	},

	tearDown: function() {
		this.inlineStyleValidator = null;
		this.getValue = null;
	},

	'test empty styles validates to true': function() {
		setupValueGetter( '', this );
		assert.isTrue( this.inlineStyleValidator() );
	},

	'test valid styles validates to true': function() {
		setupValueGetter( 'height: 10px; width: 20px;', this );
		assert.isTrue( this.inlineStyleValidator() );
	},

	'test valid styles (no spacing) validates to true': function() {
		setupValueGetter( 'height:10px;width:20px;', this );
		assert.isTrue( this.inlineStyleValidator() );
	},

	'test valid styles (additional spacing, missing ; at the end) validates to true': function() {
		setupValueGetter( '  height:     10px; width:         20px', this );
		assert.isTrue( this.inlineStyleValidator() );
	},

	'test valid styles (long version) validates to true': function() {
		setupValueGetter( 'font-family: \'Arial\', \'Helvetica\', sans-serif; font-size: 14px; position: absolute; top: 0; right: 0;' +
			'width: 100%; list-style-type: none; margin: 0; padding: 56px 0 0; z-index: 1000; text-shadow: none;', this );
		assert.isTrue( this.inlineStyleValidator() );
	},

	'test valid styles (long version with no \' escaping) validates to true': function() {
		setupValueGetter( "font-family: 'Arial', 'Helvetica', sans-serif; font-size: 14px; position: absolute; top: 0; right: 0;" +
			'width: 100%; list-style-type: none; margin: 0; padding: 56px 0 0; z-index: 1000; text-shadow: none;', this );
		assert.isTrue( this.inlineStyleValidator() );
	},

	'test valid styles validates to true (edge case #1)': function() {
		setupValueGetter( '\\9: bar;', this );
		assert.isTrue( this.inlineStyleValidator() );
	},

	'test invalid styles returns error message': function() {
		setupValueGetter( 'test', this );
		assert.areEqual( this.inlineStyleValidator(), 'Invalid inline styles!' );
	},

	'test valid styles but with duplicated ; returns error message': function() {
		setupValueGetter( 'height: 10px;; width: 20px;', this );
		assert.areEqual( this.inlineStyleValidator(), 'Invalid inline styles!' );
	},

	'test valid styles but with duplicated : returns error message': function() {
		setupValueGetter( 'height:: 10px;', this );
		assert.areEqual( this.inlineStyleValidator(), 'Invalid inline styles!' );
	},

	'test invalid styles returns error message (edge case #1)': function() {
		setupValueGetter( '-: foo;', this );
		assert.areEqual( this.inlineStyleValidator(), 'Invalid inline styles!' );
	},

	'test invalid styles returns error message (edge case #2)': function() {
		setupValueGetter( '9: bar;', this );
		assert.areEqual( this.inlineStyleValidator(), 'Invalid inline styles!' );
	},

	'test invalid styles returns error message (edge case #3)': function() {
		setupValueGetter( 'foo: ;', this );
		assert.areEqual( this.inlineStyleValidator(), 'Invalid inline styles!' );
	},

	'test invalid styles returns error message (edge case #4)': function() {
		setupValueGetter( 'foo: ', this );
		assert.areEqual( this.inlineStyleValidator(), 'Invalid inline styles!' );
	}
} );

// Setup `getValue()` method for the current context due to #4473.
function setupValueGetter( value, context ) {
	context.getValue = function() {
		return value;
	};
}