Revision 441:cbce1fd3b1b7 test/unit/lib/redmine/wiki_formatting

View differences:

test/unit/lib/redmine/wiki_formatting/.svn/all-wcprops
1 1
K 25
2 2
svn:wc:ra_dav:version-url
3
V 62
4
/svn/!svn/ver/4509/trunk/test/unit/lib/redmine/wiki_formatting
3
V 76
4
/svn/!svn/ver/5878/branches/1.2-stable/test/unit/lib/redmine/wiki_formatting
5 5
END
6
textile_formatter_test.rb
7
K 25
8
svn:wc:ra_dav:version-url
9
V 88
10
/svn/!svn/ver/4509/trunk/test/unit/lib/redmine/wiki_formatting/textile_formatter_test.rb
11
END
12
macros_test.rb
13
K 25
14
svn:wc:ra_dav:version-url
15
V 77
16
/svn/!svn/ver/4509/trunk/test/unit/lib/redmine/wiki_formatting/macros_test.rb
17
END
test/unit/lib/redmine/wiki_formatting/.svn/entries
1 1
10
2 2

  
3 3
dir
4
4993
5
http://redmine.rubyforge.org/svn/trunk/test/unit/lib/redmine/wiki_formatting
4
6000
5
http://redmine.rubyforge.org/svn/branches/1.2-stable/test/unit/lib/redmine/wiki_formatting
6 6
http://redmine.rubyforge.org/svn
7 7

  
8 8

  
9 9

  
10
2010-12-12T23:24:34.194336Z
11
4509
12
jbbarth
10
2011-03-14T20:35:36.619571Z
11
5133
12
jplang
13 13

  
14 14

  
15 15

  
......
32 32

  
33 33

  
34 34

  
35
2011-03-03T11:05:08.000000Z
36
5acd95498f8f2e52e8ad2b70961a21ad
37
2010-12-12T23:24:34.194336Z
38
4509
39
jbbarth
35
2011-06-06T13:17:45.000000Z
36
577e7247310738d58d7399685323ba1f
37
2011-03-14T20:35:36.619571Z
38
5133
39
jplang
40 40
has-props
41 41

  
42 42

  
......
58 58

  
59 59

  
60 60

  
61
3473
61
6180
62 62

63 63
macros_test.rb
64 64
file
......
66 66

  
67 67

  
68 68

  
69
2011-03-03T11:05:08.000000Z
69
2011-06-06T13:15:00.000000Z
70 70
41000dcb1febd4ce59305bb36a369cf0
71 71
2010-12-12T23:24:34.194336Z
72 72
4509
test/unit/lib/redmine/wiki_formatting/.svn/text-base/textile_formatter_test.rb.svn-base
64 64
      '@<Location /redmine>@'    => '<code>&lt;Location /redmine&gt;</code>'
65 65
    )
66 66
  end
67
  
67

  
68 68
  def test_escaping
69 69
    assert_html_output(
70 70
      'this is a <script>'      => 'this is a &lt;script&gt;'
71 71
    )
72 72
  end
73

  
74
  def test_use_of_backslashes_followed_by_numbers_in_headers
75
    assert_html_output({
76
      'h1. 2009\02\09'      => '<h1>2009\02\09</h1>'
77
    }, false)
78
  end
73 79
  
74 80
  def test_double_dashes_should_not_strikethrough
75 81
    assert_html_output(
......
86 92
    )
87 93
  end
88 94
  
95
  def test_blockquote
96
    # orig raw text
97
    raw = <<-RAW
98
John said:
99
> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
100
> Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
101
> * Donec odio lorem,
102
> * sagittis ac,
103
> * malesuada in,
104
> * adipiscing eu, dolor.
105
>
106
> >Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.
107
> Proin a tellus. Nam vel neque.
108

  
109
He's right.
110
RAW
111
    
112
    # expected html
113
    expected = <<-EXPECTED
114
<p>John said:</p>
115
<blockquote>
116
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.<br />
117
Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
118
<ul>
119
  <li>Donec odio lorem,</li>
