2011-10-29 16:19:11 +04:00
|
|
|
#-- encoding: UTF-8
|
2011-05-30 00:11:52 +04:00
|
|
|
#-- copyright
|
|
|
|
# ChiliProject is a project management system.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# Copyright (C) 2010-2011 the ChiliProject Team
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2009-11-25 08:36:44 +03:00
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# See doc/COPYRIGHT.rdoc for more details.
|
|
|
|
#++
|
2010-12-13 02:24:34 +03:00
|
|
|
require File.expand_path('../../../../../test_helper', __FILE__)
|
2009-11-25 08:36:44 +03:00
|
|
|
|
|
|
|
module RedmineMenuTestHelper
|
|
|
|
# Helpers
|
|
|
|
def get_menu_item(menu_name, item_name)
|
|
|
|
Redmine::MenuManager.items(menu_name).find {|item| item.name == item_name.to_sym}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-08-08 11:07:38 +04:00
|
|
|
class Redmine::MenuManager::MenuItemTest < ActiveSupport::TestCase
|
2009-11-25 08:36:44 +03:00
|
|
|
include RedmineMenuTestHelper
|
|
|
|
|
|
|
|
Redmine::MenuManager.map :test_menu do |menu|
|
2009-11-25 08:36:56 +03:00
|
|
|
menu.push(:parent, '/test', { })
|
|
|
|
menu.push(:child_menu, '/test', { :parent => :parent})
|
|
|
|
menu.push(:child2_menu, '/test', { :parent => :parent})
|
2009-11-25 08:36:44 +03:00
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2009-11-25 08:36:44 +03:00
|
|
|
context "MenuItem#caption" do
|
|
|
|
should "be tested"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "MenuItem#html_options" do
|
|
|
|
should "be tested"
|
|
|
|
end
|
|
|
|
|
|
|
|
# context new menu item
|
|
|
|
def test_new_menu_item_should_require_a_name
|
|
|
|
assert_raises ArgumentError do
|
|
|
|
Redmine::MenuManager::MenuItem.new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_new_menu_item_should_require_an_url
|
|
|
|
assert_raises ArgumentError do
|
|
|
|
Redmine::MenuManager::MenuItem.new(:test_missing_url)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_new_menu_item_should_require_the_options
|
|
|
|
assert_raises ArgumentError do
|
|
|
|
Redmine::MenuManager::MenuItem.new(:test_missing_options, '/test')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_new_menu_item_with_all_required_parameters
|
|
|
|
assert Redmine::MenuManager::MenuItem.new(:test_good_menu, '/test', {})
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_new_menu_item_should_require_a_proc_to_use_for_the_if_condition
|
|
|
|
assert_raises ArgumentError do
|
|
|
|
Redmine::MenuManager::MenuItem.new(:test_error, '/test',
|
|
|
|
{
|
|
|
|
:if => ['not_a_proc']
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
assert Redmine::MenuManager::MenuItem.new(:test_good_if, '/test',
|
|
|
|
{
|
|
|
|
:if => Proc.new{}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_new_menu_item_should_allow_a_hash_for_extra_html_options
|
|
|
|
assert_raises ArgumentError do
|
|
|
|
Redmine::MenuManager::MenuItem.new(:test_error, '/test',
|
|
|
|
{
|
|
|
|
:html => ['not_a_hash']
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
assert Redmine::MenuManager::MenuItem.new(:test_good_html, '/test',
|
|
|
|
{
|
|
|
|
:html => { :onclick => 'doSomething'}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2009-11-25 08:36:56 +03:00
|
|
|
def test_new_menu_item_should_require_a_proc_to_use_the_children_option
|
2009-11-25 08:36:50 +03:00
|
|
|
assert_raises ArgumentError do
|
|
|
|
Redmine::MenuManager::MenuItem.new(:test_error, '/test',
|
|
|
|
{
|
2009-11-25 08:36:56 +03:00
|
|
|
:children => ['not_a_proc']
|
2009-11-25 08:36:50 +03:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2009-11-25 08:36:56 +03:00
|
|
|
assert Redmine::MenuManager::MenuItem.new(:test_good_children, '/test',
|
2009-11-25 08:36:50 +03:00
|
|
|
{
|
2009-11-25 08:36:56 +03:00
|
|
|
:children => Proc.new{}
|
2009-11-25 08:36:50 +03:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2009-11-25 08:36:56 +03:00
|
|
|
def test_new_should_not_allow_setting_the_parent_item_to_the_current_item
|
2009-11-25 08:36:44 +03:00
|
|
|
assert_raises ArgumentError do
|
2009-11-25 08:36:56 +03:00
|
|
|
Redmine::MenuManager::MenuItem.new(:test_error, '/test', { :parent => :test_error })
|
2009-11-25 08:36:44 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_has_children
|
2009-11-25 08:36:56 +03:00
|
|
|
parent_item = get_menu_item(:test_menu, :parent)
|
2009-11-25 08:36:44 +03:00
|
|
|
assert parent_item.hasChildren?
|
|
|
|
assert_equal 2, parent_item.children.size
|
|
|
|
assert_equal get_menu_item(:test_menu, :child_menu), parent_item.children[0]
|
|
|
|
assert_equal get_menu_item(:test_menu, :child2_menu), parent_item.children[1]
|
|
|
|
end
|
|
|
|
end
|