govspeak 6.5.0 → 6.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,9 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'test_helper'
4
- require 'govspeak_test_helper'
3
+ require "test_helper"
4
+ require "govspeak_test_helper"
5
5
 
6
- require 'ostruct'
6
+ require "ostruct"
7
7
 
8
8
  class GovspeakTest < Minitest::Test
9
9
  include GovspeakTestHelper
@@ -42,7 +42,7 @@ class GovspeakTest < Minitest::Test
42
42
 
43
43
  # Test that nothing renders when not given a link
44
44
  test_given_govspeak "{button}I shouldn't render a button{/button}" do
45
- assert_html_output '<p>{button}I shouldn’t render a button{/button}</p>'
45
+ assert_html_output "<p>{button}I shouldn’t render a button{/button}</p>"
46
46
  end
47
47
 
48
48
  test_given_govspeak "Text before the button with line breaks \n\n\n{button}[Start Now](http://www.gov.uk){/button}\n\n\n test after the button" do
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'test_helper'
3
+ require "test_helper"
4
4
 
5
5
  class GovspeakContactsTest < Minitest::Test
6
6
  def build_contact(attrs = {})
@@ -19,8 +19,8 @@ class GovspeakContactsTest < Minitest::Test
19
19
  region: "London",
20
20
  postal_code: "WC2B 6NH",
21
21
  world_location: "United Kingdom",
22
- }
23
- ]
22
+ },
23
+ ],
24
24
  ),
25
25
  email_addresses: attrs.fetch(
26
26
  :email_addresses,
@@ -28,8 +28,8 @@ class GovspeakContactsTest < Minitest::Test
28
28
  {
29
29
  title: "",
30
30
  email: "people@digital.cabinet-office.gov.uk",
31
- }
32
- ]
31
+ },
32
+ ],
33
33
  ),
34
34
  phone_numbers: attrs.fetch(
35
35
  :phone_numbers,
@@ -37,23 +37,23 @@ class GovspeakContactsTest < Minitest::Test
37
37
  {
38
38
  title: "helpdesk",
39
39
  number: "+4412345 67890",
40
- }
41
- ]
40
+ },
41
+ ],
42
42
  ),
43
43
  contact_form_links: attrs.fetch(
44
44
  :contact_form_links,
45
45
  [
46
46
  {
47
- link: "https://www.gov.uk/contact"
48
- }
49
- ]
50
- )
51
- }
47
+ link: "https://www.gov.uk/contact",
48
+ },
49
+ ],
50
+ ),
51
+ },
52
52
  }
53
53
  end
54
54
 
55
55
  def compress_html(html)
56
- html.gsub(/[\n\r]+[\s]*/, '')
56
+ html.gsub(/[\n\r]+[\s]*/, "")
57
57
  end
58
58
 
59
59
  test "contact is rendered when present in options[:contacts]" do
@@ -136,7 +136,7 @@ class GovspeakContactsTest < Minitest::Test
136
136
  {
137
137
  street_address: "125 Kingsway",
138
138
  country_name: "United Kingdom",
139
- }
139
+ },
140
140
  ])
141
141
  govspeak = "[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]"
142
142
  rendered = Govspeak::Document.new(govspeak, contacts: [contact]).to_html
@@ -152,7 +152,7 @@ class GovspeakContactsTest < Minitest::Test
152
152
  contact = build_contact(post_addresses: [
153
153
  {
154
154
  street_address: "",
155
- }
155
+ },
156
156
  ])
157
157
  govspeak = "[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]"
158
158
  rendered = Govspeak::Document.new(govspeak, contacts: [contact]).to_html
@@ -163,7 +163,7 @@ class GovspeakContactsTest < Minitest::Test
163
163
  contact = build_contact(email_addresses: [
164
164
  {
165
165
  email: "",
166
- }
166
+ },
167
167
  ])
168
168
  govspeak = "[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]"
