From 01f848b00a98e9c6d488f14d76bf8192be3f7196 Mon Sep 17 00:00:00 2001 From: AurelioAHeckert Date: Thu, 24 Apr 2008 22:33:51 +0000 Subject: [PATCH] ActionItem336: testing the html and the local file references --- test/functional/account_controller_test.rb | 8 ++++++++ test/functional/admin_controller_test.rb | 8 ++++++++ test/functional/admin_panel_controller_test.rb | 8 ++++++++ test/functional/application_controller_test.rb | 8 ++++++++ test/functional/catalog_controller_test.rb | 8 ++++++++ test/functional/categories_controller_test.rb | 8 ++++++++ test/functional/cms_controller_test.rb | 8 ++++++++ test/functional/consumed_products_controller_test.rb | 8 ++++++++ test/functional/content_viewer_controller_test.rb | 8 ++++++++ test/functional/edit_template_controller_test.rb | 8 ++++++++ test/functional/enterprise_editor_controller_test.rb | 8 ++++++++ test/functional/enterprise_registration_controller_test.rb | 8 ++++++++ test/functional/enterprise_validation_test.rb | 8 ++++++++ test/functional/environment_design_controller_test.rb | 8 ++++++++ test/functional/environment_role_manager_controller_test.rb | 8 ++++++++ test/functional/features_controller_test.rb | 8 ++++++++ test/functional/friends_controller_test.rb | 8 ++++++++ test/functional/home_controller_test.rb | 8 ++++++++ test/functional/manage_products_controller_test.rb | 8 ++++++++ test/functional/memberships_controller_test.rb | 8 ++++++++ test/functional/my_profile_controller_test.rb | 8 ++++++++ test/functional/profile_controller_test.rb | 8 ++++++++ test/functional/profile_design_controller_test.rb | 8 ++++++++ test/functional/profile_editor_controller_test.rb | 8 ++++++++ test/functional/profile_members_controller_test.rb | 8 ++++++++ test/functional/public_controller_test.rb | 10 ++++++++++ test/functional/region_validators_controller_test.rb | 8 ++++++++ test/functional/role_controller_test.rb | 8 ++++++++ test/functional/search_controller_test.rb | 8 ++++++++ test/functional/system_controller_test.rb | 8 ++++++++ test/functional/tasks_controller_test.rb | 8 ++++++++ test/test_helper.rb | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 32 files changed, 301 insertions(+), 0 deletions(-) diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb index d426027..fc5aa3f 100644 --- a/test/functional/account_controller_test.rb +++ b/test/functional/account_controller_test.rb @@ -17,6 +17,14 @@ class AccountControllerTest < Test::Unit::TestCase @response = ActionController::TestResponse.new end + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + def test_should_login_and_redirect post :login, :user => {:login => 'johndoe', :password => 'test'} assert session[:user] diff --git a/test/functional/admin_controller_test.rb b/test/functional/admin_controller_test.rb index e44ac94..08cf8be 100644 --- a/test/functional/admin_controller_test.rb +++ b/test/functional/admin_controller_test.rb @@ -11,6 +11,14 @@ class AdminControllerTest < Test::Unit::TestCase @response = ActionController::TestResponse.new end + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + # Replace this with your real tests. def test_truth assert true diff --git a/test/functional/admin_panel_controller_test.rb b/test/functional/admin_panel_controller_test.rb index f53bafc..31aaf04 100644 --- a/test/functional/admin_panel_controller_test.rb +++ b/test/functional/admin_panel_controller_test.rb @@ -14,6 +14,14 @@ class AdminPanelControllerTest < Test::Unit::TestCase login_as(create_admin_user(Environment.default)) end + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + def test_index get :index assert_template 'index' diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb index 16209f6..4feef02 100644 --- a/test/functional/application_controller_test.rb +++ b/test/functional/application_controller_test.rb @@ -12,6 +12,14 @@ class ApplicationControllerTest < Test::Unit::TestCase @response = ActionController::TestResponse.new end + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + def test_exist_environment_variable_to_helper_environment_identification get :index assert_not_nil assigns(:environment) diff --git a/test/functional/catalog_controller_test.rb b/test/functional/catalog_controller_test.rb index e9a8ed8..82a04b8 100644 --- a/test/functional/catalog_controller_test.rb +++ b/test/functional/catalog_controller_test.rb @@ -11,6 +11,14 @@ class CatalogControllerTest < Test::Unit::TestCase @response = ActionController::TestResponse.new end + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + should 'list products of enterprise' do ent = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1') get :index, :profile => ent.identifier diff --git a/test/functional/categories_controller_test.rb b/test/functional/categories_controller_test.rb index b03a0c6..717c9be 100644 --- a/test/functional/categories_controller_test.rb +++ b/test/functional/categories_controller_test.rb @@ -20,6 +20,14 @@ class CategoriesControllerTest < Test::Unit::TestCase attr_reader :env, :cat1, :cat2 + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + def test_index assert user = login_as(create_admin_user(Environment.default)) assert user.person.has_permission?('manage_environment_categories',Environment.default ), "#{user.login} don't have permission to manage_environment_categories in #{Environment.default.name}" diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index b3d51df..56163a5 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -19,6 +19,14 @@ class CmsControllerTest < Test::Unit::TestCase attr_reader :profile + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + should 'list top level documents on index' do get :index, :profile => profile.identifier diff --git a/test/functional/consumed_products_controller_test.rb b/test/functional/consumed_products_controller_test.rb index e131b8f..92f8d5a 100644 --- a/test/functional/consumed_products_controller_test.rb +++ b/test/functional/consumed_products_controller_test.rb @@ -17,6 +17,14 @@ class ConsumedProductsControllerTest < Test::Unit::TestCase end attr_reader :profile + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + should 'display new form' do login_as(profile.identifier) get :new, :profile => profile.identifier diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index 43904a4..a30f8ad 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -17,6 +17,14 @@ class ContentViewerControllerTest < Test::Unit::TestCase end attr_reader :profile + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + def test_should_display_page page = profile.articles.build(:name => 'test') page.save! diff --git a/test/functional/edit_template_controller_test.rb b/test/functional/edit_template_controller_test.rb index 4eabc44..fb096f2 100644 --- a/test/functional/edit_template_controller_test.rb +++ b/test/functional/edit_template_controller_test.rb @@ -15,6 +15,14 @@ class EditTemplateControllerTest < Test::Unit::TestCase login_as 'ze' end + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + def test_redirect_to_design_editor_when_index_action_is_called give_permission('ze', 'edit_environment_design', Environment.default) get :index diff --git a/test/functional/enterprise_editor_controller_test.rb b/test/functional/enterprise_editor_controller_test.rb index 4700560..690d1f1 100644 --- a/test/functional/enterprise_editor_controller_test.rb +++ b/test/functional/enterprise_editor_controller_test.rb @@ -11,6 +11,14 @@ class EnterpriseEditorControllerTest < Test::Unit::TestCase @response = ActionController::TestResponse.new end + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + should 'not see index if do not logged in' do ent1 = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1') get 'index', :profile => 'test_enterprise1' diff --git a/test/functional/enterprise_registration_controller_test.rb b/test/functional/enterprise_registration_controller_test.rb index 1e1173e..0f02482 100644 --- a/test/functional/enterprise_registration_controller_test.rb +++ b/test/functional/enterprise_registration_controller_test.rb @@ -15,6 +15,14 @@ all_fixtures login_as 'ze' end + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + should 'go to the first step on index' do get :index assert_response :success diff --git a/test/functional/enterprise_validation_test.rb b/test/functional/enterprise_validation_test.rb index 55eed40..829aba3 100644 --- a/test/functional/enterprise_validation_test.rb +++ b/test/functional/enterprise_validation_test.rb @@ -19,6 +19,14 @@ class EnterpriseValidationControllerTest < Test::Unit::TestCase Profile.expects(:find_by_identifier).with('myorg').returns(@org).at_least_once end + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + should 'list pending validations on index' do empty = [] @org.expects(:pending_validations).returns(empty) diff --git a/test/functional/environment_design_controller_test.rb b/test/functional/environment_design_controller_test.rb index bcd127c..d5e7acf 100644 --- a/test/functional/environment_design_controller_test.rb +++ b/test/functional/environment_design_controller_test.rb @@ -11,6 +11,14 @@ class EnvironmentDesignControllerTest < Test::Unit::TestCase @response = ActionController::TestResponse.new end + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + should 'indicate only actual blocks as such' do assert(@controller.available_blocks.all? {|item| item.new.is_a? Block}) end diff --git a/test/functional/environment_role_manager_controller_test.rb b/test/functional/environment_role_manager_controller_test.rb index e5adc1c..3305178 100644 --- a/test/functional/environment_role_manager_controller_test.rb +++ b/test/functional/environment_role_manager_controller_test.rb @@ -11,6 +11,14 @@ class EnvironmentRoleManagerControllerTest < Test::Unit::TestCase @response = ActionController::TestResponse.new end + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + # Replace this with your real tests. def test_truth assert true diff --git a/test/functional/features_controller_test.rb b/test/functional/features_controller_test.rb index e214344..b06b159 100644 --- a/test/functional/features_controller_test.rb +++ b/test/functional/features_controller_test.rb @@ -14,6 +14,14 @@ class FeaturesControllerTest < Test::Unit::TestCase login_as(create_admin_user(Environment.find(2))) end + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + def test_listing_features uses_host 'anhetegua.net' get :index diff --git a/test/functional/friends_controller_test.rb b/test/functional/friends_controller_test.rb index ac2f2ba..6cef61e 100644 --- a/test/functional/friends_controller_test.rb +++ b/test/functional/friends_controller_test.rb @@ -18,6 +18,14 @@ class FriendsControllerTest < Test::Unit::TestCase end attr_accessor :profile, :friend + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + should 'list friends' do get :index assert_response :success diff --git a/test/functional/home_controller_test.rb b/test/functional/home_controller_test.rb index 9d07b8d..34a1ebe 100644 --- a/test/functional/home_controller_test.rb +++ b/test/functional/home_controller_test.rb @@ -14,6 +14,14 @@ all_fixtures @response = ActionController::TestResponse.new end + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + def test_detection_of_environment_by_host uses_host 'www.colivre.net' get :index diff --git a/test/functional/manage_products_controller_test.rb b/test/functional/manage_products_controller_test.rb index 4381608..b138769 100644 --- a/test/functional/manage_products_controller_test.rb +++ b/test/functional/manage_products_controller_test.rb @@ -15,6 +15,14 @@ class ManageProductsControllerTest < Test::Unit::TestCase login_as :test_user end + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + should "not have permission" do u = create_user('user_test') login_as :user_test diff --git a/test/functional/memberships_controller_test.rb b/test/functional/memberships_controller_test.rb index f80314c..2167aeb 100644 --- a/test/functional/memberships_controller_test.rb +++ b/test/functional/memberships_controller_test.rb @@ -16,6 +16,14 @@ class MembershipsControllerTest < Test::Unit::TestCase end attr_reader :profile + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + should 'list current memberships' do get :index, :profile => profile.identifier diff --git a/test/functional/my_profile_controller_test.rb b/test/functional/my_profile_controller_test.rb index 1f12dbd..b0b9289 100644 --- a/test/functional/my_profile_controller_test.rb +++ b/test/functional/my_profile_controller_test.rb @@ -20,6 +20,14 @@ class MyProfileControllerTest < Test::Unit::TestCase @response = ActionController::TestResponse.new end + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + def test_should_allow_person @controller = OnlyForPersonTestController.new person = create_user('random_joe') diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index 58402c5..d749845 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -13,6 +13,14 @@ class ProfileControllerTest < Test::Unit::TestCase @profile = create_user('testuser').person end + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + noosfero_test :profile => 'testuser' should 'list friends' do diff --git a/test/functional/profile_design_controller_test.rb b/test/functional/profile_design_controller_test.rb index 6cfe1e0..001635f 100644 --- a/test/functional/profile_design_controller_test.rb +++ b/test/functional/profile_design_controller_test.rb @@ -62,6 +62,14 @@ class ProfileDesignControllerTest < Test::Unit::TestCase login_as 'ze' end + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + ###################################################### # BEGIN - tests for BoxOrganizerController features ###################################################### diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb index f537475..fe9c0a0 100644 --- a/test/functional/profile_editor_controller_test.rb +++ b/test/functional/profile_editor_controller_test.rb @@ -14,6 +14,14 @@ class ProfileEditorControllerTest < Test::Unit::TestCase login_as('ze') end + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + def test_index person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person person.person_info.name = 'a test profile' diff --git a/test/functional/profile_members_controller_test.rb b/test/functional/profile_members_controller_test.rb index d647700..f001ac9 100644 --- a/test/functional/profile_members_controller_test.rb +++ b/test/functional/profile_members_controller_test.rb @@ -11,6 +11,14 @@ class ProfileMembersControllerTest < Test::Unit::TestCase @response = ActionController::TestResponse.new end + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + should 'not access index if dont have permission' do user = create_user('test_user') Enterprise.create!(:identifier => 'test_enterprise', :name => 'test enterprise') diff --git a/test/functional/public_controller_test.rb b/test/functional/public_controller_test.rb index 6b74720..acffc24 100644 --- a/test/functional/public_controller_test.rb +++ b/test/functional/public_controller_test.rb @@ -5,14 +5,24 @@ require 'public_controller' class PublicController; def rescue_action(e) raise e end; end class PublicControllerTest < Test::Unit::TestCase + def setup @controller = PublicController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new end + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + # Replace this with your real tests. def test_truth assert true end + end diff --git a/test/functional/region_validators_controller_test.rb b/test/functional/region_validators_controller_test.rb index 356b52a..32c5ffc 100644 --- a/test/functional/region_validators_controller_test.rb +++ b/test/functional/region_validators_controller_test.rb @@ -13,6 +13,14 @@ class RegionValidatorsControllerTest < Test::Unit::TestCase login_as('ze') end + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + # Replace this with your real tests. should 'list regions at index' do get :index diff --git a/test/functional/role_controller_test.rb b/test/functional/role_controller_test.rb index 78cf8a2..94109db 100644 --- a/test/functional/role_controller_test.rb +++ b/test/functional/role_controller_test.rb @@ -15,6 +15,14 @@ class RoleControllerTest < Test::Unit::TestCase login_as(:ze) end + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + def test_index_should_get_roles get 'index' assert_response :success diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index 9f4499d..c0a3140 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -13,6 +13,14 @@ class SearchControllerTest < Test::Unit::TestCase @category = Category.create!(:name => 'my category', :environment => Environment.default) end + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + should 'filter stop words' do @controller.expects(:locale).returns('pt_BR').at_least_once get 'index', :query => 'a carne da vaca' diff --git a/test/functional/system_controller_test.rb b/test/functional/system_controller_test.rb index d70d96a..cc739f3 100644 --- a/test/functional/system_controller_test.rb +++ b/test/functional/system_controller_test.rb @@ -11,6 +11,14 @@ class SystemControllerTest < Test::Unit::TestCase @response = ActionController::TestResponse.new end + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + # Replace this with your real tests. def test_truth assert true diff --git a/test/functional/tasks_controller_test.rb b/test/functional/tasks_controller_test.rb index 3875bc8..aa0d698 100644 --- a/test/functional/tasks_controller_test.rb +++ b/test/functional/tasks_controller_test.rb @@ -18,6 +18,14 @@ class TasksControllerTest < Test::Unit::TestCase end attr_accessor :profile + def test_local_files_reference + assert_local_files_reference + end + + def test_valid_xhtml + assert_valid_xhtml + end + should 'list pending tasks' do get :index diff --git a/test/test_helper.rb b/test/test_helper.rb index acb906c..c3b543b 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,6 +2,8 @@ ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'test_help' require 'mocha' +require 'tidy' +require 'hpricot' require 'noosfero/test' @@ -135,6 +137,55 @@ class Test::Unit::TestCase assert_equal parent, child.superclass, "Class #{child} expected to be a subclass of #{parent}" end + def assert_valid_xhtml(method=:get, action=:index, params = {}) + if method.to_s() == 'post' + post action, params + else + get action, params + end + tidy = Tidy.open(:show_warnings=>false) + tidy.options.output_xml = true + tidy.clean @response.body + if tidy.errors + flunk "HTML ERROR - Tidy Diagnostics:\n "+ + tidy.errors.join("\n ") +"\n "+ + tidy.diagnostics.join("\n ") + end + end + + def assert_local_files_reference(method=:get, action=:index, params = {}) + if method.to_s() == 'post' + post action, params + else + get action, params + end + doc = Hpricot @response.body + + # Test style references: + (doc/'style').each do |s| + s = s.to_s().gsub( /\/\*.*\*\//, '' ). + split( /;|<|>|\n/ ). + map do |l| + patch = l.match( /@import url\((.*)\)/ ) + patch ? patch[1] : nil + end.compact + s.each do |css_ref| + if ! File.exists?( RAILS_ROOT.to_s() +'/public/'+ css_ref ) + flunk 'CSS reference missed on HTML: "%s"' % css_ref + end + end + end + + # Test image references: + (doc/'img').each do |img| + src = img.get_attribute( 'src' ) + if ! File.exists?( RAILS_ROOT.to_s() +'/public/'+ src ) + flunk 'Image reference missed on HTML: "%s"' % src + end + end + + end + # this check only if string has html tag def assert_sanitized(string) assert_no_match /<[^>]+\/?>/, string, "String #{string} expected to be sanitized" -- libgit2 0.21.2