| Class | PagesControllerTest |
| In: |
test/functional/pages_controller_test.rb
|
| Parent: | Test::Unit::TestCase |
# File test/functional/pages_controller_test.rb, line 25
25: def setup
26: logger.debug "Test Case: #{name}"
27: @controller = PagesController.new
28: @request = ActionController::TestRequest.new
29: @response = ActionController::TestResponse.new
30: @andy, @george, @tony = users(:andy), users(:george),users(:tony)
31: #@oup_20060721 = create_oup_20060721
32: #@oupwiki = create_oup_wiki(@oup_20060721)
33: @wiki = create_templates
34: @wiki.reload
35: @bp = @wiki.baseline_process
36: @emails = ActionMailer::Base::deliveries
37: @emails.clear
38: end
# File test/functional/pages_controller_test.rb, line 40
40: def teardown
41: [ENV['EPFWIKI_SITES_PATH'], ENV['EPFWIKI_WIKIS_PATH']].each do |p|
42: FileUtils.rm_r(p) if File.exists?(p)
43: File.makedirs(p)
44: end
45: end
Shows:
# File test/functional/pages_controller_test.rb, line 153
153: def test_checkout_edithtml_save_checkin_new
154: page = WikiPage.find_by_presentation_name('Toolmentor Template')
155: assert_not_nil page
156: assert !page.versions.empty?
157: # 1
158: get :edit, :id => page.id, :site_folder => @wiki.folder
159: assert_redirected_to :controller => 'login'
160: session['user'] = @tony
161: get :edit, :id => page.id, :site_folder => @wiki.folder
162: assert_redirected_to :action => 'checkout', :id => page.id, :site_folder => @wiki.folder
163: # 2
164: get :checkout, :id => page.id, :site_folder => @wiki.folder
165: assert_response :success
166: assert_not_nil assigns(:page)
167: assert_not_nil assigns(:wiki)
168: assert_not_nil assigns(:version)
169: assert_equal page.current_version, assigns(:version).source_version # source version is default current_version
170: assert_not_nil @bp
171: # 3
172: post :checkout, :version => {:version_id => assigns(:version).source_version.id, :note => 'test01_checkout'}
173: assert_not_nil page.checkout
174: assert_redirected_to :action => 'edit', :checkout_id => page.checkout.id
175: # 4
176: session['user'] = @andy
177: get :checkout, :id => page.id, :site_folder => @wiki.folder # get checkout will redirect
178: assert_redirected_to :action => 'edit', :checkout_id => page.checkout.id
179: get :edit, :checkout_id => page.checkout.id # will just open the page in the HTML editor
180: assert_response :success
181: assert_match 'The page is currently checked out by user',@response.body
182: # 7
183: checkout = Checkout.find(:first)
184: session['user'] = checkout.user
185: ENV['EPFWIKI_EDITOR'] = 'tinymce' # TODO Bug 218832 - RTE
186: assert File.exists?("#{ENV['EPFWIKI_ROOT_DIR']}public/javascripts/tiny_mce/tiny_mce.js")
187: get :edit, :checkout_id => checkout.id
188: assert_response :success
189: # 8
190: session['user'] = @andy
191: get :edit, :checkout_id => checkout.id
192: assert_response :success
193: assert_match "The page is currently checked out by user #{@tony.name}", @response.body
194: assert_match "You can modify the HTML but you cannot commit any changes", @response.body
195: session['user'] = @george
196: get :edit, :checkout_id => checkout.id
197: assert_response :success
198: assert_not_nil assigns(:checkout)
199: assert_match "The page is currently checked out by user #{@tony.name}", @response.body
200: assert_match "As you are the central administrator you can perform operations on this checkout", @response.body
201: # 9
202: page.reload
203: assert_not_nil page.checkout
204: co = page.checkout
205: assert_equal co.version.source_version.page, co.page # ordinary checkout, not a new page
206: html = co.version.html.gsub('</body>','adding some text</body>')
207: session['user'] = @andy
208: assert_raise(RuntimeError) {post :save, :html => html, :checkout_id => co.id}
209: # 10
210: session['user'] = checkout.user
211: post :save, :html => html, :checkout_id => co.id
212: assert_redirected_to :action => 'edit', :checkout_id => co.id
213: assert_match 'adding some text', checkout.version.html
214: # 11
215: session['user'] = @george
216: post :save, :checkout_id => co.id, :html => co.version.html.gsub('adding some text', 'adding some text, adding some more by by cadmin')
217: assert_redirected_to :action => 'edit', :checkout_id => co.id
218: assert_equal nil, co.version.version
219: assert_match 'adding some text, adding some more by by cadmin', co.version.html
220: # 12
221: logger.debug 'test05_checkin'
222: assert_equal 1, Checkout.count
223: #page = WikiPage.find_by_presentation_name('Role Template')
224: assert_not_nil page.checkout
225: co = page.checkout
226: session['user'] = @andy
227: assert @andy != checkout.user
228: assert_raise(RuntimeError) {post :checkin, :checkout_id => checkout.id}
229: # 13
230: session['user'] = checkout.user
231: post :checkin, :checkout_id => checkout.id
232: assert_raise(ActiveRecord::RecordNotFound) {Checkout.find(checkout.id)}
233: assert_match 'adding some text, adding some more by by cadmin', page.html
234: assert_enhanced_file(page.path)
235: assert_version_file(page.current_version.path)
236: # 14
237: page.reload
238: assert_equal 1, page.versions[1].version
239: post :checkout, :version => {:version_id => page.versions[1].id, :note => 'Checkout of version 1'}
240: assert_not_nil page.checkout
241: assert_redirected_to :action => 'edit', :checkout_id => page.checkout.id
242: co = page.checkout
243: v = co.version
244: # 15
245: post :checkin, :checkout_id => co.id, :html => checkout.version.html.gsub('</body>', 'Checkin with submit of html</body>')
246: assert_raise(ActiveRecord::RecordNotFound) {Checkout.find(co.id)}
247: assert_match 'Checkin with submit of html', page.html
248: assert_enhanced_file(page.path)
249: v.reload
250: assert_version_file(v.path)
251: # 16
252: #create_templates
253: session['user'] = @tony
254: get :new, :site_folder => @wiki.folder, :id => @wiki.pages[10]
255: assert_not_nil assigns(:wiki)
256: assert_not_nil assigns(:page)
257: assert_not_nil assigns(:new_page).source_version
258: assert_not_nil assigns(:templates)
259: assert_equal 27, assigns(:templates).size
260: assert_equal assigns(:templates)[0].id, assigns(:new_page).source_version
261: #assert_tag :tag => 'input', :attributes => {:type => 'radio', :name => 'new_page[source_version]', :value => assigns(:page).source_version, :checked => 'checked'}
262: # 17
263: #assert_field('page_presentation_name') TODO update
264: #assert_tag :tag => 'textarea', :attributes => {:id => 'new_page_note', :name => 'new_page[note]'}
265: #assigns(:templates).each do |version|
266: # assert_tag :tag => 'input', :attributes => {:type => 'radio', :id => "new_page_source_version_#{version.id.to_s}", :name => 'new_page[source_version]', :value => version.id}
267: #end
268: # 18
269: template = WikiPage.find_by_presentation_name('Toolmentor Template')
270: assert_not_nil template
271: post :new, :id => template.id, :site_folder => template.site.folder, :page => {:presentation_name => 'A strange name&2//++-09976', :source_version => template.current_version.id, :note => 'test03_new_page_using_template'}
272: assert_not_nil assigns(:checkout)
273: co = assigns(:checkout)
274: new_page = co.page
275: assert_not_nil new_page.user
276: assert_redirected_to :action => 'edit', :checkout_id => co.id
277: assert_equal template.current_version, co.version.source_version
278: assert_version_file(co.version.path)
279: assert_equal 'a_strange_name209976.html', new_page.filename
280: assert co.version.source_version.html.index('Tool Mentor: Toolmentor Template')
281: # 19
282: assert File.exists?(new_page.path) #
283: assert File.exists?(co.version.path)
284: # 20
285: # 21
286: # 22
287: page = WikiPage.find_by_presentation_name('A strange name&2//++-09976')
288: assert_not_nil page.checkout
289: co = page.checkout
290: v = co.version
291: session['user'] = co.user
292: get :edit, :checkout_id => co.id # we can edit
293: post :preview, :html => co.version.html.gsub('accomplish a piece of work', 'accomplish a piece of work####'), :checkout_id => co.id
294: assert_redirected_to '/' + co.version.rel_path_root
295: assert_match 'work####', co.version.html
296: post :save, :html => co.version.html.gsub('work####', '####work####'), :checkout_id => co.id
297: assert_match '####work####', co.version.html
298: post :checkin, :checkout_id => co.id
299: assert_raise(ActiveRecord::RecordNotFound) {Checkout.find(co.id)}
300: assert_match '####work####', page.html
301: assert_enhanced_file(page.path)
302: v.reload
303: assert_version_file(v.path)
304: end
Shows:
# File test/functional/pages_controller_test.rb, line 95
95: def test_discussion
96: # 1
97: page = WikiPage.find_by_presentation_name('Toolmentor Template')
98: get :discussion
99: assert_redirected_to :controller => 'login'
100: session['user'] = @tony
101: get :discussion, :site_folder => @wiki.folder, :id => page.id
102: assert_response :success
103: assert_not_nil assigns(:wiki)
104: assert_not_nil assigns(:page)
105: assert_not_nil assigns(:comment)
106: assert_not_nil assigns(:comments)
107: assert_equal 1, page.versions.size
108: assert_equal 0, assigns(:comments).size
109: # preparation for 3
110: [@andy, @george].each {|u|u.update_attributes(:notify_immediate => 1)}
111: assert_equal 0, @emails.size
112: # 2
113: post :discussion, :comment => {:text => 'comment 1 submitted in test01_new', :page_id => page.id}
114: assert_redirected_to :controller => 'pages', :site_folder => @wiki.folder, :id => page.id, :action => 'discussion'
115: assert_not_nil assigns(:wiki)
116: assert_not_nil assigns(:page)
117: assert_not_nil assigns(:comment)
118: assert_not_nil assigns(:comment).version
119: assert_equal page.current_version, assigns(:comment).version
120: assert_not_nil assigns(:comments)
121: assert_no_errors
122: assert_no_errors(assigns(:comment))
123: assert_equal 1, assigns(:comments).size
124: get :discussion, :site_folder => @wiki.folder, :id => page.id
125: assert_response :success
126: # 3
127: assert_equal 1, @emails.size
128: assert_equal "[EPF Wiki - Test Enviroment] New comment about #{page.presentation_name}", @emails[0].subject
129: assert_equal [@andy.email, @george.email, @tony.email], @emails[0].bcc # tony because he created the comment, george and andy because they want to be notified immediately
130: end
Shows:
# File test/functional/pages_controller_test.rb, line 364
364: def test_rollback
365: get :new
366: session['user'] = @tony
367: page = WikiPage.find_by_presentation_name('Toolmentor Template')
368: assert_equal 1, page.versions.size
369: # 1
370: post :checkout, :version => {:version_id => page.current_version.id, :note => 'test_rollback'}
371: assert_not_nil page.checkout
372: co = page.checkout
373: post :checkin, :checkout_id => co.id, :html => co.version.html.gsub('</body>', '####</body>')
374: page.reload
375: assert_nil page.checkout
376: assert_match '####', page.html
377: # 2
378: post :rollback, :version => {:version_id => page.versions[0].id}
379: page.reload
380: assert_nil page.checkout
381: assert_equal 2, page.versions.last.version
382: assert !page.versions.last.html.index('#### 1')
383: assert !page.html.index('####')
384: end
Shows:
# File test/functional/pages_controller_test.rb, line 311
311: def test_undocheckout
312: get :checkout
313: session['user'] = @tony
314: page = WikiPage.find_by_presentation_name('Toolmentor Template')
315: assert_nil page.checkout
316: # 1
317: v = page.current_version
318: assert_not_nil v
319: post :checkout, :version => {:version_id => v.id, :note => 'test_undocheckout'}
320: assert_not_nil page.checkout
321: assert_redirected_to :action => 'edit', :checkout_id => page.checkout.id
322: co = page.checkout
323: v = page.checkout.version
324: get :undocheckout, :checkout_id => co.id
325: assert !Checkout.exists?(co.id)
326: assert !Version.exists?(v.id)
327: # 2
328: post :checkout, :version => {:version_id => page.current_version.id, :note => 'test_undocheckout'}
329: co = page.checkout
330: v = page.checkout.version
331: session['user'] = @andy
332: assert_raise(RuntimeError) {get :undocheckout, :checkout_id => co.id}
333: # 3
334: session['user'] = @george
335:
336: get :undocheckout, :checkout_id => co.id
337: assert_redirected_to '/' + @wiki.rel_path + '/' + page.rel_path
338: assert_nil page.checkout
339: assert !Checkout.exists?(co.id)
340: assert !Version.exists?(v.id)
341: # 4
342: session['user'] = @tony
343: page.reload
344: assert_not_nil page
345: assert_not_nil page.site
346: assert page.site.pages.size > 0
347: post :new, :id => page.site.pages[0].id, :site_folder =>page.site.folder, :page => {:presentation_name => "New page based on #{page.presentation_name}", :source_version => page.versions.last.id, :note => 'Undo also deletes page'}
348: new_page = WikiPage.find_by_presentation_name("New page based on #{page.presentation_name}")
349: assert_not_nil new_page
350: assert_not_nil new_page.checkout
351: assert_not_nil new_page.checkout.version
352: co, v = new_page.checkout, new_page.checkout.version
353: post :undocheckout, :checkout_id => new_page.checkout.id
354: assert !Page.exists?(new_page.id)
355: assert !Checkout.exists?(co.id)
356: assert !Version.exists?(v.id)
357: assert_redirected_to page.site.pages[0].url
358: end
Shows:
# File test/functional/pages_controller_test.rb, line 52
52: def test_view
53: # 1
54: @wiki.pages.each do |page|
55: id = (@wiki.rel_path + page.rel_path).gsub('/', '_') # id allows us to cache the requests (pages)
56: get :view, :url => page.url(true), :id => id
57: assert_response :success
58: assert_equal @wiki, assigns(:wiki)
59: assert_equal page, assigns(:page)
60: assert_not_nil assigns(:version)
61: assert_equal [], assigns(:comments)
62: assert_nil assigns(:checkout)
63: assert_equal [], assigns(:contributor_names)
64: end
65: # 2
66: page = @wiki.pages[3]
67: Comment.create(:text => 'Comment', :user => @andy, :page => page, :site => @wiki, :version => page.current_version)
68: Comment.create(:text => 'Another comment', :user => @andy, :page => page, :site => @wiki, :version => page.current_version)
69: Comment.create(:text => 'And another comment', :user => @andy, :page => page, :site => @wiki, :version => page.current_version)
70: page.reload
71: assert_equal 3, page.comments.size
72: get :view, :url => page.url(true)
73: assert_response :success
74: assert_match "Comment", @response.body
75: assert_match "Another comment", @response.body
76: assert_match "And another comment", @response.body
77: # 3
78: assert_equal [@andy.name], assigns(:contributor_names)
79: assert_match @andy.name, @response.body
80: # 4
81: co = Checkout.new(:user => @andy, :page => page, :site => @wiki)
82: assert co.save
83: get :view, :url => page.url(true)
84: assert_response :success
85: assert_match 'This page is currently being modified by ' + @andy.name, @response.body
86: end