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:
- 17760 Bytes
1 | require File.dirname(__FILE__) + '/../test_helper' |
2 | require 'articles_controller' |
3 | require 'dns_mock' |
4 | require 'http_mock' |
5 | |
6 | require 'content' |
7 | |
8 | # |
9 | # Re-raise errors caught by the controller. |
10 | class ArticlesController; def rescue_action(e) raise e end; end |
11 | |
12 | class Content |
13 | def self.find_last_posted |
14 | self.find(:first, :conditions => ['created_at < ?', Time.now], |
15 | :order => 'created_at desc') |
16 | end |
17 | end |
18 | |
19 | class ArticlesControllerTest < Test::Unit::TestCase |
20 | fixtures :contents, :feedback, :categories, :blogs, :users, :categorizations, :text_filters, :articles_tags, :tags |
21 | include ArticlesHelper |
22 | |
23 | def setup |
24 | @controller = ArticlesController.new |
25 | @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new |
26 | |
27 | Article.create!(:title => "News from the future!", |
28 | :body => "The future is cool!", |
29 | :keywords => "future", |
30 | :created_at => Time.now + 12.minutes) |
31 | Sidebar.delete_all |
32 | end |
33 | |
34 | # Category subpages |
35 | def test_category |
36 | get :category, :id => "software" |
37 | |
38 | assert_response :success |
39 | assert_template "index" |
40 | assert_tag :tag => 'title', :content => 'test blog : category software' |
41 | |
42 | # Check it works when permalink != name. Ticket #736 |
43 | get :category, :id => "weird-permalink" |
44 | |
45 | assert_response :success |
46 | assert_template "index" |
47 | end |
48 | |
49 | def test_empty_category |
50 | get :category, :id => "life-on-mars" |
51 | assert_response :success |
52 | assert_template "error" |
53 | end |
54 | |
55 | def test_nonexistent_category |
56 | get :category, :id => 'nonexistent-category' |
57 | assert_response :success |
58 | assert_template "error" |
59 | end |
60 | |
61 | def test_tag |
62 | get :tag, :id => "foo" |
63 | |
64 | assert_response :success |
65 | assert_template "index" |
66 | |
67 | assert_tag :tag => 'title', :content => 'test blog : tag foo' |
68 | assert_tag :tag => 'h2', :content => 'Article 2!' |
69 | assert_tag :tag => 'h2', :content => 'Article 1!' |
70 | end |
71 | |
72 | def test_nonexistent_tag |
73 | get :tag, :id => "nonexistent" |
74 | assert_response :success |
75 | assert_template "error" |
76 | end |
77 | |
78 | def test_tag_routes |
79 | opts = {:controller => "articles", :action => "tag", :id => "foo", :page => "2"} |
80 | assert_routing("articles/tag/foo/page/2", opts) |
81 | end |
82 | |
83 | def test_simple_tag_pagination |
84 | this_blog.limit_article_display = 1 |
85 | get :tag, :id => "foo" |
86 | assert_equal 1, assigns(:articles).size |
87 | assert_tag(:tag => 'p', |
88 | :attributes =>{ :id => 'pagination' }, |
89 | :content => %r{Older posts: 1}, |
90 | :descendant => {:tag => 'a', |
91 | :attributes =>{ |
92 | :href => "/articles/tag/foo/page/2"}, |
93 | :content => "2"}) |
94 | end |
95 | |
96 | # Main index |
97 | def test_index |
98 | get :index |
99 | assert_response :success |
100 | assert_template "index" |
101 | end |
102 | |
103 | # Archives page |
104 | def test_archives |
105 | get :archives |
106 | assert_response :success |
107 | assert_template "archives" |
108 | end |
109 | |
110 | def test_blog_title |
111 | blogs(:default).title_prefix = 1 |
112 | get :permalink, :year => 2004, :month => 06, :day => 01, :title => "article-3" |
113 | assert_response :success |
114 | assert_tag :tag => 'title', :content => /^test blog : Article 3!$/ |
115 | |
116 | blogs(:default).title_prefix = 0 |
117 | @controller = ArticlesController.new |
118 | assert_equal 0, blogs(:default).title_prefix |
119 | get :permalink, :year => 2004, :month => 06, :day => 01, :title => "article-3" |
120 | assert_response :success |
121 | assert_tag :tag => 'title', :content => /^Article 3!$/ |
122 | end |
123 | |
124 | # Permalinks |
125 | def test_permalink |
126 | get :permalink, :year => 2004, :month => 06, :day => 01, :title => "article-3" |
127 | assert_response :success |
128 | assert_template "read" |
129 | assert_not_nil assigns(:article) |
130 | assert_equal contents(:article3), assigns(:article) |
131 | end |
132 | |
133 | # Posts for given day |
134 | def test_find_by_date |
135 | get :find_by_date, :year => 2004, :month => 06, :day => 01 |
136 | assert_response :success |
137 | assert_template "index" |
138 | end |
139 | |
140 | def test_comment_posting |
141 | emails = ActionMailer::Base.deliveries |
142 | emails.clear |
143 | |
144 | assert_equal 0, emails.size |
145 | |
146 | Article.find(1).notify_users << users(:tobi) |
147 | |
148 | post :comment, { :id => 1, :comment => {'body' => 'This is *markdown*', 'author' => 'bob' }} |
149 | |
150 | assert_response :success |
151 | assert_tag :tag => 'em', :content => 'markdown' |
152 | |
153 | comment = Article.find(1).comments.last |
154 | assert comment |
155 | |
156 | assert_not_nil cookies["typoapp_author"] |
157 | |
158 | assert_equal "<p>This is <em>markdown</em></p>", comment.html.to_s |
159 | |
160 | assert_equal 2, emails.size |
161 | assert_equal User.find(:all, |
162 | :conditions => ['(notify_via_email = ?) and (notify_on_comments = ?)', true, true], |
163 | :order => 'email').collect { |each| each.email }, |
164 | emails.collect { |each| each.to[0] }.sort |
165 | end |
166 | |
167 | def test_comment_spam_markdown_smarty |
168 | this_blog.comment_text_filter = "markdown smartypants" |
169 | test_comment_spam1 |
170 | end |
171 | |
172 | def comment_template_test(expected_html, source_text, |
173 | art_id=1, author='bob', email='foo', args={}) |
174 | post :comment, { |
175 | :id => art_id, |
176 | :comment => { |
177 | 'body' => source_text, |
178 | 'author' => author, |
179 | 'email' => email }.merge(args) } |
180 | |
181 | assert_response :success |
182 | comment = Article.find(art_id).comments.last |
183 | assert comment |
184 | |
185 | assert_match expected_html, comment.html.to_s |
186 | $do_breakpoints |
187 | end |
188 | |
189 | def test_comment_spam1 |
190 | comment_template_test "<p>Link to <a href=\"http://spammer.example.com\" rel=\"nofollow\">spammy goodness</a></p>", 'Link to <a href="http://spammer.example.com">spammy goodness</a>' |
191 | end |
192 | |
193 | def test_comment_spam2 |
194 | comment_template_test %r{<p>Link to <a href=["']http://spammer.example.com['"] rel=["']nofollow['"]>spammy goodness</a></p>}, 'Link to [spammy goodness](http://spammer.example.com)' |
195 | end |
196 | |
197 | def test_comment_spam3 |
198 | post :comment, :id => 1, :comment => {:body => '<a href="http://spam.org">spam</a>', :author => '<a href="spamme.com">spamme</a>', :email => '<a href="http://morespam.net">foo</a>'} |
199 | |
200 | assert_response :success |
201 | comment = Article.find(1).comments.last |
202 | assert comment |
203 | |
204 | get :read, :id => 1 |
205 | assert_response 200 |
206 | |
207 | assert ! (@response.body =~ %r{<a href="http://spamme.com">}), "Author leaks" |
208 | assert ! (@response.body =~ %r{<a href="http://spam.org">}), "Body leaks <a>" |
209 | assert ! (@response.body =~ %r{<a href="http://morespam.net">}), "Email leaks" |
210 | end |
211 | |
212 | def test_comment_xss1 |
213 | this_blog.comment_text_filter = "none" |
214 | comment_template_test %{Have you ever alert("foo"); been hacked?}, |
215 | %{Have you ever <script lang="javascript">alert("foo");</script> been hacked?} |
216 | end |
217 | |
218 | def test_comment_xss2 |
219 | this_blog.comment_text_filter = "none" |
220 | comment_template_test "Have you ever <a href=\"#\" rel=\"nofollow\">been hacked?</a>", 'Have you ever <a href="#" onclick="javascript">been hacked?</a>' |
221 | end |
222 | |
223 | def test_comment_autolink |
224 | comment_template_test "<p>What's up with <a href=\"http://slashdot.org\" rel=\"nofollow\">http://slashdot.org</a> these days?</p>", "What's up with http://slashdot.org these days\?" |
225 | end |
226 | |
227 | ### TODO -- there's a bug in Rails with auto_links |
228 | # def test_comment_autolink2 |
229 | # comment_template_test "<p>My web page is <a href='http://somewhere.com/~me/index.html' rel=\"nofollow\">http://somewhere.com/~me/index.html</a></p>", "My web page is http://somewhere.com/~me/index.html" |
230 | # end |
231 | |
232 | def test_comment_nuking |
233 | num_comments = Comment.count |
234 | post :nuke_comment, { :id => feedback(:spam_comment).id }, {} |
235 | assert_response 403 |
236 | |
237 | get :nuke_comment, { :id => feedback(:spam_comment).id }, { :user => users(:bob)} |
238 | assert_response 403 |
239 | |
240 | post :nuke_comment, { :id => feedback(:spam_comment).id }, { :user => users(:bob)} |
241 | assert_response :success |
242 | assert_equal num_comments -1, Comment.count |
243 | end |
244 | |
245 | def test_comment_user_blank |
246 | post :comment, { :id => 2, :comment => {'body' => 'foo', 'author' => 'bob' }} |
247 | assert_response :success |
248 | |
249 | comment = Article.find(2).comments.last |
250 | assert comment |
251 | assert comment.published? |
252 | assert_nil comment.user_id |
253 | |
254 | get :read, {:id => 2} |
255 | assert_response :success |
256 | assert_no_tag :tag => "li", |
257 | :attributes => { :class => "author_comment"} |
258 | |
259 | end |
260 | |
261 | def test_comment_user_set |
262 | @request.session = { :user => users(:tobi) } |
263 | post :comment, { :id => 2, :comment => {'body' => 'foo', 'author' => 'bob' }} |
264 | assert_response :success |
265 | |
266 | comment = Article.find(2).comments.last |
267 | assert comment |
268 | assert_equal users(:tobi), comment.user |
269 | |
270 | get :read, {:id => 2} |
271 | assert_response :success |
272 | assert_tag :tag => "li", |
273 | :attributes => { :class => "author_comment"} |
274 | end |
275 | |
276 | def test_trackback |
277 | num_trackbacks = Article.find(2).trackbacks.count |
278 | post :trackback, { :id => 2, :url => "http://www.google.com", :title => "My Trackback", :excerpt => "This is a test" } |
279 | assert_response :success |
280 | assert_no_tag :tag => "response", |
281 | :child => {:tag => "error", :content => "1"} |
282 | |
283 | assert_equal num_trackbacks+1, Article.find(2).trackbacks.count |
284 | end |
285 | |
286 | def test_trackback_nuking |
287 | num_comments = Trackback.count |
288 | |
289 | post :nuke_trackback, { :id => 7 }, {} |
290 | assert_response 403 |
291 | |
292 | get :nuke_trackback, { :id => 7 }, { :user => users(:bob)} |
293 | assert_response 403 |
294 | |
295 | post :nuke_trackback, { :id => 7 }, { :user => users(:bob)} |
296 | assert_response :success |
297 | assert_equal num_comments -1, Trackback.count |
298 | end |
299 | |
300 | def test_no_settings |
301 | this_blog.update_attribute(:settings, { }) |
302 | |
303 | get :index |
304 | |
305 | assert_response :redirect, |
306 | :controller => "admin/general", :action => "redirect" |
307 | end |
308 | |
309 | def test_no_users_exist |
310 | this_blog.update_attribute(:settings, { }) |
311 | |
312 | User.destroy_all |
313 | assert User.count.zero? |
314 | |
315 | get :index |
316 | assert_response :redirect, :controller => "accounts", :action => "signup" |
317 | |
318 | end |
319 | |
320 | def test_pages_static |
321 | get :view_page, :name => 'page_one' |
322 | assert_response :success |
323 | assert_template "view_page" |
324 | |
325 | get :view_page, :name => 'page one' |
326 | assert_response 404 |
327 | end |
328 | |
329 | def test_read_non_published |
330 | get :read, :id => 4 |
331 | assert_response :success |
332 | assert_template "error" |
333 | end |
334 | |
335 | def test_tags_non_published |
336 | get :tag, :id => 'bar' |
337 | assert_response :success |
338 | assert_equal 1, assigns(:articles).size |
339 | assert ! assigns(:articles).include?(@article4), "Unpublished article displayed" |
340 | end |
341 | |
342 | def test_gravatar |
343 | assert ! this_blog.use_gravatar |
344 | get :read, :id => 1 |
345 | assert_response :success |
346 | assert_template "read" |
347 | assert_no_tag :tag => "img", |
348 | :attributes => { :class => "gravatar" } |
349 | |
350 | # Switch gravatar integration to on |
351 | this_blog.use_gravatar = true |
352 | @controller = ArticlesController.new |
353 | assert this_blog.use_gravatar |
354 | get :read, :id => 1 |
355 | assert_response :success |
356 | assert_template "read" |
357 | assert_tag :tag => "img", |
358 | :attributes => { |
359 | :class => "gravatar", |
360 | :src => "http://www.gravatar.com/avatar.php?gravatar_id=740618d2fe0450ec244d8b86ac1fe3f8&size=60" |
361 | } |
362 | end |
363 | |
364 | def test_comment_preview |
365 | get :comment_preview |
366 | assert_response :success |
367 | assert_template nil |
368 | |
369 | get :comment_preview, :comment => { :author => "bob", :body => "comment preview" } |
370 | assert_response :success |
371 | assert_template "comment_preview" |
372 | |
373 | assert_tag :tag => "cite", |
374 | :children => { :count => 1, |
375 | :only => { :tag => "strong", |
376 | :content => "bob" } } |
377 | |
378 | assert_tag :tag => "p", |
379 | :content => "comment preview" |
380 | end |
381 | |
382 | def test_read_article_with_comments_and_trackbacks |
383 | get :read, :id => contents(:article1).id |
384 | assert_response :success |
385 | assert_template "read" |
386 | |
387 | assert_equal contents(:article1).comments.to_a.select{|c| c.published?}, contents(:article1).published_comments |
388 | |
389 | assert_tag :tag => "ol", |
390 | :attributes => { :id => "commentList"}, |
391 | :children => { :count => contents(:article1).comments.to_a.select{|c| c.published?}.size, |
392 | :only => { :tag => "li" } } |
393 | |
394 | assert_tag :tag => "li", |
395 | :attributes => { :class => "author_comment"} |
396 | |
397 | assert_tag :tag => "ol", |
398 | :attributes => { :id => "trackbackList" }, |
399 | :children => { :count => contents(:article1).trackbacks.size, |
400 | :only => { :tag => "li" } } |
401 | end |
402 | |
403 | def test_read_article_no_comments_no_trackbacks |
404 | get :read, :id => contents(:article3).id |
405 | assert_response :success |
406 | assert_template "read" |
407 | |
408 | assert_tag :tag => "ol", |
409 | :attributes => { :id => "commentList"}, |
410 | :children => { :count => 1, |
411 | :only => { :tag => "li", |
412 | :attributes => { :id => "dummy_comment", :style => "display: none" } } } |
413 | |
414 | assert_no_tag :tag => "ol", |
415 | :attributes => { :id => "trackbackList" } |
416 | end |
417 | |
418 | def test_autodiscovery_default |
419 | |
420 | get :index |
421 | assert_response :success |
422 | assert_tag :tag => 'link', :attributes => |
423 | { :rel => 'alternate', :type => 'application/rss+xml', :title => 'RSS', |
424 | :href => 'http://test.host/xml/rss20/feed.xml'} |
425 | assert_tag :tag => 'link', :attributes => |
426 | { :rel => 'alternate', :type => 'application/atom+xml', :title => 'Atom', |
427 | :href => 'http://test.host/xml/atom/feed.xml'} |
428 | end |
429 | |
430 | |
431 | def test_autodiscovery_article |
432 | get :read, :id => 1 |
433 | assert_response :success |
434 | assert_tag :tag => 'link', :attributes => |
435 | { :rel => 'alternate', :type => 'application/rss+xml', :title => 'RSS', |
436 | :href => 'http://test.host/xml/rss20/article/1/feed.xml'} |
437 | assert_tag :tag => 'link', :attributes => |
438 | { :rel => 'alternate', :type => 'application/atom+xml', :title => 'Atom', |
439 | :href => 'http://test.host/xml/atom/article/1/feed.xml'} |
440 | end |
441 | |
442 | def test_autodiscovery_category |
443 | get :category, :id => 'hardware' |
444 | assert_response :success |
445 | assert_tag :tag => 'link', :attributes => |
446 | { :rel => 'alternate', :type => 'application/rss+xml', :title => 'RSS', |
447 | :href => 'http://test.host/xml/rss20/category/hardware/feed.xml'} |
448 | assert_tag :tag => 'link', :attributes => |
449 | { :rel => 'alternate', :type => 'application/atom+xml', :title => 'Atom', |
450 | :href => 'http://test.host/xml/atom/category/hardware/feed.xml'} |
451 | end |
452 | |
453 | def test_autodiscovery_tag |
454 | get :tag, :id => 'hardware' |
455 | assert_response :success |
456 | assert_tag :tag => 'link', :attributes => |
457 | { :rel => 'alternate', :type => 'application/rss+xml', :title => 'RSS', |
458 | :href => 'http://test.host/xml/rss20/tag/hardware/feed.xml'} |
459 | assert_tag :tag => 'link', :attributes => |
460 | { :rel => 'alternate', :type => 'application/atom+xml', :title => 'Atom', |
461 | :href => 'http://test.host/xml/atom/tag/hardware/feed.xml'} |
462 | end |
463 | |
464 | def test_disabled_ajax_comments |
465 | this_blog.sp_allow_non_ajax_comments = false |
466 | assert_equal false, this_blog.sp_allow_non_ajax_comments |
467 | |
468 | post :comment, :id => 1, :comment => {'body' => 'This is posted without ajax', 'author' => 'bob' } |
469 | assert_response 500 |
470 | assert_equal "non-ajax commenting is disabled", @response.body |
471 | |
472 | @request.env['HTTP_X_REQUESTED_WITH'] = "XMLHttpRequest" |
473 | post :comment, :id => 1, :comment => {'body' => 'This is posted *with* ajax', 'author' => 'bob' } |
474 | assert_response :success |
475 | ajax_comment = Article.find(1).comments.last |
476 | assert_equal "This is posted *with* ajax", ajax_comment.body |
477 | end |
478 | |
479 | def test_tag_max_article_count_is_first |
480 | tags = Tag.find_all_with_article_counters |
481 | assert tags.size > 1 |
482 | max = tags[0].article_counter |
483 | tags.each do |tag| |
484 | assert tag.article_counter <= max |
485 | end |
486 | end |
487 | |
488 | def test_calc_distributed_class_basic |
489 | assert_equal "prefix5", calc_distributed_class(0, 0, "prefix", 5, 15) |
490 | (0..10).each do |article| |
491 | assert_equal "prefix#{article}", calc_distributed_class(article, 10, "prefix", 0, 10) |
492 | end |
493 | (0..20).each do |article| |
494 | assert_equal "prefix#{(article/2).to_i}", calc_distributed_class(article, 20, "prefix", 0, 10) |
495 | end |
496 | (0..5).each do |article| |
497 | assert_equal "prefix#{(article*2).to_i}", calc_distributed_class(article, 5, "prefix", 0, 10) |
498 | end |
499 | end |
500 | |
501 | def test_calc_distributed_class_offset |
502 | (0..10).each do |article| |
503 | assert_equal "prefix#{article+6}", calc_distributed_class(article, 10, "prefix", 6, 16) |
504 | end |
505 | end |
506 | |
507 | def test_hide_future_article |
508 | @article = Article.find_last_posted |
509 | |
510 | Article.create!(:title => "News from the future!", |
511 | :body => "The future is cool!", |
512 | :keywords => "future", |
513 | :published => true, |
514 | :published_at => Time.now + 12.minutes) |
515 | get :index |
516 | assert_equal @article, assigns(:articles).first |
517 | assert @response.lifetime.to_i <= 12.minutes |
518 | end |
519 | |
520 | def test_search |
521 | get :search, :q => "search target" |
522 | assert_equal 1, assigns(:articles).size |
523 | end |
524 | |
525 | def test_author |
526 | get :author, :id => 'tobi' |
527 | |
528 | assert_response :success |
529 | assert_template 'index' |
530 | assert assigns(:articles) |
531 | assert_equal users(:tobi).articles.published, assigns(:articles) |
532 | # This is until we write a proper author feed |
533 | assert_equal('http://test.host/xml/rss20/feed.xml', |
534 | assigns(:auto_discovery_url_rss)) |
535 | end |
536 | |
537 | def test_nonexistent_author |
538 | get :author, :id => 'nonexistent-chap' |
539 | |
540 | assert_response :success |
541 | assert_template 'error' |
542 | assert assigns(:message) |
543 | assert_equal "Can't find posts with author 'nonexistent-chap'", assigns(:message) |
544 | end |
545 | |
546 | def test_author_list |
547 | get :author |
548 | |
549 | assert_response :success |
550 | assert_template 'groupings' |
551 | |
552 | assert_tag(:tag => 'ul', |
553 | :descendant => {\ |
554 | :tag => 'a', |
555 | :attributes => { :href => '/articles/author/tobi' }, |
556 | }) |
557 | end |
558 | end |