Commit 01f848b00a98e9c6d488f14d76bf8192be3f7196

Authored by AurelioAHeckert
1 parent 7a67c87d

ActionItem336: testing the html and the local file references

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1697 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing 32 changed files with 301 additions and 0 deletions   Show diff stats
test/functional/account_controller_test.rb
... ... @@ -17,6 +17,14 @@ class AccountControllerTest < Test::Unit::TestCase
17 17 @response = ActionController::TestResponse.new
18 18 end
19 19  
  20 + def test_local_files_reference
  21 + assert_local_files_reference
  22 + end
  23 +
  24 + def test_valid_xhtml
  25 + assert_valid_xhtml
  26 + end
  27 +
20 28 def test_should_login_and_redirect
21 29 post :login, :user => {:login => 'johndoe', :password => 'test'}
22 30 assert session[:user]
... ...
test/functional/admin_controller_test.rb
... ... @@ -11,6 +11,14 @@ class AdminControllerTest < Test::Unit::TestCase
11 11 @response = ActionController::TestResponse.new
12 12 end
13 13  
  14 + def test_local_files_reference
  15 + assert_local_files_reference
  16 + end
  17 +
  18 + def test_valid_xhtml
  19 + assert_valid_xhtml
  20 + end
  21 +
14 22 # Replace this with your real tests.
15 23 def test_truth
16 24 assert true
... ...
test/functional/admin_panel_controller_test.rb
... ... @@ -14,6 +14,14 @@ class AdminPanelControllerTest < Test::Unit::TestCase
14 14 login_as(create_admin_user(Environment.default))
15 15 end
16 16  
  17 + def test_local_files_reference
  18 + assert_local_files_reference
  19 + end
  20 +
  21 + def test_valid_xhtml
  22 + assert_valid_xhtml
  23 + end
  24 +
17 25 def test_index
18 26 get :index
19 27 assert_template 'index'
... ...
test/functional/application_controller_test.rb
... ... @@ -12,6 +12,14 @@ class ApplicationControllerTest < Test::Unit::TestCase
12 12 @response = ActionController::TestResponse.new
13 13 end
14 14  
  15 + def test_local_files_reference
  16 + assert_local_files_reference
  17 + end
  18 +
  19 + def test_valid_xhtml
  20 + assert_valid_xhtml
  21 + end
  22 +
15 23 def test_exist_environment_variable_to_helper_environment_identification
16 24 get :index
17 25 assert_not_nil assigns(:environment)
... ...
test/functional/catalog_controller_test.rb
... ... @@ -11,6 +11,14 @@ class CatalogControllerTest < Test::Unit::TestCase
11 11 @response = ActionController::TestResponse.new
12 12 end
13 13  
  14 + def test_local_files_reference
  15 + assert_local_files_reference
  16 + end
  17 +
  18 + def test_valid_xhtml
  19 + assert_valid_xhtml
  20 + end
  21 +
14 22 should 'list products of enterprise' do
15 23 ent = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1')
16 24 get :index, :profile => ent.identifier
... ...
test/functional/categories_controller_test.rb
... ... @@ -20,6 +20,14 @@ class CategoriesControllerTest < Test::Unit::TestCase
20 20  
21 21 attr_reader :env, :cat1, :cat2
22 22  
  23 + def test_local_files_reference
  24 + assert_local_files_reference
  25 + end
  26 +
  27 + def test_valid_xhtml
  28 + assert_valid_xhtml
  29 + end
  30 +
23 31 def test_index
24 32 assert user = login_as(create_admin_user(Environment.default))
25 33 assert user.person.has_permission?('manage_environment_categories',Environment.default ), "#{user.login} don't have permission to manage_environment_categories in #{Environment.default.name}"
... ...
test/functional/cms_controller_test.rb
... ... @@ -19,6 +19,14 @@ class CmsControllerTest < Test::Unit::TestCase
19 19  
20 20 attr_reader :profile
21 21  
  22 + def test_local_files_reference
  23 + assert_local_files_reference
  24 + end
  25 +
  26 + def test_valid_xhtml
  27 + assert_valid_xhtml
  28 + end
  29 +
