Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 71
- Log:
Start of upgrade to Typo 4.0.0, the latest stable release since
2.6.0. Note test/mocks/themes/azure changes from a file to a
directory, so the file has been removed in this revision and
the directory will be added in the next revision.
- Author:
- adh
- Date:
- Mon Aug 07 22:18:11 +0100 2006
- Size:
- 16417 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, :categories, :blogs, :users, :articles_categories, :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 | |
32 | end |
33 | |
34 | # Category subpages |
35 | def test_category |
36 | get :category, :id => "software" |
37 | |
38 | assert_response :success |
39 | assert_rendered_file "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_rendered_file "index" |
47 | end |
48 | |
49 | def test_empty_category |
50 | get :category, :id => "life-on-mars" |
51 | assert_response :success |
52 | assert_rendered_file "error" |
53 | end |
54 | |
55 | def test_nonexistent_category |
56 | get :category, :id => 'nonexistent-category' |
57 | assert_response :success |
58 | assert_rendered_file "error" |
59 | end |
60 | |
61 | def test_tag |
62 | get :tag, :id => "foo" |
63 | |
64 | assert_response :success |
65 | assert_rendered_file "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_rendered_file "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 =>{ |
89 | :id => 'pagination'}, |
90 | :content => 'Older posts: 1', |
91 | :descendant => {:tag => 'a', |
92 | :attributes =>{ |
93 | :href => "/articles/tag/foo/page/2"}, |
94 | :content => "2"}) |
95 | end |
96 | |
97 | # Main index |
98 | def test_index |
99 | get :index |
100 | assert_response :success |
101 | assert_rendered_file "index" |
102 | end |
103 | |
104 | # Archives page |
105 | def test_archives |
106 | get :archives |
107 | assert_response :success |
108 | assert_rendered_file "archives" |
109 | end |
110 | |
111 | # Permalinks |
112 | def test_permalink |
113 | get :permalink, :year => 2004, :month => 06, :day => 01, :title => "article-3" |
114 | assert_response :success |
115 | assert_template "read" |
116 | assert_not_nil assigns(:article) |
117 | assert_equal contents(:article3), assigns(:article) |
118 | end |
119 | |
120 | # Posts for given day |
121 | def test_find_by_date |
122 | get :find_by_date, :year => 2004, :month => 06, :day => 01 |
123 | assert_response :success |
124 | assert_rendered_file "index" |
125 | end |
126 | |
127 | def test_comment_posting |
128 | emails = ActionMailer::Base.deliveries |
129 | emails.clear |
130 | |
131 | assert_equal 0, emails.size |
132 | |
133 | Article.find(1).notify_users << users(:tobi) |
134 | |
135 | post :comment, { :id => 1, :comment => {'body' => 'This is *textile*', 'author' => 'bob' }} |
136 | |
137 | assert_response :success |
138 | assert_tag :tag => 'strong', :content => 'textile' |
139 | |
140 | comment = Article.find(1).comments.last |
141 | assert comment |
142 | |
143 | assert_not_nil cookies["author"] |
144 | |
145 | assert_equal "<p>This is <strong>textile</strong></p>", comment.html(@controller).to_s |
146 | |
147 | assert_equal User.find(:all, |
148 | :conditions => ['(notify_via_email = ?) and (notify_on_comments = ?)', true, true], |
149 | :order => 'email').collect { |each| each.email }, |
150 | emails.collect { |each| each.to[0] }.sort |
151 | end |
152 | |
153 | def test_comment_spam_markdown_smarty |
154 | this_blog.comment_text_filter = "markdown smartypants" |
155 | test_comment_spam1 |
156 | end |
157 | |
158 | def comment_template_test(expected_html, source_text, |
159 | art_id=1, author='bob', email='foo', args={}) |
160 | post :comment, { |
161 | :id => art_id, |
162 | :comment => { |
163 | 'body' => source_text, |
164 | 'author' => author, |
165 | 'email' => email }.merge(args) } |
166 | |
167 | assert_response :success |
168 | comment = Article.find(art_id).comments.last |
169 | assert comment |
170 | |
171 | assert_match expected_html, comment.html(@controller).to_s |
172 | $do_breakpoints |
173 | end |
174 | |
175 | def test_comment_spam1 |
176 | 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>' |
177 | end |
178 | |
179 | def test_comment_spam2 |
180 | 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' |
181 | end |
182 | |
183 | def test_comment_xss1 |
184 | this_blog.comment_text_filter = "none" |
185 | comment_template_test %{Have you ever alert("foo"); been hacked?}, |
186 | %{Have you ever <script lang="javascript">alert("foo");</script> been hacked?} |
187 | end |
188 | |
189 | def test_comment_xss2 |
190 | this_blog.comment_text_filter = "none" |
191 | comment_template_test "Have you ever <a href=\"#\" rel=\"nofollow\">been hacked?</a>", 'Have you ever <a href="#" onclick="javascript">been hacked?</a>' |
192 | end |
193 | |
194 | def test_comment_autolink |
195 | 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?" |
196 | end #" |
197 | |
198 | ### TODO -- there's a bug in Rails with auto_links |
199 | # def test_comment_autolink2 |
200 | # 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" |
201 | # end |
202 | |
203 | def test_comment_nuking |
204 | num_comments = Comment.count |
205 | post :nuke_comment, { :id => 5 }, {} |
206 | assert_response 403 |
207 | |
208 | get :nuke_comment, { :id => 5 }, { :user => users(:bob)} |
209 | assert_response 403 |
210 | |
211 | post :nuke_comment, { :id => 5 }, { :user => users(:bob)} |
212 | assert_response :success |
213 | assert_equal num_comments -1, Comment.count |
214 | end |
215 | |
216 | def test_comment_user_blank |
217 | post :comment, { :id => 2, :comment => {'body' => 'foo', 'author' => 'bob' }} |
218 | assert_response :success |
219 | |
220 | comment = Article.find(2).comments.last |
221 | assert comment |
222 | assert comment.published? |
223 | assert_nil comment.user_id |
224 | |
225 | get :read, {:id => 2} |
226 | assert_response :success |
227 | assert_no_tag :tag => "li", |
228 | :attributes => { :class => "author_comment"} |
229 | |
230 | end |
231 | |
232 | def test_comment_user_set |
233 | @request.session = { :user => users(:tobi) } |
234 | post :comment, { :id => 2, :comment => {'body' => 'foo', 'author' => 'bob' }} |
235 | assert_response :success |
236 | |
237 | comment = Article.find(2).comments.last |
238 | assert comment |
239 | assert_equal users(:tobi), comment.user |
240 | |
241 | get :read, {:id => 2} |
242 | assert_response :success |
243 | assert_tag :tag => "li", |
244 | :attributes => { :class => "author_comment"} |
245 | end |
246 | |
247 | def test_trackback |
248 | num_trackbacks = Article.find(2).trackbacks.count |
249 | post :trackback, { :id => 2, :url => "http://www.google.com", :title => "My Trackback", :excerpt => "This is a test" } |
250 | assert_response :success |
251 | assert_not_xpath(%{/response/error[text()="1"]}, "Error: " + get_xpath("/response/message/text()").first.to_s) |
252 | |
253 | assert_equal num_trackbacks+1, Article.find(2).trackbacks.count |
254 | end |
255 | |
256 | def test_trackback_nuking |
257 | num_comments = Trackback.count |
258 | |
259 | post :nuke_trackback, { :id => 7 }, {} |
260 | assert_response 403 |
261 | |
262 | get :nuke_trackback, { :id => 7 }, { :user => users(:bob)} |
263 | assert_response 403 |
264 | |
265 | post :nuke_trackback, { :id => 7 }, { :user => users(:bob)} |
266 | assert_response :success |
267 | assert_equal num_comments -1, Trackback.count |
268 | end |
269 | |
270 | def test_no_settings |
271 | this_blog.update_attribute(:settings, { }) |
272 | |
273 | get :index |
274 | |
275 | assert_redirect |
276 | assert_redirected_to :controller => "admin/general", :action => "redirect" |
277 | |
278 | end |
279 | |
280 | def test_no_users_exist |
281 | this_blog.update_attribute(:settings, { }) |
282 | |
283 | User.destroy_all |
284 | assert User.count.zero? |
285 | |
286 | get :index |
287 | assert_redirect |
288 | assert_redirected_to :controller => "accounts", :action => "signup" |
289 | |
290 | end |
291 | |
292 | def test_pages_static |
293 | get :view_page, :name => 'page_one' |
294 | assert_response :success |
295 | assert_rendered_file "view_page" |
296 | |
297 | get :view_page, :name => 'page one' |
298 | assert_response 404 |
299 | end |
300 | |
301 | def test_read_non_published |
302 | get :read, :id => 4 |
303 | assert_response :success |
304 | assert_template "error" |
305 | end |
306 | |
307 | def test_tags_non_published |
308 | get :tag, :id => 'bar' |
309 | assert_response :success |
310 | assert_equal 1, assigns(:articles).size |
311 | assert ! assigns(:articles).include?(@article4), "Unpublished article displayed" |
312 | end |
313 | |
314 | def test_gravatar |
315 | assert ! this_blog.use_gravatar |
316 | get :read, :id => 1 |
317 | assert_response :success |
318 | assert_template "read" |
319 | assert_no_tag :tag => "img", |
320 | :attributes => { :class => "gravatar" } |
321 | |
322 | # Switch gravatar integration to on |
323 | this_blog.use_gravatar = true |
324 | assert this_blog.use_gravatar |
325 | get :read, :id => 1 |
326 | assert_response :success |
327 | assert_template "read" |
328 | assert_tag :tag => "img", |
329 | :attributes => { |
330 | :class => "gravatar", |
331 | :src => "http://www.gravatar.com/avatar.php?gravatar_id=740618d2fe0450ec244d8b86ac1fe3f8&size=60" |
332 | } |
333 | end |
334 | |
335 | def test_comment_preview |
336 | get :comment_preview |
337 | assert_response :success |
338 | assert_template nil |
339 | |
340 | get :comment_preview, :comment => { :author => "bob", :body => "comment preview" } |
341 | assert_response :success |
342 | assert_template "comment_preview" |
343 | |
344 | assert_tag :tag => "cite", |
345 | :children => { :count => 1, |
346 | :only => { :tag => "strong", |
347 | :content => "bob" } } |
348 | |
349 | assert_tag :tag => "p", |
350 | :content => "comment preview" |
351 | end |
352 | |
353 | def test_read_article_with_comments_and_trackbacks |
354 | get :read, :id => contents(:article1).id |
355 | assert_response :success |
356 | assert_template "read" |
357 | |
358 | assert_tag :tag => "ol", |
359 | :attributes => { :id => "commentList"}, |
360 | :children => { :count => contents(:article1).comments.to_a.select{|c| c.published?}.size, |
361 | :only => { :tag => "li" } } |
362 | |
363 | assert_tag :tag => "li", |
364 | :attributes => { :class => "author_comment"} |
365 | |
366 | assert_tag :tag => "ol", |
367 | :attributes => { :id => "trackbackList" }, |
368 | :children => { :count => contents(:article1).trackbacks.size, |
369 | :only => { :tag => "li" } } |
370 | end |
371 | |
372 | def test_read_article_no_comments_no_trackbacks |
373 | get :read, :id => contents(:article3).id |
374 | assert_response :success |
375 | assert_template "read" |
376 | |
377 | assert_tag :tag => "ol", |
378 | :attributes => { :id => "commentList"}, |
379 | :children => { :count => 1, |
380 | :only => { :tag => "li", |
381 | :attributes => { :id => "dummy_comment", :style => "display: none" } } } |
382 | |
383 | assert_no_tag :tag => "ol", |
384 | :attributes => { :id => "trackbackList" } |
385 | end |
386 | |
387 | def test_autodiscovery_default |
388 | |
389 | get :index |
390 | assert_response :success |
391 | assert_tag :tag => 'link', :attributes => |
392 | { :rel => 'alternate', :type => 'application/rss+xml', :title => 'RSS', |
393 | :href => 'http://test.host/xml/rss20/feed.xml'} |
394 | assert_tag :tag => 'link', :attributes => |
395 | { :rel => 'alternate', :type => 'application/atom+xml', :title => 'Atom', |
396 | :href => 'http://test.host/xml/atom/feed.xml'} |
397 | end |
398 | |
399 | |
400 | def test_autodiscovery_article |
401 | get :read, :id => 1 |
402 | assert_response :success |
403 | assert_tag :tag => 'link', :attributes => |
404 | { :rel => 'alternate', :type => 'application/rss+xml', :title => 'RSS', |
405 | :href => 'http://test.host/xml/rss20/article/1/feed.xml'} |
406 | assert_tag :tag => 'link', :attributes => |
407 | { :rel => 'alternate', :type => 'application/atom+xml', :title => 'Atom', |
408 | :href => 'http://test.host/xml/atom/article/1/feed.xml'} |
409 | end |
410 | |
411 | def test_autodiscovery_category |
412 | get :category, :id => 'hardware' |
413 | assert_response :success |
414 | assert_tag :tag => 'link', :attributes => |
415 | { :rel => 'alternate', :type => 'application/rss+xml', :title => 'RSS', |
416 | :href => 'http://test.host/xml/rss20/category/hardware/feed.xml'} |
417 | assert_tag :tag => 'link', :attributes => |
418 | { :rel => 'alternate', :type => 'application/atom+xml', :title => 'Atom', |
419 | :href => 'http://test.host/xml/atom/category/hardware/feed.xml'} |
420 | end |
421 | |
422 | def test_autodiscovery_tag |
423 | get :tag, :id => 'hardware' |
424 | assert_response :success |
425 | assert_tag :tag => 'link', :attributes => |
426 | { :rel => 'alternate', :type => 'application/rss+xml', :title => 'RSS', |
427 | :href => 'http://test.host/xml/rss20/tag/hardware/feed.xml'} |
428 | assert_tag :tag => 'link', :attributes => |
429 | { :rel => 'alternate', :type => 'application/atom+xml', :title => 'Atom', |
430 | :href => 'http://test.host/xml/atom/tag/hardware/feed.xml'} |
431 | end |
432 | |
433 | def test_disabled_ajax_comments |
434 | this_blog.sp_allow_non_ajax_comments = false |
435 | assert_equal false, this_blog.sp_allow_non_ajax_comments |
436 | |
437 | post :comment, :id => 1, :comment => {'body' => 'This is posted without ajax', 'author' => 'bob' } |
438 | assert_response 500 |
439 | assert_equal "non-ajax commenting is disabled", @response.body |
440 | |
441 | @request.env['HTTP_X_REQUESTED_WITH'] = "XMLHttpRequest" |
442 | post :comment, :id => 1, :comment => {'body' => 'This is posted *with* ajax', 'author' => 'bob' } |
443 | assert_response :success |
444 | ajax_comment = Article.find(1).comments.last |
445 | assert_equal "This is posted *with* ajax", ajax_comment.body |
446 | end |
447 | |
448 | def test_tag_max_article_count_is_first |
449 | tags = Tag.find_all_with_article_counters |
450 | assert tags.size > 1 |
451 | max = tags[0].article_counter |
452 | tags.each do |tag| |
453 | assert tag.article_counter <= max |
454 | end |
455 | end |
456 | |
457 | def test_calc_distributed_class_basic |
458 | assert_equal "prefix5", calc_distributed_class(0, 0, "prefix", 5, 15) |
459 | (0..10).each do |article| |
460 | assert_equal "prefix#{article}", calc_distributed_class(article, 10, "prefix", 0, 10) |
461 | end |
462 | (0..20).each do |article| |
463 | assert_equal "prefix#{(article/2).to_i}", calc_distributed_class(article, 20, "prefix", 0, 10) |
464 | end |
465 | (0..5).each do |article| |
466 | assert_equal "prefix#{(article*2).to_i}", calc_distributed_class(article, 5, "prefix", 0, 10) |
467 | end |
468 | end |
469 | |
470 | def test_calc_distributed_class_offset |
471 | (0..10).each do |article| |
472 | assert_equal "prefix#{article+6}", calc_distributed_class(article, 10, "prefix", 6, 16) |
473 | end |
474 | end |
475 | |
476 | def test_hide_future_article |
477 | @article = Article.find_last_posted |
478 | |
479 | Article.create!(:title => "News from the future!", |
480 | :body => "The future is cool!", |
481 | :keywords => "future", |
482 | :published => true, |
483 | :published_at => Time.now + 12.minutes) |
484 | get :index |
485 | assert_equal @article, assigns(:articles).first |
486 | assert @response.lifetime.to_i <= 12.minutes |
487 | end |
488 | |
489 | def test_search |
490 | get :search, :q => "search target" |
491 | assert_equal 1, assigns(:articles).size |
492 | end |
493 | |
494 | def test_author |
495 | get :author, :id => 'tobi' |
496 | |
497 | assert_success |
498 | assert_rendered_file 'index' |
499 | assert assigns(:articles) |
500 | assert_equal users(:tobi).articles.published, assigns(:articles) |
501 | # This is until we write a proper author feed |
502 | assert_equal('http://test.host/xml/rss20/feed.xml', |
503 | assigns(:auto_discovery_url_rss)) |
504 | end |
505 | |
506 | def test_nonexistent_author |
507 | get :author, :id => 'nonexistent-chap' |
508 | |
509 | assert_success |
510 | assert_rendered_file 'error' |
511 | assert assigns(:message) |
512 | assert_equal "Can't find posts with author 'nonexistent-chap'", assigns(:message) |
513 | end |
514 | |
515 | def test_author_list |
516 | get :author |
517 | |
518 | assert_success |
519 | assert_rendered_file 'groupings' |
520 | |
521 | assert_tag(:tag => 'ul', |
522 | :descendant => {\ |
523 | :tag => 'a', |
524 | :attributes => { :href => '/articles/author/tobi' }, |
525 | }) |
526 | end |
527 | end |