OSDN Git Service

Move database.yml to template
[redminele/redminele.git] / redmine / test / unit / lib / redmine / plugin_test.rb
1 # Redmine - project management software
2 # Copyright (C) 2006-2008  Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17
18 require File.dirname(__FILE__) + '/../../../test_helper'
19
20 class Redmine::PluginTest < ActiveSupport::TestCase
21
22   def setup
23     @klass = Redmine::Plugin
24     # In case some real plugins are installed
25     @klass.clear
26   end
27   
28   def teardown
29     @klass.clear
30   end
31   
32   def test_register
33     @klass.register :foo do
34       name 'Foo plugin'
35       url 'http://example.net/plugins/foo'
36       author 'John Smith'
37       author_url 'http://example.net/jsmith'
38       description 'This is a test plugin'
39       version '0.0.1'
40       settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings'
41     end
42     
43     assert_equal 1, @klass.all.size
44     
45     plugin = @klass.find('foo')
46     assert plugin.is_a?(Redmine::Plugin)
47     assert_equal :foo, plugin.id
48     assert_equal 'Foo plugin', plugin.name
49     assert_equal 'http://example.net/plugins/foo', plugin.url
50     assert_equal 'John Smith', plugin.author
51     assert_equal 'http://example.net/jsmith', plugin.author_url
52     assert_equal 'This is a test plugin', plugin.description
53     assert_equal '0.0.1', plugin.version
54   end
55   
56   def test_requires_redmine
57     test = self
58     version = Redmine::VERSION.to_a.slice(0,3).join('.')
59     
60     @klass.register :foo do
61       test.assert requires_redmine(:version_or_higher => '0.1.0')
62       test.assert requires_redmine(:version_or_higher => version)
63       test.assert requires_redmine(version)
64       test.assert_raise Redmine::PluginRequirementError do
65         requires_redmine(:version_or_higher => '99.0.0')
66       end
67       
68       test.assert requires_redmine(:version => version)
69       test.assert requires_redmine(:version => [version, '99.0.0'])
70       test.assert_raise Redmine::PluginRequirementError do
71         requires_redmine(:version => '99.0.0')
72       end
73       test.assert_raise Redmine::PluginRequirementError do
74         requires_redmine(:version => ['98.0.0', '99.0.0'])
75       end
76     end
77   end
78
79   def test_requires_redmine_plugin
80     test = self
81     other_version = '0.5.0'
82     
83     @klass.register :other do
84       name 'Other'
85       version other_version
86     end
87     
88     @klass.register :foo do
89       test.assert requires_redmine_plugin(:other, :version_or_higher => '0.1.0')
90       test.assert requires_redmine_plugin(:other, :version_or_higher => other_version)
91       test.assert requires_redmine_plugin(:other, other_version)
92       test.assert_raise Redmine::PluginRequirementError do
93         requires_redmine_plugin(:other, :version_or_higher => '99.0.0')
94       end
95       
96       test.assert requires_redmine_plugin(:other, :version => other_version)
97       test.assert requires_redmine_plugin(:other, :version => [other_version, '99.0.0'])
98       test.assert_raise Redmine::PluginRequirementError do
99         requires_redmine_plugin(:other, :version => '99.0.0')
100       end
101       test.assert_raise Redmine::PluginRequirementError do
102         requires_redmine_plugin(:other, :version => ['98.0.0', '99.0.0'])
103       end
104       # Missing plugin
105       test.assert_raise Redmine::PluginNotFound do
106         requires_redmine_plugin(:missing, :version_or_higher => '0.1.0')
107       end
108       test.assert_raise Redmine::PluginNotFound do
109         requires_redmine_plugin(:missing, '0.1.0')
110       end
111       test.assert_raise Redmine::PluginNotFound do
112         requires_redmine_plugin(:missing, :version => '0.1.0')
113       end
114       
115     end
116   end
117 end