22 30 should 'list top level documents on index' do
23 31 get :index, :profile => profile.identifier
24 32  
... ...
test/functional/consumed_products_controller_test.rb
... ... @@ -17,6 +17,14 @@ class ConsumedProductsControllerTest < Test::Unit::TestCase
17 17 end
18 18 attr_reader :profile
19 19  
  20 + def test_local_files_reference
  21 + assert_local_files_reference
  22 + end
  23 +
  24 + def test_valid_xhtml
  25 + assert_valid_xhtml
  26 + end
  27 +
20 28 should 'display new form' do
21 29 login_as(profile.identifier)
22 30 get :new, :profile => profile.identifier
... ...
test/functional/content_viewer_controller_test.rb
... ... @@ -17,6 +17,14 @@ class ContentViewerControllerTest < Test::Unit::TestCase
17 17 end
18 18 attr_reader :profile
19 19  
  20 + def test_local_files_reference
  21 + assert_local_files_reference
  22 + end
  23 +
  24 + def test_valid_xhtml
  25 + assert_valid_xhtml
  26 + end
  27 +
20 28 def test_should_display_page
21 29 page = profile.articles.build(:name => 'test')
22 30 page.save!
... ...
test/functional/edit_template_controller_test.rb
... ... @@ -15,6 +15,14 @@ class EditTemplateControllerTest < Test::Unit::TestCase
15 15 login_as 'ze'
16 16 end
17 17  
  18 + def test_local_files_reference
  19 + assert_local_files_reference
  20 + end
  21 +
  22 + def test_valid_xhtml
  23 + assert_valid_xhtml
  24 + end
  25 +
18 26 def test_redirect_to_design_editor_when_index_action_is_called
19 27 give_permission('ze', 'edit_environment_design', Environment.default)
20 28 get :index
... ...
test/functional/enterprise_editor_controller_test.rb
... ... @@ -11,6 +11,14 @@ class EnterpriseEditorControllerTest < Test::Unit::TestCase
11 11 @response = ActionController::TestResponse.new
12 12 end
13 13  
  14 + def test_local_files_reference
  15 + assert_local_files_reference
  16 + end
  17 +
  18 + def test_valid_xhtml
  19 + assert_valid_xhtml
  20 + end
  21 +
14 22 should 'not see index if do not logged in' do
15 23 ent1 = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1')
16 24 get 'index', :profile => 'test_enterprise1'
... ...
test/functional/enterprise_registration_controller_test.rb
... ... @@ -15,6 +15,14 @@ all_fixtures
15 15 login_as 'ze'
16 16 end
17 17  
  18 + def test_local_files_reference
  19 + assert_local_files_reference
  20 + end
  21 +
  22 + def test_valid_xhtml
  23 + assert_valid_xhtml
  24 + end
  25 +
18 26 should 'go to the first step on index' do
19 27 get :index
20 28 assert_response :success
... ...
test/functional/enterprise_validation_test.rb
... ... @@ -19,6 +19,14 @@ class EnterpriseValidationControllerTest < Test::Unit::TestCase
19 19 Profile.expects(:find_by_identifier).with('myorg').returns(@org).at_least_once
20 20 end
21 21  
  22 + def test_local_files_reference
  23 + assert_local_files_reference
  24 + end
  25 +
  26 + def test_valid_xhtml
  27 + assert_valid_xhtml
  28 + end
  29 +
22 30 should 'list pending validations on index' do
23 31 empty = []
24 32 @org.expects(:pending_validations).returns(empty)
... ...
test/functional/environment_design_controller_test.rb
... ... @@ -11,6 +11,14 @@ class EnvironmentDesignControllerTest < Test::Unit::TestCase
11 11 @response = ActionController::TestResponse.new
12 12 end
13 13  
  14 + def test_local_files_reference
  15 + assert_local_files_reference
  16 + end
  17 +
  18 + def test_valid_xhtml
  19 + assert_valid_xhtml
  20 + end
  21 +
