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