Commit 2402b6ba2d835672f9af80a98bac3e27ccdbff62
1 parent
5ee35053
Exists in
master
and in
28 other branches
Tests added to breadcrumbs block
Showing
8 changed files
with
165 additions
and
6 deletions
Show diff stats
plugins/breadcrumbs/lib/breadcrumbs_block.rb
| ... | ... | @@ -11,25 +11,33 @@ class BreadcrumbsBlock < Block |
| 11 | 11 | _('This block displays breadcrumb trail.') |
| 12 | 12 | end |
| 13 | 13 | |
| 14 | - def trail(page, params={}) | |
| 14 | + def page_trail(page, params={}) | |
| 15 | 15 | links = [] |
| 16 | 16 | if page |
| 17 | 17 | links = page.ancestors.reverse.map { |p| { :name => p.title, :url => p.url } } |
| 18 | 18 | links << { :name => page.title, :url => page.url } |
| 19 | 19 | elsif params[:controller] == 'cms' |
| 20 | 20 | id = params[:id] || params[:parent_id] |
| 21 | - links = trail(Article.find(id)) if id | |
| 22 | - links << { :name => params[:action], :url => params } if show_cms_action | |
| 21 | + links = page_trail(Article.find(id)) if id | |
| 22 | + links << { :name => cms_action(params[:action]), :url => params } if show_cms_action | |
| 23 | 23 | end |
| 24 | 24 | links |
| 25 | 25 | end |
| 26 | 26 | |
| 27 | + def trail(page, profile=nil, params={}) | |
| 28 | + links = page_trail(page, params) | |
| 29 | + if profile && !links.empty? && show_profile | |
| 30 | + [ {:name => profile.name, :url => profile.url} ] + links | |
| 31 | + else | |
| 32 | + links | |
| 33 | + end | |
| 34 | + end | |
| 35 | + | |
| 27 | 36 | def content(args={}) |
| 28 | 37 | block = self |
| 29 | 38 | lambda do |
| 30 | - trail = block.trail(@page, params) | |
| 39 | + trail = block.trail(@page, @profile, params) | |
| 31 | 40 | if !trail.empty? |
| 32 | - trail = [ {:name => @profile.name, :url => @profile.url} ] + trail if block.show_profile | |
| 33 | 41 | trail.map { |t| link_to(t[:name], t[:url], :class => 'item') }.join(content_tag('span', ' > ', :class => 'separator')) |
| 34 | 42 | else |
| 35 | 43 | '' |
| ... | ... | @@ -37,4 +45,12 @@ class BreadcrumbsBlock < Block |
| 37 | 45 | end |
| 38 | 46 | end |
| 39 | 47 | |
| 48 | + protected | |
| 49 | + | |
| 50 | + CMS_ACTIONS = {:edit => _('Edit'), :upload_files => _('Upload Files'), :new => _('New')} | |
| 51 | + | |
| 52 | + def cms_action(action) | |
| 53 | + CMS_ACTIONS[action.to_sym] || action | |
| 54 | + end | |
| 55 | + | |
| 40 | 56 | end | ... | ... |
plugins/breadcrumbs/lib/breadcrumbs_plugin.rb
plugins/breadcrumbs/test/functional/profile_design_controller_test.rb
0 → 100644
| ... | ... | @@ -0,0 +1,45 @@ |
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | |
| 2 | + | |
| 3 | +class ProfileDesignController | |
| 4 | + append_view_path File.join(File.dirname(__FILE__) + '/../../views') | |
| 5 | + def rescue_action(e) | |
| 6 | + raise e | |
| 7 | + end | |
| 8 | +end | |
| 9 | + | |
| 10 | +class ProfileDesignControllerTest < ActionController::TestCase | |
| 11 | + | |
| 12 | + def setup | |
| 13 | + Environment.delete_all | |
| 14 | + @environment = Environment.create(:name => 'testenv', :is_default => true) | |
| 15 | + @environment.enabled_plugins = ['BreadcrumbsPlugin'] | |
| 16 | + @environment.save! | |
| 17 | + | |
| 18 | + @profile = fast_create(Community, :environment_id => @environment.id) | |
| 19 | + @page = fast_create(Folder, :profile_id => @profile.id) | |
| 20 | + | |
| 21 | + box = Box.create!(:owner => @profile) | |
| 22 | + @block = BreadcrumbsBlock.create!(:box => box) | |
| 23 | + | |
| 24 | + user = create_user('testinguser') | |
| 25 | + @profile.add_admin(user.person) | |
| 26 | + login_as(user.login) | |
| 27 | + end | |
| 28 | + | |
| 29 | + should 'be able to edit breadcrumbs block' do | |
| 30 | + get :edit, :id => @block.id, :profile => @profile.identifier | |
| 31 | + assert_tag :tag => 'input', :attributes => { :id => 'block_title' } | |
| 32 | + assert_tag :tag => 'input', :attributes => { :id => 'block_show_cms_action' } | |
| 33 | + assert_tag :tag => 'input', :attributes => { :id => 'block_show_profile' } | |
| 34 | + end | |
| 35 | + | |
| 36 | + should 'be able to save breadcrumbs block' do | |
| 37 | + get :edit, :id => @block.id, :profile => @profile.identifier | |
| 38 | + post :save, :id => @block.id, :profile => @profile.identifier, :block => {:title => 'breadcrumbs', :show_cms_action => false, :show_profile => false} | |
| 39 | + @block.reload | |
| 40 | + assert_equal 'breadcrumbs', @block.title | |
| 41 | + assert !@block.show_profile | |
| 42 | + assert !@block.show_cms_action | |
| 43 | + end | |
| 44 | + | |
| 45 | +end | ... | ... |
| ... | ... | @@ -0,0 +1 @@ |
| 1 | +require File.dirname(__FILE__) + '/../../../test/test_helper' | ... | ... |
| ... | ... | @@ -0,0 +1,71 @@ |
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | |
| 2 | + | |
| 3 | +class BreadcrumbsBlockTest < ActiveSupport::TestCase | |
| 4 | + | |
| 5 | + include NoosferoTestHelper | |
| 6 | + | |
| 7 | + def setup | |
| 8 | + @block = BreadcrumbsBlock.new | |
| 9 | + @profile = fast_create(Community) | |
| 10 | + @folder = fast_create(Folder, :profile_id => @profile.id) | |
| 11 | + @article = fast_create(Folder, :profile_id => @profile.id, :parent_id => @folder.id) | |
| 12 | + @params = {} | |
| 13 | + end | |
| 14 | + | |
| 15 | + attr_reader :params | |
| 16 | + | |
| 17 | + should 'has a description' do | |
| 18 | + assert_not_equal Block.description, BreadcrumbsBlock.description | |
| 19 | + end | |
| 20 | + | |
| 21 | + should 'has a help' do | |
| 22 | + assert @block.help | |
| 23 | + end | |
| 24 | + | |
| 25 | + should 'return path of links to reach a page' do | |
| 26 | + links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}] | |
| 27 | + assert_equal links, @block.page_trail(@article) | |
| 28 | + end | |
| 29 | + | |
| 30 | + should 'return path of links when current page is at cms controller' do | |
| 31 | + params = {:controller => 'cms', :action => 'edit', :id => @article.id} | |
| 32 | + links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}, {:url=>{:controller=>"cms", :action=>"edit", :id=>@article.id}, :name=>"Edit"}] | |
| 33 | + assert_equal links, @block.page_trail(nil, params) | |
| 34 | + end | |
| 35 | + | |
| 36 | + should 'not return cms action link when show_cms_action is false' do | |
| 37 | + params = {:controller => 'cms', :action => 'edit', :id => @article.id} | |
| 38 | + links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}] | |
| 39 | + @block.show_cms_action = false | |
| 40 | + assert_equal links, @block.page_trail(nil, params) | |
| 41 | + end | |
| 42 | + | |
| 43 | + should 'include profile link on path of links to reach a page' do | |
| 44 | + links = [{:name => @profile.name, :url => @profile.url}, {:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}] | |
| 45 | + assert_equal links, @block.trail(@article, @profile) | |
| 46 | + end | |
| 47 | + | |
| 48 | + should 'not include profile link on path of links when show_profile is false' do | |
| 49 | + links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}] | |
| 50 | + @block.show_profile = false | |
| 51 | + assert_equal links, @block.trail(@article, @profile) | |
| 52 | + end | |
| 53 | + | |
| 54 | + should 'not include profile link on path of links when trail is empty' do | |
| 55 | + assert_equal [], @block.trail(nil, @profile) | |
| 56 | + end | |
| 57 | + | |
| 58 | + should 'render trail if there is links to show' do | |
| 59 | + @page = @article | |
| 60 | + trail = instance_eval(&@block.content) | |
| 61 | + assert_match /#{@profile.name}/, trail | |
| 62 | + assert_match /#{@folder.name}/, trail | |
| 63 | + assert_match /#{@page.name}/, trail | |
| 64 | + end | |
| 65 | + | |
| 66 | + should 'render nothing if there is no links to show' do | |
| 67 | + @page = nil | |
| 68 | + assert_equal '', instance_eval(&@block.content) | |
| 69 | + end | |
| 70 | + | |
| 71 | +end | ... | ... |
plugins/breadcrumbs/test/unit/breadcrumbs_plugin_test.rb
0 → 100644
| ... | ... | @@ -0,0 +1,21 @@ |
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | |
| 2 | + | |
| 3 | +class BreadcrumbsPluginTest < ActiveSupport::TestCase | |
| 4 | + | |
| 5 | + def setup | |
| 6 | + @plugin = BreadcrumbsPlugin.new | |
| 7 | + end | |
| 8 | + | |
| 9 | + should 'has a name' do | |
| 10 | + assert !BreadcrumbsPlugin.plugin_name.blank? | |
| 11 | + end | |
| 12 | + | |
| 13 | + should 'has a description' do | |
| 14 | + assert !BreadcrumbsPlugin.plugin_description.blank? | |
| 15 | + end | |
| 16 | + | |
| 17 | + should 'add a block' do | |
| 18 | + assert_equal [BreadcrumbsBlock], BreadcrumbsPlugin.extra_blocks.keys | |
| 19 | + end | |
| 20 | + | |
| 21 | +end | ... | ... |
plugins/breadcrumbs/views/box_organizer/_breadcrumbs_block.rhtml
0 → 100644