menu_item_test.rb
108 lines
| 4.0 KiB
| text/x-ruby
|
RubyLexer
|
r2976 | # Redmine - project management software | ||
|
r14857 | # Copyright (C) 2006-2016 Jean-Philippe Lang | ||
|
r2976 | # | ||
# 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. | ||||
|
r6673 | # | ||
|
r2976 | # This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
# GNU General Public License for more details. | ||||
|
r6673 | # | ||
|
r2976 | # You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
|
r4395 | require File.expand_path('../../../../../test_helper', __FILE__) | ||
|
r2976 | |||
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 | ||||
|
r3812 | class Redmine::MenuManager::MenuItemTest < ActiveSupport::TestCase | ||
|
r2976 | include RedmineMenuTestHelper | ||
Redmine::MenuManager.map :test_menu do |menu| | ||||
|
r2978 | menu.push(:parent, '/test', { }) | ||
menu.push(:child_menu, '/test', { :parent => :parent}) | ||||
menu.push(:child2_menu, '/test', { :parent => :parent}) | ||||
|
r2976 | end | ||
|
r6673 | |||
|
r2976 | # 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_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 | ||||
|
r2978 | def test_new_menu_item_should_require_a_proc_to_use_the_children_option | ||
|
r2977 | assert_raises ArgumentError do | ||
Redmine::MenuManager::MenuItem.new(:test_error, '/test', | ||||
{ | ||||
|
r2978 | :children => ['not_a_proc'] | ||
|
r2977 | }) | ||
end | ||||
|
r2978 | assert Redmine::MenuManager::MenuItem.new(:test_good_children, '/test', | ||
|
r2977 | { | ||
|
r2978 | :children => Proc.new{} | ||
|
r2977 | }) | ||
end | ||||
|
r2978 | def test_new_should_not_allow_setting_the_parent_item_to_the_current_item | ||
|
r2976 | assert_raises ArgumentError do | ||
|
r2978 | Redmine::MenuManager::MenuItem.new(:test_error, '/test', { :parent => :test_error }) | ||
|
r2976 | end | ||
end | ||||
def test_has_children | ||||
|
r2978 | parent_item = get_menu_item(:test_menu, :parent) | ||
|
r8094 | assert parent_item.children.present? | ||
|
r2976 | 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 | ||||