$:.unshift "#{File.dirname(__FILE__)}/.."
require 'test/unit'
require 'rubygems'
require 'action_controller'
require 'action_controller/test_process'
require 'action_view/helpers/css_browser_selector'
# browser strings found at : http://www.zytrax.com/tech/web/browser_ids.htm
class TestController
attr_accessor :page_cached
alias_method :page_cached?, :page_cached
end
class CssBrowswerSelectorTest < Test::Unit::TestCase
include ActionView::Helpers::CssBrowserSelector
include ActionView::Helpers::JavascriptHelper
attr_accessor :request, :controller
def setup
self.request = ActionController::TestRequest.new
self.controller = TestController.new
self.controller.page_cached = false
end
def test_html_tag_helper
_erbout = ''
request.env["HTTP_USER_AGENT"]="Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"
expected = %(
test)
html { _erbout.concat "test" }
assert_dom_equal expected, _erbout
end
def test_body_tag_helper
_erbout = ''
request.env["HTTP_USER_AGENT"]="Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"
expected = %(test
)
body { _erbout.concat "test
" }
assert_dom_equal expected, _erbout
end
def test_html_tag_helper_exclude_browser_and_os
_erbout = ''
request.env["HTTP_USER_AGENT"]="Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"
expected = %(test)
html(:exclude_browser_and_os => true) { _erbout.concat "test" }
assert_dom_equal expected, _erbout
end
def test_body_tag_helper_exclude_browser_and_os
_erbout = ''
request.env["HTTP_USER_AGENT"]="Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"
expected = %(test
)
body(:exclude_browser_and_os => true) { _erbout.concat "test
" }
assert_dom_equal expected, _erbout
end
def test_body_tag_helper_does_not_add_js_to_body_onload_when_no_browser_or_os_detected
_erbout = ''
request.env["HTTP_USER_AGENT"]=""
expected = %(test
)
body { _erbout.concat "test
" }
assert_dom_equal expected, _erbout
end
def test_html_tag_helper_does_not_add_js_to_body_onload_when_no_browser_or_os_detected
_erbout = ''
request.env["HTTP_USER_AGENT"]=""
expected = %(test)
html { _erbout.concat "test" }
assert_dom_equal expected, _erbout
end
def test_html_continues_to_pass_html_options
_erbout = ''
request.env["HTTP_USER_AGENT"]="Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"
expected = %(test)
html(:lang=>"fr", :id=>"news", :class=>"sports") { _erbout.concat "test" }
assert_dom_equal expected, _erbout
end
def test_body_continues_to_pass_html_options
_erbout = ''
request.env["HTTP_USER_AGENT"]="Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"
expected = %(test
)
body(:onclick=>"alert('yo')", :class => "message") { _erbout.concat "test
" }
assert_dom_equal expected, _erbout
end
def test_window_add_load_event_script
expected = %()
assert_equal expected, javascript_tag(window_add_load_event)
end
def test_window_on_load_add_js_to_tag_script
expected = %()
assert_equal expected, javascript_tag(window_on_load_add_js_to_tag(:body))
end
# def test_html_content_tag_with_browser_selectors
# request.env["HTTP_USER_AGENT"]="Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"
# expected = %(Hello world!)
# assert_dom_equal expected, content_tag(:html, "Hello world!")
#
# expected = %(Hello world!