govspeak 6.5.1 → 6.5.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  require "test_helper"
4
2
 
5
3
  class GovspeakExtractContactContentIdsTest < Minitest::Test
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  require "test_helper"
4
2
  require "govspeak_test_helper"
5
3
 
@@ -20,40 +18,40 @@ class GovspeakImagesBangTest < Minitest::Test
20
18
  test "!!n syntax renders an image in options[:images]" do
21
19
  given_govspeak "!!1", images: [Image.new] do
22
20
  assert_html_output(
23
- %{<figure class="image embedded">} +
24
- %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>} +
25
- %{</figure>},
21
+ %(<figure class="image embedded">) +
22
+ %(<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>) +
23
+ %(</figure>),
26
24
  )
27
25
  end
28
26
  end
29
27
 
30
28
  test "!!n syntax escapes alt text" do
31
- given_govspeak "!!1", images: [Image.new(alt_text: %{my alt '&"<>})] do
29
+ given_govspeak "!!1", images: [Image.new(alt_text: %(my alt '&"<>))] do
32
30
  assert_html_output(
33
- %{<figure class="image embedded">} +
34
- %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt '&amp;&quot;&lt;&gt;"></div>} +
35
- %{</figure>},
31
+ %(<figure class="image embedded">) +
32
+ %(<div class="img"><img src="http://example.com/image.jpg" alt="my alt '&amp;&quot;&lt;&gt;"></div>) +
33
+ %(</figure>),
36
34
  )
37
35
  end
38
36
  end
39
37
 
40
38
  test "!!n syntax renders nothing if not found" do
41
39
  doc = Govspeak::Document.new("!!1")
42
- assert_equal %{\n}, doc.to_html
40
+ assert_equal %(\n), doc.to_html
43
41
  end
44
42
 
45
43
  test "Image:image-id syntax renders nothing" do
46
44
  doc = Govspeak::Document.new("[Image:another-id]", images: [Image.new])
47
- assert_equal %{\n}, doc.to_html
45
+ assert_equal %(\n), doc.to_html
48
46
  end
49
47
 
50
48
  test "!!n syntax adds image caption if given" do
51
49
  given_govspeak "!!1", images: [Image.new(caption: "My Caption & so on")] do
52
50
  assert_html_output(
53
- %{<figure class="image embedded">} +
54
- %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>\n} +
55
- %{<figcaption><p>My Caption &amp; so on</p></figcaption>} +
56
- %{</figure>},
51
+ %(<figure class="image embedded">) +
52
+ %(<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>\n) +
53
+ %(<figcaption><p>My Caption &amp; so on</p></figcaption>) +
54
+ %(</figure>),
57
55
  )
58
56
  end
59
57
  end
@@ -61,9 +59,9 @@ class GovspeakImagesBangTest < Minitest::Test
61
59
  test "!!n syntax ignores a blank caption" do
62
60
  given_govspeak "!!1", images: [Image.new(caption: " ")] do
63
61
  assert_html_output(
64
- %{<figure class="image embedded">} +
65
- %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>} +
66
- %{</figure>},
62
+ %(<figure class="image embedded">) +
63
+ %(<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>) +
64
+ %(</figure>),
67
65
  )
68
66
  end
69
67
  end
@@ -71,10 +69,10 @@ class GovspeakImagesBangTest < Minitest::Test
71
69
  test "¡¡n syntax adds image credit if given" do
72
70
  given_govspeak "!!1", images: [Image.new(credit: "My Credit & so on")] do
73
71
  assert_html_output(
74
- %{<figure class="image embedded">} +
75
- %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>\n} +
76
- %{<figcaption><p>Image credit: My Credit &amp; so on</p></figcaption>} +
77
- %{</figure>},
72
+ %(<figure class="image embedded">) +
73
+ %(<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>\n) +
74
+ %(<figcaption><p>Image credit: My Credit &amp; so on</p></figcaption>) +
75
+ %(</figure>),
78
76
  )
79
77
  end
80
78
  end
@@ -82,9 +80,9 @@ class GovspeakImagesBangTest < Minitest::Test
82
80
  test "!!n syntax ignores a blank credit" do
83
81
  given_govspeak "!!1", images: [Image.new(credit: " ")] do
84
82
  assert_html_output(
85
- %{<figure class="image embedded">} +
86
- %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>} +
87
- %{</figure>},
83
+ %(<figure class="image embedded">) +
84
+ %(<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>) +
85
+ %(</figure>),
88
86
  )
89
87
  end
90
88
  end
@@ -92,13 +90,13 @@ class GovspeakImagesBangTest < Minitest::Test
92
90
  test "!!n syntax adds image caption and credit if given" do
93
91
  given_govspeak "!!1", images: [Image.new(caption: "My Caption & so on", credit: "My Credit & so on")] do
94
92
  assert_html_output(
95
- %{<figure class="image embedded">} +
96
- %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>\n} +
97
- %{<figcaption>} +
98
- %{<p>My Caption &amp; so on</p>\n} +
99
- %{<p>Image credit: My Credit &amp; so on</p>} +
100
- %{</figcaption>} +
101
- %{</figure>},
93
+ %(<figure class="image embedded">) +
94
+ %(<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>\n) +
95
+ %(<figcaption>) +
96
+ %(<p>My Caption &amp; so on</p>\n) +
97
+ %(<p>Image credit: My Credit &amp; so on</p>) +
98
+ %(</figcaption>) +
99
+ %(</figure>),
102
100
  )
103
101
  end
104
102
  end
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  require "test_helper"
4
2
  require "govspeak_test_helper"
5
3
 
@@ -16,35 +14,35 @@ class GovspeakImagesTest < Minitest::Test
16
14
  test "Image:image-id syntax renders an image in options[:images]" do
17
15
  given_govspeak "[Image:image-id]", images: [build_image] do
18
16
  assert_html_output(
19
- %{<figure class="image embedded">} +
20
- %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>} +
21
- %{</figure>},
17
+ %(<figure class="image embedded">) +
18
+ %(<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>) +
19
+ %(</figure>),
22
20
  )