169
169
  rendered = Govspeak::Document.new(govspeak, contacts: [contact]).to_html
@@ -174,7 +174,7 @@ class GovspeakContactsTest < Minitest::Test
174
174
  contact = build_contact(contact_form_links: [
175
175
  {
176
176
  link: "",
177
- }
177
+ },
178
178
  ])
179
179
  govspeak = "[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]"
180
180
  rendered = Govspeak::Document.new(govspeak, contacts: [contact]).to_html
@@ -185,7 +185,7 @@ class GovspeakContactsTest < Minitest::Test
185
185
  contact = build_contact(phone_numbers: [
186
186
  {
187
187
  number: "",
188
- }
188
+ },
189
189
  ])
190
190
  govspeak = "[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]"
191
191
  rendered = Govspeak::Document.new(govspeak, contacts: [contact]).to_html
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'test_helper'
3
+ require "test_helper"
4
4
 
5
5
  class GovspeakExtractContactContentIdsTest < Minitest::Test
6
6
  test "contact content ids can be extracted from govspeak" do
@@ -1,7 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'test_helper'
4
- require 'govspeak_test_helper'
3
+ require "test_helper"
4
+ require "govspeak_test_helper"
5
5
 
6
6
  class GovspeakImagesBangTest < Minitest::Test
7
7
  include GovspeakTestHelper
@@ -22,7 +22,7 @@ class GovspeakImagesBangTest < Minitest::Test
22
22
  assert_html_output(
23
23
  %{<figure class="image embedded">} +
24
24
  %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>} +
25
- %{</figure>}
25
+ %{</figure>},
26
26
  )
27
27
  end
28
28
  end
@@ -32,7 +32,7 @@ class GovspeakImagesBangTest < Minitest::Test
32
32
  assert_html_output(
33
33
  %{<figure class="image embedded">} +
34
34
  %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt '&amp;&quot;&lt;&gt;"></div>} +
35
- %{</figure>}
35
+ %{</figure>},
36
36
  )
37
37
  end
38
38
  end
@@ -48,49 +48,49 @@ class GovspeakImagesBangTest < Minitest::Test
48
48
  end
49
49
 
50
50
  test "!!n syntax adds image caption if given" do
51
- given_govspeak "!!1", images: [Image.new(caption: 'My Caption & so on')] do
51
+ given_govspeak "!!1", images: [Image.new(caption: "My Caption & so on")] do
52
52
  assert_html_output(
53
53
  %{<figure class="image embedded">} +
54
54
  %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>\n} +
55
55
  %{<figcaption><p>My Caption &amp; so on</p></figcaption>} +
56
- %{</figure>}
56
+ %{</figure>},
57
57
  )
58
58
  end
59
59
  end
60
60
 
61
61
  test "!!n syntax ignores a blank caption" do
62
- given_govspeak "!!1", images: [Image.new(caption: ' ')] do
62
+ given_govspeak "!!1", images: [Image.new(caption: " ")] do
63
63
  assert_html_output(
64
64
  %{<figure class="image embedded">} +
65
65
  %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>} +
66
- %{</figure>}
66
+ %{</figure>},
67
67
  )
68
68
  end
69
69
  end
70
70
 
71
71
  test "¡¡n syntax adds image credit if given" do
72
- given_govspeak "!!1", images: [Image.new(credit: 'My Credit & so on')] do
72
+ given_govspeak "!!1", images: [Image.new(credit: "My Credit & so on")] do
73
73
  assert_html_output(
74
74
  %{<figure class="image embedded">} +
75
75
  %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>\n} +
76
76
  %{<figcaption><p>Image credit: My Credit &amp; so on</p></figcaption>} +
77
- %{</figure>}
77
+ %{</figure>},
78
78
  )
79
79
  end
80
80
  end
81
81
 
82
82
  test "!!n syntax ignores a blank credit" do
