Chris@1494
|
1 # Redmine - project management software
|
Chris@1494
|
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
|
Chris@1494
|
3 #
|
Chris@1494
|
4 # This program is free software; you can redistribute it and/or
|
Chris@1494
|
5 # modify it under the terms of the GNU General Public License
|
Chris@1494
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@1494
|
7 # of the License, or (at your option) any later version.
|
Chris@1494
|
8 #
|
Chris@1494
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@1494
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@1494
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@1494
|
12 # GNU General Public License for more details.
|
Chris@1494
|
13 #
|
Chris@1494
|
14 # You should have received a copy of the GNU General Public License
|
Chris@1494
|
15 # along with this program; if not, write to the Free Software
|
Chris@1494
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@1494
|
17
|
Chris@1494
|
18 require File.expand_path('../../../../../test_helper', __FILE__)
|
Chris@1494
|
19
|
Chris@1494
|
20 class Redmine::MenuManager::MapperTest < ActiveSupport::TestCase
|
Chris@1494
|
21 test "Mapper#initialize should define a root MenuNode if menu is not present in items" do
|
Chris@1494
|
22 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
|
Chris@1494
|
23 node = menu_mapper.menu_items
|
Chris@1494
|
24 assert_not_nil node
|
Chris@1494
|
25 assert_equal :root, node.name
|
Chris@1494
|
26 end
|
Chris@1494
|
27
|
Chris@1494
|
28 test "Mapper#initialize should use existing MenuNode if present" do
|
Chris@1494
|
29 node = "foo" # just an arbitrary reference
|
Chris@1494
|
30 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {:test_menu => node})
|
Chris@1494
|
31 assert_equal node, menu_mapper.menu_items
|
Chris@1494
|
32 end
|
Chris@1494
|
33
|
Chris@1494
|
34 def test_push_onto_root
|
Chris@1494
|
35 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
|
Chris@1494
|
36 menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
|
Chris@1494
|
37
|
Chris@1494
|
38 menu_mapper.exists?(:test_overview)
|
Chris@1494
|
39 end
|
Chris@1494
|
40
|
Chris@1494
|
41 def test_push_onto_parent
|
Chris@1494
|
42 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
|
Chris@1494
|
43 menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
|
Chris@1494
|
44 menu_mapper.push :test_child, { :controller => 'projects', :action => 'show'}, {:parent => :test_overview}
|
Chris@1494
|
45
|
Chris@1494
|
46 assert menu_mapper.exists?(:test_child)
|
Chris@1494
|
47 assert_equal :test_child, menu_mapper.find(:test_child).name
|
Chris@1494
|
48 end
|
Chris@1494
|
49
|
Chris@1494
|
50 def test_push_onto_grandparent
|
Chris@1494
|
51 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
|
Chris@1494
|
52 menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
|
Chris@1494
|
53 menu_mapper.push :test_child, { :controller => 'projects', :action => 'show'}, {:parent => :test_overview}
|
Chris@1494
|
54 menu_mapper.push :test_grandchild, { :controller => 'projects', :action => 'show'}, {:parent => :test_child}
|
Chris@1494
|
55
|
Chris@1494
|
56 assert menu_mapper.exists?(:test_grandchild)
|
Chris@1494
|
57 grandchild = menu_mapper.find(:test_grandchild)
|
Chris@1494
|
58 assert_equal :test_grandchild, grandchild.name
|
Chris@1494
|
59 assert_equal :test_child, grandchild.parent.name
|
Chris@1494
|
60 end
|
Chris@1494
|
61
|
Chris@1494
|
62 def test_push_first
|
Chris@1494
|
63 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
|
Chris@1494
|
64 menu_mapper.push :test_second, { :controller => 'projects', :action => 'show'}, {}
|
Chris@1494
|
65 menu_mapper.push :test_third, { :controller => 'projects', :action => 'show'}, {}
|
Chris@1494
|
66 menu_mapper.push :test_fourth, { :controller => 'projects', :action => 'show'}, {}
|
Chris@1494
|
67 menu_mapper.push :test_fifth, { :controller => 'projects', :action => 'show'}, {}
|
Chris@1494
|
68 menu_mapper.push :test_first, { :controller => 'projects', :action => 'show'}, {:first => true}
|
Chris@1494
|
69
|
Chris@1494
|
70 root = menu_mapper.find(:root)
|
Chris@1494
|
71 assert_equal 5, root.children.size
|
Chris@1494
|
72 {0 => :test_first, 1 => :test_second, 2 => :test_third, 3 => :test_fourth, 4 => :test_fifth}.each do |position, name|
|
Chris@1494
|
73 assert_not_nil root.children[position]
|
Chris@1494
|
74 assert_equal name, root.children[position].name
|
Chris@1494
|
75 end
|
Chris@1494
|
76
|
Chris@1494
|
77 end
|
Chris@1494
|
78
|
Chris@1494
|
79 def test_push_before
|
Chris@1494
|
80 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
|
Chris@1494
|
81 menu_mapper.push :test_first, { :controller => 'projects', :action => 'show'}, {}
|
Chris@1494
|
82 menu_mapper.push :test_second, { :controller => 'projects', :action => 'show'}, {}
|
Chris@1494
|
83 menu_mapper.push :test_fourth, { :controller => 'projects', :action => 'show'}, {}
|
Chris@1494
|
84 menu_mapper.push :test_fifth, { :controller => 'projects', :action => 'show'}, {}
|
Chris@1494
|
85 menu_mapper.push :test_third, { :controller => 'projects', :action => 'show'}, {:before => :test_fourth}
|
Chris@1494
|
86
|
Chris@1494
|
87 root = menu_mapper.find(:root)
|
Chris@1494
|
88 assert_equal 5, root.children.size
|
Chris@1494
|
89 {0 => :test_first, 1 => :test_second, 2 => :test_third, 3 => :test_fourth, 4 => :test_fifth}.each do |position, name|
|
Chris@1494
|
90 assert_not_nil root.children[position]
|
Chris@1494
|
91 assert_equal name, root.children[position].name
|
Chris@1494
|
92 end
|
Chris@1494
|
93
|
Chris@1494
|
94 end
|
Chris@1494
|
95
|
Chris@1494
|
96 def test_push_after
|
Chris@1494
|
97 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
|
Chris@1494
|
98 menu_mapper.push :test_first, { :controller => 'projects', :action => 'show'}, {}
|
Chris@1494
|
99 menu_mapper.push :test_second, { :controller => 'projects', :action => 'show'}, {}
|
Chris@1494
|
100 menu_mapper.push :test_third, { :controller => 'projects', :action => 'show'}, {}
|
Chris@1494
|
101 menu_mapper.push :test_fifth, { :controller => 'projects', :action => 'show'}, {}
|
Chris@1494
|
102 menu_mapper.push :test_fourth, { :controller => 'projects', :action => 'show'}, {:after => :test_third}
|
Chris@1494
|
103
|
Chris@1494
|
104 root = menu_mapper.find(:root)
|
Chris@1494
|
105 assert_equal 5, root.children.size
|
Chris@1494
|
106 {0 => :test_first, 1 => :test_second, 2 => :test_third, 3 => :test_fourth, 4 => :test_fifth}.each do |position, name|
|
Chris@1494
|
107 assert_not_nil root.children[position]
|
Chris@1494
|
108 assert_equal name, root.children[position].name
|
Chris@1494
|
109 end
|
Chris@1494
|
110
|
Chris@1494
|
111 end
|
Chris@1494
|
112
|
Chris@1494
|
113 def test_push_last
|
Chris@1494
|
114 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
|
Chris@1494
|
115 menu_mapper.push :test_first, { :controller => 'projects', :action => 'show'}, {}
|
Chris@1494
|
116 menu_mapper.push :test_second, { :controller => 'projects', :action => 'show'}, {}
|
Chris@1494
|
117 menu_mapper.push :test_third, { :controller => 'projects', :action => 'show'}, {}
|
Chris@1494
|
118 menu_mapper.push :test_fifth, { :controller => 'projects', :action => 'show'}, {:last => true}
|
Chris@1494
|
119 menu_mapper.push :test_fourth, { :controller => 'projects', :action => 'show'}, {}
|
Chris@1494
|
120
|
Chris@1494
|
121 root = menu_mapper.find(:root)
|
Chris@1494
|
122 assert_equal 5, root.children.size
|
Chris@1494
|
123 {0 => :test_first, 1 => :test_second, 2 => :test_third, 3 => :test_fourth, 4 => :test_fifth}.each do |position, name|
|
Chris@1494
|
124 assert_not_nil root.children[position]
|
Chris@1494
|
125 assert_equal name, root.children[position].name
|
Chris@1494
|
126 end
|
Chris@1494
|
127
|
Chris@1494
|
128 end
|
Chris@1494
|
129
|
Chris@1494
|
130 def test_exists_for_child_node
|
Chris@1494
|
131 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
|
Chris@1494
|
132 menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
|
Chris@1494
|
133 menu_mapper.push :test_child, { :controller => 'projects', :action => 'show'}, {:parent => :test_overview }
|
Chris@1494
|
134
|
Chris@1494
|
135 assert menu_mapper.exists?(:test_child)
|
Chris@1494
|
136 end
|
Chris@1494
|
137
|
Chris@1494
|
138 def test_exists_for_invalid_node
|
Chris@1494
|
139 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
|
Chris@1494
|
140 menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
|
Chris@1494
|
141
|
Chris@1494
|
142 assert !menu_mapper.exists?(:nothing)
|
Chris@1494
|
143 end
|
Chris@1494
|
144
|
Chris@1494
|
145 def test_find
|
Chris@1494
|
146 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
|
Chris@1494
|
147 menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
|
Chris@1494
|
148
|
Chris@1494
|
149 item = menu_mapper.find(:test_overview)
|
Chris@1494
|
150 assert_equal :test_overview, item.name
|
Chris@1494
|
151 assert_equal({:controller => 'projects', :action => 'show'}, item.url)
|
Chris@1494
|
152 end
|
Chris@1494
|
153
|
Chris@1494
|
154 def test_find_missing
|
Chris@1494
|
155 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
|
Chris@1494
|
156 menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
|
Chris@1494
|
157
|
Chris@1494
|
158 item = menu_mapper.find(:nothing)
|
Chris@1494
|
159 assert_equal nil, item
|
Chris@1494
|
160 end
|
Chris@1494
|
161
|
Chris@1494
|
162 def test_delete
|
Chris@1494
|
163 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
|
Chris@1494
|
164 menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
|
Chris@1494
|
165 assert_not_nil menu_mapper.delete(:test_overview)
|
Chris@1494
|
166
|
Chris@1494
|
167 assert_nil menu_mapper.find(:test_overview)
|
Chris@1494
|
168 end
|
Chris@1494
|
169
|
Chris@1494
|
170 def test_delete_missing
|
Chris@1494
|
171 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
|
Chris@1494
|
172 assert_nil menu_mapper.delete(:test_missing)
|
Chris@1494
|
173 end
|
Chris@1494
|
174
|
Chris@1494
|
175 test 'deleting all items' do
|
Chris@1494
|
176 # Exposed by deleting :last items
|
Chris@1494
|
177 Redmine::MenuManager.map :test_menu do |menu|
|
Chris@1494
|
178 menu.push :not_last, Redmine::Info.help_url
|
Chris@1494
|
179 menu.push :administration, { :controller => 'projects', :action => 'show'}, {:last => true}
|
Chris@1494
|
180 menu.push :help, Redmine::Info.help_url, :last => true
|
Chris@1494
|
181 end
|
Chris@1494
|
182
|
Chris@1494
|
183 assert_nothing_raised do
|
Chris@1494
|
184 Redmine::MenuManager.map :test_menu do |menu|
|
Chris@1494
|
185 menu.delete(:administration)
|
Chris@1494
|
186 menu.delete(:help)
|
Chris@1494
|
187 menu.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
|
Chris@1494
|
188 end
|
Chris@1494
|
189 end
|
Chris@1494
|
190 end
|
Chris@1494
|
191 end
|