14 22 should 'indicate only actual blocks as such' do
15 23 assert(@controller.available_blocks.all? {|item| item.new.is_a? Block})
16 24 end
... ...
test/functional/environment_role_manager_controller_test.rb
... ... @@ -11,6 +11,14 @@ class EnvironmentRoleManagerControllerTest < Test::Unit::TestCase
11 11 @response = ActionController::TestResponse.new
12 12 end
13 13  
  14 + def test_local_files_reference
  15 + assert_local_files_reference
  16 + end
  17 +
  18 + def test_valid_xhtml
  19 + assert_valid_xhtml
  20 + end
  21 +
14 22 # Replace this with your real tests.
15 23 def test_truth
16 24 assert true
... ...
test/functional/features_controller_test.rb
... ... @@ -14,6 +14,14 @@ class FeaturesControllerTest < Test::Unit::TestCase
14 14 login_as(create_admin_user(Environment.find(2)))
15 15 end
16 16  
  17 + def test_local_files_reference
  18 + assert_local_files_reference
  19 + end
  20 +
  21 + def test_valid_xhtml
  22 + assert_valid_xhtml
  23 + end
  24 +
17 25 def test_listing_features
18 26 uses_host 'anhetegua.net'
19 27 get :index
... ...
test/functional/friends_controller_test.rb
... ... @@ -18,6 +18,14 @@ class FriendsControllerTest < Test::Unit::TestCase
18 18 end
19 19 attr_accessor :profile, :friend
20 20  
  21 + def test_local_files_reference
  22 + assert_local_files_reference
  23 + end
  24 +
  25 + def test_valid_xhtml
  26 + assert_valid_xhtml
  27 + end
  28 +
21 29 should 'list friends' do
22 30 get :index
23 31 assert_response :success
... ...
test/functional/home_controller_test.rb
... ... @@ -14,6 +14,14 @@ all_fixtures
14 14 @response = ActionController::TestResponse.new
15 15 end
16 16  
  17 + def test_local_files_reference
  18 + assert_local_files_reference
  19 + end
  20 +
  21 + def test_valid_xhtml
  22 + assert_valid_xhtml
  23 + end
  24 +
17 25 def test_detection_of_environment_by_host
18 26 uses_host 'www.colivre.net'
19 27 get :index
... ...
test/functional/manage_products_controller_test.rb
... ... @@ -15,6 +15,14 @@ class ManageProductsControllerTest < Test::Unit::TestCase
15 15 login_as :test_user
16 16 end
17 17  
  18 + def test_local_files_reference
  19 + assert_local_files_reference
  20 + end
  21 +
  22 + def test_valid_xhtml
  23 + assert_valid_xhtml
  24 + end
  25 +
18 26 should "not have permission" do
19 27 u = create_user('user_test')
20 28 login_as :user_test
... ...
test/functional/memberships_controller_test.rb
... ... @@ -16,6 +16,14 @@ class MembershipsControllerTest < Test::Unit::TestCase
16 16 end
17 17 attr_reader :profile
18 18  
  19 + def test_local_files_reference
  20 + assert_local_files_reference
  21 + end
  22 +
  23 + def test_valid_xhtml
  24 + assert_valid_xhtml
  25 + end
  26 +
19 27 should 'list current memberships' do
20 28 get :index, :profile => profile.identifier
21 29  
... ...
test/functional/my_profile_controller_test.rb
... ... @@ -20,6 +20,14 @@ class MyProfileControllerTest < Test::Unit::TestCase
20 20 @response = ActionController::TestResponse.new
21 21 end
22 22  
  23 + def test_local_files_reference
  24 + assert_local_files_reference
  25 + end
  26 +
  27 + def test_valid_xhtml
  28 + assert_valid_xhtml
  29 + end
  30 +
23 31 def test_should_allow_person
24 32 @controller = OnlyForPersonTestController.new
25 33 person = create_user('random_joe')
... ...
test/functional/profile_controller_test.rb
... ... @@ -13,6 +13,14 @@ class ProfileControllerTest < Test::Unit::TestCase
13 13 @profile = create_user('testuser').person
14 14 end
15 15  
  16 + def test_local_files_reference
  17 + assert_local_files_reference
  18 + end
  19 +
  20 + def test_valid_xhtml
  21 + assert_valid_xhtml
  22 + end
  23 +
