Commit 0759f7f1e52d87a55da43a5ae063187922926888
1 parent
9796d5e3
Exists in
staging
and in
7 other branches
unit tests for BoxOrganizerHelper::display_icon method
Showing
2 changed files
with
124 additions
and
4 deletions
Show diff stats
app/helpers/box_organizer_helper.rb
@@ -4,9 +4,7 @@ module BoxOrganizerHelper | @@ -4,9 +4,7 @@ module BoxOrganizerHelper | ||
4 | 7 | 4 | 7 |
5 | end | 5 | end |
6 | 6 | ||
7 | - #FIXME make this test | ||
8 | def display_icon(block) | 7 | def display_icon(block) |
9 | - | ||
10 | image_path = nil | 8 | image_path = nil |
11 | plugin = @plugins.fetch_first_plugin(:has_block?, block) | 9 | plugin = @plugins.fetch_first_plugin(:has_block?, block) |
12 | 10 |
test/unit/box_organizer_helper_test.rb
1 | # encoding: UTF-8 | 1 | # encoding: UTF-8 |
2 | require File.dirname(__FILE__) + '/../test_helper' | 2 | require File.dirname(__FILE__) + '/../test_helper' |
3 | 3 | ||
4 | -class BoxOrganizerHelperTest < ActiveSupport::TestCase | 4 | +class BoxOrganizerHelperTest < ActionView::TestCase |
5 | 5 | ||
6 | - include BoxOrganizerHelper | 6 | + |
7 | + def setup | ||
8 | + @environment = Environment.default | ||
9 | + end | ||
10 | + | ||
11 | + attr_reader :environment | ||
7 | 12 | ||
8 | should 'max number of blocks be 7' do | 13 | should 'max number of blocks be 7' do |
9 | assert_equal 7, max_number_of_blocks_per_line | 14 | assert_equal 7, max_number_of_blocks_per_line |
10 | end | 15 | end |
11 | 16 | ||
17 | + should 'display the default icon for block without icon' do | ||
18 | + class SomeBlock < Block; end | ||
19 | + block = SomeBlock | ||
20 | + @plugins = mock | ||
21 | + @plugins.stubs(:fetch_first_plugin).with(:has_block?, block).returns(nil) | ||
22 | + assert_match '/images/icon_block.png', display_icon(block) | ||
23 | + end | ||
24 | + | ||
25 | + should 'display the icon block' do | ||
26 | + class SomeBlock < Block; end | ||
27 | + block = SomeBlock | ||
28 | + @plugins = mock | ||
29 | + @plugins.stubs(:fetch_first_plugin).with(:has_block?, block).returns(nil) | ||
30 | + | ||
31 | + File.stubs(:exists?).returns(false) | ||
32 | + File.stubs(:exists?).with(File.join(Rails.root, 'public', 'images', '/blocks/some_block/icon.png')).returns(true) | ||
33 | + assert_match 'blocks/some_block/icon.png', display_icon(block) | ||
34 | + end | ||
35 | + | ||
36 | + should 'display the plugin icon block' do | ||
37 | + class SomeBlock < Block; end | ||
38 | + block = SomeBlock | ||
39 | + class SomePlugin < Noosfero::Plugin; end | ||
40 | + SomePlugin.stubs(:name).returns('SomePlugin') | ||
41 | + @plugins = mock | ||
42 | + @plugins.stubs(:fetch_first_plugin).with(:has_block?, block).returns(SomePlugin) | ||
43 | + | ||
44 | + File.stubs(:exists?).returns(false) | ||
45 | + File.stubs(:exists?).with(File.join(Rails.root, 'public', 'plugins/some/images/blocks/some_block/icon.png')).returns(true) | ||
46 | + assert_match 'plugins/some/images/blocks/some_block/icon.png', display_icon(block) | ||
47 | + end | ||
48 | + | ||
49 | + should 'display the theme icon block' do | ||
50 | + class SomeBlock < Block; end | ||
51 | + block = SomeBlock | ||
52 | + | ||
53 | + @plugins = mock | ||
54 | + @plugins.stubs(:fetch_first_plugin).with(:has_block?, block).returns(nil) | ||
55 | + | ||
56 | + @environment = mock | ||
57 | + @environment.stubs(:theme).returns('some_theme') | ||
58 | + | ||
59 | + File.stubs(:exists?).returns(false) | ||
60 | + File.stubs(:exists?).with(File.join(Rails.root, 'public', 'designs/themes/some_theme/images/blocks/some_block/icon.png')).returns(true) | ||
61 | + assert_match 'designs/themes/some_theme/images/blocks/some_block/icon.png', display_icon(block) | ||
62 | + end | ||
63 | + | ||
64 | + should 'display the theme icon block instead of block icon' do | ||
65 | + class SomeBlock < Block; end | ||
66 | + block = SomeBlock | ||
67 | + | ||
68 | + @plugins = mock | ||
69 | + @plugins.stubs(:fetch_first_plugin).with(:has_block?, block).returns(nil) | ||
70 | + | ||
71 | + @environment = mock | ||
72 | + @environment.stubs(:theme).returns('some_theme') | ||
73 | + | ||
74 | + File.stubs(:exists?).returns(false) | ||
75 | + File.stubs(:exists?).with(File.join(Rails.root, 'public', 'designs/themes/some_theme/images/blocks/some_block/icon.png')).returns(true) | ||
76 | + File.stubs(:exists?).with(File.join(Rails.root, 'public', 'images', '/blocks/some_block/icon.png')).returns(true) | ||
77 | + assert_match 'designs/themes/some_theme/images/blocks/some_block/icon.png', display_icon(block) | ||
78 | + end | ||
79 | + | ||
80 | + should 'display the theme icon block instead of plugin block icon' do | ||
81 | + class SomeBlock < Block; end | ||
82 | + block = SomeBlock | ||
83 | + | ||
84 | + class SomePlugin < Noosfero::Plugin; end | ||
85 | + SomePlugin.stubs(:name).returns('SomePlugin') | ||
86 | + @plugins = mock | ||
87 | + @plugins.stubs(:fetch_first_plugin).with(:has_block?, block).returns(SomePlugin) | ||
88 | + | ||
89 | + @environment = mock | ||
90 | + @environment.stubs(:theme).returns('some_theme') | ||
91 | + | ||
92 | + File.stubs(:exists?).returns(false) | ||
93 | + File.stubs(:exists?).with(File.join(Rails.root, 'public', 'designs/themes/some_theme/images/blocks/some_block/icon.png')).returns(true) | ||
94 | + File.stubs(:exists?).with(File.join(Rails.root, 'public', 'plugins/some/images/blocks/some_block/icon.png')).returns(true) | ||
95 | + assert_match 'designs/themes/some_theme/images/blocks/some_block/icon.png', display_icon(block) | ||
96 | + end | ||
97 | + | ||
98 | + should 'display the theme icon block instead of block icon and plugin icon' do | ||
99 | + class SomeBlock < Block; end | ||
100 | + block = SomeBlock | ||
101 | + | ||
102 | + class SomePlugin < Noosfero::Plugin; end | ||
103 | + SomePlugin.stubs(:name).returns('SomePlugin') | ||
104 | + @plugins = mock | ||
105 | + @plugins.stubs(:fetch_first_plugin).with(:has_block?, block).returns(SomePlugin) | ||
106 | + | ||
107 | + | ||
108 | + @environment = mock | ||
109 | + @environment.stubs(:theme).returns('some_theme') | ||
110 | + | ||
111 | + File.stubs(:exists?).returns(false) | ||
112 | + File.stubs(:exists?).with(File.join(Rails.root, 'public', 'designs/themes/some_theme/images/blocks/some_block/icon.png')).returns(true) | ||
113 | + File.stubs(:exists?).with(File.join(Rails.root, 'public', 'plugins/some/images/blocks/some_block/icon.png')).returns(true) | ||
114 | + File.stubs(:exists?).with(File.join(Rails.root, 'public', 'images', '/blocks/some_block/icon.png')).returns(true) | ||
115 | + assert_match 'designs/themes/some_theme/images/blocks/some_block/icon.png', display_icon(block) | ||
116 | + end | ||
117 | + | ||
118 | + should 'display the plugin icon block instead of block icon' do | ||
119 | + class SomeBlock < Block; end | ||
120 | + block = SomeBlock | ||
121 | + | ||
122 | + class SomePlugin < Noosfero::Plugin; end | ||
123 | + SomePlugin.stubs(:name).returns('SomePlugin') | ||
124 | + @plugins = mock | ||
125 | + @plugins.stubs(:fetch_first_plugin).with(:has_block?, block).returns(SomePlugin) | ||
126 | + | ||
127 | + | ||
128 | + File.stubs(:exists?).returns(false) | ||
129 | + File.stubs(:exists?).with(File.join(Rails.root, 'public', 'plugins/some/images/blocks/some_block/icon.png')).returns(true) | ||
130 | + File.stubs(:exists?).with(File.join(Rails.root, 'public', 'images', '/blocks/some_block/icon.png')).returns(true) | ||
131 | + assert_match 'plugins/some/images/blocks/some_block/icon.png', display_icon(block) | ||
132 | + end | ||
133 | + | ||
12 | end | 134 | end |