annotate .svn/pristine/f7/f756220d88e0b1f85f12b2d05c2b0e7f2c78a4d3.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

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