Commit 03d5c15ca9c4ce80d805dd34cfe642999a014a93

Authored by Victor Costa
1 parent f9835ac9

Fix the use of theme images block store

app/models/theme.rb
... ... @@ -13,8 +13,14 @@ class Theme
13 13 Rails.root.join('public', 'user_themes')
14 14 end
15 15  
  16 + #FIXME make this test
16 17 def system_themes_dir
17   - Rails.root.join('public', 'designs', 'themes')
  18 + Rails.root.join('public', relative_themes_dir)
  19 + end
  20 +
  21 + #FIXME make this test
  22 + def relative_themes_dir
  23 + File.join('designs', 'themes')
18 24 end
19 25  
20 26 def create(id, attributes = {})
... ... @@ -94,6 +100,11 @@ class Theme
94 100 end
95 101  
96 102 #FIXME make this test
  103 + def public_path
  104 + File.join('/', self.class.relative_themes_dir, self.id)
  105 + end
  106 +
  107 + #FIXME make this test
97 108 def filesystem_path
98 109 File.join(self.class.system_themes_dir, self.id)
99 110 end
... ...
test/unit/box_organizer_helper_test.rb 0 → 100644
... ... @@ -0,0 +1,312 @@
  1 +# encoding: UTF-8
  2 +require File.dirname(__FILE__) + '/../test_helper'
  3 +
  4 +class BoxOrganizerHelperTest < ActionView::TestCase
  5 +
  6 +
  7 + def setup
  8 + @environment = Environment.default
  9 + end
  10 +
  11 + attr_reader :environment
  12 +
  13 + should 'display the default icon for block without icon' do
  14 + class SomeBlock < Block; end
  15 + block = SomeBlock
  16 + @plugins = mock
  17 + @plugins.stubs(:fetch_first_plugin).with(:has_block?, block).returns(nil)
  18 + assert_match '/images/icon_block.png', display_icon(block)
  19 + end
  20 +
  21 + should 'display the icon block' do
  22 + class SomeBlock < Block; end
  23 + block = SomeBlock
  24 + @plugins = mock
  25 + @plugins.stubs(:fetch_first_plugin).with(:has_block?, block).returns(nil)
  26 +
  27 + File.stubs(:exists?).returns(false)
  28 + File.stubs(:exists?).with(File.join(Rails.root, 'public', 'images', '/blocks/some_block/icon.png')).returns(true)
  29 + assert_match 'blocks/some_block/icon.png', display_icon(block)
  30 + end
  31 +
  32 + should 'display the plugin icon block' do
  33 + class SomeBlock < Block; end
  34 + block = SomeBlock
  35 + class SomePlugin < Noosfero::Plugin; end
  36 + SomePlugin.stubs(:name).returns('SomePlugin')
  37 + @plugins = mock
  38 + @plugins.stubs(:fetch_first_plugin).with(:has_block?, block).returns(SomePlugin)
  39 +
  40 + File.stubs(:exists?).returns(false)
  41 + File.stubs(:exists?).with(File.join(Rails.root, 'public', 'plugins/some/images/blocks/some_block/icon.png')).returns(true)
  42 + assert_match 'plugins/some/images/blocks/some_block/icon.png', display_icon(block)
  43 + end
  44 +
  45 + should 'display the theme icon block' do
  46 + class SomeBlock < Block; end
  47 + block = SomeBlock
  48 +
  49 + @plugins = mock
  50 + @plugins.stubs(:fetch_first_plugin).with(:has_block?, block).returns(nil)
  51 +
  52 + @environment = mock
  53 + @environment.stubs(:theme).returns('some_theme')
  54 +
  55 + File.stubs(:exists?).returns(false)
  56 + File.stubs(:exists?).with(File.join(Rails.root, 'public', 'designs/themes/some_theme/images/blocks/some_block/icon.png')).returns(true)
  57 + assert_match 'designs/themes/some_theme/images/blocks/some_block/icon.png', display_icon(block)
  58 + end
  59 +
  60 + should 'display the theme icon block instead of block icon' do
  61 + class SomeBlock < Block; end
  62 + block = SomeBlock
  63 +
  64 + @plugins = mock
  65 + @plugins.stubs(:fetch_first_plugin).with(:has_block?, block).returns(nil)
  66 +
  67 + @environment = mock
  68 + @environment.stubs(:theme).returns('some_theme')
  69 +
  70 + File.stubs(:exists?).returns(false)
  71 + File.stubs(:exists?).with(File.join(Rails.root, 'public', 'designs/themes/some_theme/images/blocks/some_block/icon.png')).returns(true)
  72 + File.stubs(:exists?).with(File.join(Rails.root, 'public', 'images', '/blocks/some_block/icon.png')).returns(true)
  73 + assert_match 'designs/themes/some_theme/images/blocks/some_block/icon.png', display_icon(block)
  74 + end
  75 +
  76 + should 'display the theme icon block instead of plugin block icon' do
  77 + class SomeBlock < Block; end
  78 + block = SomeBlock
  79 +
  80 + class SomePlugin < Noosfero::Plugin; end
  81 + SomePlugin.stubs(:name).returns('SomePlugin')
  82 + @plugins = mock
  83 + @plugins.stubs(:fetch_first_plugin).with(:has_block?, block).returns(SomePlugin)
  84 +
  85 + @environment = mock
  86 + @environment.stubs(:theme).returns('some_theme')
  87 +
  88 + File.stubs(:exists?).returns(false)
  89 + File.stubs(:exists?).with(File.join(Rails.root, 'public', 'designs/themes/some_theme/images/blocks/some_block/icon.png')).returns(true)
  90 + File.stubs(:exists?).with(File.join(Rails.root, 'public', 'plugins/some/images/blocks/some_block/icon.png')).returns(true)
  91 + assert_match 'designs/themes/some_theme/images/blocks/some_block/icon.png', display_icon(block)
  92 + end
  93 +
  94 + should 'display the theme icon block instead of block icon and plugin icon' do
  95 + class SomeBlock < Block; end
  96 + block = SomeBlock
  97 +
  98 + class SomePlugin < Noosfero::Plugin; end
  99 + SomePlugin.stubs(:name).returns('SomePlugin')
  100 + @plugins = mock
  101 + @plugins.stubs(:fetch_first_plugin).with(:has_block?, block).returns(SomePlugin)
  102 +
  103 +
  104 + @environment = mock
  105 + @environment.stubs(:theme).returns('some_theme')
  106 +
  107 + File.stubs(:exists?).returns(false)
  108 + File.stubs(:exists?).with(File.join(Rails.root, 'public', 'designs/themes/some_theme/images/blocks/some_block/icon.png')).returns(true)
  109 + File.stubs(:exists?).with(File.join(Rails.root, 'public', 'plugins/some/images/blocks/some_block/icon.png')).returns(true)
  110 + File.stubs(:exists?).with(File.join(Rails.root, 'public', 'images', '/blocks/some_block/icon.png')).returns(true)
  111 + assert_match 'designs/themes/some_theme/images/blocks/some_block/icon.png', display_icon(block)
  112 + end
  113 +
  114 + should 'display the plugin icon block instead of block icon' do
  115 + class SomeBlock < Block; end
  116 + block = SomeBlock
  117 +
  118 + class SomePlugin < Noosfero::Plugin; end
  119 + SomePlugin.stubs(:name).returns('SomePlugin')
  120 + @plugins = mock
  121 + @plugins.stubs(:fetch_first_plugin).with(:has_block?, block).returns(SomePlugin)
  122 +
  123 +
  124 + File.stubs(:exists?).returns(false)
  125 + File.stubs(:exists?).with(File.join(Rails.root, 'public', 'plugins/some/images/blocks/some_block/icon.png')).returns(true)
  126 + File.stubs(:exists?).with(File.join(Rails.root, 'public', 'images', '/blocks/some_block/icon.png')).returns(true)
  127 + assert_match 'plugins/some/images/blocks/some_block/icon.png', display_icon(block)
  128 + end
  129 +
  130 + should 'display the default preview for block without previews images' do
  131 + class SomeBlock < Block; end
  132 + block = SomeBlock
  133 + @plugins = mock
  134 + @plugins.stubs(:fetch_first_plugin).with(:has_block?, block).returns(nil)
  135 +
  136 + doc = HTML::Document.new display_previews(block)
  137 + assert_select doc.root, 'li' do |elements|
  138 + assert_match /img.* src="\/images\/block_preview.png.*"/, elements[0].to_s
  139 + assert_match /img.* src="\/images\/block_preview.png.*"/, elements[1].to_s
  140 + assert_match /img.* src="\/images\/block_preview.png.*"/, elements[2].to_s
  141 + end
  142 + end
  143 +
  144 + should 'display the previews of block' do
  145 + class SomeBlock < Block; end
  146 + block = SomeBlock
  147 + @plugins = mock
  148 + @plugins.stubs(:fetch_first_plugin).with(:has_block?, block).returns(nil)
  149 +
  150 + Dir.stubs(:glob).returns([])
  151 + base_path = File.join(Rails.root, 'public', 'images', '/blocks/some_block/previews/')
  152 + Dir.stubs(:glob).with(File.join(base_path, '*')).returns([File.join(base_path, 'p1.png'), File.join(base_path, 'p2.png')])
  153 + doc = HTML::Document.new display_previews(block)
  154 + assert_select doc.root, 'li' do |elements|
  155 + assert_match /img.* src="\/images\/blocks\/some_block\/previews\/p1.png"/, elements[0].to_s
  156 + assert_match /img.* src="\/images\/blocks\/some_block\/previews\/p2.png"/, elements[1].to_s
  157 + end
  158 + end
  159 +
  160 + should 'display the plugin preview images of block' do
  161 + class SomeBlock < Block; end
  162 + block = SomeBlock
  163 + class SomePlugin < Noosfero::Plugin; end
  164 + SomePlugin.stubs(:name).returns('SomePlugin')
  165 + @plugins = mock
  166 + @plugins.stubs(:fetch_first_plugin).with(:has_block?, block).returns(SomePlugin)
  167 +
  168 +
  169 + Dir.stubs(:glob).returns([])
  170 + base_path = File.join(Rails.root, 'public', 'plugins/some/', 'images', '/blocks/some_block/previews/')
  171 + Dir.stubs(:glob).with(File.join(base_path, '*')).returns([File.join(base_path, 'p1.png'), File.join(base_path, 'p2.png')])
  172 + doc = HTML::Document.new display_previews(block)
  173 + assert_select doc.root, 'li' do |elements|
  174 + assert_match /img.* src="\/plugins\/some\/images\/blocks\/some_block\/previews\/p1.png"/, elements[0].to_s
  175 + assert_match /img.* src="\/plugins\/some\/images\/blocks\/some_block\/previews\/p2.png"/, elements[1].to_s
  176 + end
  177 +
  178 + end
  179 +
  180 + should 'display the theme previews of block' do
  181 + class SomeBlock < Block; end
  182 + block = SomeBlock
  183 +
  184 + @plugins = mock
  185 + @plugins.stubs(:fetch_first_plugin).with(:has_block?, block).returns(nil)
  186 +
  187 + @environment = mock
  188 + @environment.stubs(:theme).returns('some_theme')
  189 +
  190 +
  191 + Dir.stubs(:glob).returns([])
  192 + base_path = File.join(Rails.root, 'public', 'designs/themes/some_theme/', 'images', '/blocks/some_block/previews/')
  193 + Dir.stubs(:glob).with(File.join(base_path, '*')).returns([File.join(base_path, 'p1.png'), File.join(base_path, 'p2.png')])
  194 + doc = HTML::Document.new display_previews(block)
  195 + assert_select doc.root, 'li' do |elements|
  196 + assert_match /img.* src="\/designs\/themes\/some_theme\/images\/blocks\/some_block\/previews\/p1.png"/, elements[0].to_s
  197 + assert_match /img.* src="\/designs\/themes\/some_theme\/images\/blocks\/some_block\/previews\/p2.png"/, elements[1].to_s
  198 + end
  199 +
  200 + end
  201 +
  202 + should 'display the theme preview images of block instead of block preview images' do
  203 + class SomeBlock < Block; end
  204 + block = SomeBlock
  205 +
  206 + @plugins = mock
  207 + @plugins.stubs(:fetch_first_plugin).with(:has_block?, block).returns(nil)
  208 +
  209 + @environment = mock
  210 + @environment.stubs(:theme).returns('some_theme')
  211 +
  212 + Dir.stubs(:glob).returns([])
  213 + base_path = File.join(Rails.root, 'public', 'designs/themes/some_theme/', 'images', '/blocks/some_block/previews/')
  214 + Dir.stubs(:glob).with(File.join(base_path, '*')).returns([File.join(base_path, 'p1.png'), File.join(base_path, 'p2.png')])
  215 +
  216 + base_path = File.join(Rails.root, 'public', 'images', '/blocks/some_block/previews/')
  217 + Dir.stubs(:glob).with(File.join(base_path, '*')).returns([File.join(base_path, 'p1.png'), File.join(base_path, 'p2.png')])
  218 +
  219 + doc = HTML::Document.new display_previews(block)
  220 + assert_select doc.root, 'li' do |elements|
  221 + assert_match /img.* src="\/designs\/themes\/some_theme\/images\/blocks\/some_block\/previews\/p1.png"/, elements[0].to_s
  222 + assert_match /img.* src="\/designs\/themes\/some_theme\/images\/blocks\/some_block\/previews\/p2.png"/, elements[1].to_s
  223 + end
  224 + end
  225 +
  226 + should 'display the theme preview images of block instead of plugin preview images' do
  227 + class SomeBlock < Block; end
  228 + block = SomeBlock
  229 +
  230 + class SomePlugin < Noosfero::Plugin; end
  231 + SomePlugin.stubs(:name).returns('SomePlugin')
  232 + @plugins = mock
  233 + @plugins.stubs(:fetch_first_plugin).with(:has_block?, block).returns(SomePlugin)
  234 +
  235 + @environment = mock
  236 + @environment.stubs(:theme).returns('some_theme')
  237 +
  238 + Dir.stubs(:glob).returns([])
  239 + base_path = File.join(Rails.root, 'public', 'designs/themes/some_theme/', 'images', '/blocks/some_block/previews/')
  240 + Dir.stubs(:glob).with(File.join(base_path, '*')).returns([File.join(base_path, 'p1.png'), File.join(base_path, 'p2.png')])
  241 +
  242 + base_path = File.join(Rails.root, 'public', 'plugins/some/', 'images', '/blocks/some_block/previews/')
  243 + Dir.stubs(:glob).with(File.join(base_path, '*')).returns([File.join(base_path, 'p1.png'), File.join(base_path, 'p2.png')])
  244 +
  245 + doc = HTML::Document.new display_previews(block)
  246 + assert_select doc.root, 'li' do |elements|
  247 + assert_match /img.* src="\/designs\/themes\/some_theme\/images\/blocks\/some_block\/previews\/p1.png"/, elements[0].to_s
  248 + assert_match /img.* src="\/designs\/themes\/some_theme\/images\/blocks\/some_block\/previews\/p2.png"/, elements[1].to_s
  249 + end
  250 +
  251 + end
  252 +
  253 + should 'display the theme preview images of block instead of block previews and plugin previews' do
  254 + class SomeBlock < Block; end
  255 + block = SomeBlock
  256 +
  257 + class SomePlugin < Noosfero::Plugin; end
  258 + SomePlugin.stubs(:name).returns('SomePlugin')
  259 + @plugins = mock
  260 + @plugins.stubs(:fetch_first_plugin).with(:has_block?, block).returns(SomePlugin)
  261 +
  262 +
  263 + @environment = mock
  264 + @environment.stubs(:theme).returns('some_theme')
  265 +
  266 + Dir.stubs(:glob).returns([])
  267 + base_path = File.join(Rails.root, 'public', 'designs/themes/some_theme/', 'images', '/blocks/some_block/previews/')
  268 + Dir.stubs(:glob).with(File.join(base_path, '*')).returns([File.join(base_path, 'p1.png'), File.join(base_path, 'p2.png')])
  269 +
  270 + base_path = File.join(Rails.root, 'public', 'plugins/some/', 'images', '/blocks/some_block/previews/')
  271 + Dir.stubs(:glob).with(File.join(base_path, '*')).returns([File.join(base_path, 'p1.png'), File.join(base_path, 'p2.png')])
  272 +
  273 + base_path = File.join(Rails.root, 'public', 'images', '/blocks/some_block/previews/')
  274 + Dir.stubs(:glob).with(File.join(base_path, '*')).returns([File.join(base_path, 'p1.png'), File.join(base_path, 'p2.png')])
  275 +
  276 + doc = HTML::Document.new display_previews(block)
  277 + assert_select doc.root, 'li' do |elements|
  278 + assert_match /img.* src="\/designs\/themes\/some_theme\/images\/blocks\/some_block\/previews\/p1.png"/, elements[0].to_s
  279 + assert_match /img.* src="\/designs\/themes\/some_theme\/images\/blocks\/some_block\/previews\/p2.png"/, elements[1].to_s
  280 + end
  281 +
  282 + end
  283 +
  284 + should 'display the plugin preview images of block instead of block previews' do
  285 + class SomeBlock < Block; end
  286 + block = SomeBlock
  287 +
  288 + class SomePlugin < Noosfero::Plugin; end
  289 + SomePlugin.stubs(:name).returns('SomePlugin')
  290 + @plugins = mock
  291 + @plugins.stubs(:fetch_first_plugin).with(:has_block?, block).returns(SomePlugin)
  292 +
  293 + Dir.stubs(:glob).returns([])
  294 + base_path = File.join(Rails.root, 'public', 'designs/themes/some_theme/', 'images', '/blocks/some_block/previews/')
  295 + Dir.stubs(:glob).with(File.join(base_path, '*')).returns([File.join(base_path, 'p1.png'), File.join(base_path, 'p2.png')])
  296 +
  297 + base_path = File.join(Rails.root, 'public', 'plugins/some/', 'images', '/blocks/some_block/previews/')
  298 + Dir.stubs(:glob).with(File.join(base_path, '*')).returns([File.join(base_path, 'p1.png'), File.join(base_path, 'p2.png')])
  299 +
  300 + base_path = File.join(Rails.root, 'public', 'images', '/blocks/some_block/previews/')
  301 + Dir.stubs(:glob).with(File.join(base_path, '*')).returns([File.join(base_path, 'p1.png'), File.join(base_path, 'p2.png')])
  302 +
  303 + doc = HTML::Document.new display_previews(block)
  304 + assert_select doc.root, 'li' do |elements|
  305 + assert_match /img.* src="\/plugins\/some\/images\/blocks\/some_block\/previews\/p1.png"/, elements[0].to_s
  306 + assert_match /img.* src="\/plugins\/some\/images\/blocks\/some_block\/previews\/p2.png"/, elements[1].to_s
  307 + end
  308 +
  309 + end
  310 +
  311 +
  312 +end
... ...