blob: 807e42f8b22c453e79a4a73a4d2fd8232e9204dd [file] [log] [blame]
require File.dirname(__FILE__) + '/../test_helper'
#--######################################################################
# Copyright (c) 2006 LogicaCMG
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
#
# Onno van der Straaten:: initial implementation
#++######################################################################
# {Copyright (c) 2006 LogicaCMG}[link:files/COPYRIGHT.html]
class PageTest < Test::Unit::TestCase
fixtures :users
def setup
@openupwiki = Site.find_by_title('OpenUP Wiki')
@openup0721 = Site.find_by_folder(openup0721_folder)
@openup0728 = Site.find_by_folder(openup0728_folder)
@openup0825 = Site.find_by_folder(openup0825_folder)
@html = IO.readlines('unit/page_test/test_html.txt').join.split("####")
@onno = User.find(1)
@onno_cadmin = User.find(5)
@user4 = User.find(4)
@user3 = User.find(3)
end
def test01_find_or_new
treebrowser_tag_count = 0
copyright_tag_count = 0
text_count = 0
body_tag_count = 0
@openupwiki.pages.each do |page|
find_page = Page.find_or_new({:rel_path => page.rel_path}, @openupwiki)
assert_not_nil find_page
assert_equal page, find_page
treebrowser_tag_count = treebrowser_tag_count + 1 if !find_page.treebrowser_tag.nil?
copyright_tag_count = copyright_tag_count + 1 if !find_page.copyright_tag.nil?
text_count = text_count + 1 if !find_page.text.nil?
body_tag_count = body_tag_count + 1 if !find_page.body_tag.nil?
end
assert_equal 503, treebrowser_tag_count if ENV['EPFWIKI_TESTDATA'].blank?
assert_equal 617, copyright_tag_count if ENV['EPFWIKI_TESTDATA'].blank?
assert_equal 617, text_count if ENV['EPFWIKI_TESTDATA'].blank?
assert_equal 617, body_tag_count if ENV['EPFWIKI_TESTDATA'].blank?
assert_equal 8, treebrowser_tag_count if !ENV['EPFWIKI_TESTDATA'].blank?
assert_equal 10, copyright_tag_count if !ENV['EPFWIKI_TESTDATA'].blank?
assert_equal 10, text_count if !ENV['EPFWIKI_TESTDATA'].blank?
assert_equal 10, body_tag_count if !ENV['EPFWIKI_TESTDATA'].blank?
end
def test02_treebrowser_pattern
assert_pattern(Page::TREEBROWSER_PATTERN, @html[0],
"<script src=\"./../../../scripts/treebrowser.js\" type=\"text/javascript\" language=\"JavaScript\"></script>")
assert_pattern(Page::TREEBROWSER_PATTERN, @html[1],
"<script src=./../../../scripts/treebrowser.js\" type=\"text/javascript\" language=\"JavaScript\"></script>")
assert_pattern(Page::TREEBROWSER_PATTERN, @html[2],
"<scRipT SrC=./../../../../../../../../scripts/treebrowser.js\" type=\"text/javascript\" language=\"JavaScript\"></scripT>")
assert_pattern(Page::TREEBROWSER_PATTERN, @html[3],
"<script src=\"./../../scripts/treebrowser.js\" type=\"text/javascript\" language=\"JavaScript\"></script>")
end
def test03_body_tag_pattern
assert_pattern(Page::BODY_TAG_PATTERN, @html[0],
"<body onload=\"createSectionLinks('div', 'sectionHeading', './../../../images/');\">")
assert_pattern(Page::BODY_TAG_PATTERN, @html[1],
"<BoDy>")
assert_pattern(Page::BODY_TAG_PATTERN, @html[4],
"<body onload=\"createSectionLinks('div', 'sectionHeading', './../../../images/');\">")
end
def test05_iframe_pattern
assert_pattern(Page::IFRAME_PATTERN, @html[4],
"<!-- epfwiki iframe start -->\n<script language=\"JavaScript\">\n\n aURL = \"http://localhost:3000/epfwiki/toolbar?url=\" + document.location.href;\n\n document.write(\" <div id=\\\"topbar\\\">\\n\");\n\n document.write(\" <iframe width=\\\"100%\\\" height=\\\"25\\\" frameborder=\\\"0\\\" src=\\\"\" + aURL + \"\\\" scrolling=\\\"no\\\" marginwidth=\\\"0\\\">\\n\");\n\n document.writeln(\" </div>\");\n\n </script>\n<!-- epfwiki iframe end -->")
end
def test06_shim_tag_pattern
assert_pattern(Page::SHIM_TAG_PATTERN, @html[4],
"images/shim.gif\"></td>")
assert_pattern(Page::SHIM_TAG_PATTERN,@html[2],
"images/shim.gif\" />\n </td>")
assert_pattern(Page::SHIM_TAG_PATTERN, @html[3],
"images/shim.gif\"></td>")
end
def test07_copyright_pattern
assert_pattern(Page::COPYRIGHT_PATTERN, @html[5],
"<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>")
assert_pattern(Page::COPYRIGHT_PATTERN, @html[2],
"<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>")
end
# Shows:
# 1. can extract title from the file using Page.title_from_file
def test09_title_from_file
openup0721 = Site.find_by_folder(openup0721_folder)
filenames = Array.new
filenames << ['about_base_concepts,_uvje4D_fEdqDFvujd6NHiA.html','Supporting Material: About Base Concepts']
filenames << ['any_role,_3TCEoeB5EdqnKu908IEluw.html', 'Role Descriptor: Any Role']
filenames << ['determine_architectural_feasibility_0oreoclgEdmt3adZL5Dmdw_desc.html', 'Activity: Determine Architectural Feasibility']
for filename in filenames
page = Page.find_by_filename(filename[0])
assert_not_nil page
assert_equal filename[1], page.title_from_file(openup0721)
end
pages = Page.find_all
end
# Shows:
# 1. requesting Site.templates creates a templates dir and pages
# 2. new Page based on a template create a Page, a Version, a Checkout
# 3. a Page file does not exist after new page, before checkin
# 4. a Version file is created and prepared for edit
def test10_new_page_using_template
assert !File.exists?(@openupwiki.templates_dir)
version_count = Version.count
page_count = Page.count
checkout_count = Checkout.count
templates = @openupwiki.templates
assert_equal 2, templates.size
for template in templates
assert_enhanced_file(template.path(@openupwiki))
end
assert_equal 2, Page.count - page_count
assert_equal 2, Version.count - version_count
assert_equal 0, Checkout.count - checkout_count
# 2
tool_tpl = Page.find_by_filename('Tool Mentor Template.html')
source_version = Version.find_current_version(@openupwiki, tool_tpl)
new_page = Page.new(:presentation_name => 'New Tool Mentor created in test10_new_page_using_tempalte', :source_version => source_version, :user => @onno, :site => @openupwiki)
assert_equal 2, Page.count - page_count
assert_equal 2, Version.count - version_count
assert_equal 0, Checkout.count - checkout_count
assert new_page.save
assert_equal 3, Page.count - page_count # extra page
assert_equal 3, Version.count - version_count # extra version
assert_equal 1, Checkout.count - checkout_count # 1 checkout
checkout = new_page.checkout(@openupwiki)
new_page.reload
assert_equal 'New Tool Mentor created in test10_new_page_using_tempalte', new_page.presentation_name
assert_equal 'new_tool_mentor_created_in_test10_new_page_using_tempalte.html', new_page.filename
assert_equal "#{ENV['EPFWIKI_ROOT_DIR']}public/#{ENV['EPFWIKI_WIKIS_FOLDER']}/openup/wiki/new/#{new_page.filename}", new_page.path(@openupwiki)
# 3
assert !File.exists?(new_page.path(@openupwiki))
# 4
assert File.exists?(checkout.version.path)
assert_version_file(checkout.version.path)
end
def test11_treebrowser
assert_pattern(Page::TREEBROWSER_PATTERN, @html[7],"<script src=\"./../../scripts/treebrowser.js\" type=\"text/javascript\" language=\"JavaScript\"></script>")
assert_pattern(Page::TREEBROWSER_PATTERN, @html[8],"<script src=\"./../../scripts/treebrowser.js\" type=\"text/javascript\" language=\"JavaScript\"></script>")
end
def test12_element_type_pattern
assert_pattern(Page::ELEMENT_TYPE_PATTERN, @html[9], '<meta content="Checklist" name="element_type">')
assert_pattern(Page::ELEMENT_TYPE_PATTERN, @html[10], '<meta content=Checklist name=element_type>') #'< MetA name="element_type" content="Tool Mentor" >'
assert_pattern(Page::ELEMENT_TYPE_PATTERN, @html[11], nil)
assert_pattern(Page::ELEMENT_TYPE_PATTERN, @html[12], '<META NAME="element_type" CONTENT=" Tool Mentor " >')
assert_pattern(Page::ELEMENT_TYPE_PATTERN, @html[13], '<meta content="Checklist" name="element_type">')
assert_pattern(Page::ELEMENT_TYPE_PATTERN, @html[14], '<meta content="Checklist" name="element_type">')
assert_pattern(Page::ELEMENT_TYPE_PATTERN, @html[15], nil)
assert_equal 'Checklist', Page.meta_tag_content_type(@html[9])
assert_equal 'Checklist', Page.meta_tag_content_type(@html[10])
assert_equal '', Page.meta_tag_content_type(@html[11])
assert_equal 'Tool mentor', Page.meta_tag_content_type(@html[12])
assert_equal 'Checklist', Page.meta_tag_content_type(@html[13])
assert_equal 'Checklist', Page.meta_tag_content_type(@html[14])
assert_equal '', Page.meta_tag_content_type(@html[15])
end
# Shows:
# 1. we replace 'UMA Method Architecture' with 'Unified Method Architecture (UMA)' in about base concepts
# 2. we create a new page based on that changed version and then remove 'Method'
def test13_new_page_using_other_page
# 1
page = Page.find_by_filename('about_base_concepts,_uvje4D_fEdqDFvujd6NHiA.html')
assert_equal 0, page.versions.size
checkout = Checkout.new(:user => @onno, :page => page, :site => @openupwiki, :note => 'test13_new_page_using_other_page')
assert checkout.save
checkout.reload
page.reload
assert_equal 'test13_new_page_using_other_page', checkout.version.note
assert_equal 2, page.versions.size
assert_equal 1, checkout.version.version
checkout.checkin(@onno, checkout.version.html.gsub('UMA Method Architecture', 'Unified Method Architecture (UMA)'))
version = Version.find_current_version(@openupwiki, page)
assert_equal 1, version.version
assert version.html.index('Unified Method Architecture (UMA)')
assert page.html(@openupwiki).index('Unified Method Architecture (UMA)')
assert_enhanced_file(page.path(@openupwiki))
assert_version_file(version.path)
# 2
pages_count = @openupwiki.pages.size
page = Page.new(:presentation_name => 'New page created using base concepts', :source_version => version, :user => @onno, :site => @openupwiki)
assert page.save
page.reload
@openupwiki.reload
assert_equal pages_count + 1, @openupwiki.pages.size
assert_equal 1, page.versions.size
assert_equal version, page.versions[0].source_version
assert page.versions[0].previous_version.nil?
checkout = page.checkout(@openupwiki)
assert_not_nil checkout
assert checkout.version.html.index('Unified Method Architecture (UMA)')
checkout.checkin(@onno, checkout.version.html.gsub('Unified Method Architecture (UMA)','Unified Architecture (UMA)'))
version = Version.find_current_version(@openupwiki, page)
assert_equal 1, version.version
assert version.html.index('Unified Architecture (UMA)')
assert page.html(@openupwiki).index('Unified Architecture (UMA)')
assert_enhanced_file(page.path(@openupwiki))
assert_version_file(version.path)
end
def showRE(a,re)
if a =~ re
puts "#{$`}<<#{$&}>>#{$'}"
else
puts "no match"
end
end
end