plugin_manager_test.rb
2.59 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
require File.dirname(__FILE__) + '/../test_helper'
class PluginManagerTest < ActiveSupport::TestCase
include Noosfero::Plugin::HotSpot
def setup
@environment = Environment.default
end
attr_reader :environment
should 'return the intersection between environment\'s enabled plugins and system available plugins' do
class Plugin1 < Noosfero::Plugin; end;
class Plugin2 < Noosfero::Plugin; end;
class Plugin3 < Noosfero::Plugin; end;
class Plugin4 < Noosfero::Plugin; end;
environment.stubs(:enabled_plugins).returns([Plugin1.to_s, Plugin2.to_s, Plugin4.to_s])
Noosfero::Plugin.stubs(:all).returns([Plugin1.to_s, Plugin3.to_s, Plugin4.to_s])
results = plugins.enabled_plugins.map { |instance| instance.class.to_s }
assert_equal [Plugin1.to_s, Plugin4.to_s], results
end
should 'map events to registered plugins' do
class Noosfero::Plugin
def random_event
nil
end
end
class Plugin1 < Noosfero::Plugin
def random_event
'Plugin 1 action.'
end
end
class Plugin2 < Noosfero::Plugin
def random_event
'Plugin 2 action.'
end
end
environment.stubs(:enabled_plugins).returns([Plugin1.to_s, Plugin2.to_s])
p1 = Plugin1.new
p2 = Plugin2.new
assert_equal [p1.random_event, p2.random_event], plugins.dispatch(:random_event)
end
should 'dispatch_first method returns the first plugin response if there is many plugins to responde the event' do
class Plugin1 < Noosfero::Plugin
def random_event
'Plugin 1 action.'
end
end
class Plugin2 < Noosfero::Plugin
def random_event
'Plugin 2 action.'
end
end
class Plugin3 < Noosfero::Plugin
def random_event
'Plugin 3 action.'
end
end
environment.stubs(:enabled_plugins).returns([Plugin1.to_s, Plugin2.to_s, Plugin3.to_s])
p1 = Plugin1.new
assert_equal p1.random_event, plugins.dispatch_first(:random_event)
end
should 'dispatch_first method returns the first plugin response if there is many plugins to responde the event and the first one respond nil' do
class Plugin1 < Noosfero::Plugin
def random_event
nil
end
end
class Plugin2 < Noosfero::Plugin
def random_event
'Plugin 2 action.'
end
end
class Plugin3 < Noosfero::Plugin
def random_event
'Plugin 3 action.'
end
end
environment.stubs(:enabled_plugins).returns([Plugin1.to_s, Plugin2.to_s, Plugin3.to_s])
p2 = Plugin2.new
assert_equal p2.random_event, plugins.dispatch_first(:random_event)
end
end