plugin_test.rb
2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
require File.dirname(__FILE__) + '/../test_helper'
class PluginTest < ActiveSupport::TestCase
def setup
@environment = Environment.default
end
attr_reader :environment
include Noosfero::Plugin::HotSpot
should 'keep the list of all loaded subclasses' do
class Plugin1 < Noosfero::Plugin
end
class Plugin2 < Noosfero::Plugin
end
assert_includes Noosfero::Plugin.all, Plugin1.to_s
assert_includes Noosfero::Plugin.all, Plugin2.to_s
end
should 'returns url to plugin management if plugin has admin_controller' do
class Plugin1 < Noosfero::Plugin
end
File.stubs(:exists?).with(anything).returns(true)
assert_equal({:controller => 'plugin_test/plugin1_admin', :action => 'index'}, Plugin1.admin_url)
end
should 'register its macros in the environment when instantiated' do
class Plugin1 < Noosfero::Plugin
def macro_example1(params, inner_html, source)
end
def example2(params, inner_html, source)
end
def not_macro
end
def macro_methods
['macro_example1', 'example2']
end
end
Environment.macros = {}
Environment.macros[environment.id] = {}
macros = Environment.macros[environment.id]
context = mock()
context.stubs(:environment).returns(environment)
plugin_instance = Plugin1.new(context)
assert_equal plugin_instance, macros['macro_example1']
assert_equal plugin_instance, macros['example2']
assert_nil macros['not_macro']
end
should 'load_comments return nil by default' do
class Plugin1 < Noosfero::Plugin; end;
environment.stubs(:enabled_plugins).returns([Plugin1.to_s])
profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile')
a = fast_create(Article, :name => 'my article', :profile_id => profile.id)
assert_nil plugins.dispatch_first(:load_comments, a)
end
should 'load_comments return the value defined by plugin' do
class Plugin1 < Noosfero::Plugin
def load_comments(page)
'some value'
end
end
environment.stubs(:enabled_plugins).returns([Plugin1.to_s])
profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile')
a = fast_create(Article, :name => 'my article', :profile_id => profile.id)
assert_equal 'some value', plugins.dispatch_first(:load_comments, a)
end
end