83
- given_govspeak "!!1", images: [Image.new(credit: ' ')] do
83
+ given_govspeak "!!1", images: [Image.new(credit: " ")] do
84
84
  assert_html_output(
85
85
  %{<figure class="image embedded">} +
86
86
  %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>} +
87
- %{</figure>}
87
+ %{</figure>},
88
88
  )
89
89
  end
90
90
  end
91
91
 
92
92
  test "!!n syntax adds image caption and credit if given" do
93
- given_govspeak "!!1", images: [Image.new(caption: 'My Caption & so on', credit: 'My Credit & so on')] do
93
+ given_govspeak "!!1", images: [Image.new(caption: "My Caption & so on", credit: "My Credit & so on")] do
94
94
  assert_html_output(
95
95
  %{<figure class="image embedded">} +
96
96
  %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>\n} +
@@ -98,7 +98,7 @@ class GovspeakImagesBangTest < Minitest::Test
98
98
  %{<p>My Caption &amp; so on</p>\n} +
99
99
  %{<p>Image credit: My Credit &amp; so on</p>} +
100
100
  %{</figcaption>} +
101
- %{</figure>}
101
+ %{</figure>},
102
102
  )
103
103
  end
104
104
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'test_helper'
4
- require 'govspeak_test_helper'
3
+ require "test_helper"
4
+ require "govspeak_test_helper"
5
5
 
6
6
  class GovspeakImagesTest < Minitest::Test
7
7
  include GovspeakTestHelper
@@ -18,7 +18,7 @@ class GovspeakImagesTest < Minitest::Test
18
18
  assert_html_output(
19
19
  %{<figure class="image embedded">} +
20
20
  %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>} +
21
- %{</figure>}
21
+ %{</figure>},
22
22
  )
23
23
  end
24
24
  end
@@ -28,7 +28,7 @@ class GovspeakImagesTest < Minitest::Test
28
28
  assert_html_output(
29
29
  %{<figure class="image embedded">} +
30
30
  %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt '&amp;&quot;&lt;&gt;"></div>} +
31
- %{</figure>}
31
+ %{</figure>},
32
32
  )
33
33
  end
34
34
  end
@@ -39,49 +39,49 @@ class GovspeakImagesTest < Minitest::Test
39
39
  end
40
40
 
41
41
  test "Image:image-id syntax adds image caption if given" do
42
- given_govspeak "[Image:image-id]", images: [build_image(caption: 'My Caption & so on')] do
42
+ given_govspeak "[Image:image-id]", images: [build_image(caption: "My Caption & so on")] do
43
43
  assert_html_output(
44
44
  %{<figure class="image embedded">} +
45
45
  %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>\n} +
46
46
  %{<figcaption><p>My Caption &amp; so on</p></figcaption>} +
47
- %{</figure>}
47
+ %{</figure>},
48
48
  )
49
49
  end
50
50
  end
51
51
 
52
52
  test "Image:image-id syntax ignores a blank caption" do
53
- given_govspeak "[Image:image-id]", images: [build_image(caption: ' ')] do
53
+ given_govspeak "[Image:image-id]", images: [build_image(caption: " ")] do
54
54
  assert_html_output(
55
55
  %{<figure class="image embedded">} +
56
56
  %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>} +
57
- %{</figure>}
57
+ %{</figure>},
58
58
  )
59
59
  end
60
60
  end
61
61
 
62
62
  test "Image:image-id syntax adds image credit if given" do
63
- given_govspeak "[Image:image-id]", images: [build_image(credit: 'My Credit & so on')] do
63
+ given_govspeak "[Image:image-id]", images: [build_image(credit: "My Credit & so on")] do
64
64
  assert_html_output(
65
65
  %{<figure class="image embedded">} +
66
66
  %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>\n} +
67
67
  %{<figcaption><p>Image credit: My Credit &amp; so on</p></figcaption>} +