23
21
  end
24
22
  end
25
23
 
26
24
  test "Image:image-id syntax escapes alt text" do
27
- given_govspeak "[Image:image-id]", images: [build_image(alt_text: %{my alt '&"<>})] do
25
+ given_govspeak "[Image:image-id]", images: [build_image(alt_text: %(my alt '&"<>))] do
28
26
  assert_html_output(
29
- %{<figure class="image embedded">} +
30
- %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt '&amp;&quot;&lt;&gt;"></div>} +
31
- %{</figure>},
27
+ %(<figure class="image embedded">) +
28
+ %(<div class="img"><img src="http://example.com/image.jpg" alt="my alt '&amp;&quot;&lt;&gt;"></div>) +
29
+ %(</figure>),
32
30
  )
33
31
  end
34
32
  end
35
33
 
36
34
  test "Image:image-id syntax renders nothing if not found" do
37
35
  doc = Govspeak::Document.new("[Image:another-id]")
38
- assert_equal %{\n}, doc.to_html
36
+ assert_equal %(\n), doc.to_html
39
37
  end
40
38
 
41
39
  test "Image:image-id syntax adds image caption if given" do
42
40
  given_govspeak "[Image:image-id]", images: [build_image(caption: "My Caption & so on")] do
43
41
  assert_html_output(
44
- %{<figure class="image embedded">} +
45
- %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>\n} +
46
- %{<figcaption><p>My Caption &amp; so on</p></figcaption>} +
47
- %{</figure>},
42
+ %(<figure class="image embedded">) +
43
+ %(<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>\n) +
44
+ %(<figcaption><p>My Caption &amp; so on</p></figcaption>) +
45
+ %(</figure>),
48
46
  )
49
47
  end
50
48
  end
@@ -52,9 +50,9 @@ class GovspeakImagesTest < Minitest::Test
52
50
  test "Image:image-id syntax ignores a blank caption" do
53
51
  given_govspeak "[Image:image-id]", images: [build_image(caption: " ")] do
54
52
  assert_html_output(
55
- %{<figure class="image embedded">} +
56
- %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>} +
57
- %{</figure>},
53
+ %(<figure class="image embedded">) +
54
+ %(<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>) +
55
+ %(</figure>),
58
56
  )
59
57
  end
60
58
  end
@@ -62,10 +60,10 @@ class GovspeakImagesTest < Minitest::Test
62
60
  test "Image:image-id syntax adds image credit if given" do
63
61
  given_govspeak "[Image:image-id]", images: [build_image(credit: "My Credit & so on")] do
64
62
  assert_html_output(
65
- %{<figure class="image embedded">} +
66
- %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>\n} +
67
- %{<figcaption><p>Image credit: My Credit &amp; so on</p></figcaption>} +
68
- %{</figure>},
63
+ %(<figure class="image embedded">) +
64
+ %(<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>\n) +
65
+ %(<figcaption><p>Image credit: My Credit &amp; so on</p></figcaption>) +
66
+ %(</figure>),
69
67
  )
70
68
  end
71
69
  end
@@ -73,9 +71,9 @@ class GovspeakImagesTest < Minitest::Test
73
71
  test "Image:image-id syntax ignores a blank credit" do
74
72
  given_govspeak "[Image:image-id]", images: [build_image(credit: " ")] do
75
73
  assert_html_output(
76
- %{<figure class="image embedded">} +
77
- %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>} +
78
- %{</figure>},
74
+ %(<figure class="image embedded">) +
75
+ %(<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>) +
76
+ %(</figure>),
79
77
  )
80
78
  end
81
79
  end
@@ -83,13 +81,13 @@ class GovspeakImagesTest < Minitest::Test
83
81
  test "Image:image-id syntax adds image caption and credit if given" do
84
82
  given_govspeak "[Image:image-id]", images: [build_image(caption: "My Caption & so on", credit: "My Credit & so on")] do
85
83
  assert_html_output(
86
- %{<figure class="image embedded">} +
87
- %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>\n} +
88
- %{<figcaption>} +
89
- %{<p>My Caption &amp; so on</p>\n} +
90
- %{<p>Image credit: My Credit &amp; so on</p>} +
91
- %{</figcaption>} +
92
- %{</figure>},
84
+ %(<figure class="image embedded">) +
85
+ %(<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>\n) +
86
+ %(<figcaption>) +
87
+ %(<p>My Caption &amp; so on</p>\n) +
88
+ %(<p>Image credit: My Credit &amp; so on</p>) +
89
+ %(</figcaption>) +
90
+ %(</figure>),
93
91
  )
94
92
  end
95
93
  end
@@ -101,18 +99,18 @@ class GovspeakImagesTest < Minitest::Test
101
99
 
102
100
  given_govspeak "[Image:image-id]", images: [build_image] do
103
101
  assert_html_output(
104
- %{<figure class="image embedded">} +
105
- %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>} +
106
- %{</figure>},
102
+ %(<figure class="image embedded">) +
103
+ %(<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>) +
104
+ %(</figure>),
107
105
  )
