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