@@ -22,41 +22,74 @@ 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 ( 'src="([^"]+)' , '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 ( obj . decodeDirectives ( encodedHtmlWithForwardSlashInImgSrc ) ) . toEqual ( decodedHtml ) ;
51
+ }
52
+ ) ;
53
+ } ) ;
54
+ }
55
+
56
+ describe ( 'without secret key' , function ( ) {
57
+ var decodedHtml = '<p>' +
58
+ '<img src="{{media url="wysiwyg/banana.jpg"}}" alt="" width="612" height="459"></p>' ,
59
+ encodedHtml = '<p>' +
60
+ '<img src="http://example.com/admin/cms/wysiwyg/directive/___directive' +
61
+ '/e3ttZWRpYSB1cmw9Ind5c2l3eWcvYmFuYW5hLmpwZyJ9fQ%2C%2C" alt="" width="612" height="459">' +
62
+ '</p>' ;
63
+
64
+ beforeEach ( function ( ) {
65
+ obj . initialize ( 'id' , {
66
+ 'directives_url' : 'http://example.com/admin/cms/wysiwyg/directive/'
67
+ } ) ;
68
+ } ) ;
69
+
70
+ runTests ( decodedHtml , encodedHtml ) ;
42
71
} ) ;
43
- } ) ;
44
72
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
- ) ;
73
+ describe ( 'with secret key' , function ( ) {
74
+ var decodedHtml = '<p>' +
75
+ '<img src="{{media url="wysiwyg/banana.jpg"}}" alt="" width="612" height="459"></p>' ,
76
+ encodedHtml = '<p>' +
77
+ '<img src="http://example.com/admin/cms/wysiwyg/directive/___directive' +
78
+ '/e3ttZWRpYSB1cmw9Ind5c2l3eWcvYmFuYW5hLmpwZyJ9fQ%2C%2C/key/' +
79
+ '5552655d13a141099d27f5d5b0c58869423fd265687167da12cad2bb39aa9a58" ' +
80
+ 'alt="" width="612" height="459">' +
81
+ '</p>' ,
82
+ directiveUrl = 'http://example.com/admin/cms/wysiwyg/directive/key/' +
83
+ '5552655d13a141099d27f5d5b0c58869423fd265687167da12cad2bb39aa9a58/' ;
84
+
85
+ beforeEach ( function ( ) {
86
+ obj . initialize ( 'id' , {
87
+ 'directives_url' : directiveUrl
88
+ } ) ;
89
+ } ) ;
90
+
91
+ runTests ( decodedHtml , encodedHtml ) ;
92
+ } ) ;
60
93
} ) ;
61
94
} ) ;
62
95
} ) ;
0 commit comments