@@ -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.dirname(__FILE__) + '/../../../../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../../../../test_helper' | |
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 < |
|
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 |
@@ -1,32 +1,28 | |||||
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.dirname(__FILE__) + '/../../../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../../../test_helper' | |
19 |
|
19 | |||
20 |
class Redmine::MenuManagerTest < |
|
20 | class Redmine::MenuManagerTest < ActiveSupport::TestCase | |
21 | context "MenuManager#map" do |
|
21 | context "MenuManager#map" do | |
22 | should "be tested" |
|
22 | should "be tested" | |
23 | end |
|
23 | end | |
24 |
|
24 | |||
25 | context "MenuManager#items" do |
|
25 | context "MenuManager#items" do | |
26 | should "be tested" |
|
26 | should "be tested" | |
27 | end |
|
27 | end | |
28 |
|
||||
29 | should "be tested" do |
|
|||
30 | assert true |
|
|||
31 | end |
|
|||
32 | end |
|
28 | end |
@@ -1,84 +1,84 | |||||
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.dirname(__FILE__) + '/../../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../../test_helper' | |
19 |
|
19 | |||
20 | module RedmineMenuTestHelper |
|
20 | module RedmineMenuTestHelper | |
21 | # Assertions |
|
21 | # Assertions | |
22 | def assert_number_of_items_in_menu(menu_name, count) |
|
22 | def assert_number_of_items_in_menu(menu_name, count) | |
23 | assert Redmine::MenuManager.items(menu_name).size >= count, "Menu has less than #{count} items" |
|
23 | assert Redmine::MenuManager.items(menu_name).size >= count, "Menu has less than #{count} items" | |
24 | end |
|
24 | end | |
25 |
|
25 | |||
26 | def assert_menu_contains_item_named(menu_name, item_name) |
|
26 | def assert_menu_contains_item_named(menu_name, item_name) | |
27 | assert Redmine::MenuManager.items(menu_name).collect(&:name).include?(item_name.to_sym), "Menu did not have an item named #{item_name}" |
|
27 | assert Redmine::MenuManager.items(menu_name).collect(&:name).include?(item_name.to_sym), "Menu did not have an item named #{item_name}" | |
28 | end |
|
28 | end | |
29 |
|
29 | |||
30 | # Helpers |
|
30 | # Helpers | |
31 | def get_menu_item(menu_name, item_name) |
|
31 | def get_menu_item(menu_name, item_name) | |
32 | Redmine::MenuManager.items(menu_name).find {|item| item.name == item_name.to_sym} |
|
32 | Redmine::MenuManager.items(menu_name).find {|item| item.name == item_name.to_sym} | |
33 | end |
|
33 | end | |
34 | end |
|
34 | end | |
35 |
|
35 | |||
36 |
class RedmineTest < |
|
36 | class RedmineTest < ActiveSupport::TestCase | |
37 | include RedmineMenuTestHelper |
|
37 | include RedmineMenuTestHelper | |
38 |
|
38 | |||
39 | def test_top_menu |
|
39 | def test_top_menu | |
40 | assert_number_of_items_in_menu :top_menu, 5 |
|
40 | assert_number_of_items_in_menu :top_menu, 5 | |
41 | assert_menu_contains_item_named :top_menu, :home |
|
41 | assert_menu_contains_item_named :top_menu, :home | |
42 | assert_menu_contains_item_named :top_menu, :my_page |
|
42 | assert_menu_contains_item_named :top_menu, :my_page | |
43 | assert_menu_contains_item_named :top_menu, :projects |
|
43 | assert_menu_contains_item_named :top_menu, :projects | |
44 | assert_menu_contains_item_named :top_menu, :administration |
|
44 | assert_menu_contains_item_named :top_menu, :administration | |
45 | assert_menu_contains_item_named :top_menu, :help |
|
45 | assert_menu_contains_item_named :top_menu, :help | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
48 | def test_account_menu |
|
48 | def test_account_menu | |
49 | assert_number_of_items_in_menu :account_menu, 4 |
|
49 | assert_number_of_items_in_menu :account_menu, 4 | |
50 | assert_menu_contains_item_named :account_menu, :login |
|
50 | assert_menu_contains_item_named :account_menu, :login | |
51 | assert_menu_contains_item_named :account_menu, :register |
|
51 | assert_menu_contains_item_named :account_menu, :register | |
52 | assert_menu_contains_item_named :account_menu, :my_account |
|
52 | assert_menu_contains_item_named :account_menu, :my_account | |
53 | assert_menu_contains_item_named :account_menu, :logout |
|
53 | assert_menu_contains_item_named :account_menu, :logout | |
54 | end |
|
54 | end | |
55 |
|
55 | |||
56 | def test_application_menu |
|
56 | def test_application_menu | |
57 | assert_number_of_items_in_menu :application_menu, 0 |
|
57 | assert_number_of_items_in_menu :application_menu, 0 | |
58 | end |
|
58 | end | |
59 |
|
59 | |||
60 | def test_admin_menu |
|
60 | def test_admin_menu | |
61 | assert_number_of_items_in_menu :admin_menu, 0 |
|
61 | assert_number_of_items_in_menu :admin_menu, 0 | |
62 | end |
|
62 | end | |
63 |
|
63 | |||
64 | def test_project_menu |
|
64 | def test_project_menu | |
65 | assert_number_of_items_in_menu :project_menu, 12 |
|
65 | assert_number_of_items_in_menu :project_menu, 12 | |
66 | assert_menu_contains_item_named :project_menu, :overview |
|
66 | assert_menu_contains_item_named :project_menu, :overview | |
67 | assert_menu_contains_item_named :project_menu, :activity |
|
67 | assert_menu_contains_item_named :project_menu, :activity | |
68 | assert_menu_contains_item_named :project_menu, :roadmap |
|
68 | assert_menu_contains_item_named :project_menu, :roadmap | |
69 | assert_menu_contains_item_named :project_menu, :issues |
|
69 | assert_menu_contains_item_named :project_menu, :issues | |
70 | assert_menu_contains_item_named :project_menu, :new_issue |
|
70 | assert_menu_contains_item_named :project_menu, :new_issue | |
71 | assert_menu_contains_item_named :project_menu, :news |
|
71 | assert_menu_contains_item_named :project_menu, :news | |
72 | assert_menu_contains_item_named :project_menu, :documents |
|
72 | assert_menu_contains_item_named :project_menu, :documents | |
73 | assert_menu_contains_item_named :project_menu, :wiki |
|
73 | assert_menu_contains_item_named :project_menu, :wiki | |
74 | assert_menu_contains_item_named :project_menu, :boards |
|
74 | assert_menu_contains_item_named :project_menu, :boards | |
75 | assert_menu_contains_item_named :project_menu, :files |
|
75 | assert_menu_contains_item_named :project_menu, :files | |
76 | assert_menu_contains_item_named :project_menu, :repository |
|
76 | assert_menu_contains_item_named :project_menu, :repository | |
77 | assert_menu_contains_item_named :project_menu, :settings |
|
77 | assert_menu_contains_item_named :project_menu, :settings | |
78 | end |
|
78 | end | |
79 |
|
79 | |||
80 | def test_new_issue_should_have_root_as_a_parent |
|
80 | def test_new_issue_should_have_root_as_a_parent | |
81 | new_issue = get_menu_item(:project_menu, :new_issue) |
|
81 | new_issue = get_menu_item(:project_menu, :new_issue) | |
82 | assert_equal :root, new_issue.parent.name |
|
82 | assert_equal :root, new_issue.parent.name | |
83 | end |
|
83 | end | |
84 | end |
|
84 | end |
General Comments 0
You need to be logged in to leave comments.
Login now