16 24 noosfero_test :profile => 'testuser'
17 25  
18 26 should 'list friends' do
... ...
test/functional/profile_design_controller_test.rb
... ... @@ -62,6 +62,14 @@ class ProfileDesignControllerTest < Test::Unit::TestCase
62 62 login_as 'ze'
63 63 end
64 64  
  65 + def test_local_files_reference
  66 + assert_local_files_reference
  67 + end
  68 +
  69 + def test_valid_xhtml
  70 + assert_valid_xhtml
  71 + end
  72 +
65 73 ######################################################
66 74 # BEGIN - tests for BoxOrganizerController features
67 75 ######################################################
... ...
test/functional/profile_editor_controller_test.rb
... ... @@ -14,6 +14,14 @@ class ProfileEditorControllerTest < Test::Unit::TestCase
14 14 login_as('ze')
15 15 end
16 16  
  17 + def test_local_files_reference
  18 + assert_local_files_reference
  19 + end
  20 +
  21 + def test_valid_xhtml
  22 + assert_valid_xhtml
  23 + end
  24 +
17 25 def test_index
18 26 person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person
19 27 person.person_info.name = 'a test profile'
... ...
test/functional/profile_members_controller_test.rb
... ... @@ -11,6 +11,14 @@ class ProfileMembersControllerTest < Test::Unit::TestCase
11 11 @response = ActionController::TestResponse.new
12 12 end
13 13  
  14 + def test_local_files_reference
  15 + assert_local_files_reference
  16 + end
  17 +
  18 + def test_valid_xhtml
  19 + assert_valid_xhtml
  20 + end
  21 +
14 22 should 'not access index if dont have permission' do
15 23 user = create_user('test_user')
16 24 Enterprise.create!(:identifier => 'test_enterprise', :name => 'test enterprise')
... ...
test/functional/public_controller_test.rb
... ... @@ -5,14 +5,24 @@ require 'public_controller'
5 5 class PublicController; def rescue_action(e) raise e end; end
6 6  
7 7 class PublicControllerTest < Test::Unit::TestCase
  8 +
8 9 def setup
9 10 @controller = PublicController.new
10 11 @request = ActionController::TestRequest.new
11 12 @response = ActionController::TestResponse.new
12 13 end
13 14  
  15 + def test_local_files_reference
  16 + assert_local_files_reference
  17 + end
  18 +
  19 + def test_valid_xhtml
  20 + assert_valid_xhtml
  21 + end
  22 +
14 23 # Replace this with your real tests.
15 24 def test_truth
16 25 assert true
17 26 end
  27 +
18 28 end
... ...
test/functional/region_validators_controller_test.rb
... ... @@ -13,6 +13,14 @@ class RegionValidatorsControllerTest &lt; Test::Unit::TestCase
13 13 login_as('ze')
14 14 end
15 15  
  16 + def test_local_files_reference
  17 + assert_local_files_reference
  18 + end
  19 +
  20 + def test_valid_xhtml
  21 + assert_valid_xhtml
  22 + end
  23 +
16 24 # Replace this with your real tests.
17 25 should 'list regions at index' do
18 26 get :index
... ...
test/functional/role_controller_test.rb
... ... @@ -15,6 +15,14 @@ class RoleControllerTest &lt; Test::Unit::TestCase
15 15 login_as(:ze)
16 16 end
17 17  
  18 + def test_local_files_reference
  19 + assert_local_files_reference
  20 + end
  21 +
  22 + def test_valid_xhtml
  23 + assert_valid_xhtml
  24 + end
  25 +
18 26 def test_index_should_get_roles
19 27 get 'index'
20 28 assert_response :success
... ...
test/functional/search_controller_test.rb
... ... @@ -13,6 +13,14 @@ class SearchControllerTest &lt; Test::Unit::TestCase
13 13 @category = Category.create!(:name => 'my category', :environment => Environment.default)
14 14 end
15 15  
  16 + def test_local_files_reference
  17 + assert_local_files_reference
  18 + end
  19 +
  20 + def test_valid_xhtml
  21 + assert_valid_xhtml
  22 + end
  23 +