108
106
  end
109
107
 
110
108
  given_govspeak "[Image:image-id] some text", images: [build_image] do
111
109
  assert_html_output(
112
- %{<figure class="image embedded">} +
113
- %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>} +
114
- %{</figure>\n} +
115
- %{<p>some text</p>},
110
+ %(<figure class="image embedded">) +
111
+ %(<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>) +
112
+ %(</figure>\n) +
113
+ %(<p>some text</p>),
116
114
  )
117
115
  end
118
116
  end
@@ -40,7 +40,7 @@ class GovspeakLinkExtractorTest < Minitest::Test
40
40
  end
41
41
 
42
42
  test "Links are extracted from the body" do
43
- expected_links = %w{http://www.example.com http://www.gov.com /cais-trwydded-yrru-dros-dro http://www.example.com/from/html}
43
+ expected_links = %w[http://www.example.com http://www.gov.com /cais-trwydded-yrru-dros-dro http://www.example.com/from/html]
44
44
  assert_equal expected_links, links
45
45
  end
46
46
 
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  require "test_helper"
4
2
 
5
3
  class GovspeakLinkTest < Minitest::Test
@@ -2,7 +2,7 @@ require "test_helper"
2
2
 
3
3
  class GovspeakStructuredHeadersTest < Minitest::Test
4
4
  def document_body
5
- %{
5
+ %(
6
6
  ## Heading 1
7
7
 
8
8
  ## Heading 2
@@ -29,7 +29,7 @@ class GovspeakStructuredHeadersTest < Minitest::Test
29
29
 
30
30
  ## Heading 5
31
31
 
32
- }
32
+ )
33
33
  end
34
34
 
35
35
  def doc
@@ -96,8 +96,9 @@ class GovspeakStructuredHeadersTest < Minitest::Test
96
96
  },
97
97
  {
98
98
  text: "Sub heading 2.3",
99
- level: 3, id: "sub-heading-23",
100
- headers: []
99
+ level: 3,
100
+ id: "sub-heading-23",
101
+ headers: [],
101
102
  },
102
103
  ],
