To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / test / unit / lib / redmine / menu_manager / mapper_test.rb @ 441:cbce1fd3b1b7

History | View | Annotate | Download (7.71 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
class Redmine::MenuManager::MapperTest < ActiveSupport::TestCase
21
  context "Mapper#initialize" do
22
    should "be tested"
23
  end
24

    
25
  def test_push_onto_root
26
    menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
27
    menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
28

    
29
    menu_mapper.exists?(:test_overview)
30
  end
31

    
32
  def test_push_onto_parent
33
    menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
34
    menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
35
    menu_mapper.push :test_child, { :controller => 'projects', :action => 'show'}, {:parent => :test_overview}
36

    
37
    assert menu_mapper.exists?(:test_child)
38
    assert_equal :test_child, menu_mapper.find(:test_child).name
39
  end
40

    
41
  def test_push_onto_grandparent
42
    menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
43
    menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
44
    menu_mapper.push :test_child, { :controller => 'projects', :action => 'show'}, {:parent => :test_overview}
45
    menu_mapper.push :test_grandchild, { :controller => 'projects', :action => 'show'}, {:parent => :test_child}
46

    
47
    assert menu_mapper.exists?(:test_grandchild)
48
    grandchild = menu_mapper.find(:test_grandchild)
49
    assert_equal :test_grandchild, grandchild.name
50
    assert_equal :test_child, grandchild.parent.name
51
  end
52

    
53
  def test_push_first
54
    menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
55
    menu_mapper.push :test_second, { :controller => 'projects', :action => 'show'}, {}
56
    menu_mapper.push :test_third, { :controller => 'projects', :action => 'show'}, {}
57
    menu_mapper.push :test_fourth, { :controller => 'projects', :action => 'show'}, {}
58
    menu_mapper.push :test_fifth, { :controller => 'projects', :action => 'show'}, {}
59
    menu_mapper.push :test_first, { :controller => 'projects', :action => 'show'}, {:first => true}
60

    
61
    root = menu_mapper.find(:root)
62
    assert_equal 5, root.children.size
63
    {0 => :test_first, 1 => :test_second, 2 => :test_third, 3 => :test_fourth, 4 => :test_fifth}.each do |position, name|
64
      assert_not_nil root.children[position]
65
      assert_equal name, root.children[position].name
66
    end
67
  
68
  end
69
  
70
  def test_push_before
71
    menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
72
    menu_mapper.push :test_first, { :controller => 'projects', :action => 'show'}, {}
73
    menu_mapper.push :test_second, { :controller => 'projects', :action => 'show'}, {}
74
    menu_mapper.push :test_fourth, { :controller => 'projects', :action => 'show'}, {}
75
    menu_mapper.push :test_fifth, { :controller => 'projects', :action => 'show'}, {}
76
    menu_mapper.push :test_third, { :controller => 'projects', :action => 'show'}, {:before => :test_fourth}
77

    
78
    root = menu_mapper.find(:root)
79
    assert_equal 5, root.children.size
80
    {0 => :test_first, 1 => :test_second, 2 => :test_third, 3 => :test_fourth, 4 => :test_fifth}.each do |position, name|
81
      assert_not_nil root.children[position]
82
      assert_equal name, root.children[position].name
83
    end
84
  
85
  end
86

    
87
  def test_push_after
88
    menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
89
    menu_mapper.push :test_first, { :controller => 'projects', :action => 'show'}, {}
90
    menu_mapper.push :test_second, { :controller => 'projects', :action => 'show'}, {}
91
    menu_mapper.push :test_third, { :controller => 'projects', :action => 'show'}, {}
92
    menu_mapper.push :test_fifth, { :controller => 'projects', :action => 'show'}, {}
93
    menu_mapper.push :test_fourth, { :controller => 'projects', :action => 'show'}, {:after => :test_third}
94

    
95
    
96
    root = menu_mapper.find(:root)
97
    assert_equal 5, root.children.size
98
    {0 => :test_first, 1 => :test_second, 2 => :test_third, 3 => :test_fourth, 4 => :test_fifth}.each do |position, name|
99
      assert_not_nil root.children[position]
100
      assert_equal name, root.children[position].name
101
    end
102
  
103
  end
104

    
105
  def test_push_last
106
    menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
107
    menu_mapper.push :test_first, { :controller => 'projects', :action => 'show'}, {}
108
    menu_mapper.push :test_second, { :controller => 'projects', :action => 'show'}, {}
109
    menu_mapper.push :test_third, { :controller => 'projects', :action => 'show'}, {}
110
    menu_mapper.push :test_fifth, { :controller => 'projects', :action => 'show'}, {:last => true}
111
    menu_mapper.push :test_fourth, { :controller => 'projects', :action => 'show'}, {}
112

    
113
    root = menu_mapper.find(:root)
114
    assert_equal 5, root.children.size
115
    {0 => :test_first, 1 => :test_second, 2 => :test_third, 3 => :test_fourth, 4 => :test_fifth}.each do |position, name|
116
      assert_not_nil root.children[position]
117
      assert_equal name, root.children[position].name
118
    end
119
  
120
  end
121
  
122
  def test_exists_for_child_node
123
    menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
124
    menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
125
    menu_mapper.push :test_child, { :controller => 'projects', :action => 'show'}, {:parent => :test_overview }
126

    
127
    assert menu_mapper.exists?(:test_child)
128
  end
129

    
130
  def test_exists_for_invalid_node
131
    menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
132
    menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
133

    
134
    assert !menu_mapper.exists?(:nothing)
135
  end
136

    
137
  def test_find
138
    menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
139
    menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
140

    
141
    item = menu_mapper.find(:test_overview)
142
    assert_equal :test_overview, item.name
143
    assert_equal({:controller => 'projects', :action => 'show'}, item.url)
144
  end
145

    
146
  def test_find_missing
147
    menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
148
    menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
149

    
150
    item = menu_mapper.find(:nothing)
151
    assert_equal nil, item
152
  end
153

    
154
  def test_delete
155
    menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
156
    menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
157
    assert_not_nil menu_mapper.delete(:test_overview)
158

    
159
    assert_nil menu_mapper.find(:test_overview)
160
  end
161

    
162
  def test_delete_missing
163
    menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
164
    assert_nil menu_mapper.delete(:test_missing)
165
  end
166

    
167
  test 'deleting all items' do
168
    # Exposed by deleting :last items
169
    Redmine::MenuManager.map :test_menu do |menu|
170
      menu.push :not_last, Redmine::Info.help_url
171
      menu.push :administration, { :controller => 'projects', :action => 'show'}, {:last => true}
172
      menu.push :help, Redmine::Info.help_url, :last => true
173
    end
174

    
175
    assert_nothing_raised do
176
      Redmine::MenuManager.map :test_menu do |menu|
177
        menu.delete(:administration)
178
        menu.delete(:help)
179
        menu.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
180
     end
181
    end
182
  end
183
end