68
- %{</figure>}
68
+ %{</figure>},
69
69
  )
70
70
  end
71
71
  end
72
72
 
73
73
  test "Image:image-id syntax ignores a blank credit" do
74
- given_govspeak "[Image:image-id]", images: [build_image(credit: ' ')] do
74
+ given_govspeak "[Image:image-id]", images: [build_image(credit: " ")] do
75
75
  assert_html_output(
76
76
  %{<figure class="image embedded">} +
77
77
  %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>} +
78
- %{</figure>}
78
+ %{</figure>},
79
79
  )
80
80
  end
81
81
  end
82
82
 
83
83
  test "Image:image-id syntax adds image caption and credit if given" do
84
- given_govspeak "[Image:image-id]", images: [build_image(caption: 'My Caption & so on', credit: 'My Credit & so on')] do
84
+ given_govspeak "[Image:image-id]", images: [build_image(caption: "My Caption & so on", credit: "My Credit & so on")] do
85
85
  assert_html_output(
86
86
  %{<figure class="image embedded">} +
87
87
  %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>\n} +
@@ -89,7 +89,7 @@ class GovspeakImagesTest < Minitest::Test
89
89
  %{<p>My Caption &amp; so on</p>\n} +
90
90
  %{<p>Image credit: My Credit &amp; so on</p>} +
91
91
  %{</figcaption>} +
92
- %{</figure>}
92
+ %{</figure>},
93
93
  )
94
94
  end
95
95
  end
@@ -103,7 +103,7 @@ class GovspeakImagesTest < Minitest::Test
103
103
  assert_html_output(
104
104
  %{<figure class="image embedded">} +
105
105
  %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>} +
106
- %{</figure>}
106
+ %{</figure>},
107
107
  )
108
108
  end
109
109
 
@@ -112,7 +112,7 @@ class GovspeakImagesTest < Minitest::Test
112
112
  %{<figure class="image embedded">} +
113
113
  %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>} +
114
114
  %{</figure>\n} +
115
- %{<p>some text</p>}
115
+ %{<p>some text</p>},
116
116
  )
117
117
  end
118
118
  end
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'test_helper'
3
+ require "test_helper"
4
4
 
5
5
  class GovspeakLinkTest < Minitest::Test
6
6
  test "embedded link with link provided" do
@@ -1,4 +1,4 @@
1
- require 'test_helper'
1
+ require "test_helper"
2
2
 
3
3
  class GovspeakStructuredHeadersTest < Minitest::Test
4
4
  def document_body
@@ -90,7 +90,7 @@ class GovspeakStructuredHeadersTest < Minitest::Test
90
90
  text: "Sub sub heading 2.2.1",
91
91
  level: 4,
92
92
  id: "sub-sub-heading-221",
93
- headers: []
93
+ headers: [],
94
94
  },
95
95
  ],
96
96
  },
@@ -1,4 +1,4 @@
1
- require 'test_helper'
1
+ require "test_helper"
2
2
 
3
3
  class GovspeakTableWithHeadersTest < Minitest::Test
4
4
  def expected_outcome
@@ -1,9 +1,9 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'test_helper'
4
- require 'govspeak_test_helper'
3
+ require "test_helper"
4
+ require "govspeak_test_helper"
5
5
 
6
- require 'ostruct'
6
+ require "ostruct"
7
7
 
8
8
  class GovspeakTest < Minitest::Test
9
9
  include GovspeakTestHelper
@@ -20,7 +20,7 @@ class GovspeakTest < Minitest::Test
20
20
 
21
21
  test "strips forbidden unicode characters" do
22
22
  rendered = Govspeak::Document.new(
23
- "this is text with forbidden characters \ufffc\u2028\ufeff\u202c\u202a"
23
+ "this is text with forbidden characters \u0008\u000b\ufffe\u{2ffff}\u{5fffe}",
24
24
  ).to_html