103
104
  }
@@ -2,7 +2,7 @@ require "test_helper"
2
2
 
3
3
  class GovspeakTableWithHeadersTest < Minitest::Test
4
4
  def expected_outcome
5
- %{
5
+ %(
6
6
  <table>
7
7
  <thead>
8
8
  <tr>
@@ -24,11 +24,11 @@ class GovspeakTableWithHeadersTest < Minitest::Test
24
24
  </tr>
25
25
  </tbody>
26
26
  </table>
27
- }
27
+ )
28
28
  end
29
29
 
30
30
  def expected_outcome_with_hashes_in_cell_contents
31
- %{
31
+ %(
32
32
  <table>
33
33
  <thead>
34
34
  <tr>
@@ -50,11 +50,11 @@ class GovspeakTableWithHeadersTest < Minitest::Test
50
50
  </tr>
51
51
  </tbody>
52
52
  </table>
53
- }
53
+ )
54
54
  end
55
55
 
56
56
  def expected_outcome_for_table_with_alignments
57
- %{
57
+ %(
58
58
  <table>
59
59
  <thead>
60
60
  <tr>
@@ -76,11 +76,11 @@ class GovspeakTableWithHeadersTest < Minitest::Test
76
76
  </tr>
77
77
  </tbody>
78
78
  </table>
79
- }
79
+ )
80
80
  end
81
81
 
82
82
  def expected_outcome_for_table_headers_in_the_wrong_place
83
- %{
83
+ %(
84
84
  <table>
85
85
  <thead>
86
86
  <tr>
@@ -102,11 +102,11 @@ class GovspeakTableWithHeadersTest < Minitest::Test
102
102
  </tr>
103
103
  </tbody>
104
104
  </table>
105
- }
105
+ )
106
106
  end
107
107
 
108
108
  def expected_outcome_for_table_with_blank_table_headers
109
- %{
109
+ %(
110
110
  <table>
111
111
  <thead>
112
112
  <tr>
@@ -128,52 +128,95 @@ class GovspeakTableWithHeadersTest < Minitest::Test
128
128
  </tr>
129
129
  </tbody>
130
130
  </table>
131
- }
131
+ )
132
+ end
133
+
134
+ def expected_outcome_for_table_headers_containing_links
135
+ %(
136
+ <table>
137
+ <thead>
138
+ <tr>
139
+ <td></td>
140
+ <th scope="col">Second Column</th>
141
+ <th scope="col">Third Column</th>
142
+ </tr>
143
+ </thead>
144
+ <tbody>
145
+ <tr>
146
+ <th scope="row">Link contained in header <a rel="external" href="http://google.com">link1</a>
147
+ </th>
148
+ <td>Cell</td>
149
+ <td>Cell</td>
150
+ </tr>
151
+ <tr>
152
+ <th scope="row">No link</th>
153
+ <td>Cell</td>
154
+ <td>Cell</td>
155
+ </tr>
156
+ <tr>
157
+ <th scope="row"><a rel="external" href="http://www.bbc.co.uk">Whole header is link</a>
158
+ </th>
159
+ <td>Cell</td>
160
+ <td>Cell</td>
161
+ </tr>
162
+ </tbody>
163
+ </table>
164
+ )
132
165
  end
