annotate .svn/pristine/c7/c71c2943a1e92bfbcb19b7e4592c3d8e1f7f80fd.svn-base @ 1464:261b3d9a4903 redmine-2.4

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