Commit 3a4726cbdc0d4c2337e368f1c2e6db0940fc6879

Authored by Victor Costa
1 parent 60f17b72

Functional tests for context content block

plugins/context_content/controllers/profile/context_content_plugin_profile_controller.rb
... ... @@ -2,14 +2,18 @@ class ContextContentPluginProfileController < ProfileController
2 2 append_view_path File.join(File.dirname(__FILE__) + '/../../views')
3 3  
4 4 def view_content
5   - block = Block.find(params[:id])
6   - p = params[:page].to_i
7   - contents = block.contents(profile.articles.find(params[:article_id]), p)
8   -
9   - render :update do |page|
10   - page.replace_html "context_content_#{block.id}", :file => "blocks/context_content", :locals => {:block => block, :contents => contents}
11   - page.replace_html "context_content_more_#{block.id}", :partial => 'blocks/more', :locals => {:block => block, :contents => contents, :article_id => params[:article_id] }
12   - end
  5 + block = Block.find(params[:id])
  6 + p = params[:page].to_i
  7 + contents = block.contents(profile.articles.find(params[:article_id]), p)
  8 +
  9 + if contents
  10 + render :update do |page|
  11 + page.replace_html "context_content_#{block.id}", :file => "blocks/context_content", :locals => {:block => block, :contents => contents}
  12 + page.replace_html "context_content_more_#{block.id}", :partial => 'blocks/more', :locals => {:block => block, :contents => contents, :article_id => params[:article_id] }
  13 + end
  14 + else
  15 + render :text => "invalid page", :status => 500
  16 + end
13 17 end
14 18  
15 19 end
... ...
plugins/context_content/lib/context_content_block.rb
... ... @@ -50,8 +50,8 @@ class ContextContentBlock < Block
50 50 def footer
51 51 block = self
52 52 lambda do
53   - if @page
54   - contents = block.contents(@page)
  53 + contents = block.contents(@page)
  54 + if contents
55 55 content_tag('div',
56 56 render(:partial => 'blocks/more', :locals => {:block => block, :contents => contents, :article_id => @page.id}), :id => "context_content_more_#{block.id}", :class => "more_button")
57 57 else
... ...
plugins/context_content/test/functional/content_viewer_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,46 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class ContentViewerController
  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 ContentViewerControllerTest < ActionController::TestCase
  11 +
  12 + def setup
  13 + @profile = fast_create(Community)
  14 + @page = fast_create(Folder, :profile_id => @profile.id)
  15 +
  16 + box = Box.create!(:owner => @profile)
  17 + @block = ContextContentBlock.new(:box => box)
  18 + @block.types = ['TinyMceArticle']
  19 + @block.limit = 1
  20 + @block.save!
  21 + end
  22 +
  23 + should 'do not display context content block if it has no contents' do
  24 + get :view_page, @page.url
  25 + assert_no_tag 'div', :attributes => {:id => "context_content_#{@block.id}", :class => 'contents'}
  26 + assert_no_tag 'div', :attributes => {:id => "context_content_more_#{@block.id}", :class => 'more_button'}
  27 + end
  28 +
  29 + should 'display context content block if it has contents' do
  30 + article = fast_create(TinyMceArticle, :parent_id => @page.id, :profile_id => @profile.id, :name => 'article1')
  31 + get :view_page, @page.url
  32 + assert_tag 'div', :attributes => {:id => "context_content_#{@block.id}", :class => 'contents'}
  33 + assert_no_tag 'div', :attributes => {:id => "context_content_more_#{@block.id}", :class => 'more_button'}, :descendant => {:tag => 'a'}
  34 + assert_match /article1/, @response.body
  35 + end
  36 +
  37 + should 'display context content block with pagination' do
  38 + article1 = fast_create(TinyMceArticle, :parent_id => @page.id, :profile_id => @profile.id)
  39 + article2 = fast_create(TinyMceArticle, :parent_id => @page.id, :profile_id => @profile.id)
  40 + get :view_page, @page.url
  41 + assert_tag 'div', :attributes => {:id => "context_content_#{@block.id}", :class => 'contents'}
  42 + assert_tag 'div', :attributes => {:id => "context_content_more_#{@block.id}", :class => 'more_button'}, :descendant => {:tag => 'a', :attributes => {:class => 'button icon-button icon-left disabled'} }
  43 + assert_tag 'div', :attributes => {:id => "context_content_more_#{@block.id}", :class => 'more_button'}, :descendant => {:tag => 'a', :attributes => {:class => 'button icon-button icon-right'} }
  44 + end
  45 +
  46 +end
