display_helper_test.rb 1.6 KB
require File.dirname(__FILE__) + '/../test_helper'

class DisplayHelperTest < Test::Unit::TestCase

  include DisplayHelper
  include ActionView::Helpers::TagHelper

  #### product_path related tests ####

  # TODO: product_path has no tests!

  #### txt2html related tests ####

  should 'show txt line-breaks' do
    html = txt2html "Bli\n123"
    assert_equal "Bli\n<br/>\n123", html
    html = txt2html "Bli\n123 456\nabc"
    assert_equal "Bli\n<br/>\n123 456\n<br/>\nabc", html
  end

  should 'replace empty lines as paragraphs separators' do
    html = txt2html "Bli\n\n123"
    assert_equal "Bli\n<p/>\n123", html
    html = txt2html "Bli \n \n 123"
    assert_equal "Bli\n<p/>\n123", html
  end

  should 'trim txt before convert to html' do
    html = txt2html "\nBli\n123\n"
    assert_equal "Bli\n<br/>\n123", html
    html = txt2html " Bli\n123 "
    assert_equal "Bli\n<br/>\n123", html
    html = txt2html " \nBli\n123\n "
    assert_equal "Bli\n<br/>\n123", html
  end

  should 'linkify "http://" prepended words on txt2html' do
    html = txt2html "go to http://noosfero.org"
    assert_equal 'go to <a href="http://noosfero.org" onclick="return confirm(\'Are you sure you want to visit this web site?\')" rel="nofolow" target="_blank">noos&#x200B;fero&#x200B;.org</a>', html
  end

  should 'linkify "www." prepended words on txt2html' do
    html = txt2html "go to www.noosfero.org yeah!"
    assert_equal 'go to <a href="http://www.noosfero.org" onclick="return confirm(\'Are you sure you want to visit this web site?\')" rel="nofolow" target="_blank">www.&#x200B;noos&#x200B;fero&#x200B;.org</a> yeah!', html
  end

end