annotate .svn/pristine/f7/f756220d88e0b1f85f12b2d05c2b0e7f2c78a4d3.svn-base @ 1485:c8d3ad483bea redmine-2.4-integration

Fix stray merge markers
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 15 Jan 2014 13:34:12 +0000
parents 261b3d9a4903
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 context "Mapper#initialize" do
Chris@1464 22 should "be tested"
Chris@1464 23 end
Chris@1464 24
Chris@1464 25 def test_push_onto_root
Chris@1464 26 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
Chris@1464 27 menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
Chris@1464 28
Chris@1464 29 menu_mapper.exists?(:test_overview)
Chris@1464 30 end
Chris@1464 31
Chris@1464 32 def test_push_onto_parent
Chris@1464 33 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
Chris@1464 34 menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
Chris@1464 35 menu_mapper.push :test_child, { :controller => 'projects', :action => 'show'}, {:parent => :test_overview}
Chris@1464 36
Chris@1464 37 assert menu_mapper.exists?(:test_child)
Chris@1464 38 assert_equal :test_child, menu_mapper.find(:test_child).name
Chris@1464 39 end
Chris@1464 40
Chris@1464 41 def test_push_onto_grandparent
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 menu_mapper.push :test_grandchild, { :controller => 'projects', :action => 'show'}, {:parent => :test_child}
Chris@1464 46
Chris@1464 47 assert menu_mapper.exists?(:test_grandchild)
Chris@1464 48 grandchild = menu_mapper.find(:test_grandchild)
Chris@1464 49 assert_equal :test_grandchild, grandchild.name
Chris@1464 50 assert_equal :test_child, grandchild.parent.name
Chris@1464 51 end
Chris@1464 52
Chris@1464 53 def test_push_first
Chris@1464 54 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
Chris@1464 55 menu_mapper.push :test_second, { :controller => 'projects', :action => 'show'}, {}
Chris@1464 56 menu_mapper.push :test_third, { :controller => 'projects', :action => 'show'}, {}
Chris@1464 57 menu_mapper.push :test_fourth, { :controller => 'projects', :action => 'show'}, {}
Chris@1464 58 menu_mapper.push :test_fifth, { :controller => 'projects', :action => 'show'}, {}
Chris@1464 59 menu_mapper.push :test_first, { :controller => 'projects', :action => 'show'}, {:first => true}
Chris@1464 60
Chris@1464 61 root = menu_mapper.find(:root)
Chris@1464 62 assert_equal 5, root.children.size
Chris@1464 63 {0 => :test_first, 1 => :test_second, 2 => :test_third, 3 => :test_fourth, 4 => :test_fifth}.each do |position, name|
Chris@1464 64 assert_not_nil root.children[position]
Chris@1464 65 assert_equal name, root.children[position].name
Chris@1464 66 end
Chris@1464 67
Chris@1464 68 end
Chris@1464 69
Chris@1464 70 def test_push_before
Chris@1464 71 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
Chris@1464 72 menu_mapper.push :test_first, { :controller => 'projects', :action => 'show'}, {}
Chris@1464 73 menu_mapper.push :test_second, { :controller => 'projects', :action => 'show'}, {}
Chris@1464 74 menu_mapper.push :test_fourth, { :controller => 'projects', :action => 'show'}, {}
Chris@1464 75 menu_mapper.push :test_fifth, { :controller => 'projects', :action => 'show'}, {}
Chris@1464 76 menu_mapper.push :test_third, { :controller => 'projects', :action => 'show'}, {:before => :test_fourth}
Chris@1464 77
Chris@1464 78 root = menu_mapper.find(:root)
Chris@1464 79 assert_equal 5, root.children.size
Chris@1464 80 {0 => :test_first, 1 => :test_second, 2 => :test_third, 3 => :test_fourth, 4 => :test_fifth}.each do |position, name|
Chris@1464 81 assert_not_nil root.children[position]
Chris@1464 82 assert_equal name, root.children[position].name
Chris@1464 83 end
Chris@1464 84
Chris@1464 85 end
Chris@1464 86
Chris@1464 87 def test_push_after
Chris@1464 88 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
Chris@1464 89 menu_mapper.push :test_first, { :controller => 'projects', :action => 'show'}, {}
Chris@1464 90 menu_mapper.push :test_second, { :controller => 'projects', :action => 'show'}, {}
Chris@1464 91 menu_mapper.push :test_third, { :controller => 'projects', :action => 'show'}, {}
Chris@1464 92 menu_mapper.push :test_fifth, { :controller => 'projects', :action => 'show'}, {}
Chris@1464 93 menu_mapper.push :test_fourth, { :controller => 'projects', :action => 'show'}, {:after => :test_third}
Chris@1464 94
Chris@1464 95 root = menu_mapper.find(:root)
Chris@1464 96 assert_equal 5, root.children.size
Chris@1464 97 {0 => :test_first, 1 => :test_second, 2 => :test_third, 3 => :test_fourth, 4 => :test_fifth}.each do |position, name|
Chris@1464 98 assert_not_nil root.children[position]
Chris@1464 99 assert_equal name, root.children[position].name
Chris@1464 100 end
Chris@1464 101
Chris@1464 102 end
Chris@1464 103
Chris@1464 104 def test_push_last
Chris@1464 105 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
Chris@1464 106 menu_mapper.push :test_first, { :controller => 'projects', :action => 'show'}, {}
Chris@1464 107 menu_mapper.push :test_second, { :controller => 'projects', :action => 'show'}, {}
Chris@1464 108 menu_mapper.push :test_third, { :controller => 'projects', :action => 'show'}, {}
Chris@1464 109 menu_mapper.push :test_fifth, { :controller => 'projects', :action => 'show'}, {:last => true}
Chris@1464 110 menu_mapper.push :test_fourth, { :controller => 'projects', :action => 'show'}, {}
Chris@1464 111
Chris@1464 112 root = menu_mapper.find(:root)
Chris@1464 113 assert_equal 5, root.children.size
Chris@1464 114 {0 => :test_first, 1 => :test_second, 2 => :test_third, 3 => :test_fourth, 4 => :test_fifth}.each do |position, name|
Chris@1464 115 assert_not_nil root.children[position]
Chris@1464 116 assert_equal name, root.children[position].name
Chris@1464 117 end
Chris@1464 118
Chris@1464 119 end
Chris@1464 120
Chris@1464 121 def test_exists_for_child_node
Chris@1464 122 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
Chris@1464 123 menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
Chris@1464 124 menu_mapper.push :test_child, { :controller => 'projects', :action => 'show'}, {:parent => :test_overview }
Chris@1464 125
Chris@1464 126 assert menu_mapper.exists?(:test_child)
Chris@1464 127 end
Chris@1464 128
Chris@1464 129 def test_exists_for_invalid_node
Chris@1464 130 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
Chris@1464 131 menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
Chris@1464 132
Chris@1464 133 assert !menu_mapper.exists?(:nothing)
Chris@1464 134 end
Chris@1464 135
Chris@1464 136 def test_find
Chris@1464 137 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
Chris@1464 138 menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
Chris@1464 139
Chris@1464 140 item = menu_mapper.find(:test_overview)
Chris@1464 141 assert_equal :test_overview, item.name
Chris@1464 142 assert_equal({:controller => 'projects', :action => 'show'}, item.url)
Chris@1464 143 end
Chris@1464 144
Chris@1464 145 def test_find_missing
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(:nothing)
Chris@1464 150 assert_equal nil, item
Chris@1464 151 end
Chris@1464 152
Chris@1464 153 def test_delete
Chris@1464 154 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
Chris@1464 155 menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
Chris@1464 156 assert_not_nil menu_mapper.delete(:test_overview)
Chris@1464 157
Chris@1464 158 assert_nil menu_mapper.find(:test_overview)
Chris@1464 159 end
Chris@1464 160
Chris@1464 161 def test_delete_missing
Chris@1464 162 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
Chris@1464 163 assert_nil menu_mapper.delete(:test_missing)
Chris@1464 164 end
Chris@1464 165
Chris@1464 166 test 'deleting all items' do
Chris@1464 167 # Exposed by deleting :last items
Chris@1464 168 Redmine::MenuManager.map :test_menu do |menu|
Chris@1464 169 menu.push :not_last, Redmine::Info.help_url
Chris@1464 170 menu.push :administration, { :controller => 'projects', :action => 'show'}, {:last => true}
Chris@1464 171 menu.push :help, Redmine::Info.help_url, :last => true
Chris@1464 172 end
Chris@1464 173
Chris@1464 174 assert_nothing_raised do
Chris@1464 175 Redmine::MenuManager.map :test_menu do |menu|
Chris@1464 176 menu.delete(:administration)
Chris@1464 177 menu.delete(:help)
Chris@1464 178 menu.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
Chris@1464 179 end
Chris@1464 180 end
Chris@1464 181 end
Chris@1464 182 end