@@ -1,188 +1,176 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class Redmine::PluginTest < ActiveSupport::TestCase |
|
21 | ||
|
22 | 21 | def setup |
|
23 | 22 | @klass = Redmine::Plugin |
|
24 | 23 | # In case some real plugins are installed |
|
25 | 24 | @klass.clear |
|
26 | 25 | end |
|
27 | 26 | |
|
28 | 27 | def teardown |
|
29 | 28 | @klass.clear |
|
30 | 29 | end |
|
31 | 30 | |
|
32 | 31 | def test_register |
|
33 | 32 | @klass.register :foo do |
|
34 | 33 | name 'Foo plugin' |
|
35 | 34 | url 'http://example.net/plugins/foo' |
|
36 | 35 | author 'John Smith' |
|
37 | 36 | author_url 'http://example.net/jsmith' |
|
38 | 37 | description 'This is a test plugin' |
|
39 | 38 | version '0.0.1' |
|
40 | 39 | settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings' |
|
41 | 40 | end |
|
42 | 41 | |
|
43 | 42 | assert_equal 1, @klass.all.size |
|
44 | 43 | |
|
45 | 44 | plugin = @klass.find('foo') |
|
46 | 45 | assert plugin.is_a?(Redmine::Plugin) |
|
47 | 46 | assert_equal :foo, plugin.id |
|
48 | 47 | assert_equal 'Foo plugin', plugin.name |
|
49 | 48 | assert_equal 'http://example.net/plugins/foo', plugin.url |
|
50 | 49 | assert_equal 'John Smith', plugin.author |
|
51 | 50 | assert_equal 'http://example.net/jsmith', plugin.author_url |
|
52 | 51 | assert_equal 'This is a test plugin', plugin.description |
|
53 | 52 | assert_equal '0.0.1', plugin.version |
|
54 | 53 | end |
|
55 | 54 | |
|
56 | 55 | def test_installed |
|
57 | 56 | @klass.register(:foo) {} |
|
58 | ||
|
59 | 57 | assert_equal true, @klass.installed?(:foo) |
|
60 | 58 | assert_equal false, @klass.installed?(:bar) |
|
61 | 59 | end |
|
62 | 60 | |
|
63 | 61 | def test_menu |
|
64 | 62 | assert_difference 'Redmine::MenuManager.items(:project_menu).size' do |
|
65 | 63 | @klass.register :foo do |
|
66 | 64 | menu :project_menu, :foo_menu_item, '/foo', :caption => 'Foo' |
|
67 | 65 | end |
|
68 | 66 | end |
|
69 | 67 | menu_item = Redmine::MenuManager.items(:project_menu).detect {|i| i.name == :foo_menu_item} |
|
70 | 68 | assert_not_nil menu_item |
|
71 | 69 | assert_equal 'Foo', menu_item.caption |
|
72 | 70 | assert_equal '/foo', menu_item.url |
|
73 | 71 | end |
|
74 | 72 | |
|
75 | 73 | def test_delete_menu_item |
|
76 | 74 | Redmine::MenuManager.map(:project_menu).push(:foo_menu_item, '/foo', :caption => 'Foo') |
|
77 | ||
|
78 | 75 | assert_difference 'Redmine::MenuManager.items(:project_menu).size', -1 do |
|
79 | 76 | @klass.register :foo do |
|
80 | 77 | delete_menu_item :project_menu, :foo_menu_item |
|
81 | 78 | end |
|
82 | 79 | end |
|
83 | 80 | assert_nil Redmine::MenuManager.items(:project_menu).detect {|i| i.name == :foo_menu_item} |
|
84 | 81 | end |
|
85 | 82 | |
|
86 | 83 | def test_directory_with_override |
|
87 | 84 | @klass.register(:foo) do |
|
88 | 85 | directory '/path/to/foo' |
|
89 | 86 | end |
|
90 | 87 | assert_equal '/path/to/foo', @klass.find('foo').directory |
|
91 | 88 | end |
|
92 | 89 | |
|
93 | 90 | def test_directory_without_override |
|
94 | 91 | @klass.register(:foo) {} |
|
95 | 92 | assert_equal File.join(@klass.directory, 'foo'), @klass.find('foo').directory |
|
96 | 93 | end |
|
97 | 94 | |
|
98 | 95 | def test_requires_redmine |
|
99 | 96 | plugin = Redmine::Plugin.register(:foo) {} |
|
100 | 97 | Redmine::VERSION.stubs(:to_a).returns([2, 1, 3, "stable", 10817]) |
|
101 | ||
|
102 | 98 | # Specific version without hash |
|
103 | 99 | assert plugin.requires_redmine('2.1.3') |
|
104 | 100 | assert plugin.requires_redmine('2.1') |
|
105 | 101 | assert_raise Redmine::PluginRequirementError do |
|
106 | 102 | plugin.requires_redmine('2.1.4') |
|
107 | 103 | end |
|
108 | 104 | assert_raise Redmine::PluginRequirementError do |
|
109 | 105 | plugin.requires_redmine('2.2') |
|
110 | 106 | end |
|
111 | ||
|
112 | 107 | # Specific version |
|
113 | 108 | assert plugin.requires_redmine(:version => '2.1.3') |
|
114 | 109 | assert plugin.requires_redmine(:version => ['2.1.3', '2.2.0']) |
|
115 | 110 | assert plugin.requires_redmine(:version => '2.1') |
|
116 | 111 | assert_raise Redmine::PluginRequirementError do |
|
117 | 112 | plugin.requires_redmine(:version => '2.2.0') |
|
118 | 113 | end |
|
119 | 114 | assert_raise Redmine::PluginRequirementError do |
|
120 | 115 | plugin.requires_redmine(:version => ['2.1.4', '2.2.0']) |
|
121 | 116 | end |
|
122 | 117 | assert_raise Redmine::PluginRequirementError do |
|
123 | 118 | plugin.requires_redmine(:version => '2.2') |
|
124 | 119 | end |
|
125 | ||
|
126 | 120 | # Version range |
|
127 | 121 | assert plugin.requires_redmine(:version => '2.0.0'..'2.2.4') |
|
128 | 122 | assert plugin.requires_redmine(:version => '2.1.3'..'2.2.4') |
|
129 | 123 | assert plugin.requires_redmine(:version => '2.0.0'..'2.1.3') |
|
130 | 124 | assert plugin.requires_redmine(:version => '2.0'..'2.2') |
|
131 | 125 | assert plugin.requires_redmine(:version => '2.1'..'2.2') |
|
132 | 126 | assert plugin.requires_redmine(:version => '2.0'..'2.1') |
|
133 | 127 | assert_raise Redmine::PluginRequirementError do |
|
134 | 128 | plugin.requires_redmine(:version => '2.1.4'..'2.2.4') |
|
135 | 129 | end |
|
136 | ||
|
137 | ||
|
138 | 130 | # Version or higher |
|
139 | 131 | assert plugin.requires_redmine(:version_or_higher => '0.1.0') |
|
140 | 132 | assert plugin.requires_redmine(:version_or_higher => '2.1.3') |
|
141 | 133 | assert plugin.requires_redmine(:version_or_higher => '2.1') |
|
142 | 134 | assert_raise Redmine::PluginRequirementError do |
|
143 | 135 | plugin.requires_redmine(:version_or_higher => '2.2.0') |
|
144 | 136 | end |
|
145 | 137 | assert_raise Redmine::PluginRequirementError do |
|
146 | 138 | plugin.requires_redmine(:version_or_higher => '2.2') |
|
147 | 139 | end |
|
148 | 140 | end |
|
149 | 141 | |
|
150 | 142 | def test_requires_redmine_plugin |
|
151 | 143 | test = self |
|
152 | 144 | other_version = '0.5.0' |
|
153 | ||
|
154 | 145 | @klass.register :other do |
|
155 | 146 | name 'Other' |
|
156 | 147 | version other_version |
|
157 | 148 | end |
|
158 | ||
|
159 | 149 | @klass.register :foo do |
|
160 | 150 | test.assert requires_redmine_plugin(:other, :version_or_higher => '0.1.0') |
|
161 | 151 | test.assert requires_redmine_plugin(:other, :version_or_higher => other_version) |
|
162 | 152 | test.assert requires_redmine_plugin(:other, other_version) |
|
163 | 153 | test.assert_raise Redmine::PluginRequirementError do |
|
164 | 154 | requires_redmine_plugin(:other, :version_or_higher => '99.0.0') |
|
165 | 155 | end |
|
166 | ||
|
167 | 156 | test.assert requires_redmine_plugin(:other, :version => other_version) |
|
168 | 157 | test.assert requires_redmine_plugin(:other, :version => [other_version, '99.0.0']) |
|
169 | 158 | test.assert_raise Redmine::PluginRequirementError do |
|
170 | 159 | requires_redmine_plugin(:other, :version => '99.0.0') |
|
171 | 160 | end |
|
172 | 161 | test.assert_raise Redmine::PluginRequirementError do |
|
173 | 162 | requires_redmine_plugin(:other, :version => ['98.0.0', '99.0.0']) |
|
174 | 163 | end |
|
175 | 164 | # Missing plugin |
|
176 | 165 | test.assert_raise Redmine::PluginNotFound do |
|
177 | 166 | requires_redmine_plugin(:missing, :version_or_higher => '0.1.0') |
|
178 | 167 | end |
|
179 | 168 | test.assert_raise Redmine::PluginNotFound do |
|
180 | 169 | requires_redmine_plugin(:missing, '0.1.0') |
|
181 | 170 | end |
|
182 | 171 | test.assert_raise Redmine::PluginNotFound do |
|
183 | 172 | requires_redmine_plugin(:missing, :version => '0.1.0') |
|
184 | 173 | end |
|
185 | ||
|
186 | 174 | end |
|
187 | 175 | end |
|
188 | 176 | end |
General Comments 0
You need to be logged in to leave comments.
Login now