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