120
  <li>sagittis ac,</li>
121
  <li>malesuada in,</li>
122
  <li>adipiscing eu, dolor.</li>
123
</ul>
124
<blockquote>
125
<p>Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.</p>
126
</blockquote>
127
<p>Proin a tellus. Nam vel neque.</p>
128
</blockquote>
129
<p>He's right.</p>
130
EXPECTED
131
    
132
    assert_equal expected.gsub(%r{\s+}, ''), to_html(raw).gsub(%r{\s+}, '')
133
  end
134
  
135
  def test_table
136
    raw = <<-RAW
137
This is a table with empty cells:
138

  
139
|cell11|cell12||
140
|cell21||cell23|
141
|cell31|cell32|cell33|
142
RAW
143

  
144
    expected = <<-EXPECTED
145
<p>This is a table with empty cells:</p>
146

  
147
<table>
148
  <tr><td>cell11</td><td>cell12</td><td></td></tr>
149
  <tr><td>cell21</td><td></td><td>cell23</td></tr>
150
  <tr><td>cell31</td><td>cell32</td><td>cell33</td></tr>
151
</table>
152
EXPECTED
153

  
154
    assert_equal expected.gsub(%r{\s+}, ''), to_html(raw).gsub(%r{\s+}, '')
155
  end
156
  
157
  def test_table_with_line_breaks
158
    raw = <<-RAW
159
This is a table with line breaks:
160

  
161
|cell11
162
continued|cell12||
163
|-cell21-||cell23
164
cell23 line2
165
cell23 *line3*|
166
|cell31|cell32
167
cell32 line2|cell33|
168

  
169
RAW
170

  
171
    expected = <<-EXPECTED
172
<p>This is a table with line breaks:</p>
173

  
174
<table>
175
  <tr>
176
    <td>cell11<br />continued</td>
177
    <td>cell12</td>
178
    <td></td>
179
  </tr>
180
  <tr>
181
    <td><del>cell21</del></td>
182
    <td></td>
183
    <td>cell23<br/>cell23 line2<br/>cell23 <strong>line3</strong></td>
184
  </tr>
185
  <tr>
186
    <td>cell31</td>
187
    <td>cell32<br/>cell32 line2</td>
188
    <td>cell33</td>
189
  </tr>
190
</table>
191
EXPECTED
192

  
193
    assert_equal expected.gsub(%r{\s+}, ''), to_html(raw).gsub(%r{\s+}, '')
194
  end
195
  
196
  def test_textile_should_not_mangle_brackets
197
    assert_equal '<p>[msg1][msg2]</p>', to_html('[msg1][msg2]')
198
  end
199
  
89 200
  private
90 201
  
91
  def assert_html_output(to_test)
202
  def assert_html_output(to_test, expect_paragraph = true)
92 203
    to_test.each do |text, expected|
93
      assert_equal "<p>#{expected}</p>", @formatter.new(text).to_html, "Formatting the following text failed:\n===\n#{text}\n===\n"
204
      assert_equal(( expect_paragraph ? "<p>#{expected}</p>" : expected ), @formatter.new(text).to_html, "Formatting the following text failed:\n===\n#{text}\n===\n")
94 205
    end
95 206
  end
207
  
208
  def to_html(text)
209
    @formatter.new(text).to_html
210
  end
96 211
end
test/unit/lib/redmine/wiki_formatting/textile_formatter_test.rb
64 64
      '@<Location /redmine>@'    => '<code>&lt;Location /redmine&gt;</code>'
65 65
    )
66 66
  end
67
  
67

  
68 68
  def test_escaping
69 69
    assert_html_output(
70 70
      'this is a <script>'      => 'this is a &lt;script&gt;'
71 71
    )
72 72
  end
73

  
74
  def test_use_of_backslashes_followed_by_numbers_in_headers
75
    assert_html_output({
76
      'h1. 2009\02\09'      => '<h1>2009\02\09</h1>'
77
    }, false)
78
  end
73 79
  
74 80
  def test_double_dashes_should_not_strikethrough
