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 / .svn / pristine / 23 / 2330bc88f1bd2ce1c1b2bfa4d60a6eb823530bd2.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (7.69 KB)

1
# Redmine - project management software
2
# Copyright (C) 2006-2011  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
    root = menu_mapper.find(:root)
96
    assert_equal 5, root.children.size
97
    {0 => :test_first, 1 => :test_second, 2 => :test_third, 3 => :test_fourth, 4 => :test_fifth}.each do |position, name|
98
      assert_not_nil root.children[position]
99
      assert_equal name, root.children[position].name
100
    end
101

    
102
  end
103

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

    
112
    root = menu_mapper.find(:root)
113
    assert_equal 5, root.children.size
114
    {0 => :test_first, 1 => :test_second, 2 => :test_third, 3 => :test_fourth, 4 => :test_fifth}.each do |position, name|
115
      assert_not_nil root.children[position]
116
      assert_equal name, root.children[position].name
117
    end
118

    
119
  end
120

    
121
  def test_exists_for_child_node
122
    menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
123
    menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
124
    menu_mapper.push :test_child, { :controller => 'projects', :action => 'show'}, {:parent => :test_overview }
125

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

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

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

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

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

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

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

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

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

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

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

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