... ...
plugins/context_content/test/functional/context_content_plugin_profile_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,43 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class ContextContentPluginProfileControllerTest < ActionController::TestCase
  4 +
  5 + class ContextContentPluginProfileController; def rescue_action(e) raise e end; end
  6 +
  7 + def setup
  8 + @profile = fast_create(Community)
  9 + @block = ContextContentBlock.new
  10 + @block.types = ['TinyMceArticle']
  11 + @block.limit = 1
  12 + @block.save!
  13 + @page = fast_create(Folder, :profile_id => @profile.id)
  14 + end
  15 +
  16 + should 'render response error if contents is nil' do
  17 + xhr :get, :view_content, :id => @block.id, :article_id => @page.id, :page => 1, :profile => @profile.identifier
  18 + assert_response 500
  19 + end
  20 +
  21 + should 'render error if page do not exists' do
  22 + article = fast_create(TinyMceArticle, :parent_id => @page.id, :profile_id => @profile.id)
  23 + xhr :get, :view_content, :id => @block.id, :article_id => @page.id, :page => 2, :profile => @profile.identifier
  24 + assert_response 500
  25 + end
  26 +
  27 + should 'replace div with content for page passed as parameter' do
  28 + article1 = fast_create(TinyMceArticle, :parent_id => @page.id, :profile_id => @profile.id, :name => 'article1')
  29 + article2 = fast_create(TinyMceArticle, :parent_id => @page.id, :profile_id => @profile.id, :name => 'article2')
  30 + xhr :get, :view_content, :id => @block.id, :article_id => @page.id, :page => 2, :profile => @profile.identifier
  31 + assert_response :success
  32 + assert_match /context_content_#{@block.id}/, @response.body
  33 + assert_match /context_content_more_#{@block.id}/, @response.body
  34 + assert_match /article2/, @response.body
  35 + end
  36 +
  37 + should 'do not render pagination buttons if it has only one page' do
  38 + article1 = fast_create(TinyMceArticle, :parent_id => @page.id, :profile_id => @profile.id, :name => 'article1')
  39 + xhr :get, :view_content, :id => @block.id, :article_id => @page.id, :page => 2, :profile => @profile.identifier
  40 + assert_no_match /context_content_more_#{@block.id}/, @response.body
  41 + end
  42 +
  43 +end
... ...
plugins/context_content/test/functional/profile_design_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,54 @@
  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 = ['ContextContentPlugin']
  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 = ContextContentBlock.new(:box => box)
  23 + @block.types = ['TinyMceArticle']
  24 + @block.limit = 1
  25 + @block.save!
  26 +
  27 + user = create_user('testinguser')
  28 + @profile.add_admin(user.person)
  29 + login_as(user.login)
  30 + end
  31 +
  32 + should 'be able to edit context content block' do
  33 + get :edit, :id => @block.id, :profile => @profile.identifier
  34 + assert_tag :tag => 'input', :attributes => { :id => 'block_title' }
  35 + assert_tag :tag => 'input', :attributes => { :id => 'block_show_image' }
  36 + assert_tag :tag => 'input', :attributes => { :id => 'block_show_name' }
  37 + assert_tag :tag => 'input', :attributes => { :id => 'block_show_parent_content' }
  38 + assert_tag :tag => 'input', :attributes => { :id => 'block_types' }
  39 + end
  40 +
  41 + should 'be able to save TrackListBlock' do
  42 + @block.show_image = false
  43 + @block.show_name = false
  44 + @block.show_parent_content = false
  45 + @block.save!
  46 + get :edit, :id => @block.id, :profile => @profile.identifier
  47 + post :save, :id => @block.id, :block => {:title => 'context', :show_image => '0', :show_name => '0', :show_parent_content => '0', :types => ['TinyMceArticle', '', nil, 'Folder'] }, :profile => @profile.identifier
  48 + @block.reload
  49 + assert_equal 'context', @block.title
  50 + assert !@block.show_image && !@block.show_name && !@block.show_parent_content
  51 + assert_equal ['TinyMceArticle', 'Folder'], @block.types
  52 + end
  53 +
  54 +end
... ...
plugins/context_content/views/blocks/_more.rhtml
1 1 <% if contents.total_pages > 1 %>
2   - <%= link_to_remote(nil, :url => {:id => block.id, :controller => 'context_content_plugin_profile', :action => 'view_content', :page => contents.previous_page, :article_id => article_id }, :html => {:class => "button icon-button icon-left #{contents.previous_page ? '':'disabled'}"}, :condition => "#{!contents.previous_page.nil?}", :success => "jQuery('#context_content_#{block.id}').effect('slide', {direction: 'left'});" )%>
3   - <%= link_to_remote(nil, :url => {:id => block.id, :controller => 'context_content_plugin_profile', :action => 'view_content', :page => contents.next_page, :article_id => article_id }, :html => {:class => "button icon-button icon-right #{contents.next_page ? '':'disabled'}"}, :condition => "#{!contents.next_page.nil?}", :success => "jQuery('#context_content_#{block.id}').effect('slide', {direction: 'right'});" )%>
  2 + <%= link_to_remote(nil, :url => {:id => block.id, :controller => 'context_content_plugin_profile', :action => 'view_content', :page => contents.previous_page, :article_id => article_id }, :html => {:class => "button icon-button icon-left #{contents.previous_page ? '':'disabled'}".strip}, :condition => "#{!contents.previous_page.nil?}", :success => "jQuery('#context_content_#{block.id}').effect('slide', {direction: 'left'});" )%>
  3 + <%= link_to_remote(nil, :url => {:id => block.id, :controller => 'context_content_plugin_profile', :action => 'view_content', :page => contents.next_page, :article_id => article_id }, :html => {:class => "button icon-button icon-right #{contents.next_page ? '':'disabled'}".strip}, :condition => "#{!contents.next_page.nil?}", :success => "jQuery('#context_content_#{block.id}').effect('slide', {direction: 'right'});" )%>
4 4 <% end %>
... ...