$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib') require 'test/unit' require 'rexml/xpath' require 'buildmaster/site/template_builder' require 'buildmaster/tree_to_object' require 'yaml' module BuildMaster class TemplateBuilderTest < Test::Unit::TestCase def test_should_generate_template_document builder = TemplateBuilder.new document = builder.generate assert_equal('include', REXML::XPath.first(document, '/html/head/title/*').name) assert_css_path(document, 'buildmaster.css') end def test_should_update_header_with_title_and_css builder = TemplateBuilder.new builder.title_header = 'Title Header - ' builder.css_path = 'mycss.css' document = builder.generate first_child = REXML::XPath.first(document, '/html/head/title').children[0] assert_equal(REXML::Text, first_child.class) assert_equal('Title Header - ', first_child.value) assert_css_path(document, 'mycss.css') end def test_should_have_logo_defaults builder = TemplateBuilder.new assert_equal(nil, builder.logo.path) assert_equal('index.html', builder.logo.link) end def test_should_generate_logo_and_link builder = TemplateBuilder.new builder.logo.path = 'gif/logo.gif' builder.logo.link = 'main.html' document = builder.generate header = assert_first(document, '/html/body/div[@class="header"]') anchor_href = assert_first(header, 'a/template:href') assert_equal('main.html', anchor_href.attributes['url']) img_href = assert_first(header, 'a/img/template:href') assert_equal('gif/logo.gif', img_href.attributes['url']) end def test_should_build_left_menu builder = TemplateBuilder.new builder.left_bottom_logo.path='http://www.example.com/logo.gif' group = builder.menu_group('Software') group.menu_item('Download', 'download.html') group.menu_item('License', 'license.html') group.more='more.html' group = builder.menu_group('Documentation', 'doc/index.html') group.menu_item('Getting Started', 'doc/getting-started') document = builder.generate groups = REXML::XPath.match(document, '/html/body/div[@class="left"]/div[@class="MenuGroup"]') assert_equal(2, groups.size) first_group = groups[0] header = assert_first(first_group, 'h1') assert_equal('Software', header.text) items = REXML::XPath.match(first_group, 'ul/li') assert_equal(3, items.size) first_item = items[0] anchor = assert_first(first_item, 'template:link') assert_equal('download.html', anchor.attributes['href']) assert_equal('Download', anchor.text) more = items[2] assert_equal('More', more.attributes['class']) end def test_should_have_releases_info builder = TemplateBuilder.new releases = builder.releases releases.stable_version = '0.6' releases.pre_release_version = '0.7' releases.snap_shot_version = 'n/a' releases.download_link = 'download.html' releases.versioning_link = 'versioning.html' document = builder.generate assert_equal('Latest Versions', REXML::XPath.first(document, '/html/body/template:when/div[@class="right"]/div/h1').text) end def test_should_have_no_release_info_if_not_assigned builder = TemplateBuilder.new builder.releases.download_link = nil document = builder.generate assert_equal(0, REXML::XPath.match(document, '/html/body/template:when/div/*').size) end def test_should_read_from_yaml content = <