diff --git a/plugins/lattes_curriculum/features/lattes_curriculum.feature b/plugins/lattes_curriculum/features/lattes_curriculum.feature index 176cdab..f114cac 100644 --- a/plugins/lattes_curriculum/features/lattes_curriculum.feature +++ b/plugins/lattes_curriculum/features/lattes_curriculum.feature @@ -9,16 +9,53 @@ Feature: import lattes information And I go to /admin/plugins And I check "LattesCurriculumPlugin" And I press "Save changes" + And I go to /admin/features/manage_fields + Given I follow "Person's fields" + And I check "person_fields_lattes_url_active" + And I check "person_fields_lattes_url_signup" + And I press "save_person_fields" + And feature "skip_new_user_email_confirmation" is enabled on environment And I am not logged in @selenium Scenario: Import lattes informations after singup Given I am on signup page - And I fill in "e-Mail" with "josesilva@example.com" + When I fill in "e-Mail" with "josesilva@example.com" And I fill in "Username" with "josesilva" And I fill in "Full name" with "João Silva" And I fill in "Password" with "secret" And I fill in "Password confirmation" with "secret" - And I fill in "URL Lattes" with "http://lattes.cnpq.br/2864976228727880" + And I fill in "Lattes URL" with "http://lattes.cnpq.br/2864976228727880" And wait for the captcha signup time - And I press "Create my account" \ No newline at end of file + And I press "Create my account" + And I go to /profile/josesilva + And I follow "Lattes" within "#ui-tabs-anchor" + Then I should see "Endereço para acessar este CV: http://lattes.cnpq.br/2864976228727880" + + @selenium + Scenario: Don't show lattes informations for blank lattes urls + Given I am on signup page + When I fill in "e-Mail" with "josesilva@example.com" + And I fill in "Username" with "josesilva" + And I fill in "Full name" with "João Silva" + And I fill in "Password" with "secret" + And I fill in "Password confirmation" with "secret" + And wait for the captcha signup time + And I press "Create my account" + And I go to /profile/josesilva + Then I should not see "Lattes" within "#ui-tabs-anchor" + + @selenium + Scenario: Inform problem if the informed lattes doesn't exist + Given I am on signup page + When I fill in "e-Mail" with "josesilva@example.com" + And I fill in "Username" with "josesilva" + And I fill in "Full name" with "João Silva" + And I fill in "Password" with "secret" + And I fill in "Password confirmation" with "secret" + And I fill in "Lattes URL" with "http://lattes.cnpq.br/123456" + And wait for the captcha signup time + And I press "Create my account" + And I go to /profile/josesilva + And I follow "Lattes" within "#ui-tabs-anchor" + Then I should see "Lattes not found. Please, make sure the informed URL is correct." \ No newline at end of file diff --git a/plugins/lattes_curriculum/lib/html_parser.rb b/plugins/lattes_curriculum/lib/html_parser.rb index dbe1d8d..057faa4 100755 --- a/plugins/lattes_curriculum/lib/html_parser.rb +++ b/plugins/lattes_curriculum/lib/html_parser.rb @@ -15,8 +15,8 @@ class Html_parser page = remove_select(page) page = remove_footer(page) page = remove_further_informations(page) - rescue - page = "" + rescue OpenURI::HTTPError => e + page = _("Lattes not found. Please, make sure the informed URL is correct.") end end diff --git a/plugins/lattes_curriculum/lib/lattes_curriculum_plugin.rb b/plugins/lattes_curriculum/lib/lattes_curriculum_plugin.rb index e8d54d8..19455c1 100755 --- a/plugins/lattes_curriculum/lib/lattes_curriculum_plugin.rb +++ b/plugins/lattes_curriculum/lib/lattes_curriculum_plugin.rb @@ -49,7 +49,7 @@ class LattesCurriculumPlugin < Noosfero::Plugin end def profile_tabs - unless context.profile.academic_info.nil? || context.profile.academic_info.lattes_url.nil? + unless context.profile.academic_info.nil? || context.profile.academic_info.lattes_url.blank? href = context.profile.academic_info.lattes_url html_parser = Html_parser.new { diff --git a/plugins/lattes_curriculum/test/unit/academic_info_test.rb b/plugins/lattes_curriculum/test/unit/academic_info_test.rb new file mode 100644 index 0000000..4186bc4 --- /dev/null +++ b/plugins/lattes_curriculum/test/unit/academic_info_test.rb @@ -0,0 +1,25 @@ +require "test_helper" + +class AcademicInfoTest < ActiveSupport::TestCase + + def setup + @academic_info = AcademicInfo.new + end + + should 'not ve invalid lattes url' do + @academic_info.lattes_url = "http://softwarelivre.org/" + assert !@academic_info.save + end + + should 'accept blank lattes url' do + @academic_info.lattes_url = "" + assert @academic_info.save + end + + should 'save with correct lattes url' do + @academic_info.lattes_url = "http://lattes.cnpq.br/2193972715230641" + assert @academic_info.save + end + + +end diff --git a/plugins/lattes_curriculum/test/unit/html_parser_test.rb b/plugins/lattes_curriculum/test/unit/html_parser_test.rb index 8f01b13..9e22267 100644 --- a/plugins/lattes_curriculum/test/unit/html_parser_test.rb +++ b/plugins/lattes_curriculum/test/unit/html_parser_test.rb @@ -1,3 +1,6 @@ +#!/bin/env ruby +# encoding: utf-8 + require "test_helper" class HtmlParserTest < ActiveSupport::TestCase @@ -11,11 +14,12 @@ class HtmlParserTest < ActiveSupport::TestCase end should 'be not nil the return get_html' do - assert_not_nil @parser.get_html("http://lattes.cnpq.br/2193972715230641") + result = @parser.get_html("http://lattes.cnpq.br/2193972715230641") + assert result.include?("Endereço para acessar este CV") end - should 'return a string the return get_html' do - assert_equal "", @parser.get_html() + should 'inform that lattes was not found' do + assert_equal "Lattes not found. Please, make sure the informed URL is correct.", @parser.get_html("http://lattes.cnpq.br/123") end end -- libgit2 0.21.2