| Class | PageTest |
| In: |
test/unit/page_test.rb
|
| Parent: | Test::Unit::TestCase |
# File test/unit/page_test.rb, line 20
20: def setup
21: logger.debug "Test Case: #{name}"
22: @andy = users(:andy)
23: @george = users(:george)
24: @tony = users(:tony)
25: @cash = users(:cash)
26: @html = IO.readlines('test/unit/page_test/test_html.txt').join.split("####")
27: end
# File test/unit/page_test.rb, line 62
62: def test_copyright_pattern
63: assert_pattern(Page::COPYRIGHT_PATTERN, @html[5],
64: "<p>Copyright (c) 1987, 2006 IBM Corp. and others. All Rights Reserved.\n\n <br />This program and the accompanying materials are made available under the\n\n <br />\n\n <a href=\"http://www.eclipse.org/org/documents/epl-v10.php\" target=\"_blank\">Eclipse Public License v1.0</a> which accompanies this distribution.</p>")
65: assert_pattern(Page::COPYRIGHT_PATTERN, @html[2],
66: "<p>\n Copyright (c) 1987, 2006 IBM Corp. and others. All Rights Reserved.<br />\n This program and the accompanying materials are made available under the<br />\n <a href=\"http://www.eclipse.org/org/documents/epl-v10.php\" target=\"_blank\">Eclipse Public License v1.0</a> which\n accompanies this distribution.\n</p>")
67: end
# File test/unit/page_test.rb, line 277
277: def test_make_rel_path_unique
278: @wiki = create_templates
279: page = WikiPage.find_by_presentation_name('Toolmentor Template')
280: assert_equal 'new/guidances/toolmentors/toolmentor_template_E9930C53.html', page.rel_path
281: for i in 1..15
282: page.make_rel_path_unique
283: assert_equal "new/guidances/toolmentors/toolmentor_template_E9930C53_#{i}.html", page.rel_path
284: end
285: end
Shows:
# File test/unit/page_test.rb, line 268
268: def test_max_rel_path
269: @oup_20060721 = create_oup_20060721
270: max_rel_path = 0
271: @oup_20060721.pages.each do |page|
272: max_rel_path = page.rel_path.length if page.rel_path.length > max_rel_path
273: end
274: assert_equal 101, max_rel_path
275: end
# File test/unit/page_test.rb, line 29
29: def test_new
30: @oup_20060721 = create_oup_20060721
31: @oup_wiki = create_oup_wiki(@oup_20060721)
32: @oup_20060728 = create_oup_20060728
33: treebrowser_tag_count = 0
34: copyright_tag_count = 0
35: #text_count = 0
36: body_tag_count = 0
37: assert_equal 1, Wiki.count
38: @oup_wiki.pages.each do |page|
39: find_page = WikiPage.find_by_rel_path(page.rel_path) # assumes there is only 1 Wiki
40: assert_not_nil find_page
41: assert_equal page, find_page
42: treebrowser_tag_count = treebrowser_tag_count + 1 if !find_page.treebrowser_tag.nil?
43: copyright_tag_count = copyright_tag_count + 1 if !find_page.copyright_tag.nil?
44: #text_count = text_count + 1 if !find_page.text.nil?
45: body_tag_count = body_tag_count + 1 if !find_page.body_tag.nil?
46: end
47: assert_equal 617, treebrowser_tag_count
48: assert_equal 617, copyright_tag_count
49: # assert_equal 617, text_count
50: assert_equal 617, body_tag_count
51: end
Shows:
# File test/unit/page_test.rb, line 212
212: def test_new_page_using_other_page
213: @oup_20060721 = create_oup_20060721
214: @oup_wiki = create_oup_wiki(@oup_20060721)
215: @oup_20060728 = create_oup_20060728
216: # 1
217: assert_equal 1, WikiPage.find(:all, :conditions => ['presentation_name=?','About Base Concepts']).size
218: page = WikiPage.find_by_presentation_name('About Base Concepts')
219: assert !page.nil? # Shouldn't fail but does, this really sucks, big time.
220: assert_equal [617, 617, 617*3, 617*2], [Version.count, WikiPage.count, Page.count, BaselineProcessPage.count]
221: assert_equal 1, page.versions.size
222: checkout = Checkout.new(:user => @andy, :page => page, :site => @oup_wiki, :note => 'test13_new_page_using_other_page')
223: assert checkout.save
224: checkout.reload
225: page.reload
226: assert_equal 'test13_new_page_using_other_page', checkout.version.note
227: assert_equal 1, page.versions.size # versions doesn't count checked out
228: assert_equal nil, checkout.version.version
229: checkout.checkin(@andy, checkout.version.html.gsub('UMA Method Architecture', 'Unified Method Architecture (UMA)'))
230: page.reload
231: assert_equal 2, page.versions.size
232: version = page.current_version
233: assert_equal 1, version.version
234: assert version.html.index('Unified Method Architecture (UMA)')
235: assert page.html.index('Unified Method Architecture (UMA)')
236: assert_enhanced_file(page.path)
237: assert_version_file(version.path)
238: # 2
239: pages_count = @oup_wiki.pages.count
240: page, co = WikiPage.new_using_template(:presentation_name => 'New page created using base concepts', :source_version => version, :user => @andy, :site => @oup_wiki)
241: assert_not_nil page
242: assert_not_nil co
243: page.reload
244: co.reload
245: @oup_wiki.reload
246: assert_equal pages_count + 1, @oup_wiki.pages.count
247: assert_equal 0, page.versions.size # checkouts are not counted here
248: v = co.version
249: assert_not_nil v
250: assert_not_nil v.version_id
251: assert_equal version, v.source_version # the template version
252: assert v.previous_version.nil? # the first version of a new page
253: checkout = page.checkout
254: assert_not_nil checkout
255: assert checkout.version.html.index('Unified Method Architecture (UMA)')
256: assert_not_nil checkout.version.source_version
257: checkout.checkin(@andy, checkout.version.html.gsub('Unified Method Architecture (UMA)','Unified Architecture (UMA)'))
258: version = page.current_version
259: assert_equal 1, version.version
260: assert version.html.index('Unified Architecture (UMA)')
261: assert page.html.index('Unified Architecture (UMA)')
262: assert_enhanced_file(page.path)
263: assert_version_file(version.path)
264: end
Shows:
# File test/unit/page_test.rb, line 92
92: def test_new_page_using_template
93: @oup_20060721 = create_oup_20060721
94: @oup_wiki = create_oup_wiki(@oup_20060721)
95: #@oup_20060728 = create_oup_20060728
96: # 1
97: assert_raise(RuntimeError) {Site.templates}
98: create_templates # Using templates plugin to create the 'Templates' Wiki
99: assert_equal 26, Site.templates.size
100: @templates = Wiki.find(:first, :conditions => ['title = ?', 'Templates'])
101: # 2
102: pc, vc, cc = Page.count, Version.count, Checkout.count
103: tool_tpl = WikiPage.find_by_presentation_name('Toolmentor Template')
104: assert_not_nil tool_tpl
105: assert_equal @templates, tool_tpl.site
106: assert_equal [0,0,0], [Page.count - pc, Version.count - vc, Checkout.count - cc]
107: assert_equal 1, Version.count(:conditions => ['page_id=? and wiki_id =?', tool_tpl.id, @templates.id])
108: source_version = tool_tpl.current_version
109: assert_not_nil source_version
110: new_page, new_co = WikiPage.new_using_template(:presentation_name => 'New Tool Mentor created in test10_new_page_using_tempalte', :source_version => source_version, :user => @andy, :site => @oup_wiki)
111: #5
112: assert_no_errors(new_page)
113: assert_no_errors(new_co)
114: assert_equal [1,1,1], [Page.count - pc, Version.count - vc, Checkout.count - cc]
115: assert_equal new_co, new_page.checkout
116: new_page.reload
117: assert_equal 'New Tool Mentor created in test10_new_page_using_tempalte', new_page.presentation_name
118: assert_equal 'new_tool_mentor_created_in_test10_new_page_using_tempalte.html', new_page.filename
119: assert_equal "#{ENV['EPFWIKI_ROOT_DIR']}#{ENV['EPFWIKI_PUBLIC_FOLDER']}/#{ENV['EPFWIKI_WIKIS_FOLDER']}/openup/new/guidances/toolmentors/#{new_page.filename}", new_page.path
120: # 3
121: assert File.exists?(new_page.path)
122: # 4
123: assert File.exists?(new_co.version.path)
124: assert_version_file(new_co.version.path)
125: # 5
126: new_co.checkin(@andy)
127: assert Notification.find_all_users(new_page, Page.name).include?(@andy)
128: # 6
129: new_page2, new_co2 = WikiPage.new_using_template(:presentation_name => 'New Tool Mentor created in test10_new_page_using_tempalte', :source_version => source_version, :user => @andy, :site => @oup_wiki)
130: assert_no_errors(new_page2)
131: assert_no_errors(new_co2)
132: new_co2.checkin(@andy)
133: assert_equal new_page.rel_path.gsub('.html', '_1.html'), new_page2.rel_path
134: new_page3, new_co3 = WikiPage.new_using_template(:presentation_name => 'New Tool Mentor created in test10_new_page_using_tempalte', :source_version => source_version, :user => @andy, :site => @oup_wiki)
135: assert_no_errors(new_page3)
136: assert_no_errors(new_co3)
137: new_co3.checkin(@andy)
138: assert_equal new_page.rel_path.gsub('.html', '_2.html'), new_page3.rel_path
139: end
Shows: we do get uma_type, uma_presentation_name, uma_name, body_tag, treebrowser_tag and copyright tag from the HTML
# File test/unit/page_test.rb, line 142
142: def test_patterns
143: @wiki = create_templates
144: assert_equal ["CustomCategory",
145: "Discipline",
146: "Domain",
147: "Checklist",
148: "Concept",
149: "EstimationConsiderations",
150: "Example",
151: "Guideline",
152: "Guideline",
153: "Practice",
154: "Report",
155: "ReusableAsset",
156: "Roadmap",
157: "SupportingMaterial",
158: "Template",
159: "TermDefinition",
160: "ToolMentor",
161: "Whitepaper",
162: "Role",
163: "RoleSetGrouping",
164: "RoleSet",
165: "Task",
166: "Artifact",
167: "Deliverable",
168: "Outcome",
169: "WorkProductType"], @wiki.pages.collect {|page| page.uma_type}
170: assert_equal ["Templates",
171: "Discipline Template",
172: "Domain Template",
173: "Checklist Template",
174: "Concept Template",
175: "Estimation Considerations Template",
176: "Example Template",
177: "Estimating Guideline Template",
178: "Guideline Template",
179: "Practice Template",
180: "Report Template",
181: "Reusable Asset Template",
182: "Roadmap Template",
183: "Supporting Material Template",
184: "Template Template",
185: "Term Definition Template",
186: "Toolmentor Template",
187: "Whitepaper Template",
188: "Role Template",
189: "Role Set Grouping Template",
190: "Role Set Template",
191: "Task Template",
192: "Artifact Template",
193: "Deliverable Template",
194: "Outcome Template",
195: "Work Product Kind Template"], @wiki.pages.collect {|page| page.presentation_name}
196: assert_equal ["view", "discipline_template", "domain_template", "checklist_template",
197: "concept_template", "estimation_considerations_template", "example_template",
198: "estimating_guideline_templae", "guideline_template", "practice_template", "report_template",
199: "reusable_asset_template", "roadmap_template", "supporting_material_template",
200: "template_template", "term_definition_template", "toolmentor_template", "whitepaper_template",
201: "role_template", "role_set_grouping_template", "role_set_template", "task_template",
202: "artifact_template", "deliverable_template", "outcome_template", "work_product_kind_template"], @wiki.pages.collect {|page| page.uma_name}
203: assert_equal ["<body>"]*26, @wiki.pages.collect {|page| page.body_tag}
204: @wiki.pages.each do |p|
205: assert_equal [p.filename, true, true, true, true], [p.filename, p.treebrowser_tag.include?('treebrowser.js'), p.treebrowser_tag.include?('<script'), p.treebrowser_tag.include?('script>'), p.copyright_tag.include?('http://www.eclipse.org/org/documents/epl-v10.php')]
206: end
207: end
# File test/unit/page_test.rb, line 53
53: def test_shim_tag_pattern
54: assert_pattern(Page::SHIM_TAG_PATTERN, @html[4],
55: "images/shim.gif\"></td>")
56: assert_pattern(Page::SHIM_TAG_PATTERN,@html[2],
57: "images/shim.gif\" />\n </td>")
58: assert_pattern(Page::SHIM_TAG_PATTERN, @html[3],
59: "images/shim.gif\"></td>")
60: end
Shows:
# File test/unit/page_test.rb, line 71
71: def test_title_from_file
72: @oup_20060721 = create_oup_20060721
73: filenames = Array.new
74: filenames << ['about_base_concepts,_uvje4D_fEdqDFvujd6NHiA.html','About Base Concepts']
75: filenames << ['any_role,_3TCEoeB5EdqnKu908IEluw.html', 'Any Role']
76: filenames << ['determine_architectural_feasibility_0oreoclgEdmt3adZL5Dmdw_desc.html', 'Determine Architectural Feasibility']
77: for filename in filenames
78: page = Page.find_by_filename(filename[0])
79: assert_not_nil page
80: assert_equal filename[1], Page.uma_presentation_name_from_html(page.html)
81: end
82: #pages = Page.find(:all)
83: end