Chris@909: # Redmine - project management software Chris@909: # Copyright (C) 2006-2011 Jean-Philippe Lang Chris@909: # Chris@909: # This program is free software; you can redistribute it and/or Chris@909: # modify it under the terms of the GNU General Public License Chris@909: # as published by the Free Software Foundation; either version 2 Chris@909: # of the License, or (at your option) any later version. Chris@909: # Chris@909: # This program is distributed in the hope that it will be useful, Chris@909: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@909: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@909: # GNU General Public License for more details. Chris@909: # Chris@909: # You should have received a copy of the GNU General Public License Chris@909: # along with this program; if not, write to the Free Software Chris@909: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@909: Chris@909: require File.expand_path('../../../../test_helper', __FILE__) Chris@909: Chris@909: class Redmine::PluginTest < ActiveSupport::TestCase Chris@909: Chris@909: def setup Chris@909: @klass = Redmine::Plugin Chris@909: # In case some real plugins are installed Chris@909: @klass.clear Chris@909: end Chris@909: Chris@909: def teardown Chris@909: @klass.clear Chris@909: end Chris@909: Chris@909: def test_register Chris@909: @klass.register :foo do Chris@909: name 'Foo plugin' Chris@909: url 'http://example.net/plugins/foo' Chris@909: author 'John Smith' Chris@909: author_url 'http://example.net/jsmith' Chris@909: description 'This is a test plugin' Chris@909: version '0.0.1' Chris@909: settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings' Chris@909: end Chris@909: Chris@909: assert_equal 1, @klass.all.size Chris@909: Chris@909: plugin = @klass.find('foo') Chris@909: assert plugin.is_a?(Redmine::Plugin) Chris@909: assert_equal :foo, plugin.id Chris@909: assert_equal 'Foo plugin', plugin.name Chris@909: assert_equal 'http://example.net/plugins/foo', plugin.url Chris@909: assert_equal 'John Smith', plugin.author Chris@909: assert_equal 'http://example.net/jsmith', plugin.author_url Chris@909: assert_equal 'This is a test plugin', plugin.description Chris@909: assert_equal '0.0.1', plugin.version Chris@909: end Chris@909: Chris@909: def test_requires_redmine Chris@909: test = self Chris@909: version = Redmine::VERSION.to_a.slice(0,3).join('.') Chris@909: Chris@909: @klass.register :foo do Chris@909: test.assert requires_redmine(:version_or_higher => '0.1.0') Chris@909: test.assert requires_redmine(:version_or_higher => version) Chris@909: test.assert requires_redmine(version) Chris@909: test.assert_raise Redmine::PluginRequirementError do Chris@909: requires_redmine(:version_or_higher => '99.0.0') Chris@909: end Chris@909: Chris@909: test.assert requires_redmine(:version => version) Chris@909: test.assert requires_redmine(:version => [version, '99.0.0']) Chris@909: test.assert_raise Redmine::PluginRequirementError do Chris@909: requires_redmine(:version => '99.0.0') Chris@909: end Chris@909: test.assert_raise Redmine::PluginRequirementError do Chris@909: requires_redmine(:version => ['98.0.0', '99.0.0']) Chris@909: end Chris@909: end Chris@909: end Chris@909: Chris@909: def test_requires_redmine_plugin Chris@909: test = self Chris@909: other_version = '0.5.0' Chris@909: Chris@909: @klass.register :other do Chris@909: name 'Other' Chris@909: version other_version Chris@909: end Chris@909: Chris@909: @klass.register :foo do Chris@909: test.assert requires_redmine_plugin(:other, :version_or_higher => '0.1.0') Chris@909: test.assert requires_redmine_plugin(:other, :version_or_higher => other_version) Chris@909: test.assert requires_redmine_plugin(:other, other_version) Chris@909: test.assert_raise Redmine::PluginRequirementError do Chris@909: requires_redmine_plugin(:other, :version_or_higher => '99.0.0') Chris@909: end Chris@909: Chris@909: test.assert requires_redmine_plugin(:other, :version => other_version) Chris@909: test.assert requires_redmine_plugin(:other, :version => [other_version, '99.0.0']) Chris@909: test.assert_raise Redmine::PluginRequirementError do Chris@909: requires_redmine_plugin(:other, :version => '99.0.0') Chris@909: end Chris@909: test.assert_raise Redmine::PluginRequirementError do Chris@909: requires_redmine_plugin(:other, :version => ['98.0.0', '99.0.0']) Chris@909: end Chris@909: # Missing plugin Chris@909: test.assert_raise Redmine::PluginNotFound do Chris@909: requires_redmine_plugin(:missing, :version_or_higher => '0.1.0') Chris@909: end Chris@909: test.assert_raise Redmine::PluginNotFound do Chris@909: requires_redmine_plugin(:missing, '0.1.0') Chris@909: end Chris@909: test.assert_raise Redmine::PluginNotFound do Chris@909: requires_redmine_plugin(:missing, :version => '0.1.0') Chris@909: end Chris@909: Chris@909: end Chris@909: end Chris@909: end