To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / test / unit / lib / redmine / menu_manager / menu_item_test.rb @ 441:cbce1fd3b1b7
History | View | Annotate | Download (4.32 KB)
| 1 |
# Redmine - project management software
|
|---|---|
| 2 |
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
| 3 |
#
|
| 4 |
# This program is free software; you can redistribute it and/or
|
| 5 |
# modify it under the terms of the GNU General Public License
|
| 6 |
# as published by the Free Software Foundation; either version 2
|
| 7 |
# of the License, or (at your option) any later version.
|
| 8 |
#
|
| 9 |
# This program is distributed in the hope that it will be useful,
|
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
# GNU General Public License for more details.
|
| 13 |
#
|
| 14 |
# You should have received a copy of the GNU General Public License
|
| 15 |
# along with this program; if not, write to the Free Software
|
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
| 17 |
|
| 18 |
require File.expand_path('../../../../../test_helper', __FILE__) |
| 19 |
|
| 20 |
module RedmineMenuTestHelper |
| 21 |
# Helpers
|
| 22 |
def get_menu_item(menu_name, item_name) |
| 23 |
Redmine::MenuManager.items(menu_name).find {|item| item.name == item_name.to_sym} |
| 24 |
end
|
| 25 |
end
|
| 26 |
|
| 27 |
class Redmine::MenuManager::MenuItemTest < ActiveSupport::TestCase |
| 28 |
include RedmineMenuTestHelper
|
| 29 |
|
| 30 |
Redmine::MenuManager.map :test_menu do |menu| |
| 31 |
menu.push(:parent, '/test', { }) |
| 32 |
menu.push(:child_menu, '/test', { :parent => :parent}) |
| 33 |
menu.push(:child2_menu, '/test', { :parent => :parent}) |
| 34 |
end
|
| 35 |
|
| 36 |
context "MenuItem#caption" do |
| 37 |
should "be tested"
|
| 38 |
end
|
| 39 |
|
| 40 |
context "MenuItem#html_options" do |
| 41 |
should "be tested"
|
| 42 |
end
|
| 43 |
|
| 44 |
# context new menu item
|
| 45 |
def test_new_menu_item_should_require_a_name |
| 46 |
assert_raises ArgumentError do |
| 47 |
Redmine::MenuManager::MenuItem.new |
| 48 |
end
|
| 49 |
end
|
| 50 |
|
| 51 |
def test_new_menu_item_should_require_an_url |
| 52 |
assert_raises ArgumentError do |
| 53 |
Redmine::MenuManager::MenuItem.new(:test_missing_url) |
| 54 |
end
|
| 55 |
end
|
| 56 |
|
| 57 |
def test_new_menu_item_should_require_the_options |
| 58 |
assert_raises ArgumentError do |
| 59 |
Redmine::MenuManager::MenuItem.new(:test_missing_options, '/test') |
| 60 |
end
|
| 61 |
end
|
| 62 |
|
| 63 |
def test_new_menu_item_with_all_required_parameters |
| 64 |
assert Redmine::MenuManager::MenuItem.new(:test_good_menu, '/test', {}) |
| 65 |
end
|
| 66 |
|
| 67 |
def test_new_menu_item_should_require_a_proc_to_use_for_the_if_condition |
| 68 |
assert_raises ArgumentError do |
| 69 |
Redmine::MenuManager::MenuItem.new(:test_error, '/test', |
| 70 |
{
|
| 71 |
:if => ['not_a_proc'] |
| 72 |
}) |
| 73 |
end
|
| 74 |
|
| 75 |
assert Redmine::MenuManager::MenuItem.new(:test_good_if, '/test', |
| 76 |
{
|
| 77 |
:if => Proc.new{} |
| 78 |
}) |
| 79 |
end
|
| 80 |
|
| 81 |
def test_new_menu_item_should_allow_a_hash_for_extra_html_options |
| 82 |
assert_raises ArgumentError do |
| 83 |
Redmine::MenuManager::MenuItem.new(:test_error, '/test', |
| 84 |
{
|
| 85 |
:html => ['not_a_hash'] |
| 86 |
}) |
| 87 |
end
|
| 88 |
|
| 89 |
assert Redmine::MenuManager::MenuItem.new(:test_good_html, '/test', |
| 90 |
{
|
| 91 |
:html => { :onclick => 'doSomething'} |
| 92 |
}) |
| 93 |
end
|
| 94 |
|
| 95 |
def test_new_menu_item_should_require_a_proc_to_use_the_children_option |
| 96 |
assert_raises ArgumentError do |
| 97 |
Redmine::MenuManager::MenuItem.new(:test_error, '/test', |
| 98 |
{
|
| 99 |
:children => ['not_a_proc'] |
| 100 |
}) |
| 101 |
end
|
| 102 |
|
| 103 |
assert Redmine::MenuManager::MenuItem.new(:test_good_children, '/test', |
| 104 |
{
|
| 105 |
:children => Proc.new{} |
| 106 |
}) |
| 107 |
end
|
| 108 |
|
| 109 |
def test_new_should_not_allow_setting_the_parent_item_to_the_current_item |
| 110 |
assert_raises ArgumentError do |
| 111 |
Redmine::MenuManager::MenuItem.new(:test_error, '/test', { :parent => :test_error }) |
| 112 |
end
|
| 113 |
end
|
| 114 |
|
| 115 |
def test_has_children |
| 116 |
parent_item = get_menu_item(:test_menu, :parent) |
| 117 |
assert parent_item.hasChildren? |
| 118 |
assert_equal 2, parent_item.children.size
|
| 119 |
assert_equal get_menu_item(:test_menu, :child_menu), parent_item.children[0] |
| 120 |
assert_equal get_menu_item(:test_menu, :child2_menu), parent_item.children[1] |
| 121 |
end
|
| 122 |
end
|