<commit_before>require File.dirname(__FILE__) + '/../test_helper'

class SearchHelperTest < Test::Unit::TestCase

  include SearchHelper

  def _(any)
    any
  end

  def setup
    @profile = mock
    self.stubs(:profile_image).returns('profileimage.png')
    self.stubs(:url_for).returns('link to profile')
    profile.stubs(:name).returns('Name of Profile')
    profile.stubs(:url).returns('')
    profile.stubs(:products).returns([Product.new(:name => 'product test')])
    profile.stubs(:identifier).returns('name-of-profile')
    profile.stubs(:region).returns(Region.new(:name => 'Brazil'))
  end
  attr_reader :profile

  should 'display profile info' do
    profile.stubs(:address).returns('Address of Profile')
    profile.stubs(:contact_email).returns('Email of Profile')
    profile.stubs(:contact_phone).returns('Phone of Profile')

    result = self.display_profile_info(profile)
    assert_match /profileimage.png/, result
    assert_match /link to profile/, result
    assert_match /Email of Profile/, result
    assert_match /Phone of Profile/, result
    assert_match /Address of Profile/, result
  end

  should 'not display field if nil in profile info' do
    profile.stubs(:address).returns('nil')
    profile.stubs(:contact_email).returns('nil')
    profile.stubs(:contact_phone).returns('nil')

    result = self.display_profile_info(profile)
    assert_match /profileimage.png/, result
    assert_match /link to profile/, result
    assert_no_match /Email of Profile/, result
    assert_no_match /Phone of Profile/, result
    assert_no_match /Address of Profile/, result
  end

  should 'link to products and services of an profile' do
    enterprise = fast_create(Enterprise)
    product1 = fast_create(Product, :enterprise_id => enterprise.id)
    product2 = fast_create(Product, :enterprise_id => enterprise.id)
    result = display_profile_info(enterprise)
    assert_tag_in_string result, :tag => 'a', :attributes => {:href => /:controller=>\"manage_products\", :id=>#{product1.id}/}, :content => product1.name
    assert_tag_in_string result, :tag => 'a', :attributes => {:href => /:controller=>\"manage_products\", :id=>#{product2.id}/}, :content => product2.name
  end

  protected
  include NoosferoTestHelper

end
<commit_msg>Revert "Verifying controller on display_profile_info test"<commit_after>require File.dirname(__FILE__) + '/../test_helper'

class SearchHelperTest < Test::Unit::TestCase

  include SearchHelper

  def _(any)
    any
  end

  def setup
    @profile = mock
    self.stubs(:profile_image).returns('profileimage.png')
    self.stubs(:url_for).returns('link to profile')
    profile.stubs(:name).returns('Name of Profile')
    profile.stubs(:url).returns('')
    profile.stubs(:products).returns([Product.new(:name => 'product test')])
    profile.stubs(:identifier).returns('name-of-profile')
    profile.stubs(:region).returns(Region.new(:name => 'Brazil'))
  end
  attr_reader :profile

  should 'display profile info' do
    profile.stubs(:address).returns('Address of Profile')
    profile.stubs(:contact_email).returns('Email of Profile')
    profile.stubs(:contact_phone).returns('Phone of Profile')

    result = self.display_profile_info(profile)
    assert_match /profileimage.png/, result
    assert_match /link to profile/, result
    assert_match /Email of Profile/, result
    assert_match /Phone of Profile/, result
    assert_match /Address of Profile/, result
  end

  should 'not display field if nil in profile info' do
    profile.stubs(:address).returns('nil')
    profile.stubs(:contact_email).returns('nil')
    profile.stubs(:contact_phone).returns('nil')

    result = self.display_profile_info(profile)
    assert_match /profileimage.png/, result
    assert_match /link to profile/, result
    assert_no_match /Email of Profile/, result
    assert_no_match /Phone of Profile/, result
    assert_no_match /Address of Profile/, result
  end

  should 'link to products and services of an profile' do
    enterprise = fast_create(Enterprise)
    product1 = fast_create(Product, :enterprise_id => enterprise.id)
    product2 = fast_create(Product, :enterprise_id => enterprise.id)
    result = display_profile_info(enterprise)
    assert_tag_in_string result, :tag => 'a', :attributes => {:href => /:id=>#{product1.id}/}, :content => product1.name
    assert_tag_in_string result, :tag => 'a', :attributes => {:href => /:id=>#{product2.id}/}, :content => product2.name
  end

  protected
  include NoosferoTestHelper

end

{'fraction_non_alphanumeric': 0.12974894467896023, 'fraction_numerical': 0.0026660742057320595, 'mean_word_length': 4.2964705882352945, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5502806', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1316, 'n_words': 321}