75 81
    assert_html_output(
......
86 92
    )
87 93
  end
88 94
  
95
  def test_blockquote
96
    # orig raw text
97
    raw = <<-RAW
98
John said:
99
> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
100
> Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
101
> * Donec odio lorem,
102
> * sagittis ac,
103
> * malesuada in,
104
> * adipiscing eu, dolor.
105
>
106
> >Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.
107
> Proin a tellus. Nam vel neque.
108

  
109
He's right.
110
RAW
111
    
112
    # expected html
113
    expected = <<-EXPECTED
114
<p>John said:</p>
115
<blockquote>
116
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.<br />
117
Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
118
<ul>
119
  <li>Donec odio lorem,</li>
120
  <li>sagittis ac,</li>
121
  <li>malesuada in,</li>
122
  <li>adipiscing eu, dolor.</li>
123
</ul>
124
<blockquote>
125
<p>Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.</p>
126
</blockquote>
127
<p>Proin a tellus. Nam vel neque.</p>
128
</blockquote>
129
<p>He's right.</p>
130
EXPECTED
131
    
132
    assert_equal expected.gsub(%r{\s+}, ''), to_html(raw).gsub(%r{\s+}, '')
133
  end
134
  
135
  def test_table
136
    raw = <<-RAW
137
This is a table with empty cells:
138

  
139
|cell11|cell12||
140
|cell21||cell23|
141
|cell31|cell32|cell33|
142
RAW
143

  
144
    expected = <<-EXPECTED
145
<p>This is a table with empty cells:</p>
146

  
147
<table>
148
  <tr><td>cell11</td><td>cell12</td><td></td></tr>
149
  <tr><td>cell21</td><td></td><td>cell23</td></tr>
150
  <tr><td>cell31</td><td>cell32</td><td>cell33</td></tr>
151
</table>
152
EXPECTED
153

  
154
    assert_equal expected.gsub(%r{\s+}, ''), to_html(raw).gsub(%r{\s+}, '')
155
  end
156
  
157
  def test_table_with_line_breaks
158
    raw = <<-RAW
159
This is a table with line breaks:
160

  
161
|cell11
162
continued|cell12||
163
|-cell21-||cell23
164
cell23 line2
165
cell23 *line3*|
166
|cell31|cell32
167
cell32 line2|cell33|
168

  
169
RAW
170

  
171
    expected = <<-EXPECTED
172
<p>This is a table with line breaks:</p>
173

  
174
<table>
175
  <tr>
176
    <td>cell11<br />continued</td>
177
    <td>cell12</td>
178
    <td></td>
179
  </tr>
180
  <tr>
181
    <td><del>cell21</del></td>
182
    <td></td>
183
    <td>cell23<br/>cell23 line2<br/>cell23 <strong>line3</strong></td>
184
  </tr>
185
  <tr>
186
    <td>cell31</td>
187
    <td>cell32<br/>cell32 line2</td>
188
    <td>cell33</td>
189
  </tr>
190
</table>
191
EXPECTED
192

  
193
    assert_equal expected.gsub(%r{\s+}, ''), to_html(raw).gsub(%r{\s+}, '')
194
  end
195
  
196
  def test_textile_should_not_mangle_brackets
197
    assert_equal '<p>[msg1][msg2]</p>', to_html('[msg1][msg2]')
198
  end
199
  
89 200
  private
90 201
  
91
  def assert_html_output(to_test)
202
  def assert_html_output(to_test, expect_paragraph = true)
92 203
    to_test.each do |text, expected|
93
      assert_equal "<p>#{expected}</p>", @formatter.new(text).to_html, "Formatting the following text failed:\n===\n#{text}\n===\n"
204
      assert_equal(( expect_paragraph ? "<p>#{expected}</p>" : expected ), @formatter.new(text).to_html, "Formatting the following text failed:\n===\n#{text}\n===\n")
94 205
    end
95 206
  end
207
  
208
  def to_html(text)
209
    @formatter.new(text).to_html
210
  end
96 211
end

Also available in: Unified diff