133
166
 
134
167
  def document_body_with_hashes_for_all_headers
135
- @document_body_with_hashes_for_all_headers ||= Govspeak::Document.new(%{
168
+ @document_body_with_hashes_for_all_headers ||= Govspeak::Document.new(%(
136
169
  | |# Second Column |# Third Column |
137
170
  | --------------- | --------------- | ------------------- |
138
171
  |# First row | Cell | Cell |
139
172
  |# Second row | Cell | Cell |
140
- })
173
+ ))
141
174
  end
142
175
 
143
176
  def document_body_with_hashes_for_row_headers
144
- @document_body_with_hashes_for_row_headers ||= Govspeak::Document.new(%{
177
+ @document_body_with_hashes_for_row_headers ||= Govspeak::Document.new(%(
145
178
  | | Second Column | Third Column |
146
179
  | --------------- | --------------- | ------------------- |
147
180
  |# First row | Cell | Cell |
148
181
  |# Second row | Cell | Cell |
149
- })
182
+ ))
150
183
  end
151
184
 
152
185
  def document_body_with_alignments
153
- @document_body_with_alignments ||= Govspeak::Document.new(%{
186
+ @document_body_with_alignments ||= Govspeak::Document.new(%(
154
187
  | | Second Column | Third Column |
155
188
  | :-------------- | :-------------: | ------------------: |
156
189
  |# First row | Cell | Cell |
157
190
  |# Second row | Cell | Cell |
158
- })
191
+ ))
159
192
  end
160
193
 
161
194
  def document_body_with_table_headers_in_the_wrong_place
162
- @document_body_with_table_headers_in_the_wrong_place ||= Govspeak::Document.new(%{
195
+ @document_body_with_table_headers_in_the_wrong_place ||= Govspeak::Document.new(%(
163
196
  | | Second Column | Third Column |
164
197
  | --------------- | --------------- | ------------------- |
165
198
  |# First row |# Cell | Cell |
166
199
  |# Second row | Cell |# Cell |
167
- })
200
+ ))
168
201
  end
169
202
 
170
203
  def document_body_with_blank_table_headers
171
- @document_body_with_blank_table_headers ||= Govspeak::Document.new(%{
204
+ @document_body_with_blank_table_headers ||= Govspeak::Document.new(%(
172
205
  | | Second Column | Third Column |
173
206
  | --------------- | --------------- | ------------------- |
174
207
  |# | Cell | Cell |
175
208
  |# Second row | Cell | Cell |
176
- })
209
+ ))
210
+ end
211
+
212
+ def document_body_with_table_headers_containing_links
213
+ @document_body_with_table_headers_containing_links ||= Govspeak::Document.new(%(
214
+ | | Second Column | Third Column |
215
+ | ---------------------------------------------------- | --------------- | ------------------- |
216
+ |# Link contained in header [link1](http://google.com) | Cell | Cell |
217
+ |# No link | Cell | Cell |
218
+ |# [Whole header is link](http://www.bbc.co.uk) | Cell | Cell |
219
+ ))
177
220
  end
178
221
 
179
222
  test "Cells with |# are headers" do
@@ -192,6 +235,10 @@ class GovspeakTableWithHeadersTest < Minitest::Test
192
235
  assert_equal document_body_with_table_headers_in_the_wrong_place.to_html, expected_outcome_for_table_headers_in_the_wrong_place
193
236
  end
194
237
 
238
+ test "Table headers with a scope of row can have embedded links" do
239
+ assert_equal document_body_with_table_headers_containing_links.to_html, expected_outcome_for_table_headers_containing_links
240
+ end
241
+
195
242
  test "Table headers are not blank" do
196
243
  assert_equal document_body_with_blank_table_headers.to_html, expected_outcome_for_table_with_blank_table_headers
197
244
  end