16 24 should 'filter stop words' do
17 25 @controller.expects(:locale).returns('pt_BR').at_least_once
18 26 get 'index', :query => 'a carne da vaca'
... ...
test/functional/system_controller_test.rb
... ... @@ -11,6 +11,14 @@ class SystemControllerTest &lt; Test::Unit::TestCase
11 11 @response = ActionController::TestResponse.new
12 12 end
13 13  
  14 + def test_local_files_reference
  15 + assert_local_files_reference
  16 + end
  17 +
  18 + def test_valid_xhtml
  19 + assert_valid_xhtml
  20 + end
  21 +
14 22 # Replace this with your real tests.
15 23 def test_truth
16 24 assert true
... ...
test/functional/tasks_controller_test.rb
... ... @@ -18,6 +18,14 @@ class TasksControllerTest &lt; Test::Unit::TestCase
18 18 end
19 19 attr_accessor :profile
20 20  
  21 + def test_local_files_reference
  22 + assert_local_files_reference
  23 + end
  24 +
  25 + def test_valid_xhtml
  26 + assert_valid_xhtml
  27 + end
  28 +
21 29 should 'list pending tasks' do
22 30 get :index
23 31  
... ...
test/test_helper.rb
... ... @@ -2,6 +2,8 @@ ENV[&quot;RAILS_ENV&quot;] = &quot;test&quot;
2 2 require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
3 3 require 'test_help'
4 4 require 'mocha'
  5 +require 'tidy'
  6 +require 'hpricot'
5 7  
6 8 require 'noosfero/test'
7 9  
... ... @@ -135,6 +137,55 @@ class Test::Unit::TestCase
135 137 assert_equal parent, child.superclass, "Class #{child} expected to be a subclass of #{parent}"
136 138 end
137 139  
  140 + def assert_valid_xhtml(method=:get, action=:index, params = {})
  141 + if method.to_s() == 'post'
  142 + post action, params
  143 + else
  144 + get action, params
  145 + end
  146 + tidy = Tidy.open(:show_warnings=>false)
  147 + tidy.options.output_xml = true
  148 + tidy.clean @response.body
  149 + if tidy.errors
  150 + flunk "HTML ERROR - Tidy Diagnostics:\n "+
  151 + tidy.errors.join("\n ") +"\n "+
  152 + tidy.diagnostics.join("\n ")
  153 + end
  154 + end
  155 +
  156 + def assert_local_files_reference(method=:get, action=:index, params = {})
  157 + if method.to_s() == 'post'
  158 + post action, params
  159 + else
  160 + get action, params
  161 + end
  162 + doc = Hpricot @response.body
  163 +
  164 + # Test style references:
  165 + (doc/'style').each do |s|
  166 + s = s.to_s().gsub( /\/\*.*\*\//, '' ).
  167 + split( /;|<|>|\n/ ).
  168 + map do |l|
  169 + patch = l.match( /@import url\((.*)\)/ )
  170 + patch ? patch[1] : nil
  171 + end.compact
  172 + s.each do |css_ref|
  173 + if ! File.exists?( RAILS_ROOT.to_s() +'/public/'+ css_ref )
  174 + flunk 'CSS reference missed on HTML: "%s"' % css_ref
  175 + end
  176 + end
  177 + end
  178 +
  179 + # Test image references:
  180 + (doc/'img').each do |img|
  181 + src = img.get_attribute( 'src' )
  182 + if ! File.exists?( RAILS_ROOT.to_s() +'/public/'+ src )
  183 + flunk 'Image reference missed on HTML: "%s"' % src
  184 + end
  185 + end
  186 +
  187 + end
  188 +
138 189 # this check only if string has html tag
139 190 def assert_sanitized(string)
140 191 assert_no_match /<[^>]+\/?>/, string, "String #{string} expected to be sanitized"
... ...