impostor 0.2.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +1 -0
  3. data/.rspec +2 -0
  4. data/.rvmrc +1 -0
  5. data/Gemfile +17 -0
  6. data/Gemfile.lock +47 -0
  7. data/History.txt +8 -0
  8. data/Manifest.txt +87 -55
  9. data/README.txt +11 -11
  10. data/Rakefile +16 -20
  11. data/lib/impostor/auth.rb +103 -0
  12. data/lib/impostor/config.rb +171 -0
  13. data/lib/impostor/errors.rb +67 -0
  14. data/lib/impostor/phpbb2.rb +202 -0
  15. data/lib/impostor/phpbb3.rb +199 -0
  16. data/lib/impostor/post.rb +111 -0
  17. data/lib/impostor/topic.rb +115 -0
  18. data/lib/impostor/wwf79.rb +186 -0
  19. data/lib/impostor/wwf80.rb +190 -0
  20. data/lib/impostor.rb +108 -5
  21. data/spec/auth_spec.rb +148 -0
  22. data/spec/base_spec_helper.rb +12 -0
  23. data/{test/test_helper.rb → spec/caged_net_http.rb} +8 -17
  24. data/spec/config_spec.rb +136 -0
  25. data/spec/fixtures/junk.html +1 -0
  26. data/{test → spec}/fixtures/phpbb2-get-new_topic-form-good-response.html +0 -0
  27. data/{test → spec}/fixtures/phpbb2-get-viewtopic-for-new-topic-good-response.html +11 -11
  28. data/{test → spec}/fixtures/phpbb2-get-viewtopic-for-new-topic-malformed-response.html +0 -0
  29. data/{test → spec}/fixtures/phpbb2-index.html +0 -0
  30. data/{test → spec}/fixtures/phpbb2-logged-in.html +0 -0
  31. data/{test → spec}/fixtures/phpbb2-login.html +0 -0
  32. data/{test → spec}/fixtures/phpbb2-not-logged-in.html +0 -0
  33. data/{test → spec}/fixtures/phpbb2-post-new_topic-good-response.html +0 -0
  34. data/{test → spec}/fixtures/phpbb2-post-reply-good-response.html +0 -0
  35. data/{test → spec}/fixtures/phpbb2-post-reply-throttled-response.html +0 -0
  36. data/{test → spec}/fixtures/phpbb2-too-many-posts.html +0 -0
  37. data/{test → spec}/fixtures/phpbb3-get-new-topic-form-good-response.html +0 -0
  38. data/{test → spec}/fixtures/phpbb3-get-reply-form-good-response.html +0 -0
  39. data/{test → spec}/fixtures/phpbb3-logged-in.html +0 -0
  40. data/{test → spec}/fixtures/phpbb3-login.html +0 -0
  41. data/{test → spec}/fixtures/phpbb3-not-logged-in.html +0 -0
  42. data/{test → spec}/fixtures/phpbb3-post-new_topic-good-response.html +0 -0
  43. data/{test → spec}/fixtures/phpbb3-post-reply-good-response.html +0 -0
  44. data/spec/fixtures/vcr_cassettes/phpbb2-should-be-overlimit-creating-topic.yml +1308 -0
  45. data/spec/fixtures/vcr_cassettes/phpbb2-should-create-topic.yml +923 -0
  46. data/spec/fixtures/vcr_cassettes/phpbb2-should-login.yml +360 -0
  47. data/spec/fixtures/vcr_cassettes/phpbb2-should-not-create-new-topic.yml +497 -0
  48. data/spec/fixtures/vcr_cassettes/phpbb2-should-not-login.yml +287 -0
  49. data/spec/fixtures/vcr_cassettes/phpbb2-should-not-post.yml +497 -0
  50. data/spec/fixtures/vcr_cassettes/phpbb2-should-overlimit-error-post.yml +1140 -0
  51. data/spec/fixtures/vcr_cassettes/phpbb2-should-post.yml +751 -0
  52. data/spec/fixtures/vcr_cassettes/phpbb3-should-be-overlimit-creating-topic.yml +995 -0
  53. data/spec/fixtures/vcr_cassettes/phpbb3-should-create-topic.yml +675 -0
  54. data/spec/fixtures/vcr_cassettes/phpbb3-should-login.yml +245 -0
  55. data/spec/fixtures/vcr_cassettes/phpbb3-should-not-create-new-topic.yml +350 -0
  56. data/spec/fixtures/vcr_cassettes/phpbb3-should-not-login.yml +253 -0
  57. data/spec/fixtures/vcr_cassettes/phpbb3-should-not-post.yml +350 -0
  58. data/spec/fixtures/vcr_cassettes/phpbb3-should-overlimit-error-post.yml +1046 -0
  59. data/spec/fixtures/vcr_cassettes/phpbb3-should-post.yml +605 -0
  60. data/{test → spec}/fixtures/wwf79-forum_posts.html +0 -0
  61. data/{test → spec}/fixtures/wwf79-general-new-topic-error.html +0 -0
  62. data/{test → spec}/fixtures/wwf79-general-posting-error.html +0 -0
  63. data/{test → spec}/fixtures/wwf79-good-post-forum_posts.html +1 -1
  64. data/{test → spec}/fixtures/wwf79-index.html +0 -0
  65. data/{test → spec}/fixtures/wwf79-logged-in.html +0 -0
  66. data/{test → spec}/fixtures/wwf79-login.html +0 -0
  67. data/{test → spec}/fixtures/wwf79-new-topic-forum_posts-response.html +0 -0
  68. data/{test → spec}/fixtures/wwf79-new-topic-post_message_form.html +0 -0
  69. data/{test → spec}/fixtures/wwf79-not-logged-in.html +0 -0
  70. data/{test → spec}/fixtures/wwf79-too-many-posts.html +0 -0
  71. data/{test → spec}/fixtures/wwf79-too-many-topics.html +0 -0
  72. data/{test → spec}/fixtures/wwf80-general-posting-error.html +0 -0
  73. data/{test → spec}/fixtures/wwf80-get-new_topic-form-good-response.html +0 -0
  74. data/{test → spec}/fixtures/wwf80-get-viewtopic-for-new-topic-good-response.html +0 -0
  75. data/{test → spec}/fixtures/wwf80-index.html +0 -0
  76. data/{test → spec}/fixtures/wwf80-logged-in.html +0 -0
  77. data/{test → spec}/fixtures/wwf80-login.html +0 -0
  78. data/{test → spec}/fixtures/wwf80-new_reply_form.html +0 -0
  79. data/{test → spec}/fixtures/wwf80-not-logged-in.html +0 -0
  80. data/{test → spec}/fixtures/wwf80-post-new_topic-good-response.html +1 -1
  81. data/{test → spec}/fixtures/wwf80-post-reply-good-response.html +0 -0
  82. data/{test → spec}/fixtures/wwf80-too-many-posts.html +0 -0
  83. data/spec/impostor_spec_helper.rb +162 -0
  84. data/spec/integration/phpbb2_spec.rb +111 -0
  85. data/spec/integration/phpbb3_spec.rb +109 -0
  86. data/spec/integration_spec_helper.rb +7 -0
  87. data/spec/phpbb2_spec.rb +346 -0
  88. data/spec/phpbb3_spec.rb +332 -0
  89. data/spec/post_spec.rb +134 -0
  90. data/spec/spec_helper.rb +2 -0
  91. data/spec/test_impostor.rb +12 -0
  92. data/spec/topic_spec.rb +143 -0
  93. data/spec/wwf79_spec.rb +342 -0
  94. data/spec/wwf80_spec.rb +339 -0
  95. metadata +156 -87
  96. data/lib/www/impostor/phpbb2.rb +0 -258
  97. data/lib/www/impostor/phpbb3.rb +0 -236
  98. data/lib/www/impostor/wwf79.rb +0 -254
  99. data/lib/www/impostor/wwf80.rb +0 -264
  100. data/lib/www/impostor.rb +0 -269
  101. data/test/test_github.rb +0 -12
  102. data/test/test_www_impostor.rb +0 -165
  103. data/test/test_www_impostor_phpbb2.rb +0 -536
  104. data/test/test_www_impostor_phpbb3.rb +0 -483
  105. data/test/test_www_impostor_wwf79.rb +0 -535
  106. data/test/test_www_impostor_wwf80.rb +0 -535
  107. data/vendor/plugins/impostor/lib/autotest/discover.rb +0 -3
  108. data/vendor/plugins/impostor/lib/autotest/impostor.rb +0 -49
