annotate .svn/pristine/23/2330bc88f1bd2ce1c1b2bfa4d60a6eb823530bd2.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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