@@ -22,41 +22,119 @@ define([
22
22
Constr . prototype = wysiwygAdapter ;
23
23
24
24
obj = new Constr ( ) ;
25
- obj . initialize ( 'id' , {
26
- 'directives_url' : 'http://example.com/admin/cms/wysiwyg/directive/'
27
- } ) ;
28
25
} ) ;
29
26
30
27
describe ( 'wysiwygAdapter' , function ( ) {
31
- var decodedHtml = '<p>' +
32
- '<img src="{{media url="wysiwyg/banana.jpg"}}" alt="" width="612" height="459"></p>' ,
33
- encodedHtml = '<p>' +
34
- '<img src="http://example.com/admin/cms/wysiwyg/directive/' +
35
- '___directive/e3ttZWRpYSB1cmw9Ind5c2l3eWcvYmFuYW5hLmpwZyJ9fQ%2C%2C" alt="" width="612" height="459">' +
36
- '</p>' ,
37
- encodedHtmlWithForwardSlashInImgSrc = encodedHtml . replace ( '%2C%2C' , '%2C%2C/' ) ;
38
-
39
- describe ( '"encodeDirectives" method' , function ( ) {
40
- it ( 'converts media directive img src to directive URL' , function ( ) {
41
- expect ( obj . encodeDirectives ( decodedHtml ) ) . toEqual ( encodedHtml ) ;
28
+ describe ( 'encoding and decoding directives' , function ( ) {
29
+ function runTests ( decodedHtml , encodedHtml ) {
30
+ var encodedHtmlWithForwardSlashInImgSrc = encodedHtml . replace ( / s r c = " ( (?: (? ! " | \\ \? ) .) * ) / , 'src="$1/' ) ;
31
+
32
+ describe ( '"encodeDirectives" method' , function ( ) {
33
+ it ( 'converts media directive img src to directive URL' , function ( ) {
34
+ expect ( obj . encodeDirectives ( decodedHtml ) ) . toEqual ( encodedHtml ) ;
35
+ } ) ;
36
+ } ) ;
37
+
38
+ describe ( '"decodeDirectives" method' , function ( ) {
39
+ it (
40
+ 'converts directive URL img src without a trailing forward slash ' +
41
+ 'to media url without a trailing forward slash' ,
42
+ function ( ) {
43
+ expect ( obj . decodeDirectives ( encodedHtml ) ) . toEqual ( decodedHtml ) ;
44
+ }
45
+ ) ;
46
+
47
+ it ( 'converts directive URL img src with a trailing forward slash ' +
48
+ 'to media url without a trailing forward slash' ,
49
+ function ( ) {
50
+ expect ( encodedHtmlWithForwardSlashInImgSrc ) . not . toEqual ( encodedHtml ) ;
51
+ expect ( obj . decodeDirectives ( encodedHtmlWithForwardSlashInImgSrc ) ) . toEqual ( decodedHtml ) ;
52
+ }
53
+ ) ;
54
+ } ) ;
55
+ }
56
+
57
+ describe ( 'without SID in directive query string' , function ( ) {
58
+ describe ( 'without secret key' , function ( ) {
59
+ var decodedHtml = '<p>' +
60
+ '<img src="{{media url="wysiwyg/banana.jpg"}}" alt="" width="612" height="459"></p>' ,
61
+ encodedHtml = '<p>' +
62
+ '<img src="http://example.com/admin/cms/wysiwyg/directive/___directive' +
63
+ '/e3ttZWRpYSB1cmw9Ind5c2l3eWcvYmFuYW5hLmpwZyJ9fQ%2C%2C" alt="" width="612" height="459">' +
64
+ '</p>' ;
65
+
66
+ beforeEach ( function ( ) {
67
+ obj . initialize ( 'id' , {
68
+ 'directives_url' : 'http://example.com/admin/cms/wysiwyg/directive/'
69
+ } ) ;
70
+ } ) ;
71
+
72
+ runTests ( decodedHtml , encodedHtml ) ;
73
+ } ) ;
74
+
75
+ describe ( 'with secret key' , function ( ) {
76
+ var decodedHtml = '<p>' +
77
+ '<img src="{{media url="wysiwyg/banana.jpg"}}" alt="" width="612" height="459"></p>' ,
78
+ encodedHtml = '<p>' +
79
+ '<img src="http://example.com/admin/cms/wysiwyg/directive/___directive' +
80
+ '/e3ttZWRpYSB1cmw9Ind5c2l3eWcvYmFuYW5hLmpwZyJ9fQ%2C%2C/key/' +
81
+ '5552655d13a141099d27f5d5b0c58869423fd265687167da12cad2bb39aa9a58" ' +
82
+ 'alt="" width="612" height="459">' +
83
+ '</p>' ,
84
+ directiveUrl = 'http://example.com/admin/cms/wysiwyg/directive/key/' +
85
+ '5552655d13a141099d27f5d5b0c58869423fd265687167da12cad2bb39aa9a58/' ;
86
+
87
+ beforeEach ( function ( ) {
88
+ obj . initialize ( 'id' , {
89
+ 'directives_url' : directiveUrl
90
+ } ) ;
91
+ } ) ;
92
+
93
+ runTests ( decodedHtml , encodedHtml ) ;
94
+ } ) ;
42
95
} ) ;
43
- } ) ;
44
96
45
- describe ( '"decodeDirectives" method' , function ( ) {
46
- it (
47
- 'converts directive URL img src without a trailing forward slash ' +
48
- 'to media url without a trailing forward slash' ,
49
- function ( ) {
50
- expect ( obj . decodeDirectives ( encodedHtml ) ) . toEqual ( decodedHtml ) ;
51
- }
52
- ) ;
53
-
54
- it ( 'converts directive URL img src with a trailing forward slash ' +
55
- 'to media url without a trailing forward slash' ,
56
- function ( ) {
57
- expect ( obj . decodeDirectives ( encodedHtmlWithForwardSlashInImgSrc ) ) . toEqual ( decodedHtml ) ;
58
- }
59
- ) ;
97
+ describe ( 'with SID in directive query string' , function ( ) {
98
+ describe ( 'without secret key' , function ( ) {
99
+ var decodedHtml = '<p>' +
100
+ '<img src="{{media url="wysiwyg/banana.jpg"}}" alt="" width="612" height="459"></p>' ,
101
+ encodedHtml = '<p>' +
102
+ '<img src="http://example.com/admin/cms/wysiwyg/directive/___directive' +
103
+ '/e3ttZWRpYSB1cmw9Ind5c2l3eWcvYmFuYW5hLmpwZyJ9fQ%2C%2C?SID=something" ' +
104
+ 'alt="" width="612" height="459">' +
105
+ '</p>' ,
106
+ directiveUrl = 'http://example.com/admin/cms/wysiwyg/directive?SID=something' ;
107
+
108
+ beforeEach ( function ( ) {
109
+ obj . initialize ( 'id' , {
110
+ 'directives_url' : directiveUrl
111
+ } ) ;
112
+ } ) ;
113
+
114
+ runTests ( decodedHtml , encodedHtml ) ;
115
+ } ) ;
116
+
117
+ describe ( 'with secret key' , function ( ) {
118
+ var decodedHtml = '<p>' +
119
+ '<img src="{{media url="wysiwyg/banana.jpg"}}" alt="" width="612" height="459"></p>' ,
120
+ encodedHtml = '<p>' +
121
+ '<img src="http://example.com/admin/cms/wysiwyg/directive/___directive' +
122
+ '/e3ttZWRpYSB1cmw9Ind5c2l3eWcvYmFuYW5hLmpwZyJ9fQ%2C%2C/key/' +
123
+ '5552655d13a141099d27f5d5b0c58869423fd265687167da12cad2bb39aa9a58?SID=something" ' +
124
+ 'alt="" width="612" height="459">' +
125
+ '</p>' ,
126
+ directiveUrl = 'http://example.com/admin/cms/wysiwyg/directive/key/' +
127
+ '5552655d13a141099d27f5d5b0c58869423fd265687167da12cad2bb39aa9a58?SID=something' ;
128
+
129
+ beforeEach ( function ( ) {
130
+ obj . initialize ( 'id' , {
131
+ 'directives_url' : directiveUrl
132
+ } ) ;
133
+ } ) ;
134
+
135
+ runTests ( decodedHtml , encodedHtml ) ;
136
+ } ) ;
137
+ } ) ;
60
138
} ) ;
61
139
} ) ;
62
140
} ) ;
0 commit comments