Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 193
- Log:
First stage commit of Typo 4.1, modified for the ROOL site.
Includes all local modifications but a final pass needs to be
made to delete any files left over from earlier Typo versions
that shouldn't be here anymore. See the 'tags' section of the
repository for a clean Typo 4.1 tree.Note that symlinks to shared files in the RISC OS Open theme
directory have been deliberately included this time around; I
decided that on balance it was better to leave them in as
placeholders, since unlike symlinks in app/views/shared, the
Typo theme structure is not a standard Rails concept.
- Author:
- rool
- Date:
- Wed Apr 04 18:51:02 +0100 2007
- Size:
- 12060 Bytes
1 | require File.dirname(__FILE__) + '/../test_helper' |
2 | require 'textfilter_controller' |
3 | |
4 | require 'flickr_mock' |
5 | |
6 | # Re-raise errors caught by the controller. |
7 | class TextfilterController; def rescue_action(e) raise e end; end |
8 | class ActionController::Base; def rescue_action(e) raise e end; end |
9 | |
10 | class TextfilterControllerTest < Test::Unit::TestCase |
11 | fixtures :text_filters, :blogs |
12 | |
13 | def setup |
14 | @controller = TextfilterController.new |
15 | @request = ActionController::TestRequest.new |
16 | @response = ActionController::TestResponse.new |
17 | @controller.request = @request |
18 | @controller.response = @response |
19 | @controller.assigns ||= [] |
20 | reset_whiteboard |
21 | |
22 | get :test_action # set up @url; In Rails 1.0, we can't do url_for without it. |
23 | |
24 | # @controller.initialize_current_url #rescue nil |
25 | end |
26 | |
27 | def blog |
28 | blogs(:default) |
29 | end |
30 | |
31 | def filter_text(text, filters, filterparams={}) |
32 | TextFilter.filter_text(blog, text, self, filters, filterparams) |
33 | end |
34 | |
35 | def whiteboard |
36 | @whiteboard ||= Hash.new |
37 | end |
38 | |
39 | def reset_whiteboard |
40 | @whiteboard = nil |
41 | end |
42 | |
43 | def sparklines_available |
44 | begin |
45 | Plugins::Textfilters::SparklineController |
46 | rescue NameError |
47 | false |
48 | end |
49 | end |
50 | |
51 | def test_unknown |
52 | text = filter_text('*foo*',[:unknowndoesnotexist]) |
53 | assert_equal '*foo*', text |
54 | end |
55 | |
56 | def test_smartypants |
57 | text = filter_text('"foo"',[:smartypants]) |
58 | assert_equal '“foo”', text |
59 | end |
60 | |
61 | def test_markdown |
62 | text = filter_text('*foo*', [:markdown]) |
63 | assert_equal '<p><em>foo</em></p>', text |
64 | |
65 | text = filter_text("foo\n\nbar",[:markdown]) |
66 | assert_equal "<p>foo</p>\n\n<p>bar</p>", text |
67 | end |
68 | |
69 | def test_filterchain |
70 | assert_equal '<p><em>“foo”</em></p>', |
71 | filter_text('*"foo"*',[:markdown,:smartypants]) |
72 | |
73 | assert_equal '<p><em>“foo”</em></p>', |
74 | filter_text('*"foo"*',[:doesntexist1,:markdown,"doesn't exist 2",:smartypants,:nopenotmeeither]) |
75 | end |
76 | |
77 | def test_amazon |
78 | text = filter_text('<a href="amazon:097669400X" title="Rails">Rails book</a>', |
79 | [:amazon], |
80 | 'amazon-associate-id' => 'scottstuff-20') |
81 | assert_equal "<a href=\"http://www.amazon.com/exec/obidos/ASIN/097669400X/scottstuff-20\" title=\"Rails\">Rails book</a>", |
82 | text |
83 | assert_equal %w{097669400X}, whiteboard[:asins] |
84 | reset_whiteboard |
85 | |
86 | text = filter_text('[Rails book](amazon:097669400X)', |
87 | [:markdown,:amazon], |
88 | 'amazon-associate-id' => 'scottstuff-20') |
89 | assert_equal "<p><a href=\"http://www.amazon.com/exec/obidos/ASIN/097669400X/scottstuff-20\">Rails book</a></p>", |
90 | text |
91 | assert_equal %w{097669400X}, whiteboard[:asins] |
92 | reset_whiteboard |
93 | |
94 | |
95 | text = filter_text("Foo\n\n[Rails book](amazon:097669400X)", |
96 | [:markdown,:amazon], |
97 | 'amazon-associate-id' => 'scottstuff-20') |
98 | assert_equal "<p>Foo</p>\n\n<p><a href=\"http://www.amazon.com/exec/obidos/ASIN/097669400X/scottstuff-20\">Rails book</a></p>", |
99 | text |
100 | assert_equal %w{097669400X}, whiteboard[:asins] |
101 | reset_whiteboard |
102 | end |
103 | |
104 | def test_flickr |
105 | assert_equal "<div style=\"float:left\" class=\"flickrplugin\"><a href=\"http://www.flickr.com/users/scottlaird/31366117\"><img src=\"http://photos23.flickr.com/31366117_b1a791d68e_s.jpg\" width=\"75\" height=\"75\" alt=\"Matz\" title=\"Matz\"/></a><p class=\"caption\" style=\"width:75px\">This is Matz, Ruby's creator</p></div>", |
106 | filter_text('<typo:flickr img="31366117" size="Square" style="float:left"/>', |
107 | [:macropre,:macropost], |
108 | {'flickr-user' => 'scott@sigkill.org'}) |
109 | |
110 | # Test default image size |
111 | assert_equal "<div style=\"\" class=\"flickrplugin\"><a href=\"http://www.flickr.com/users/scottlaird/31366117\"><img src=\"http://photos23.flickr.com/31366117_b1a791d68e_s.jpg\" width=\"75\" height=\"75\" alt=\"Matz\" title=\"Matz\"/></a><p class=\"caption\" style=\"width:75px\">This is Matz, Ruby's creator</p></div>", |
112 | filter_text('<typo:flickr img="31366117"/>', |
113 | [:macropre,:macropost], |
114 | {'flickr-user' => 'scott@sigkill.org'}) |
115 | |
116 | # Test with caption="" |
117 | assert_equal "<div style=\"\" class=\"flickrplugin\"><a href=\"http://www.flickr.com/users/scottlaird/31366117\"><img src=\"http://photos23.flickr.com/31366117_b1a791d68e_s.jpg\" width=\"75\" height=\"75\" alt=\"Matz\" title=\"Matz\"/></a></div>", |
118 | filter_text('<typo:flickr img="31366117" caption=""/>', |
119 | [:macropre,:macropost], |
120 | {'flickr-user' => 'scott@sigkill.org'}) |
121 | end |
122 | |
123 | def test_broken_flickr_link |
124 | assert_equal %{<div class='broken_flickr_link'>\`notaflickrid\' could not be displayed because: <br />Photo not found</div>}, |
125 | filter_text('<typo:flickr img="notaflickrid" />', |
126 | [:macropre, :macropost], |
127 | { 'flickr-user' => 'scott@sigkill.org' }) |
128 | end |
129 | |
130 | def test_sparkline |
131 | return unless sparklines_available |
132 | |
133 | tag = filter_text('<typo:sparkline foo="bar"/>',[:macropre,:macropost]) |
134 | # url_for returns query params in hash order, which isn't stable, so we can't just compare |
135 | # with a static string. Yuck. |
136 | assert tag =~ %r{^<img src="http://test.host/plugins/filters/sparkline/plot\?(data=|foo=bar|&)+"/>$} |
137 | |
138 | assert_equal "<img title=\"aaa\" src=\"http://test.host/plugins/filters/sparkline/plot?data=\"/>", |
139 | filter_text('<typo:sparkline title="aaa"/>',[:macropre,:macropost]) |
140 | |
141 | assert_equal "<img style=\"bbb\" src=\"http://test.host/plugins/filters/sparkline/plot?data=\"/>", |
142 | filter_text('<typo:sparkline style="bbb"/>',[:macropre,:macropost]) |
143 | |
144 | tag = filter_text('<typo:sparkline alt="ccc"/>',[:macropre,:macropost]) |
145 | assert_tag_in tag, :tag => 'img', :attributes => { |
146 | 'alt' => 'ccc', |
147 | 'src' => URI.parse('http://test.host/plugins/filters/sparkline/plot?data=') |
148 | }, :children => { :count => 0 } |
149 | |
150 | tag = filter_text('<typo:sparkline type="smooth" data="1 2 3 4"/>',[:macropre,:macropost]) |
151 | assert_tag_in tag, :tag => 'img', :attributes => { |
152 | 'src' => URI.parse('http://test.host/plugins/filters/sparkline/plot?data=1%2C2%2C3%2C4&type=smooth') |
153 | }, :children => { :count => 0 } |
154 | |
155 | assert_equal "<img src=\"http://test.host/plugins/filters/sparkline/plot?data=1%2C2%2C3%2C4%2C5%2C6\"/>", |
156 | filter_text('<typo:sparkline>1 2 3 4 5 6</typo:sparkline>',[:macropre,:macropost]) |
157 | end |
158 | |
159 | def test_sparkline_plot |
160 | return unless sparklines_available |
161 | |
162 | get 'public_action', :filter => 'sparkline', :public_action => 'plot', :data => '1,2,3' |
163 | assert_response :success |
164 | |
165 | get 'public_action', :filter => 'sparkline', :public_action => 'plot2', :data => '1,2,3' |
166 | assert_response :missing |
167 | |
168 | get 'public_action', :filter => 'sparkline', :public_action => 'plot', :data => '1,2,3', :type => 'smooth' |
169 | assert_response :success |
170 | |
171 | get 'public_action', :filter => 'sparkline', :public_action => 'plot', :data => '1,2,3', :type => 'instance_methods' |
172 | assert_response :error |
173 | end |
174 | |
175 | def test_code |
176 | assert_equal %{<div class="typocode"><pre><code class="typocode_default "><notextile>foo-code</notextile></code></pre></div>}, |
177 | filter_text('<typo:code>foo-code</typo:code>',[:macropre,:macropost]) |
178 | |
179 | assert_equal %{<div class="typocode"><pre><code class="typocode_ruby "><notextile><span class="ident">foo</span><span class="punct">-</span><span class="ident">code</span></notextile></code></pre></div>}, |
180 | filter_text('<typo:code lang="ruby">foo-code</typo:code>',[:macropre,:macropost]) |
181 | |
182 | assert_equal %{<div class="typocode"><pre><code class="typocode_ruby "><notextile><span class="ident">foo</span><span class="punct">-</span><span class="ident">code</span></notextile></code></pre></div> blah blah <div class="typocode"><pre><code class="typocode_xml "><notextile>zzz</notextile></code></pre></div>}, |
183 | filter_text('<typo:code lang="ruby">foo-code</typo:code> blah blah <typo:code lang="xml">zzz</typo:code>',[:macropre,:macropost]) |
184 | end |
185 | |
186 | def test_code_multiline |
187 | assert_equal %{\n<div class="typocode"><pre><code class="typocode_ruby "><notextile><span class="keyword">class </span><span class="class">Foo</span>\n <span class="keyword">def </span><span class="method">bar</span>\n <span class="attribute">@a</span> <span class="punct">=</span> <span class="punct">"</span><span class="string">zzz</span><span class="punct">"</span>\n <span class="keyword">end</span>\n<span class="keyword">end</span></notextile></code></pre></div>\n}, |
188 | filter_text(%{ |
189 | <typo:code lang="ruby"> |
190 | class Foo |
191 | def bar |
192 | @a = "zzz" |
193 | end |
194 | end |
195 | </typo:code> |
196 | },[:macropre,:macropost]) |
197 | end |
198 | |
199 | def test_named_filter |
200 | assert_equal '<p><em>“foo”</em></p>', |
201 | TextFilter.filter_text_by_name(blog, '*"foo"*', 'markdown smartypants') |
202 | end |
203 | |
204 | def test_code_plus_markup_chain |
205 | text = <<-EOF |
206 | *header text here* |
207 | |
208 | <typo:code lang="ruby"> |
209 | class test |
210 | def method |
211 | "foo" |
212 | end |
213 | end |
214 | </typo:code> |
215 | |
216 | _footer text here_ |
217 | |
218 | EOF |
219 | |
220 | expects_markdown = <<-EOF |
221 | <p><em>header text here</em></p> |
222 | |
223 | <div class="typocode"><pre><code class="typocode_ruby "><span class="keyword">class </span><span class="class">test</span> |
224 | <span class="keyword">def </span><span class="method">method</span> |
225 | <span class="punct">"</span><span class="string">foo</span><span class="punct">"</span> |
226 | <span class="keyword">end</span> |
227 | <span class="keyword">end</span></code></pre></div> |
228 | |
229 | <p><em>footer text here</em></p> |
230 | EOF |
231 | |
232 | expects_textile = <<-EOF |
233 | <p><strong>header text here</strong></p> |
234 | |
235 | |
236 | <div class="typocode"><pre><code class="typocode_ruby "><span class="keyword">class </span><span class="class">test</span> |
237 | <span class="keyword">def </span><span class="method">method</span> |
238 | <span class="punct">"</span><span class="string">foo</span><span class="punct">"</span> |
239 | <span class="keyword">end</span> |
240 | <span class="keyword">end</span></code></pre></div> |
241 | |
242 | \t<p><em>footer text here</em></p> |
243 | EOF |
244 | |
245 | assert_equal expects_markdown.strip, TextFilter.filter_text_by_name(blog, text, 'markdown') |
246 | assert_equal expects_textile.strip, TextFilter.filter_text_by_name(blog, text, 'textile') |
247 | end |
248 | |
249 | def test_lightbox |
250 | assert_equal "<div style=\"float:left\" class=\"lightboxplugin\"><a href=\"http://photos23.flickr.com/31366117_b1a791d68e_b.jpg\" rel=\"lightbox\" title=\"Matz\"><img src=\"http://photos23.flickr.com/31366117_b1a791d68e_t.jpg\" width=\"67\" height=\"100\" alt=\"Matz\" title=\"Matz\"/></a><p class=\"caption\" style=\"width:67px\">This is Matz, Ruby's creator</p></div>", |
251 | filter_text('<typo:lightbox img="31366117" thumbsize="Thumbnail" displaysize="Large" style="float:left"/>', |
252 | [:macropre,:macropost], |
253 | {}) |
254 | |
255 | # Test default thumb image size |
256 | assert_equal "<div style=\"\" class=\"lightboxplugin\"><a href=\"http://photos23.flickr.com/31366117_b1a791d68e_b.jpg\" rel=\"lightbox\" title=\"Matz\"><img src=\"http://photos23.flickr.com/31366117_b1a791d68e_s.jpg\" width=\"75\" height=\"75\" alt=\"Matz\" title=\"Matz\"/></a><p class=\"caption\" style=\"width:75px\">This is Matz, Ruby's creator</p></div>", |
257 | filter_text('<typo:lightbox img="31366117" displaysize="Large"/>', |
258 | [:macropre,:macropost], |
259 | {}) |
260 | |
261 | # Test default display image size |
262 | assert_equal "<div style=\"\" class=\"lightboxplugin\"><a href=\"http://photos23.flickr.com/31366117_b1a791d68e_o.jpg\" rel=\"lightbox\" title=\"Matz\"><img src=\"http://photos23.flickr.com/31366117_b1a791d68e_s.jpg\" width=\"75\" height=\"75\" alt=\"Matz\" title=\"Matz\"/></a><p class=\"caption\" style=\"width:75px\">This is Matz, Ruby's creator</p></div>", |
263 | filter_text('<typo:lightbox img="31366117"/>', |
264 | [:macropre,:macropost], |
265 | {}) |
266 | |
267 | # Test with caption="" |
268 | assert_equal "<div style=\"\" class=\"lightboxplugin\"><a href=\"http://photos23.flickr.com/31366117_b1a791d68e_o.jpg\" rel=\"lightbox\" title=\"Matz\"><img src=\"http://photos23.flickr.com/31366117_b1a791d68e_s.jpg\" width=\"75\" height=\"75\" alt=\"Matz\" title=\"Matz\"/></a></div>", |
269 | filter_text('<typo:lightbox img="31366117" caption=""/>', |
270 | [:macropre,:macropost], |
271 | {}) |
272 | end |
273 | end |