Chris@0
|
1 # Redmine - project management software
|
Chris@909
|
2 # Copyright (C) 2006-2011 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@909
|
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@909
|
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@119
|
18 require File.expand_path('../../../../test_helper', __FILE__)
|
Chris@0
|
19
|
Chris@0
|
20 class Redmine::PluginTest < ActiveSupport::TestCase
|
Chris@0
|
21
|
Chris@0
|
22 def setup
|
Chris@0
|
23 @klass = Redmine::Plugin
|
Chris@0
|
24 # In case some real plugins are installed
|
Chris@0
|
25 @klass.clear
|
Chris@0
|
26 end
|
Chris@909
|
27
|
Chris@0
|
28 def teardown
|
Chris@0
|
29 @klass.clear
|
Chris@0
|
30 end
|
Chris@909
|
31
|
Chris@0
|
32 def test_register
|
Chris@0
|
33 @klass.register :foo do
|
Chris@0
|
34 name 'Foo plugin'
|
Chris@0
|
35 url 'http://example.net/plugins/foo'
|
Chris@0
|
36 author 'John Smith'
|
Chris@0
|
37 author_url 'http://example.net/jsmith'
|
Chris@0
|
38 description 'This is a test plugin'
|
Chris@0
|
39 version '0.0.1'
|
Chris@0
|
40 settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings'
|
Chris@0
|
41 end
|
Chris@909
|
42
|
Chris@0
|
43 assert_equal 1, @klass.all.size
|
Chris@909
|
44
|
Chris@0
|
45 plugin = @klass.find('foo')
|
Chris@0
|
46 assert plugin.is_a?(Redmine::Plugin)
|
Chris@0
|
47 assert_equal :foo, plugin.id
|
Chris@0
|
48 assert_equal 'Foo plugin', plugin.name
|
Chris@0
|
49 assert_equal 'http://example.net/plugins/foo', plugin.url
|
Chris@0
|
50 assert_equal 'John Smith', plugin.author
|
Chris@0
|
51 assert_equal 'http://example.net/jsmith', plugin.author_url
|
Chris@0
|
52 assert_equal 'This is a test plugin', plugin.description
|
Chris@0
|
53 assert_equal '0.0.1', plugin.version
|
Chris@0
|
54 end
|
Chris@909
|
55
|
Chris@0
|
56 def test_requires_redmine
|
Chris@0
|
57 test = self
|
Chris@0
|
58 version = Redmine::VERSION.to_a.slice(0,3).join('.')
|
Chris@909
|
59
|
Chris@0
|
60 @klass.register :foo do
|
Chris@0
|
61 test.assert requires_redmine(:version_or_higher => '0.1.0')
|
Chris@0
|
62 test.assert requires_redmine(:version_or_higher => version)
|
Chris@0
|
63 test.assert requires_redmine(version)
|
Chris@0
|
64 test.assert_raise Redmine::PluginRequirementError do
|
Chris@0
|
65 requires_redmine(:version_or_higher => '99.0.0')
|
Chris@0
|
66 end
|
Chris@909
|
67
|
Chris@0
|
68 test.assert requires_redmine(:version => version)
|
Chris@0
|
69 test.assert requires_redmine(:version => [version, '99.0.0'])
|
Chris@0
|
70 test.assert_raise Redmine::PluginRequirementError do
|
Chris@0
|
71 requires_redmine(:version => '99.0.0')
|
Chris@0
|
72 end
|
Chris@0
|
73 test.assert_raise Redmine::PluginRequirementError do
|
Chris@0
|
74 requires_redmine(:version => ['98.0.0', '99.0.0'])
|
Chris@0
|
75 end
|
Chris@0
|
76 end
|
Chris@0
|
77 end
|
Chris@0
|
78
|
Chris@0
|
79 def test_requires_redmine_plugin
|
Chris@0
|
80 test = self
|
Chris@0
|
81 other_version = '0.5.0'
|
Chris@909
|
82
|
Chris@0
|
83 @klass.register :other do
|
Chris@0
|
84 name 'Other'
|
Chris@0
|
85 version other_version
|
Chris@0
|
86 end
|
Chris@909
|
87
|
Chris@0
|
88 @klass.register :foo do
|
Chris@0
|
89 test.assert requires_redmine_plugin(:other, :version_or_higher => '0.1.0')
|
Chris@0
|
90 test.assert requires_redmine_plugin(:other, :version_or_higher => other_version)
|
Chris@0
|
91 test.assert requires_redmine_plugin(:other, other_version)
|
Chris@0
|
92 test.assert_raise Redmine::PluginRequirementError do
|
Chris@0
|
93 requires_redmine_plugin(:other, :version_or_higher => '99.0.0')
|
Chris@0
|
94 end
|
Chris@909
|
95
|
Chris@0
|
96 test.assert requires_redmine_plugin(:other, :version => other_version)
|
Chris@0
|
97 test.assert requires_redmine_plugin(:other, :version => [other_version, '99.0.0'])
|
Chris@0
|
98 test.assert_raise Redmine::PluginRequirementError do
|
Chris@0
|
99 requires_redmine_plugin(:other, :version => '99.0.0')
|
Chris@0
|
100 end
|
Chris@0
|
101 test.assert_raise Redmine::PluginRequirementError do
|
Chris@0
|
102 requires_redmine_plugin(:other, :version => ['98.0.0', '99.0.0'])
|
Chris@0
|
103 end
|
Chris@0
|
104 # Missing plugin
|
Chris@0
|
105 test.assert_raise Redmine::PluginNotFound do
|
Chris@0
|
106 requires_redmine_plugin(:missing, :version_or_higher => '0.1.0')
|
Chris@0
|
107 end
|
Chris@0
|
108 test.assert_raise Redmine::PluginNotFound do
|
Chris@0
|
109 requires_redmine_plugin(:missing, '0.1.0')
|
Chris@0
|
110 end
|
Chris@0
|
111 test.assert_raise Redmine::PluginNotFound do
|
Chris@0
|
112 requires_redmine_plugin(:missing, :version => '0.1.0')
|
Chris@0
|
113 end
|
Chris@909
|
114
|
Chris@0
|
115 end
|
Chris@0
|
116 end
|
Chris@0
|
117 end
|