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