annotate test/unit/lib/redmine/menu_manager/mapper_test.rb @ 36:de76cd3e8c8e cc-branches

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