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:
- 7774 Bytes
1 | require File.dirname(__FILE__) + '/../test_helper' |
2 | |
3 | require 'http_mock' |
4 | |
5 | class ArticleTest < Test::Unit::TestCase |
6 | fixtures :blogs, :contents, :articles_tags, :tags, :resources, :categories, :articles_categories, :users, :notifications |
7 | |
8 | def setup |
9 | @articles = [] |
10 | end |
11 | |
12 | def assert_results_are(*expected) |
13 | assert_equal expected.size, @articles.size |
14 | expected.each do |i| |
15 | assert @articles.include?(i.is_a?(Symbol) ? contents(i) : i) |
16 | end |
17 | end |
18 | |
19 | def test_blog |
20 | a = Article.new |
21 | |
22 | assert_equal(1, a.blog_id) |
23 | assert_kind_of(Blog, a.blog) |
24 | end |
25 | |
26 | def test_create |
27 | a = Article.new |
28 | a.user_id = 1 |
29 | a.body = "Foo" |
30 | a.title = "Zzz" |
31 | assert a.save |
32 | |
33 | a.categories << Category.find(1) |
34 | assert_equal 1, a.categories.size |
35 | |
36 | b = Article.find(a.id) |
37 | assert_equal 1, b.categories.size |
38 | end |
39 | |
40 | def test_permalink |
41 | assert_equal( contents(:article3), this_blog.articles.find_by_date(2004,06,01) ) |
42 | assert_equal( [contents(:article2), contents(:article1)], |
43 | this_blog.articles.find_all_by_date(2.days.ago.year) ) |
44 | end |
45 | |
46 | def test_permalink_with_title |
47 | assert_equal( contents(:article3), |
48 | this_blog.articles.find_by_permalink(2004, 06, 01, "article-3") ) |
49 | assert_nil this_blog.articles.find_by_permalink(2005, 06, 01, "article-5") |
50 | end |
51 | |
52 | def test_strip_title |
53 | assert_equal "article-3", "Article-3".to_url |
54 | assert_equal "article-3", "Article 3!?#".to_url |
55 | assert_equal "there-is-sex-in-my-violence", "There is Sex in my Violence!".to_url |
56 | assert_equal "article", "-article-".to_url |
57 | assert_equal "lorem-ipsum-dolor-sit-amet-consectetaur-adipisicing-elit", "Lorem ipsum dolor sit amet, consectetaur adipisicing elit".to_url |
58 | assert_equal "my-cats-best-friend", "My Cat's Best Friend".to_url |
59 | end |
60 | |
61 | def test_perma_title |
62 | assert_equal "article-1", contents(:article1).stripped_title |
63 | assert_equal "article-2", contents(:article2).stripped_title |
64 | assert_equal "article-3", contents(:article3).stripped_title |
65 | end |
66 | |
67 | def test_html_title |
68 | a = Article.new |
69 | a.title = "This <i>is</i> a <b>test</b>" |
70 | assert a.save |
71 | |
72 | assert_equal 'this-is-a-test', a.permalink |
73 | end |
74 | |
75 | def test_urls |
76 | urls = contents(:article4).html_urls |
77 | assert_equal ["http://www.example.com/public"], urls |
78 | end |
79 | |
80 | ### XXX: Should we have a test here? |
81 | def test_send_pings |
82 | end |
83 | |
84 | ### XXX: Should we have a test here? |
85 | def test_send_multiple_pings |
86 | end |
87 | |
88 | def test_tags |
89 | a = Article.new(:title => 'Test tag article', |
90 | :keywords => 'test tag tag stuff'); |
91 | |
92 | assert_kind_of Article, a |
93 | assert_equal 0, a.tags.size |
94 | |
95 | a.keywords_to_tags |
96 | |
97 | assert_equal 3, a.tags.size |
98 | assert_equal ["test", "tag", "stuff"].sort , a.tags.collect {|t| t.name}.sort |
99 | assert a.save |
100 | |
101 | a.keywords = 'tag bar stuff foo' |
102 | a.keywords_to_tags |
103 | |
104 | assert_equal 4, a.tags.size |
105 | assert_equal ["foo", "bar", "tag", "stuff"].sort , a.tags.collect {|t| t.name}.sort |
106 | |
107 | a.keywords='tag bar' |
108 | a.keywords_to_tags |
109 | |
110 | assert_equal 2, a.tags.size |
111 | |
112 | a.keywords='' |
113 | a.keywords_to_tags |
114 | |
115 | assert_equal 0, a.tags.size |
116 | |
117 | b = Article.new(:title => 'Tag Test 2', |
118 | :keywords => 'tag test article one two three') |
119 | |
120 | assert_kind_of Article,b |
121 | assert_equal 0, b.tags.size |
122 | |
123 | c = Article.new(:title => 'Foo', :keywords => 'test "tag test" web2.0') |
124 | c.keywords_to_tags |
125 | |
126 | assert_equal 3, c.tags.size |
127 | assert_equal ['test', 'tagtest', 'web2.0'].sort, c.tags.collect(&:name).sort |
128 | end |
129 | |
130 | def test_find_published_by_tag_name |
131 | @articles = Tag.find_by_name(tags(:foo_tag).name).published_articles |
132 | |
133 | assert_results_are(:article1, :article2) |
134 | end |
135 | |
136 | |
137 | def test_find_published |
138 | @articles = this_blog.articles.find_published |
139 | assert_results_are(:search_target, :article1, :article2, |
140 | :article3, :inactive_article,:xmltest) |
141 | |
142 | @articles = this_blog.articles.find_published(:all, |
143 | :conditions => "title = 'Article 1!'") |
144 | assert_results_are :article1 |
145 | end |
146 | |
147 | def test_just_published_flag |
148 | art = this_blog.articles.build(:title => 'title', |
149 | :body => 'body', |
150 | :published => true) |
151 | assert art.just_published? |
152 | assert art.save |
153 | assert !art.just_published? |
154 | |
155 | art = Article.create!(:title => 'title2', |
156 | :body => 'body', |
157 | :published => false) |
158 | |
159 | assert ! art.just_published? |
160 | end |
161 | |
162 | def test_future_publishing |
163 | assert_sets_trigger(Article.create!(:title => 'title', :body => 'body', |
164 | :published => true, |
165 | :published_at => Time.now + 2.seconds)) |
166 | end |
167 | |
168 | def test_future_publishing_without_published_flag |
169 | assert_sets_trigger Article.create!(:title => 'title', :body => 'body', |
170 | :published_at => Time.now + 2.seconds) |
171 | end |
172 | |
173 | def test_triggers_are_dependent |
174 | art = Article.create!(:title => 'title', :body => 'body', |
175 | :published_at => Time.now + 1.hour) |
176 | assert_equal 1, Trigger.count |
177 | art.destroy |
178 | assert_equal 0, Trigger.count |
179 | end |
180 | |
181 | def assert_sets_trigger(art) |
182 | assert_equal 1, Trigger.count |
183 | assert Trigger.find(:first, :conditions => ['pending_item_id = ?', art.id]) |
184 | sleep 2 |
185 | Trigger.fire |
186 | art.reload |
187 | assert art.published |
188 | end |
189 | |
190 | def test_find_published_by_category |
191 | Article.create!(:title => "News from the future!", |
192 | :body => "The future is cool!", |
193 | :keywords => "future", |
194 | :published_at => Time.now + 12.minutes) |
195 | |
196 | @articles = Category.find_by_permalink('personal').published_articles |
197 | assert_results_are :article1, :article2, :article3 |
198 | |
199 | @articles = Category.find_by_permalink('foobar').published_articles |
200 | assert @articles.empty? |
201 | |
202 | @articles = Category.find_by_permalink('software').published_articles |
203 | assert_results_are :article1 |
204 | end |
205 | |
206 | def test_destroy_file_upload_associations |
207 | assert_equal 2, contents(:article1).resources.size |
208 | contents(:article1).resources << resources(:resource1) << resources(:resource2) |
209 | assert_equal 4, contents(:article1).resources.size |
210 | contents(:article1).destroy |
211 | assert_equal 0, Resource.find(:all, :conditions => "article_id = #{contents(:article1).id}").size |
212 | end |
213 | |
214 | def test_notifications |
215 | a = Article.new(:title => 'New Article', :body => 'Foo', :author => 'Tobi', :user => users(:tobi)) |
216 | assert a.save |
217 | |
218 | assert_equal 2, a.notify_users.size |
219 | assert_equal ['bob', 'randomuser'], a.notify_users.collect {|u| u.login }.sort |
220 | end |
221 | |
222 | def test_tags_on_update |
223 | contents(:article3).update_attribute :keywords, "my new tags" |
224 | assert_equal 3, contents(:article3).reload.tags.size |
225 | assert contents(:article3).tags.include?(Tag.find_by_name("new")) |
226 | end |
227 | |
228 | # this also tests time_delta, indirectly |
229 | def test_find_all_by_date |
230 | feb28 = this_blog.articles.build(:published => true) |
231 | mar1 = this_blog.articles.build(:published => true) |
232 | mar2 = this_blog.articles.build(:published => true) |
233 | |
234 | feb28.title = "February 28" |
235 | mar1.title = "March 1" |
236 | mar2.title = "March 2" |
237 | |
238 | feb28.created_at = feb28.published_at = "2004-02-28" |
239 | mar1.created_at = mar1.published_at = "2004-03-01" |
240 | mar2.created_at = mar2.published_at = "2004-03-02" |
241 | |
242 | [feb28, mar1, mar2].each do |x| |
243 | x.state = ContentState::Published.instance |
244 | x.save |
245 | end |
246 | |
247 | assert_equal(1, Article.find_all_by_date(2004,02).size) |
248 | assert_equal(2, Article.find_all_by_date(2004,03).size) |
249 | assert_equal(1, Article.find_all_by_date(2004,03,01).size) |
250 | end |
251 | end |