25
25
  assert_equal "<p>this is text with forbidden characters</p>\n", rendered
26
26
  end
@@ -44,17 +44,17 @@ class GovspeakTest < Minitest::Test
44
44
  ## Medium title
45
45
  }
46
46
  assert_equal [
47
- Govspeak::Header.new('Big title', 1, 'big-title'),
48
- Govspeak::Header.new('Small subtitle', 3, 'small-subtitle'),
49
- Govspeak::Header.new('Medium title', 2, 'medium-title')
47
+ Govspeak::Header.new("Big title", 1, "big-title"),
48
+ Govspeak::Header.new("Small subtitle", 3, "small-subtitle"),
49
+ Govspeak::Header.new("Medium title", 2, "medium-title"),
50
50
  ], document.headers
51
51
  end
52
52
 
53
53
  test "extracts different ids for duplicate headers" do
54
54
  document = Govspeak::Document.new("## Duplicate header\n\n## Duplicate header")
55
55
  assert_equal [
56
- Govspeak::Header.new('Duplicate header', 2, 'duplicate-header'),
57
- Govspeak::Header.new('Duplicate header', 2, 'duplicate-header-1')
56
+ Govspeak::Header.new("Duplicate header", 2, "duplicate-header"),
57
+ Govspeak::Header.new("Duplicate header", 2, "duplicate-header-1"),
58
58
  ], document.headers
59
59
  end
60
60
 
@@ -76,10 +76,10 @@ class GovspeakTest < Minitest::Test
76
76
  </div>
77
77
  }
78
78
  assert_equal [
79
- Govspeak::Header.new('First title', 1, 'first-title'),
80
- Govspeak::Header.new('Nested subtitle', 2, 'nested-subtitle'),
81
- Govspeak::Header.new('Double nested subtitle', 3, 'double-nested-subtitle'),
82
- Govspeak::Header.new('Second double subtitle', 3, 'second-double-subtitle')
79
+ Govspeak::Header.new("First title", 1, "first-title"),
80
+ Govspeak::Header.new("Nested subtitle", 2, "nested-subtitle"),
81
+ Govspeak::Header.new("Double nested subtitle", 3, "double-nested-subtitle"),
82
+ Govspeak::Header.new("Second double subtitle", 3, "second-double-subtitle"),
83
83
  ], document.headers
84
84
  end
85
85
 
@@ -90,8 +90,8 @@ class GovspeakTest < Minitest::Test
90
90
  ## Second title {#special}
91
91
  }
92
92
  assert_equal [
93
- Govspeak::Header.new('First title', 1, 'first-title'),
94
- Govspeak::Header.new('Second title', 2, 'special'),
93
+ Govspeak::Header.new("First title", 1, "first-title"),
94
+ Govspeak::Header.new("Second title", 2, "special"),
95
95
  ], document.headers
96
96
  end
97
97
 
@@ -360,7 +360,7 @@ Teston
360
360
  # TODO: review whether we should require closing symbols for these extensions
361
361
  # need to check all existing content.
362
362
  test_given_govspeak "xaa" do
363
- assert_html_output '<p>xaa</p>'
363
+ assert_html_output "<p>xaa</p>"
364
364
  assert_text_output "xaa"
365
365
  end
366
366
 
@@ -639,12 +639,12 @@ Teston
639
639
  }
640
640
  end
641
641
 
642
- test 'sanitize source input by default' do
642
+ test "sanitize source input by default" do
643
643
  document = Govspeak::Document.new("<script>doBadThings();</script>")
644
644
  assert_equal "", document.to_html.strip
645
645
  end
646
646
 
647
- test 'it can have sanitizing disabled' do
647
+ test "it can have sanitizing disabled" do
648
648
  document = Govspeak::Document.new("<script>doGoodThings();</script>", sanitize: false)
649
649
  assert_equal "<script>doGoodThings();</script>", document.to_html.strip
650
650
  end