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,483 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "..", "lib", "www", "impostor")
2
- require File.join(File.dirname(__FILE__), "..", "lib", "www", "impostor", "phpbb3")
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 TestWwwImpostorPhpbb3 < 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/phpbb3/'
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 => :phpbb3,
25
- :app_root => @app_root,
26
- :login_page => 'ucp.php?mode=login',
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 phpbb3_good_submit_new_topic_form
37
- load_page('phpbb3-get-new-topic-form-good-response.html').join
38
- end
39
-
40
- def phpbb3_good_submit_post_form
41
- body = load_page('phpbb3-get-reply-form-good-response.html').join
42
- end
43
-
44
- def test_initialize_with_cookie_jar
45
- FileUtils.touch(@cookie_jar)
46
-
47
- WWW::Mechanize::CookieJar.any_instance.expects(:load).once.with(@cookie_jar)
48
- im = WWW::Impostor.new(config())
49
- assert im
50
- end
51
-
52
- def test_initialize_without_cookie_jar
53
- WWW::Mechanize::CookieJar.any_instance.expects(:load).never
54
- im = WWW::Impostor.new(config())
55
- assert im
56
- end
57
-
58
- def test_version
59
- assert_equal @im.version, "WWW::Impostor::Phpbb3"
60
- end
61
-
62
- def test_fetch_login_page
63
- page = load_page('phpbb3-login.html').join
64
- WWW::Mechanize.any_instance.expects(:get).once.with(
65
- URI.join(@app_root, config[:login_page])
66
- ).returns(page)
67
-
68
- assert_equal page, @im.send(:fetch_login_page)
69
- end
70
-
71
- def test_login_form_and_button_should_return_a_form_and_button
72
- response = {'content-type' => 'text/html'}
73
- body = load_page('phpbb3-login.html').join
74
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
75
- form, button = @im.send(:login_form_and_button, page)
76
- assert_equal "POST", form.method
77
- assert_equal "./ucp.php?mode=login&sid=a9b66b7fedae3d5696d297194f940aa4", form.action
78
- assert_equal true, form.is_a?(WWW::Mechanize::Form)
79
- assert_equal true, button.is_a?(WWW::Mechanize::Form::Button)
80
- end
81
-
82
- def test_login_form_and_button_should_raise_login_error_when_form_is_missing
83
- err = assert_raise(WWW::Impostor::LoginError) do
84
- form, button = @im.send(:login_form_and_button, nil)
85
- end
86
- assert_equal "unknown login page format", err.original_exception.message
87
- end
88
-
89
- def test_post_login_should_return_page
90
- response = {'content-type' => 'text/html'}
91
- body = load_page('phpbb3-logged-in.html').join
92
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
93
- form = mock()
94
- button = mock()
95
- WWW::Mechanize.any_instance.expects(:submit).once.with(form, button).returns(page)
96
-
97
- assert_equal page, @im.send(:post_login, form, button)
98
- end
99
-
100
- def test_post_login_should_raise_login_error
101
- errmsg = "from test #{Time.now.to_s}"
102
- WWW::Mechanize.any_instance.expects(:submit).raises(StandardError, errmsg)
103
- err = assert_raise(WWW::Impostor::LoginError) do
104
- page = @im.send(:post_login, nil, nil)
105
- end
106
- assert_equal errmsg, err.original_exception.message
107
- end
108
-
109
- def test_bad_login_page_should_raise_exception
110
- errmsg = "from test #{Time.now.to_s}"
111
- WWW::Mechanize.any_instance.expects(:get).once.with(
112
- URI.join(@app_root, config[:login_page])
113
- ).raises(StandardError, errmsg)
114
-
115
- err = assert_raise(WWW::Impostor::LoginError) do
116
- @im.send(:fetch_login_page)
117
- end
118
- assert_equal errmsg, err.original_exception.message
119
- end
120
-
121
- def test_already_logged_in_should_not_post_login_information_again_instance_varialbe
122
- @im.instance_variable_set(:@loggedin, true)
123
- @im.expects(:fetch_login_page).never
124
- assert_equal true, @im.login
125
- end
126
-
127
- def test_already_logged_in_should_not_post_login_information_again
128
- @im.instance_variable_set(:@loggedin, false)
129
- page = mock()
130
- @im.stubs(:fetch_login_page).returns(page)
131
- @im.expects(:logged_in?).once.with(page).returns(true)
132
- @im.expects(:login_form_and_button).with(page).never
133
- @im.login
134
- end
135
-
136
- def test_login_should_login
137
- @im.instance_variable_set(:@loggedin, false)
138
- login_page = mock()
139
- @im.stubs(:fetch_login_page).returns(login_page)
140
- @im.expects(:logged_in?).once.with(login_page).returns(false)
141
- form = mock()
142
- button = mock()
143
- @im.expects(:login_form_and_button).with(login_page).returns([form, button])
144
- logged_in_page = mock()
145
- @im.expects(:post_login).with(form, button).returns(logged_in_page)
146
- @im.expects(:logged_in?).once.with(logged_in_page).returns(true)
147
- @im.expects(:load_topics).once.returns(true)
148
-
149
- assert_equal true, @im.login
150
- end
151
-
152
- def test_should_be_logged_in?
153
- response = {'content-type' => 'text/html'}
154
- body = load_page('phpbb3-logged-in.html').join
155
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
156
- assert_equal true, @im.send(:logged_in?, page)
157
- end
158
-
159
- def test_should_not_be_logged_in?
160
- response = {'content-type' => 'text/html'}
161
- body = load_page('phpbb3-not-logged-in.html').join
162
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
163
- assert_equal false, @im.send(:logged_in?, page)
164
- end
165
-
166
- def test_logout_does_nothing_if_logged_out
167
- @im.instance_variable_set(:@loggedin, false)
168
- @im.expects(:cookie_jar).never
169
- @im.expects(:save_topics).never
170
- assert_equal false, @im.logout
171
- end
172
-
173
- def test_logout
174
- @im.instance_variable_set(:@loggedin, true)
175
- cookie_jar = mock()
176
- @im.expects(:cookie_jar).times(2).returns(cookie_jar)
177
- WWW::Mechanize::CookieJar.any_instance.expects(:save_as).once.with(cookie_jar).returns(nil)
178
- @im.expects(:save_topics).once
179
- assert_equal true, @im.logout
180
- assert_equal nil, @im.instance_variable_get(:@forum)
181
- assert_equal nil, @im.instance_variable_get(:@topic)
182
- assert_equal nil, @im.instance_variable_get(:@subject)
183
- assert_equal nil, @im.instance_variable_get(:@message)
184
- assert_equal false, @im.instance_variable_get(:@loggedin)
185
- end
186
-
187
-
188
- def test_new_topic_without_forum_set_should_raise_exception
189
- @im.instance_variable_set(:@forum, nil)
190
- err = assert_raise(WWW::Impostor::PostError) do
191
- @im.new_topic
192
- end
193
- assert_equal "forum not set", err.original_exception.message
194
- err = assert_raise(WWW::Impostor::PostError) do
195
- @im.new_topic(f=nil,s="hello world",m="hello world")
196
- end
197
- assert_equal "forum not set", err.original_exception.message
198
- end
199
-
200
- def test_new_topic_without_subject_set_should_raise_exception
201
- @im.instance_variable_set(:@forum, 1)
202
- @im.instance_variable_set(:@subject, nil)
203
- err = assert_raise(WWW::Impostor::PostError) do
204
- assert @im.new_topic
205
- end
206
- assert_equal "topic name not given", err.original_exception.message
207
- err = assert_raise(WWW::Impostor::PostError) do
208
- @im.new_topic(f=1,s=nil,m="hello world")
209
- end
210
- assert_equal "topic name not given", err.original_exception.message
211
- end
212
-
213
- def test_new_topic_without_message_set_should_raise_exception
214
- @im.instance_variable_set(:@forum, 1)
215
- @im.instance_variable_set(:@subject, 'test')
216
- @im.instance_variable_set(:@message, nil)
217
- err = assert_raise(WWW::Impostor::PostError) do
218
- @im.new_topic
219
- end
220
- assert_equal "message not set", err.original_exception.message
221
- err = assert_raise(WWW::Impostor::PostError) do
222
- @im.new_topic(f=1,s="hello world",m=nil)
223
- end
224
- assert_equal "message not set", err.original_exception.message
225
- end
226
-
227
- def test_new_topic_not_logged_in_should_raise_exception
228
- @im.expects(:login).once.returns(false)
229
- @im.instance_variable_set(:@loggedin, false)
230
-
231
- err = assert_raise(WWW::Impostor::PostError) do
232
- @im.new_topic(f=2,s="hello world",m="hello ruby")
233
- end
234
- assert_equal "not logged in", err.original_exception.message
235
- end
236
-
237
- def test_getting_bad_post_page_for_new_topic_should_raise_exception
238
- @im.instance_variable_set(:@loggedin, true)
239
- forum = 2
240
- posting_page = @im.posting_page
241
- posting_page.query = "mode=post&f=#{forum}"
242
- errmsg = "from test #{Time.now.to_s}"
243
- WWW::Mechanize.any_instance.expects(:get).once.with(
244
- posting_page
245
- ).raises(StandardError, errmsg)
246
-
247
- err = assert_raise(WWW::Impostor::PostError) do
248
- @im.new_topic(f=forum,s="hello world",m="hello ruby")
249
- end
250
- assert_equal errmsg, err.original_exception.message
251
- end
252
-
253
- def test_getting_bad_post_form_for_new_topic_should_raise_exception
254
- @im.instance_variable_set(:@loggedin, true)
255
- response = {'content-type' => 'text/html'}
256
- body = '<form action="./posting.php?mode=post&amp;f=37&amp;sid=a56da5e50e92e3f2d8dc14bb8c4936bf" method="post" name="BADPOSTFORM" enctype="multipart/form-data"></form>'
257
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
258
- forum = 2
259
- posting_page = @im.posting_page
260
- posting_page.query = "mode=post&f=#{forum}"
261
- WWW::Mechanize.any_instance.expects(:get).once.with(posting_page).returns(page)
262
- err = assert_raise(WWW::Impostor::PostError) do
263
- @im.new_topic(f=forum,s="hello world",m="hello ruby")
264
- end
265
- assert_equal 'post form not found', err.original_exception.message
266
- end
267
-
268
- def test_submitting_bad_post_for_new_topic_form_should_raise_exception
269
- @im.instance_variable_set(:@loggedin, true)
270
- response = {'content-type' => 'text/html'}
271
- body = "<html><body>#{phpbb3_good_submit_new_topic_form}</body></html"
272
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
273
- forum = 2
274
- posting_page = @im.posting_page
275
- posting_page.query = "mode=post&f=#{forum}"
276
- WWW::Mechanize.any_instance.expects(:get).once.with(posting_page).returns(page)
277
- errmsg = "from test #{Time.now.to_s}"
278
- WWW::Mechanize.any_instance.expects(:submit).once.raises(StandardError, errmsg)
279
- err = assert_raise(WWW::Impostor::PostError) do
280
- @im.new_topic(f=forum,s="hello world",m="hello ruby")
281
- end
282
- assert_equal errmsg, err.original_exception.message
283
- end
284
-
285
- def test_unexpected_viewtopic_for_new_topic_should_raise_exception
286
- @im.instance_variable_set(:@loggedin, true)
287
- response = {'content-type' => 'text/html'}
288
- body = phpbb3_good_submit_new_topic_form
289
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
290
- forum = 2
291
- posting_page = @im.posting_page
292
- posting_page.query = "mode=post&f=#{forum}"
293
- WWW::Mechanize.any_instance.expects(:get).once.with(posting_page).returns(page)
294
- WWW::Mechanize.any_instance.expects(:submit).once.returns('JUNK')
295
- err = assert_raise(WWW::Impostor::PostError) do
296
- @im.new_topic(f=forum,s="hello world",m="hello ruby")
297
- end
298
- assert_equal "unexpected new topic ID", err.original_exception.message
299
- end
300
-
301
- def test_malformed_viewtopic_response_for_new_topic_should_raise_exception
302
- @im.instance_variable_set(:@loggedin, true)
303
- response = {'content-type' => 'text/html'}
304
- body = phpbb3_good_submit_new_topic_form
305
- post_page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
306
- forum = 2
307
- posting_page = @im.posting_page
308
- posting_page.query = "mode=post&f=#{forum}"
309
- WWW::Mechanize.any_instance.expects(:get).with(posting_page).returns(post_page)
310
- body = "JUNK"
311
- #uri = URI.parse("http://localhost/forum/viewtopic.php?f=37&t=205")
312
- uri = URI.parse("http://localhost/forum/viewtopic.php?f=2")
313
- page = WWW::Mechanize::Page.new(uri, response, body, code=nil, mech=nil)
314
- form = post_page.forms.first
315
- button = form.buttons.detect{|b| b.name == 'post'}
316
- WWW::Mechanize.any_instance.expects(:submit).with(form, button).once.returns(page)
317
- err = assert_raise(WWW::Impostor::PostError) do
318
- @im.new_topic(f=forum,s="hello world",m="hello ruby")
319
- end
320
- assert_equal "unexpected new topic ID", err.original_exception.message
321
- end
322
-
323
- def test_new_topic_should_work
324
- @im.instance_variable_set(:@loggedin, true)
325
- response = {'content-type' => 'text/html'}
326
- body = phpbb3_good_submit_new_topic_form
327
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
328
- forum = 2
329
- subject = "hello world"
330
- message = "hello ruby"
331
- posting_page = @im.posting_page
332
- posting_page.query = "mode=post&f=#{forum}"
333
- WWW::Mechanize.any_instance.expects(:get).with(posting_page).returns(page)
334
-
335
- body = load_page('phpbb3-post-new_topic-good-response.html').join
336
- uri = URI.parse("http://localhost/forum/viewtopic.php?f=2&t=29")
337
- page = WWW::Mechanize::Page.new(uri, response, body, code=nil, mech=nil)
338
- WWW::Mechanize.any_instance.expects(:submit).once.returns(page)
339
-
340
- @im.expects(:add_subject).once.with(forum,29,subject)
341
- assert_equal true, @im.new_topic(f=forum,s=subject,m=message)
342
- assert_equal forum, @im.instance_variable_get(:@forum)
343
- assert_equal 29, @im.instance_variable_get(:@topic)
344
- assert_equal subject, @im.instance_variable_get(:@subject)
345
- assert_equal message, @im.instance_variable_get(:@message)
346
- end
347
-
348
- def test_posting_page
349
- c = config
350
- assert_equal URI.join(@app_root, c[:posting_page]), @im.posting_page
351
- end
352
-
353
- def test_post_without_forum_set_should_raise_exception
354
- @im.instance_variable_set(:@forum, nil)
355
- err = assert_raise(WWW::Impostor::PostError) do
356
- @im.post
357
- end
358
- assert_equal "forum not set", err.original_exception.message
359
- err = assert_raise(WWW::Impostor::PostError) do
360
- @im.post(f=nil,t=nil,m=nil)
361
- end
362
- assert_equal "forum not set", err.original_exception.message
363
- end
364
-
365
- def test_post_without_topic_set_should_raise_exception
366
- @im.instance_variable_set(:@forum, 1)
367
- @im.instance_variable_set(:@topic, nil)
368
- err = assert_raise(WWW::Impostor::PostError) do
369
- @im.post
370
- end
371
- assert_equal "topic not set", err.original_exception.message
372
- err = assert_raise(WWW::Impostor::PostError) do
373
- @im.post(f=2,t=nil,m=nil)
374
- end
375
- assert_equal "topic not set", err.original_exception.message
376
- end
377
-
378
- def test_post_without_message_set_should_raise_exception
379
- @im.instance_variable_set(:@forum, 1)
380
- @im.instance_variable_set(:@topic, 1)
381
- @im.instance_variable_set(:@message, nil)
382
- err = assert_raise(WWW::Impostor::PostError) do
383
- @im.post
384
- end
385
- assert_equal "message not set", err.original_exception.message
386
- err = assert_raise(WWW::Impostor::PostError) do
387
- @im.post(f=2,t=2,m=nil)
388
- end
389
- assert_equal "message not set", err.original_exception.message
390
- end
391
-
392
- def test_post_not_logged_in_should_raise_exception
393
- @im.expects(:login).once.returns(false)
394
- @im.instance_variable_set(:@loggedin, false)
395
- err = assert_raise(WWW::Impostor::PostError) do
396
- @im.post(2,2,'hello')
397
- end
398
- assert_equal "not logged in", err.original_exception.message
399
- end
400
-
401
- def test_bad_post_page_for_post_should_raise_exception
402
- @im.instance_variable_set(:@loggedin, true)
403
- topic = 1
404
- forum = 2
405
- posting_page = @im.posting_page
406
- posting_page.query = "mode=reply&f=#{forum}&t=#{topic}"
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
- err = assert_raise(WWW::Impostor::PostError) do
412
- @im.post(forum,topic,'hello')
413
- end
414
- assert_equal errmsg, err.original_exception.message
415
- end
416
-
417
- def test_bad_post_form_for_post_should_raise_exception
418
- @im.instance_variable_set(:@loggedin, true)
419
- response = {'content-type' => 'text/html'}
420
- body = '<form action="posting.php" method="post" name="post"></form>'
421
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
422
- topic = 2
423
- forum = 5
424
- posting_page = @im.posting_page
425
- posting_page.query = "mode=reply&f=#{forum}&t=#{topic}"
426
- WWW::Mechanize.any_instance.expects(:get).once.with(posting_page).returns(page)
427
- err = assert_raise(WWW::Impostor::PostError) do
428
- @im.post(forum,topic,'hello')
429
- end
430
- assert_equal "post form not found", err.original_exception.message
431
- end
432
-
433
- def test_submitting_bad_post_form_for_post_should_raise_exception
434
- @im.instance_variable_set(:@loggedin, true)
435
- response = {'content-type' => 'text/html'}
436
- body = phpbb3_good_submit_post_form
437
- page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
438
- topic = 2
439
- forum = 9
440
- posting_page = @im.posting_page
441
- posting_page.query = "mode=reply&f=#{forum}&t=#{topic}"
442
- WWW::Mechanize.any_instance.expects(:get).once.with(posting_page).returns(page)
443
- errmsg = "from test #{Time.now.to_s}"
444
- WWW::Mechanize.any_instance.expects(:submit).once.raises(StandardError, errmsg)
445
- err = assert_raise(WWW::Impostor::PostError) do
446
- @im.post(forum,topic,'hello')
447
- end
448
- assert_equal errmsg, err.original_exception.message
449
- end
450
-
451
- def test_should_post
452
- @im.instance_variable_set(:@loggedin, true)
453
- response = {'content-type' => 'text/html'}
454
- body = phpbb3_good_submit_post_form
455
- form_page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
456
- topic = 2
457
- forum = 1
458
- posting_page = @im.posting_page
459
- posting_page.query = "mode=reply&f=#{forum}&t=#{topic}"
460
- WWW::Mechanize.any_instance.expects(:get).once.with(posting_page).returns(form_page)
461
- form = form_page.forms.first
462
- button = form.buttons.detect{|b| b.name == 'post'}
463
- body = load_page('phpbb3-post-reply-good-response.html').join
464
- posting_page.query = "mode=reply&f=#{forum}&t=#{topic}"
465
- page_url = @im.posting_page
466
- page_url.path = "/forum/viewtopic.php"
467
- page_url.query = "f=#{forum}&t=#{topic}&p=3725"
468
- page_url.fragment = "p3725"
469
- page = WWW::Mechanize::Page.new(uri=page_url, response, body, code=nil, mech=nil)
470
- WWW::Mechanize.any_instance.expects(:submit).with(form, button).once.returns(page)
471
-
472
- subject = "test #{Time.now.to_s}"
473
- @im.expects(:get_subject).once.returns(subject)
474
-
475
- assert_equal true, @im.post(1,topic,'hello')
476
- assert_equal 1, @im.instance_variable_get(:@forum)
477
- assert_equal topic, @im.instance_variable_get(:@topic)
478
- assert_equal subject, @im.instance_variable_get(:@subject)
479
- assert_equal 'hello', @im.instance_variable_get(:@message)
480
- end
481
-
482
- end
483
-