1 $:.unshift(File.dirname(__FILE__) + '/../lib')
2 require 'http_accept_language'
6 include HttpAcceptLanguage
8 @env ||= {'HTTP_ACCEPT_LANGUAGE' => 'en-us,en-gb;q=0.8,en;q=0.6'}
12 class HttpAcceptLanguageTest < Test::Unit::TestCase
13 def test_should_return_empty_array
14 request.env['HTTP_ACCEPT_LANGUAGE'] = nil
15 assert_equal [], request.user_preferred_languages
18 def test_should_properly_split
19 assert_equal %w{en-US en-GB en}, request.user_preferred_languages
22 def test_should_ignore_jambled_header
23 request.env['HTTP_ACCEPT_LANGUAGE'] = 'odkhjf89fioma098jq .,.,'
24 assert_equal [], request.user_preferred_languages
27 def test_should_find_first_available_language
28 assert_equal 'en-GB', request.preferred_language_from(%w{en en-GB})
31 def test_should_find_first_compatible_language
32 assert_equal 'en-hk', request.compatible_language_from(%w{en-hk})
33 assert_equal 'en', request.compatible_language_from(%w{en})
36 def test_should_find_first_compatible_from_user_preferred
37 request.env['HTTP_ACCEPT_LANGUAGE'] = 'en-us,de-de'
38 assert_equal 'en', request.compatible_language_from(%w{de en})
43 @request ||= MockedCgiRequest.new