Commit 8398fa805d2c6106b446280566cb9c87d430711d
1 parent
b0370b85
Exists in
master
and in
28 other branches
ActionItem373: make tests for language selector
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1931 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
29 additions
and
14 deletions
Show diff stats
test/functional/application_controller_test.rb
| ... | ... | @@ -143,4 +143,23 @@ class ApplicationControllerTest < Test::Unit::TestCase |
| 143 | 143 | assert_no_tag :tag => 'a', :content => /Category 2/ |
| 144 | 144 | end |
| 145 | 145 | |
| 146 | + should 'display dropdown for select language' do | |
| 147 | + Noosfero.expects(:locales).returns({ 'en' => 'English', 'pt_BR' => 'Português Brasileiro', 'fr' => 'Français', 'it' => 'Italiano' }).at_least_once | |
| 148 | + get :index, :lang => 'en' | |
| 149 | + assert_tag :tag => 'option', :attributes => { :value => 'en', :selected => 'selected' }, :content => 'English' | |
| 150 | + assert_no_tag :tag => 'option', :attributes => { :value => 'pt_BR', :selected => 'selected' }, :content => 'Português Brasileiro' | |
| 151 | + assert_tag :tag => 'option', :attributes => { :value => 'pt_BR' }, :content => 'Português Brasileiro' | |
| 152 | + assert_tag :tag => 'option', :attributes => { :value => 'fr' }, :content => 'Français' | |
| 153 | + assert_tag :tag => 'option', :attributes => { :value => 'it' }, :content => 'Italiano' | |
| 154 | + end | |
| 155 | + | |
| 156 | + should 'display links for select language' do | |
| 157 | + Noosfero.expects(:locales).returns({ 'en' => 'English', 'pt_BR' => 'Português Brasileiro', 'fr' => 'Français', 'it' => 'Italiano' }).at_least_once | |
| 158 | + get :index, :lang => 'en' | |
| 159 | + assert_no_tag :tag => 'a', :attributes => { :href => /\?lang=en/ }, :content => 'English' | |
| 160 | + assert_tag :tag => 'a', :attributes => { :href => /\?lang=pt_BR/ }, :content => 'Português Brasileiro' | |
| 161 | + assert_tag :tag => 'a', :attributes => { :href => /\?lang=fr/ }, :content => 'Français' | |
| 162 | + assert_tag :tag => 'a', :attributes => { :href => /\?lang=it/ }, :content => 'Italiano' | |
| 163 | + end | |
| 164 | + | |
| 146 | 165 | end | ... | ... |
test/unit/language_helper_test.rb
| ... | ... | @@ -4,6 +4,7 @@ class LanguageHelperTest < Test::Unit::TestCase |
| 4 | 4 | |
| 5 | 5 | include LanguageHelper |
| 6 | 6 | |
| 7 | + | |
| 7 | 8 | should 'return current language' do |
| 8 | 9 | locale = mock |
| 9 | 10 | locale.expects(:to_s).returns('pt_BR') |
| ... | ... | @@ -36,25 +37,20 @@ class LanguageHelperTest < Test::Unit::TestCase |
| 36 | 37 | |
| 37 | 38 | end |
| 38 | 39 | |
| 40 | + include ActionView::Helpers::FormOptionsHelper | |
| 41 | + include ActionView::Helpers::FormTagHelper | |
| 39 | 42 | should 'generate drodown language chooser correcly' do |
| 40 | 43 | Noosfero.expects(:locales).returns({ 'en' => 'English', 'pt_BR' => 'Português Brasileiro', 'fr' => 'Français', 'it' => 'Italiano' }).at_least_once |
| 41 | 44 | |
| 42 | - self.expects(:language).returns('pt_BR') | |
| 45 | + self.expects(:language).returns('en') | |
| 43 | 46 | result = self.language_chooser(:element => 'dropdown') |
| 44 | 47 | assert_match /<option value="en" selected="selected">English<\/option>/, result |
| 45 | - | |
| 46 | - #assert_match /<strong>Português Brasileiro<\/strong>/, result | |
| 47 | - #assert_no_match /<strong>English<\/strong>/, result | |
| 48 | - #assert_no_match /<strong>Français<\/strong>/, result | |
| 49 | - #assert_no_match /<strong>Italiano<\/strong>/, result | |
| 50 | - | |
| 51 | - #self.expects(:language).returns('fr') | |
| 52 | - #result = self.language_chooser | |
| 53 | - #assert_no_match /<strong>Português Brasileiro<\/strong>/, result | |
| 54 | - #assert_no_match /<strong>English<\/strong>/, result | |
| 55 | - #assert_match /<strong>Français<\/strong>/, result | |
| 56 | - #assert_no_match /<strong>Italiano<\/strong>/, result | |
| 57 | - | |
| 48 | + assert_match /<option value="pt_BR">Português Brasileiro<\/option>/, result | |
| 49 | + assert_match /<option value="fr">Français<\/option>/, result | |
| 50 | + assert_match /<option value="it">Italiano<\/option>/, result | |
| 51 | + assert_no_match /<option value="pt_BR" selected="selected">Português Brasileiro<\/option>/, result | |
| 52 | + assert_no_match /<option value="fr" selected="selected">Français<\/option>/, result | |
| 53 | + assert_no_match /<option value="it" selected="selected">Italiano<\/option>/, result | |
| 58 | 54 | end |
| 59 | 55 | |
| 60 | 56 | protected | ... | ... |