@@ -1,536 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "..", "lib", "www", "impostor")
2
- require File.join(File.dirname(__FILE__), "..", "lib", "www", "impostor", "phpbb2")
3
- require File.join(File.dirname(__FILE__), "test_helper")
4
-
5
- require 'test/unit'
6
- require 'rubygems'
7
- require 'mocha'
8
- require 'mechanize'
9
-
10
- class TestWwwImpostorPhpbb2 < Test::Unit::TestCase
11
- include TestHelper
12
-
13
- def setup
14
- @cookie_jar = File.join(Dir.tmpdir, 'www_impostor_phpbb_test.yml')
15
- @app_root = 'http://localhost/phpbb2/'
16
- @im = WWW::Impostor.new(config())
17
- end
18
-
19
- def teardown
20
- File.delete(@cookie_jar) if File.exist?(@cookie_jar)
21
- end
22
-
23
- def config(config={})
24
- c = {:type => :phpbb2,
25
- :app_root => @app_root,
26
- :login_page => 'login.php',
27
- :posting_page => 'posting.php',
28
- :user_agent => 'Windows IE 7',
29
- :username => 'tester',
30
- :password => 'test',
31
- :cookie_jar => @cookie_jar
32
- }.merge(config)
33
- c
34
- end
35
-
36
- def phpbb2_good_submit_post_form
37
- %q!<form action="posting.php" method="post" name="post">
38
- <input name="post" type="submit">
39
- <input name="message" value="" type="hidden">
40
- </form>!
41
- end
42
-
43
- def phpbb2_good_submit_new_topic_form
44
- %q!<form action="posting.php" method="post" name="post">
45
- <input name="post" type="submit">
46
- <input name="subject" type="text">
47
- <input name="message" value="" type="hidden">
48
- </form>!
49
- end
50
-
51
- def test_initialize_with_cookie_jar
52
- FileUtils.touch(@cookie_jar)
53
-
54
- WWW::Mechanize::CookieJar.any_instance.expects(:load).once.with(@cookie_jar)
55
- im = WWW::Impostor.new(config())
56
- assert im
57
- end
58
-
59
- def test_initialize_without_cookie_jar
60
- WWW::Mechanize::CookieJar.any_instance.expects(:load).never
61
- im = WWW::Impostor.new(config())
62
- assert im
63
- end
64
-
65
- def test_version
66
- assert @im.version
67
- end
68
-
69
- def test_should_be_logged_in?
70
- response = {'content-type' => 'text/html'}
71
- body = load_page('phpbb2-logged-in.html').join
72
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
73
- assert_equal true, @im.send(:logged_in?, page)
74
- end
75
-
76
- def test_should_not_be_logged_in?
77
- response = {'content-type' => 'text/html'}
78
- body = load_page('phpbb2-not-logged-in.html').join
79
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
80
- assert_equal false, @im.send(:logged_in?, page)
81
- end
82
-
83
- def test_fetch_login_page
84
- page = load_page('phpbb2-login.html').join
85
- WWW::Mechanize.any_instance.expects(:get).once.with(
86
- URI.join(@app_root, config[:login_page])
87
- ).returns(page)
88
-
89
- assert_equal page, @im.send(:fetch_login_page)
90
- end
91
-
92
- def test_login_form_and_button_should_raise_login_error_when_form_is_missing
93
- err = assert_raise(WWW::Impostor::LoginError) do
94
- form, button = @im.send(:login_form_and_button, nil)
95
- end
96
- assert_equal "unknown login page format", err.original_exception.message
97
- end
98
-
99
- def test_login_form_and_button_should_return_a_form_and_button
100
- response = {'content-type' => 'text/html'}
101
- body = load_page('phpbb2-login.html').join
102
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
103
- form, button = @im.send(:login_form_and_button, page)
104
- assert_equal true, form.is_a?(WWW::Mechanize::Form)
105
- assert_equal true, button.is_a?(WWW::Mechanize::Form::Button)
106
- end
107
-
108
- def test_post_login_should_return_page
109
- response = {'content-type' => 'text/html'}
110
- body = load_page('phpbb2-logged-in.html').join
111
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
112
- form = mock()
113
- button = mock()
114
- WWW::Mechanize.any_instance.expects(:submit).once.with(form, button).returns(page)
115
-
116
- assert_equal page, @im.send(:post_login, form, button)
117
- end
118
-
119
- def test_post_login_should_raise_login_error
120
- errmsg = "from test #{Time.now.to_s}"
121
- WWW::Mechanize.any_instance.expects(:submit).raises(StandardError, errmsg)
122
- err = assert_raise(WWW::Impostor::LoginError) do
123
- page = @im.send(:post_login, nil, nil)
124
- end
125
- assert_equal errmsg, err.original_exception.message
126
- end
127
-
128
- def test_bad_login_page_should_raise_exception
129
- errmsg = "from test #{Time.now.to_s}"
130
- WWW::Mechanize.any_instance.expects(:get).once.with(
131
- URI.join(@app_root, config[:login_page])
132
- ).raises(StandardError, errmsg)
133
-
134
- err = assert_raise(WWW::Impostor::LoginError) do
135
- @im.send(:fetch_login_page)
136
- end
137
- assert_equal errmsg, err.original_exception.message
138
- end
139
-
140
- def test_already_logged_in_should_not_post_login_information_again_instance_varialbe
141
- @im.instance_variable_set(:@loggedin, true)
142
- @im.expects(:fetch_login_page).never
143
- assert_equal true, @im.login
144
- end
145
-
146
- def test_already_logged_in_should_not_post_login_information_again
147
- @im.instance_variable_set(:@loggedin, false)
148
- page = mock()
149
- @im.stubs(:fetch_login_page).returns(page)
150
- @im.expects(:logged_in?).once.with(page).returns(true)
151
- @im.expects(:login_form_and_button).with(page).never
152
- @im.login
153
- end
154
-
155
- def test_login_should_login
156
- @im.instance_variable_set(:@loggedin, false)
157
- login_page = mock()
158
- @im.stubs(:fetch_login_page).returns(login_page)
159
- @im.expects(:logged_in?).once.with(login_page).returns(false)
160
- form = mock()
161
- button = mock()
162
- @im.expects(:login_form_and_button).with(login_page).returns([form, button])
163
- logged_in_page = mock()
164
- @im.expects(:post_login).with(form, button).returns(logged_in_page)
165
- @im.expects(:logged_in?).once.with(logged_in_page).returns(true)
166
- @im.expects(:load_topics).once.returns(true)
167
-
168
- assert_equal true, @im.login
169
- end
170
-
171
- def test_logout_does_nothing_if_logged_out
172
- @im.instance_variable_set(:@loggedin, false)
173
- @im.expects(:cookie_jar).never
174
- @im.expects(:save_topics).never
175
- assert_equal false, @im.logout
176
- end
177
-
178
- def test_logout
179
- @im.instance_variable_set(:@loggedin, true)
180
- cookie_jar = mock()
181
- @im.expects(:cookie_jar).times(2).returns(cookie_jar)
182
- WWW::Mechanize::CookieJar.any_instance.expects(:save_as).once.with(cookie_jar).returns(nil)
183
- @im.expects(:save_topics).once
184
- assert_equal true, @im.logout
185
- assert_equal nil, @im.instance_variable_get(:@forum)
186
- assert_equal nil, @im.instance_variable_get(:@topic)
187
- assert_equal nil, @im.instance_variable_get(:@subject)
188
- assert_equal nil, @im.instance_variable_get(:@message)
189
- assert_equal false, @im.instance_variable_get(:@loggedin)
190
- end
191
-
192
- def test_posting_page
193
- c = config
194
- assert_equal URI.join(@app_root, c[:posting_page]), @im.posting_page
195
- end
196
-
197
- def test_post_without_forum_set_should_raise_exception
198
- @im.instance_variable_set(:@forum, nil)
199
- err = assert_raise(WWW::Impostor::PostError) do
200
- @im.post
201
- end
202
- assert_equal "forum not set", err.original_exception.message
203
- err = assert_raise(WWW::Impostor::PostError) do
204
- @im.post(f=nil,t=nil,m=nil)
205
- end
206
- assert_equal "forum not set", err.original_exception.message
207
- end
208
-
209
- def test_post_without_topic_set_should_raise_exception
210
- @im.instance_variable_set(:@forum, 1)
211
- @im.instance_variable_set(:@topic, nil)
212
- err = assert_raise(WWW::Impostor::PostError) do
213
- @im.post
214
- end
215
- assert_equal "topic not set", err.original_exception.message
216
- err = assert_raise(WWW::Impostor::PostError) do
217
- @im.post(f=2,t=nil,m=nil)
218
- end
219
- assert_equal "topic not set", err.original_exception.message
220
- end
221
-
222
- def test_post_without_message_set_should_raise_exception
223
- @im.instance_variable_set(:@forum, 1)
224
- @im.instance_variable_set(:@topic, 1)
225
- @im.instance_variable_set(:@message, nil)
226
- err = assert_raise(WWW::Impostor::PostError) do
227
- @im.post
228
- end
229
- assert_equal "message not set", err.original_exception.message
230
- err = assert_raise(WWW::Impostor::PostError) do
231
- @im.post(f=2,t=2,m=nil)
232
- end
233
- assert_equal "message not set", err.original_exception.message
234
- end
235
-
236
- def test_post_not_logged_in_should_raise_exception
237
- @im.expects(:login).once.returns(false)
238
- @im.instance_variable_set(:@loggedin, false)
239
- err = assert_raise(WWW::Impostor::PostError) do
240
- @im.post(2,2,'hello')
241
- end
242
- assert_equal "not logged in", err.original_exception.message
243
- end
244
-
245
- def test_bad_post_page_for_post_should_raise_exception
246
- @im.instance_variable_set(:@loggedin, true)
247
- topic = 1
248
- posting_page = @im.posting_page
249
- posting_page.query = "mode=reply&t=#{topic}"
250
- errmsg = "from test #{Time.now.to_s}"
251
- WWW::Mechanize.any_instance.expects(:get).once.with(
252
- posting_page
253
- ).raises(StandardError, errmsg)
254
- err = assert_raise(WWW::Impostor::PostError) do
255
- @im.post(7,topic,'hello')
256
- end
257
- assert_equal errmsg, err.original_exception.message
258
- end
259
-
260
- def test_bad_post_form_for_post_should_raise_exception
261
- @im.instance_variable_set(:@loggedin, true)
262
- response = {'content-type' => 'text/html'}
263
- body = '<form action="posting.php" method="post" name="post"></form>'
264
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
265
- topic = 2
266
- posting_page = @im.posting_page
267
- posting_page.query = "mode=reply&t=#{topic}"
268
- WWW::Mechanize.any_instance.expects(:get).once.with(posting_page).returns(page)
269
- err = assert_raise(WWW::Impostor::PostError) do
270
- @im.post(1,topic,'hello')
271
- end
272
- assert_equal "post form not found", err.original_exception.message
273
- end
274
-
275
- def test_submitting_bad_post_form_for_post_should_raise_exception
276
- @im.instance_variable_set(:@loggedin, true)
277
- response = {'content-type' => 'text/html'}
278
- body = phpbb2_good_submit_post_form
279
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
280
- topic = 2
281
- posting_page = @im.posting_page
282
- posting_page.query = "mode=reply&t=#{topic}"
283
- WWW::Mechanize.any_instance.expects(:get).once.with(posting_page).returns(page)
284
- errmsg = "from test #{Time.now.to_s}"
285
- WWW::Mechanize.any_instance.expects(:submit).once.raises(StandardError, errmsg)
286
- err = assert_raise(WWW::Impostor::PostError) do
287
- @im.post(1,topic,'hello')
288
- end
289
- assert_equal errmsg, err.original_exception.message
290
- end
291
-
292
- def test_should_post
293
- @im.instance_variable_set(:@loggedin, true)
294
- response = {'content-type' => 'text/html'}
295
- body = phpbb2_good_submit_post_form
296
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
297
- topic = 2
298
- posting_page = @im.posting_page
299
- posting_page.query = "mode=reply&t=#{topic}"
300
- WWW::Mechanize.any_instance.expects(:get).once.with(posting_page).returns(page)
301
- body = load_page('phpbb2-post-reply-good-response.html').join
302
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
303
- WWW::Mechanize.any_instance.expects(:submit).once.returns(page)
304
- subject = "test #{Time.now.to_s}"
305
- @im.expects(:get_subject).once.returns(subject)
306
-
307
- assert_equal true, @im.post(1,topic,'hello')
308
- assert_equal 1, @im.instance_variable_get(:@forum)
309
- assert_equal topic, @im.instance_variable_get(:@topic)
310
- assert_equal subject, @im.instance_variable_get(:@subject)
311
- assert_equal 'hello', @im.instance_variable_get(:@message)
312
- end
313
-
314
- def test_too_many_posts_for_post_should_raise_exception
315
- @im.instance_variable_set(:@loggedin, true)
316
- response = {'content-type' => 'text/html'}
317
- body = phpbb2_good_submit_post_form
318
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
319
- topic = 2
320
- posting_page = @im.posting_page
321
- posting_page.query = "mode=reply&t=#{topic}"
322
- WWW::Mechanize.any_instance.expects(:get).once.with(posting_page).returns(page)
323
- body = load_page('phpbb2-post-reply-throttled-response.html').join
324
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
325
- WWW::Mechanize.any_instance.expects(:submit).once.returns(page)
326
-
327
- err = assert_raise(WWW::Impostor::ThrottledError) do
328
- @im.post(1,topic,'hello')
329
- end
330
- assert_equal "too many posts in too short amount of time", err.original_exception.message
331
- end
332
-
333
- def test_getting_unknown_post_response_should_return_false
334
- @im.instance_variable_set(:@loggedin, true)
335
- response = {'content-type' => 'text/html'}
336
- body = phpbb2_good_submit_post_form
337
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
338
- topic = 2
339
- posting_page = @im.posting_page
340
- posting_page.query = "mode=reply&t=#{topic}"
341
- WWW::Mechanize.any_instance.expects(:get).once.with(posting_page).returns(page)
342
- body = 'junk'
343
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
344
- WWW::Mechanize.any_instance.expects(:submit).once.returns(page)
345
-
346
- assert_equal false, @im.post(1,topic,'hello')
347
- assert_equal nil, @im.instance_variable_get(:@forum)
348
- assert_equal nil, @im.instance_variable_get(:@topic)
349
- assert_equal nil, @im.instance_variable_get(:@subject)
350
- assert_equal nil, @im.instance_variable_get(:@message)
351
- end
352
-
353
- def test_new_topic_without_forum_set_should_raise_exception
354
- @im.instance_variable_set(:@forum, nil)
355
- err = assert_raise(WWW::Impostor::PostError) do
356
- @im.new_topic
357
- end
358
- assert_equal "forum not set", err.original_exception.message
359
- err = assert_raise(WWW::Impostor::PostError) do
360
- @im.new_topic(f=nil,s="hello world",m="hello world")
361
- end
362
- assert_equal "forum not set", err.original_exception.message
363
- end
364
-
365
- def test_new_topic_without_subject_set_should_raise_exception
366
- @im.instance_variable_set(:@forum, 1)
367
- @im.instance_variable_set(:@subject, nil)
368
- err = assert_raise(WWW::Impostor::PostError) do
369
- assert @im.new_topic
370
- end
371
- assert_equal "topic name not given", err.original_exception.message
372
- err = assert_raise(WWW::Impostor::PostError) do
373
- @im.new_topic(f=1,s=nil,m="hello world")
374
- end
375
- assert_equal "topic name not given", err.original_exception.message
376
- end
377
-
378
- def test_new_topic_without_message_set_should_raise_exception
379
- @im.instance_variable_set(:@forum, 1)
380
- @im.instance_variable_set(:@subject, 'test')
381
- @im.instance_variable_set(:@message, nil)
382
- err = assert_raise(WWW::Impostor::PostError) do
383
- @im.new_topic
384
- end
385
- assert_equal "message not set", err.original_exception.message
386
- err = assert_raise(WWW::Impostor::PostError) do
387
- @im.new_topic(f=1,s="hello world",m=nil)
388
- end
389
- assert_equal "message not set", err.original_exception.message
390
- end
391
-
392
- def test_new_topic_not_logged_in_should_raise_exception
393
- @im.expects(:login).once.returns(false)
394
- @im.instance_variable_set(:@loggedin, false)
395
-
396
- err = assert_raise(WWW::Impostor::PostError) do
397
- @im.new_topic(f=2,s="hello world",m="hello ruby")
398
- end
399
- assert_equal "not logged in", err.original_exception.message
400
- end
401
-
402
- def test_getting_bad_post_page_for_new_topic_should_raise_exception
403
- @im.instance_variable_set(:@loggedin, true)
404
- forum = 2
405
- posting_page = @im.posting_page
406
- posting_page.query = "mode=newtopic&f=#{forum}"
407
- errmsg = "from test #{Time.now.to_s}"
408
- WWW::Mechanize.any_instance.expects(:get).once.with(
409
- posting_page
410
- ).raises(StandardError, errmsg)
411
-
412
- err = assert_raise(WWW::Impostor::PostError) do
413
- @im.new_topic(f=forum,s="hello world",m="hello ruby")
414
- end
415
- assert_equal errmsg, err.original_exception.message
416
- end
417
-
418
- def test_getting_bad_post_form_for_new_topic_should_raise_exception
419
- @im.instance_variable_set(:@loggedin, true)
420
- response = {'content-type' => 'text/html'}
421
- body = '<form action="posting.php" method="post" name="post"></form>'
422
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
423
- forum = 2
424
- posting_page = @im.posting_page
425
- posting_page.query = "mode=newtopic&f=#{forum}"
426
- WWW::Mechanize.any_instance.expects(:get).once.with(posting_page).returns(page)
427
- err = assert_raise(WWW::Impostor::PostError) do
428
- @im.new_topic(f=forum,s="hello world",m="hello ruby")
429
- end
430
- assert_equal 'post form not found', err.original_exception.message
431
- end
432
-
433
- def test_submitting_bad_post_for_new_topic_form_should_raise_exception
434
- @im.instance_variable_set(:@loggedin, true)
435
- response = {'content-type' => 'text/html'}
436
- body = phpbb2_good_submit_new_topic_form
437
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
438
- forum = 2
439
- posting_page = @im.posting_page
440
- posting_page.query = "mode=newtopic&f=#{forum}"
441
- WWW::Mechanize.any_instance.expects(:get).once.with(posting_page).returns(page)
442
- errmsg = "from test #{Time.now.to_s}"
443
- WWW::Mechanize.any_instance.expects(:submit).once.raises(StandardError, errmsg)
444
- err = assert_raise(WWW::Impostor::PostError) do
445
- @im.new_topic(f=forum,s="hello world",m="hello ruby")
446
- end
447
- assert_equal errmsg, err.original_exception.message
448
- end
449
-
450
- def test_unexpected_viewtopic_for_new_topic_should_raise_exception
451
- @im.instance_variable_set(:@loggedin, true)
452
- response = {'content-type' => 'text/html'}
453
- body = phpbb2_good_submit_new_topic_form
454
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
455
- forum = 2
456
- posting_page = @im.posting_page
457
- posting_page.query = "mode=newtopic&f=#{forum}"
458
- WWW::Mechanize.any_instance.expects(:get).once.with(posting_page).returns(page)
459
- WWW::Mechanize.any_instance.expects(:submit).once.returns('junk')
460
- err = assert_raise(WWW::Impostor::PostError) do
461
- @im.new_topic(f=forum,s="hello world",m="hello ruby")
462
- end
463
- assert_equal "unexpected new topic response from refresh", err.original_exception.message
464
- end
465
-
466
- def test_malformed_viewtopic_response_for_new_topic_should_raise_exception
467
- @im.instance_variable_set(:@loggedin, true)
468
- response = {'content-type' => 'text/html'}
469
- body = phpbb2_good_submit_new_topic_form
470
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
471
- forum = 2
472
- posting_page = @im.posting_page
473
- posting_page.query = "mode=newtopic&f=#{forum}"
474
- WWW::Mechanize.any_instance.expects(:get).with(posting_page).returns(page)
475
- body = load_page('phpbb2-post-new_topic-good-response.html').join
476
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
477
- WWW::Mechanize.any_instance.expects(:submit).once.returns(page)
478
- follow = URI.join(@app_root, 'viewtopic.php?p=60#60')
479
- body = 'junk'
480
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
481
- WWW::Mechanize.any_instance.expects(:get).with(follow).returns(body)
482
- err = assert_raise(WWW::Impostor::PostError) do
483
- @im.new_topic(f=forum,s="hello world",m="hello ruby")
484
- end
485
- assert_equal "unexpected new topic response from link prev", err.original_exception.message
486
- end
487
-
488
- def test_malformed_viewtopic_response_prev_url_for_new_topic_should_raise_exception
489
- @im.instance_variable_set(:@loggedin, true)
490
- response = {'content-type' => 'text/html'}
491
- body = phpbb2_good_submit_new_topic_form
492
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
493
- forum = 2
494
- posting_page = @im.posting_page
495
- posting_page.query = "mode=newtopic&f=#{forum}"
496
- WWW::Mechanize.any_instance.expects(:get).with(posting_page).returns(page)
497
- body = load_page('phpbb2-post-new_topic-good-response.html').join
498
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
499
- WWW::Mechanize.any_instance.expects(:submit).once.returns(page)
500
- follow = URI.join(@app_root, 'viewtopic.php?p=60#60')
501
- body = '<html><head><link rel="prev" href="http://localhost/phpBB2/viewtopic.php?junk" title="View previous topic"></head><body></body></html>'
502
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
503
- WWW::Mechanize.any_instance.expects(:get).with(follow).returns(page)
504
- err = assert_raise(WWW::Impostor::PostError) do
505
- @im.new_topic(f=forum,s="hello world",m="hello ruby")
506
- end
507
- assert_equal "unexpected new topic ID", err.original_exception.message
508
- end
509
-
510
- def test_new_topic_should_work
511
- @im.instance_variable_set(:@loggedin, true)
512
- response = {'content-type' => 'text/html'}
513
- body = phpbb2_good_submit_new_topic_form
514
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
515
- forum = 2
516
- subject = "hello world"
517
- message = "hello ruby"
518
- posting_page = @im.posting_page
519
- posting_page.query = "mode=newtopic&f=#{forum}"
520
- WWW::Mechanize.any_instance.expects(:get).with(posting_page).returns(page)
521
- body = load_page('phpbb2-post-new_topic-good-response.html').join
522
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
523
- WWW::Mechanize.any_instance.expects(:submit).once.returns(page)
524
- follow = URI.join(@app_root, 'viewtopic.php?p=60#60')
525
- body = load_page('phpbb2-get-viewtopic-for-new-topic-good-response.html').join
526
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
527
- WWW::Mechanize.any_instance.expects(:get).with(follow).returns(page)
528
-
529
- @im.expects(:add_subject).once.with(forum,29,subject)
530
- assert_equal true, @im.new_topic(f=forum,s=subject,m=message)
531
- assert_equal forum, @im.instance_variable_get(:@forum)
532
- assert_equal 29, @im.instance_variable_get(:@topic)
533
- assert_equal subject, @im.instance_variable_get(:@subject)
534
- assert_equal message, @im.instance_variable_get(:@message)
535
- end
536
- end