Project

General

Profile

Patch #35952 » 35952-r21314.patch

Go MAEDA, 2021-12-15 00:41

View differences:

test/functional/issues_controller_test.rb
1701 1701
  end
1702 1702

  
1703 1703
  def test_index_with_last_notes_column
1704
    get(
1705
      :index,
1706
      :params => {
1707
        :set_filter => 1,
1708
        :c => %w(subject last_notes)
1709
      }
1710
    )
1711
    assert_response :success
1712
    assert_select 'table.issues thead th', 4 # columns: chekbox + id + subject
1704
    with_settings :text_formatting => 'textile' do
1705
      get(
1706
        :index,
1707
        :params => {
1708
          :set_filter => 1,
1709
          :c => %w(subject last_notes)
1710
        }
1711
      )
1712
      assert_response :success
1713
      assert_select 'table.issues thead th', 4 # columns: chekbox + id + subject
1713 1714

  
1714
    assert_select 'td.last_notes[colspan="4"]', :text => 'Some notes with Redmine links: #2, r2.'
1715
    assert_select(
1716
      'td.last_notes[colspan="4"]',
1717
      :text => 'A comment with inline image:  and a reference to #1 and r2.'
1718
    )
1719
    get(
1720
      :index,
1721
      :params => {
1722
        :set_filter => 1,
1723
        :c => %w(subject last_notes),
1724
        :format => 'pdf'
1725
      }
1726
    )
1727
    assert_response :success
1728
    assert_equal 'application/pdf', response.media_type
1715
      assert_select 'td.last_notes[colspan="4"]', :text => 'Some notes with Redmine links: #2, r2.'
1716
      assert_select(
1717
        'td.last_notes[colspan="4"]',
1718
        :text => 'A comment with inline image:  and a reference to #1 and r2.'
1719
      )
1720
      get(
1721
        :index,
1722
        :params => {
1723
          :set_filter => 1,
1724
          :c => %w(subject last_notes),
1725
          :format => 'pdf'
1726
        }
1727
      )
1728
      assert_response :success
1729
      assert_equal 'application/pdf', response.media_type
1730
    end
1729 1731
  end
1730 1732

  
1731 1733
  def test_index_with_last_notes_column_should_display_private_notes_with_permission_only
......
2876 2878
  end
2877 2879

  
2878 2880
  def test_show_atom
2879
    get(
2880
      :show,
2881
      :params => {
2882
        :id => 2,
2883
        :format => 'atom'
2884
      }
2885
    )
2886
    assert_response :success
2887
    assert_equal 'application/atom+xml', response.media_type
2888
    # Inline image
2889
    assert_select(
2890
      'content',
2891
      :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
2892
    )
2881
    with_settings :text_formatting => 'textile' do
2882
      get(
2883
        :show,
2884
        :params => {
2885
          :id => 2,
2886
          :format => 'atom'
2887
        }
2888
      )
2889
      assert_response :success
2890
      assert_equal 'application/atom+xml', response.media_type
2891
      # Inline image
2892
      assert_select(
2893
        'content',
2894
        :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
2895
      )
2896
    end
2893 2897
  end
2894 2898

  
2895 2899
  def test_show_export_to_pdf
test/functional/projects_controller_test.rb
96 96
  end
97 97

  
98 98
  def test_index_as_list_should_format_column_value
99
    get :index, :params => {
100
      :c => ['name', 'status', 'short_description', 'homepage', 'parent_id', 'identifier', 'is_public', 'created_on', 'cf_3'],
101
      :display_type => 'list'
102
    }
103
    assert_response :success
99
    with_settings :text_formatting => 'textile' do
100
      get :index, :params => {
101
        :c => ['name', 'status', 'short_description', 'homepage', 'parent_id', 'identifier', 'is_public', 'created_on', 'cf_3'],
102
        :display_type => 'list'
103
      }
104
      assert_response :success
104 105

  
105
    project = Project.find(1)
106
    assert_select 'table.projects' do
107
      assert_select 'tr[id=?]', 'project-1' do
108
        assert_select 'td.name a[href=?]', '/projects/ecookbook', :text => 'eCookbook'
109
        assert_select 'td.status', :text => 'active'
110
        assert_select 'td.short_description', :text => 'Recipes management application'
111
        assert_select 'td.homepage a.external', :text => 'http://ecookbook.somenet.foo/'
112
        assert_select 'td.identifier', :text => 'ecookbook'
113
        assert_select 'td.is_public', :text => 'Yes'
114
        assert_select 'td.created_on', :text => format_time(project.created_on)
115
        assert_select 'td.cf_3.list', :text => 'Stable'
116
      end
117
      assert_select 'tr[id=?]', 'project-4' do
118
        assert_select 'td.parent_id a[href=?]', '/projects/ecookbook', :text => 'eCookbook'
106
      project = Project.find(1)
107
      assert_select 'table.projects' do
108
        assert_select 'tr[id=?]', 'project-1' do
109
          assert_select 'td.name a[href=?]', '/projects/ecookbook', :text => 'eCookbook'
110
          assert_select 'td.status', :text => 'active'
111
          assert_select 'td.short_description', :text => 'Recipes management application'
112
          assert_select 'td.homepage a.external', :text => 'http://ecookbook.somenet.foo/'
113
          assert_select 'td.identifier', :text => 'ecookbook'
114
          assert_select 'td.is_public', :text => 'Yes'
115
          assert_select 'td.created_on', :text => format_time(project.created_on)
116
          assert_select 'td.cf_3.list', :text => 'Stable'
117
        end
118
        assert_select 'tr[id=?]', 'project-4' do
119
          assert_select 'td.parent_id a[href=?]', '/projects/ecookbook', :text => 'eCookbook'
120
        end
119 121
      end
120 122
    end
121 123
  end
test/functional/wiki_controller_test.rb
30 30
  end
31 31

  
32 32
  def test_show_start_page
33
    get :show, :params => {:project_id => 'ecookbook'}
34
    assert_response :success
33
    with_settings :text_formatting => 'textile' do
34
      get :show, :params => {:project_id => 'ecookbook'}
35
      assert_response :success
35 36

  
36
    assert_select 'h1', :text => /CookBook documentation/
37
    # child_pages macro
38
    assert_select 'ul.pages-hierarchy>li>a[href=?]', '/projects/ecookbook/wiki/Page_with_an_inline_image',
39
                  :text => 'Page with an inline image'
37
      assert_select 'h1', :text => /CookBook documentation/
38
      # child_pages macro
39
      assert_select 'ul.pages-hierarchy>li>a[href=?]', '/projects/ecookbook/wiki/Page_with_an_inline_image',
40
                    :text => 'Page with an inline image'
41
    end
40 42
  end
41 43

  
42 44
  def test_export_link
......
55 57
  end
56 58

  
57 59
  def test_show_page_with_name
58
    get :show, :params => {:project_id => 1, :id => 'Another_page'}
59
    assert_response :success
60
    with_settings :text_formatting => 'textile' do
61
      get :show, :params => {:project_id => 1, :id => 'Another_page'}
62
      assert_response :success
60 63

  
61
    assert_select 'h1', :text => /Another page/
62
    # Included page with an inline image
63
    assert_select 'p', :text => /This is an inline image/
64
    assert_select 'img[src=?][alt=?]', '/attachments/download/3/logo.gif', 'This is a logo'
64
      assert_select 'h1', :text => /Another page/
65
      # Included page with an inline image
66
      assert_select 'p', :text => /This is an inline image/
67
      assert_select 'img[src=?][alt=?]', '/attachments/download/3/logo.gif', 'This is a logo'
68
    end
65 69
  end
66 70

  
67 71
  def test_show_old_version
......
147 151
  end
148 152

  
149 153
  def test_show_should_display_section_edit_links
150
    @request.session[:user_id] = 2
151
    get :show, :params => {:project_id => 1, :id => 'Page with sections'}
154
    with_settings :text_formatting => 'textile' do
155
      @request.session[:user_id] = 2
156
      get :show, :params => {:project_id => 1, :id => 'Page with sections'}
152 157

  
153
    assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=1', 0
154
    assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
155
    assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=3'
158
      assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=1', 0
159
      assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
160
      assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=3'
161
    end
156 162
  end
157 163

  
158 164
  def test_show_current_version_should_display_section_edit_links
159
    @request.session[:user_id] = 2
160
    get :show, :params => {:project_id => 1, :id => 'Page with sections', :version => 3}
165
    with_settings :text_formatting => 'textile' do
166
      @request.session[:user_id] = 2
167
      get :show, :params => {:project_id => 1, :id => 'Page with sections', :version => 3}
161 168

  
162
    assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
169
      assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
170
    end
163 171
  end
164 172

  
165 173
  def test_show_old_version_should_not_display_section_edit_links
......
353 361
  end
354 362

  
355 363
  def test_edit_section
356
    @request.session[:user_id] = 2
357
    get :edit, :params => {:project_id => 'ecookbook', :id => 'Page_with_sections', :section => 2}
364
    with_settings :text_formatting => 'textile' do
365
      @request.session[:user_id] = 2
366
      get :edit, :params => {:project_id => 'ecookbook', :id => 'Page_with_sections', :section => 2}
358 367

  
359
    assert_response :success
368
      assert_response :success
360 369

  
361
    page = WikiPage.find_by_title('Page_with_sections')
362
    section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
370
      page = WikiPage.find_by_title('Page_with_sections')
371
      section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
363 372

  
364
    assert_select 'textarea[name=?]', 'content[text]', :text => section
365
    assert_select 'input[name=section][type=hidden][value="2"]'
366
    assert_select 'input[name=section_hash][type=hidden][value=?]', hash
373
      assert_select 'textarea[name=?]', 'content[text]', :text => section
374
      assert_select 'input[name=section][type=hidden][value="2"]'
375
      assert_select 'input[name=section_hash][type=hidden][value=?]', hash
376
    end
367 377
  end
368 378

  
369 379
  def test_edit_invalid_section_should_respond_with_404
......
589 599
  end
590 600

  
591 601
  def test_update_section
592
    @request.session[:user_id] = 2
593
    page = WikiPage.find_by_title('Page_with_sections')
594
    section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
595
    text = page.content.text
596

  
597
    assert_no_difference 'WikiPage.count' do
598
      assert_no_difference 'WikiContent.count' do
599
        assert_difference 'WikiContentVersion.count' do
600
          put :update, :params => {
601
            :project_id => 1,
602
            :id => 'Page_with_sections',
603
            :content => {
604
              :text => "New section content",
605
              :version => 3
606
            },
607
            :section => 2,
608
            :section_hash => hash
609
          }
602
    with_settings :text_formatting => 'textile' do
603
      @request.session[:user_id] = 2
604
      page = WikiPage.find_by(title: 'Page_with_sections')
605
      section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
606
      text = page.content.text
607

  
608
      assert_no_difference 'WikiPage.count' do
609
        assert_no_difference 'WikiContent.count' do
610
          assert_difference 'WikiContentVersion.count' do
611
            put :update, :params => {
612
              :project_id => 1,
613
              :id => 'Page_with_sections',
614
              :content => {
615
                :text => 'New section content',
616
                :version => 3
617
              },
618
              :section => 2,
619
              :section_hash => hash
620
            }
621
          end
610 622
        end
611 623
      end
624
      assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2'
625
      assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, 'New section content'), page.reload.content.text
612 626
    end
613
    assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2'
614
    assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.reload.content.text
615 627
  end
616 628

  
617 629
  def test_update_section_should_allow_stale_page_update
618
    @request.session[:user_id] = 2
619
    page = WikiPage.find_by_title('Page_with_sections')
620
    section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
621
    text = page.content.text
622

  
623
    assert_no_difference 'WikiPage.count' do
624
      assert_no_difference 'WikiContent.count' do
625
        assert_difference 'WikiContentVersion.count' do
626
          put :update, :params => {
627
            :project_id => 1,
628
            :id => 'Page_with_sections',
629
            :content => {
630
              :text => "New section content",
631
              :version => 2 # Current version is 3
632
            },
633
            :section => 2,
634
            :section_hash => hash
635
          }
630
    with_settings :text_formatting => 'textile' do
631
      @request.session[:user_id] = 2
632
      page = WikiPage.find_by(title: 'Page_with_sections')
633
      section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
634
      text = page.content.text
635

  
636
      assert_no_difference 'WikiPage.count' do
637
        assert_no_difference 'WikiContent.count' do
638
          assert_difference 'WikiContentVersion.count' do
639
            put :update, :params => {
640
              :project_id => 1,
641
              :id => 'Page_with_sections',
642
              :content => {
643
                :text => 'New section content',
644
                :version => 2 # Current version is 3
645
              },
646
              :section => 2,
647
              :section_hash => hash
648
            }
649
          end
636 650
        end
637 651
      end
652
      assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2'
653
      page.reload
654
      assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, 'New section content'), page.content.text
655
      assert_equal 4, page.content.version
638 656
    end
639
    assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2'
640
    page.reload
641
    assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.content.text
642
    assert_equal 4, page.content.version
643 657
  end
644 658

  
645 659
  def test_update_section_should_not_allow_stale_section_update
......
669 683
  end
670 684

  
671 685
  def test_preview
672
    @request.session[:user_id] = 2
673
    post :preview, :params => {
674
      :project_id => 1,
675
      :id => 'CookBook_documentation',
676
      :content => {
677
        :comments => '',
678
        :text => 'this is a *previewed text*',
679
        :version => 3
680
      }
681
    }, :xhr => true
682
    assert_response :success
683
    assert_select 'strong', :text => /previewed text/
686
    with_settings :text_formatting => 'textile' do
687
      @request.session[:user_id] = 2
688
      post :preview, :params => {
689
        :project_id => 1,
690
        :id => 'CookBook_documentation',
691
        :content => {
692
          :comments => '',
693
          :text => 'this is a *previewed text*',
694
          :version => 3
695
        }
696
      }, :xhr => true
697
      assert_response :success
698
      assert_select 'strong', :text => /previewed text/
699
    end
684 700
  end
685 701

  
686 702
  def test_preview_new_page
687
    @request.session[:user_id] = 2
688
    post :preview, :params => {
689
      :project_id => 1,
690
      :id => 'New page',
691
      :content => {
692
        :text => 'h1. New page',
693
        :comments => '',
694
        :version => 0
695
      }
696
    }, :xhr => true
697
    assert_response :success
698
    assert_select 'h1', :text => /New page/
703
    with_settings :text_formatting => 'textile' do
704
      @request.session[:user_id] = 2
705
      post :preview, :params => {
706
        :project_id => 1,
707
        :id => 'New page',
708
        :content => {
709
          :text => 'h1. New page',
710
          :comments => '',
711
          :version => 0
712
        }
713
      }, :xhr => true
714
      assert_response :success
715
      assert_select 'h1', :text => /New page/
716
    end
699 717
  end
700 718

  
701 719
  def test_history
......
1134 1152
  end
1135 1153

  
1136 1154
  def test_show_html
1137
    @request.session[:user_id] = 2
1138
    get :show, :params => {:project_id => 1, :format => 'html'}
1139
    assert_response :success
1155
    with_settings :text_formatting => 'textile' do
1156
      @request.session[:user_id] = 2
1157
      get :show, :params => {:project_id => 1, :format => 'html'}
1158
      assert_response :success
1140 1159

  
1141
    assert_equal 'text/html', @response.media_type
1142
    assert_equal "attachment; filename=\"CookBook_documentation.html\"; filename*=UTF-8''CookBook_documentation.html",
1143
                 @response.headers['Content-Disposition']
1144
    assert_select 'h1', :text => /CookBook documentation/
1160
      assert_equal 'text/html', @response.media_type
1161
      assert_equal "attachment; filename=\"CookBook_documentation.html\"; filename*=UTF-8''CookBook_documentation.html",
1162
                  @response.headers['Content-Disposition']
1163
      assert_select 'h1', :text => /CookBook documentation/
1164
    end
1145 1165
  end
1146 1166

  
1147 1167
  def test_show_versioned_html
1148
    @request.session[:user_id] = 2
1149
    get :show, :params => {:project_id => 1, :format => 'html', :version => 2}
1150
    assert_response :success
1168
    with_settings :text_formatting => 'textile' do
1169
      @request.session[:user_id] = 2
1170
      get :show, :params => {:project_id => 1, :format => 'html', :version => 2}
1171
      assert_response :success
1151 1172

  
1152
    assert_equal 'text/html', @response.media_type
1153
    assert_equal "attachment; filename=\"CookBook_documentation.html\"; filename*=UTF-8''CookBook_documentation.html",
1154
                 @response.headers['Content-Disposition']
1155
    assert_select 'h1', :text => /CookBook documentation v2/
1173
      assert_equal 'text/html', @response.media_type
1174
      assert_equal "attachment; filename=\"CookBook_documentation.html\"; filename*=UTF-8''CookBook_documentation.html",
1175
                  @response.headers['Content-Disposition']
1176
      assert_select 'h1', :text => /CookBook documentation v2/
1177
    end
1156 1178
  end
1157 1179

  
1158 1180
  def test_show_txt
test/helpers/application_helper_test.rb
115 115
      'http://www.redmine.org/example-' =>
116 116
        '<a class="external" href="http://www.redmine.org/example-">http://www.redmine.org/example-</a>',
117 117
    }
118
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
118
    with_settings :text_formatting => 'textile' do
119
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
120
    end
119 121
  end
120 122

  
121 123
  def test_auto_links_with_non_ascii_characters
......
123 125
      "http://foo.bar/#{@russian_test}" =>
124 126
        %|<a class="external" href="http://foo.bar/#{@russian_test}">http://foo.bar/#{@russian_test}</a>|
125 127
    }
126
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
128
    with_settings :text_formatting => 'textile' do
129
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
130
    end
127 131
  end
128 132

  
129 133
  def test_auto_mailto
......
131 135
      'test@foo.bar' => '<a class="email" href="mailto:test@foo.bar">test@foo.bar</a>',
132 136
      'test@www.foo.bar' => '<a class="email" href="mailto:test@www.foo.bar">test@www.foo.bar</a>',
133 137
    }
134
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
138
    with_settings :text_formatting => 'textile' do
139
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
140
    end
135 141
  end
136 142

  
137 143
  def test_inline_images
......
153 159
      'with query string !http://foo.bar/image.cgi?a=1&b=2!' =>
154 160
        'with query string <img src="http://foo.bar/image.cgi?a=1&#38;b=2" alt="" />'
155 161
    }
156
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
162
    with_settings :text_formatting => 'textile' do
163
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
164
    end
157 165
  end
158 166

  
159 167
  def test_inline_images_inside_tags
......
164 172

  
165 173
      p=. !bar.gif!
166 174
    RAW
167
    assert textilizable(raw).include?('<img src="foo.png" alt="" />')
168
    assert textilizable(raw).include?('<img src="bar.gif" alt="" />')
175
    with_settings :text_formatting => 'textile' do
176
      assert textilizable(raw).include?('<img src="foo.png" alt="" />')
177
      assert textilizable(raw).include?('<img src="bar.gif" alt="" />')
178
    end
169 179
  end
170 180

  
171 181
  def test_attached_images
......
181 191
         '<a href="http://foo.bar/"><img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" loading="lazy" /></a>',
182 192
    }
183 193
    attachments = Attachment.all
184
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments)}
194
    with_settings :text_formatting => 'textile' do
195
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments)}
196
    end
185 197
  end
186 198

  
187 199
  def test_attached_images_on_issue
......
196 208
      !attached_on_journal.png!'
197 209
    RAW
198 210

  
199
    assert textilizable(raw, :object => journal).include?("<img src=\"/attachments/download/#{attachment_1.id}/attached_on_issue.png\" alt=\"\" loading=\"lazy\" />")
200
    assert textilizable(raw, :object => journal).include?("<img src=\"/attachments/download/#{attachment_2.id}/attached_on_journal.png\" alt=\"\" loading=\"lazy\" />")
211
    with_settings :text_formatting => 'textile' do
212
      assert textilizable(raw, :object => journal).include?("<img src=\"/attachments/download/#{attachment_1.id}/attached_on_issue.png\" alt=\"\" loading=\"lazy\" />")
213
      assert textilizable(raw, :object => journal).include?("<img src=\"/attachments/download/#{attachment_2.id}/attached_on_journal.png\" alt=\"\" loading=\"lazy\" />")
214
    end
201 215
  end
202 216

  
203 217
  def test_attached_images_with_textile_and_non_ascii_filename
......
232 246

  
233 247
  def test_attached_images_with_hires_naming
234 248
    attachment = Attachment.generate!(:filename => 'image@2x.png')
235
    assert_equal(
236
      %(<p><img src="/attachments/download/#{attachment.id}/image@2x.png" ) +
237
        %(srcset="/attachments/download/#{attachment.id}/image@2x.png 2x" alt="" loading="lazy" /></p>),
238
      textilizable("!image@2x.png!", :attachments => [attachment])
239
    )
249
    with_settings :text_formatting => 'textile' do
250
      assert_equal(
251
        %(<p><img src="/attachments/download/#{attachment.id}/image@2x.png" ) +
252
          %(srcset="/attachments/download/#{attachment.id}/image@2x.png 2x" alt="" loading="lazy" /></p>),
253
        textilizable("!image@2x.png!", :attachments => [attachment])
254
      )
255
    end
240 256
  end
241 257

  
242 258
  def test_attached_images_filename_extension
......
296 312
    }
297 313

  
298 314
    attachments = [a1, a2, a3, a4]
299
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments)}
315
    with_settings :text_formatting => 'textile' do
316
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments)}
317
    end
300 318
  end
301 319

  
302 320
  def test_attached_images_should_read_later
......
320 338
        'Inline image: <img src="/attachments/download/' + a2.id.to_s + '/testfile.PNG" alt="" loading="lazy" />',
321 339
    }
322 340
    attachments = [a1, a2]
323
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments)}
341
    with_settings :text_formatting => 'textile' do
342
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments)}
343
    end
324 344
  ensure
325 345
    set_tmp_attachments_directory
326 346
  end
......
351 371
        '<a class="external" href="http://foo.bar/page?p=1&#38;t=z&#38;s=-">http://foo.bar/page?p=1&#38;t=z&#38;s=-</a>',
352 372
      'This is an intern "link":/foo/bar-' => 'This is an intern <a href="/foo/bar-">link</a>'
353 373
    }
354
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
374
    with_settings :text_formatting => 'textile' do
375
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
376
    end
355 377
  end
356 378

  
357 379
  def test_textile_external_links_with_non_ascii_characters
......
359 381
      %|This is a "link":http://foo.bar/#{@russian_test}| =>
360 382
        %|This is a <a href="http://foo.bar/#{@russian_test}" class="external">link</a>|
361 383
    }
362
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
384
    with_settings :text_formatting => 'textile' do
385
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
386
    end
363 387
  end
364 388

  
365 389
  def test_redmine_links
......
549 573
      'user:foobar'                 => 'user:foobar',
550 574
    }
551 575
    @project = Project.find(1)
552
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"}
576
    with_settings :text_formatting => 'textile' do
577
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"}
578
    end
553 579
  end
554 580

  
555 581
  def test_link_to_note_within_the_same_page
556
    issue = Issue.find(1)
557
    assert_equal '<p><a href="#note-14">#note-14</a></p>', textilizable('#note-14', :object => issue)
582
    with_settings :text_formatting => 'textile' do
583
      issue = Issue.find(1)
584
      assert_equal '<p><a href="#note-14">#note-14</a></p>', textilizable('#note-14', :object => issue)
558 585

  
559
    journal = Journal.find(2)
560
    assert_equal '<p><a href="#note-2">#note-2</a></p>', textilizable('#note-2', :object => journal)
586
      journal = Journal.find(2)
587
      assert_equal '<p><a href="#note-2">#note-2</a></p>', textilizable('#note-2', :object => journal)
588
    end
561 589
  end
562 590

  
563 591
  def test_user_links_with_email_as_login_name_should_not_be_parsed_textile
......
603 631
  def test_should_not_parse_redmine_links_inside_link
604 632
    raw = "r1 should not be parsed in http://example.com/url-r1/"
605 633
    html = '<a class="external" href="http://example.com/url-r1/">http://example.com/url-r1/</a>'
606
    assert_match(
607
      %r{<p><a class="changeset".*>r1</a> should not be parsed in #{html}</p>},
608
      textilizable(raw, :project => Project.find(1))
609
    )
634
    with_settings :text_formatting => 'textile' do
635
      assert_match(
636
        %r{<p><a class="changeset".*>r1</a> should not be parsed in #{html}</p>},
637
        textilizable(raw, :project => Project.find(1))
638
      )
639
    end
610 640
  end
611 641

  
612 642
  def test_redmine_links_with_a_different_project_before_current_project
......
615 645
    @project = Project.find(3)
616 646
    result1 = link_to("1.4.4", "/versions/#{vp1.id}", :class => "version")
617 647
    result2 = link_to("1.4.4", "/versions/#{vp3.id}", :class => "version")
618
    assert_equal "<p>#{result1} #{result2}</p>",
619
                 textilizable("ecookbook:version:1.4.4 version:1.4.4")
648
    with_settings :text_formatting => 'textile' do
649
      assert_equal "<p>#{result1} #{result2}</p>",
650
                   textilizable('ecookbook:version:1.4.4 version:1.4.4')
651
    end
620 652
  end
621 653

  
622 654
  def test_escaped_redmine_links_should_not_be_parsed
......
633 665
      'source:/some/file'
634 666
    ]
635 667
    @project = Project.find(1)
636
    to_test.each {|text| assert_equal "<p>#{text}</p>", textilizable("!" + text), "#{text} failed"}
668
    with_settings :text_formatting => 'textile' do
669
      to_test.each {|text| assert_equal "<p>#{text}</p>", textilizable("!#{text}"), "#{text} failed"}
670
    end
637 671
  end
638 672

  
639 673
  def test_cross_project_redmine_links
......
667 701
      'invalid:source:/some/file'             => 'invalid:source:/some/file',
668 702
    }
669 703
    @project = Project.find(3)
670
    to_test.each do |text, result|
671
      assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"
704
    with_settings :text_formatting => 'textile' do
705
      to_test.each do |text, result|
706
        assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"
707
      end
672 708
    end
673 709
  end
674 710

  
......
677 713
    link = link_to("Test & Show.txt", "/versions/#{v.id}", :class => "version")
678 714

  
679 715
    @project = v.project
680
    assert_equal "<p>#{link}</p>", textilizable('version:"Test & Show.txt"')
716
    with_settings :text_formatting => 'textile' do
717
      assert_equal "<p>#{link}</p>", textilizable('version:"Test & Show.txt"')
718
    end
681 719
  end
682 720

  
683 721
  def test_link_to_issue_subject
......
767 805
    }
768 806

  
769 807
    @project = Project.find(1)
770
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"}
808
    with_settings :text_formatting => 'textile' do
809
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"}
810
    end
771 811
  end
772 812

  
773 813
  def test_cross_project_multiple_repositories_redmine_links
......
824 864
      'invalid:source:invalid|some/file'       => 'invalid:source:invalid|some/file',
825 865
    }
826 866
    @project = Project.find(3)
827
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"}
867
    with_settings :text_formatting => 'textile' do
868
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"}
869
    end
828 870
  end
829 871

  
830 872
  def test_redmine_links_git_commit
......
853 895
    to_test = {
854 896
      'commit:abcd' => changeset_link,
855 897
    }
856
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
898
    with_settings :text_formatting => 'textile' do
899
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
900
    end
857 901
  end
858 902

  
859 903
  # TODO: Bazaar commit id contains mail address, so it contains '@' and '_'.
......
896 940
      'r123' => changeset_link_rev,
897 941
      'commit:abcd' => changeset_link_commit,
898 942
    }
899
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
943
    with_settings :text_formatting => 'textile' do
944
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
945
    end
900 946
  end
901 947

  
902 948
  def test_attachment_links
903 949
    text = 'attachment:error281.txt'
904 950
    result = link_to("error281.txt", "/attachments/1",
905 951
                     :class => "attachment")
906
    assert_equal "<p>#{result}</p>",
907
                 textilizable(text,
908
                              :attachments => Issue.find(3).attachments),
909
                 "#{text} failed"
952
    with_settings :text_formatting => 'textile' do
953
      assert_equal "<p>#{result}</p>",
954
                  textilizable(text,
955
                                :attachments => Issue.find(3).attachments),
956
                  "#{text} failed"
957
    end
910 958
  end
911 959

  
912 960
  def test_attachment_link_should_link_to_latest_attachment
......
914 962
    a2 = Attachment.generate!(:filename => "test.txt")
915 963
    result = link_to("test.txt", "/attachments/#{a2.id}",
916 964
                     :class => "attachment")
917
    assert_equal "<p>#{result}</p>",
918
                 textilizable('attachment:test.txt', :attachments => [a1, a2])
965
    with_settings :text_formatting => 'textile' do
966
      assert_equal "<p>#{result}</p>",
967
                   textilizable('attachment:test.txt', :attachments => [a1, a2])
968
    end
919 969
  end
920 970

  
921 971
  def test_attachment_links_to_images_with_email_format_should_not_be_parsed
......
1031 1081
      '[[private-child:Wiki]]' => '[[private-child:Wiki]]',
1032 1082
    }
1033 1083
    @project = Project.find(1)
1034
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
1084
    with_settings :text_formatting => 'textile' do
1085
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
1086
    end
1035 1087
  end
1036 1088

  
1037 1089
  def test_wiki_links_with_special_characters_should_work_in_textile
......
1124 1176
                 :class => "wiki-page new"),
1125 1177
    }
1126 1178
    @project = Project.find(1)
1127
    to_test.each do |text, result|
1128
      assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :local)
1179
    with_settings :text_formatting => 'textile' do
1180
      to_test.each do |text, result|
1181
        assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :local)
1182
      end
1129 1183
    end
1130 1184
  end
1131 1185

  
......
1184 1238
                 :class => "wiki-page new"),
1185 1239
    }
1186 1240
    @project = Project.find(1)
1187
    to_test.each do |text, result|
1188
      assert_equal "<p>#{result}</p>",
1189
                   textilizable(WikiContent.new(:text => text, :page => page), :text)
1241
    with_settings :text_formatting => 'textile' do
1242
      to_test.each do |text, result|
1243
        assert_equal "<p>#{result}</p>",
1244
                     textilizable(WikiContent.new(:text => text, :page => page), :text)
1245
      end
1190 1246
    end
1191 1247
  end
1192 1248

  
......
1228 1284
                  :class => "wiki-page new"),
1229 1285
    }
1230 1286
    @project = Project.find(1)
1231
    to_test.each do |text, result|
1232
      assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :anchor)
1287
    with_settings :text_formatting => 'textile' do
1288
      to_test.each do |text, result|
1289
        assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :anchor)
1290
      end
1233 1291
    end
1234 1292
  end
1235 1293

  
......
1254 1312
      '<pre><code class=""onmouseover="alert(1)">text</code></pre>' => '<pre><code>text</code></pre>',
1255 1313
      '<pre class=""onmouseover="alert(1)">text</pre>' => '<pre>text</pre>',
1256 1314
    }
1257
    to_test.each {|text, result| assert_equal result, textilizable(text)}
1315
    with_settings :text_formatting => 'textile' do
1316
      to_test.each {|text, result| assert_equal result, textilizable(text)}
1317
    end
1258 1318
  end
1259 1319

  
1260 1320
  def test_allowed_html_tags
......
1263 1323
      "<notextile>no *textile* formatting</notextile>" => "no *textile* formatting",
1264 1324
      "<notextile>this is <tag>a tag</tag></notextile>" => "this is &lt;tag&gt;a tag&lt;/tag&gt;"
1265 1325
    }
1266
    to_test.each {|text, result| assert_equal result, textilizable(text)}
1326
    with_settings :text_formatting => 'textile' do
1327
      to_test.each {|text, result| assert_equal result, textilizable(text)}
1328
    end
1267 1329
  end
1268 1330

  
1269 1331
  def test_pre_tags
......
1283 1345
      </pre>
1284 1346
      <p>After</p>
1285 1347
    EXPECTED
1286
    assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
1348
    with_settings :text_formatting => 'textile' do
1349
      assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
1350
    end
1287 1351
  end
1288 1352

  
1289 1353
  def test_pre_content_should_not_parse_wiki_and_redmine_links
......
1315 1379
      </pre>
1316 1380
    EXPECTED
1317 1381
    @project = Project.find(1)
1318
    assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
1382
    with_settings :text_formatting => 'textile' do
1383
      assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
1384
    end
1319 1385
  end
1320 1386

  
1321 1387
  def test_non_closing_pre_blocks_should_be_closed
......
1327 1393
      </code></pre>
1328 1394
    EXPECTED
1329 1395
    @project = Project.find(1)
1330
    assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
1396
    with_settings :text_formatting => 'textile' do
1397
      assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
1398
    end
1331 1399
  end
1332 1400

  
1333 1401
  def test_unbalanced_closing_pre_tag_should_not_error
......
1346 1414
    expected = <<~EXPECTED
1347 1415
      <pre><code class="ECMA_script syntaxhl" data-language=\"ECMA_script\"><span class="cm">/* Hello */</span><span class="nb">document</span><span class="p">.</span><span class="nx">write</span><span class="p">(</span><span class="dl">"</span><span class="s2">Hello World!</span><span class="dl">"</span><span class="p">);</span></code></pre>
1348 1416
    EXPECTED
1349
    assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
1417
    with_settings :text_formatting => 'textile' do
1418
      assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
1419
    end
1350 1420
  end
1351 1421

  
1352 1422
  def test_syntax_highlight_ampersand_in_textile
......
1383 1453
               "<td>#{link2}</td>" +
1384 1454
               "</tr><tr><td>Cell 21</td><td>#{link3}</td></tr>"
1385 1455
    @project = Project.find(1)
1386
    assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '')
1456
    with_settings :text_formatting => 'textile' do
1457
      assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '')
1458
    end
1387 1459
  end
1388 1460

  
1389 1461
  def test_text_formatting
......
1396 1468
      'a *H* umane *W* eb *T* ext *G* enerator' =>
1397 1469
        'a <strong>H</strong> umane <strong>W</strong> eb <strong>T</strong> ext <strong>G</strong> enerator',
1398 1470
    }
1399
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
1471
    with_settings :text_formatting => 'textile' do
1472
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
1473
    end
1400 1474
  end
1401 1475

  
1402 1476
  def test_wiki_horizontal_rule
1403
    assert_equal '<hr />', textilizable('---')
1404
    assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---')
1477
    with_settings :text_formatting => 'textile' do
1478
      assert_equal '<hr />', textilizable('---')
1479
      assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---')
1480
    end
1405 1481
  end
1406 1482

  
1407 1483
  def test_headings
......
1409 1485
    expected =
1410 1486
      %|<a name="Some-heading"></a>\n<h1 >Some heading| +
1411 1487
        %|<a href="#Some-heading" class="wiki-anchor">&para;</a></h1>|
1412
    assert_equal expected, textilizable(raw)
1488
    with_settings :text_formatting => 'textile' do
1489
      assert_equal expected, textilizable(raw)
1490
    end
1413 1491
  end
1414 1492

  
1415 1493
  def test_headings_with_special_chars
......
1420 1498
    expected =
1421 1499
      %|<a name="#{anchor}"></a>\n<h1 >Some heading related to version 0.5| +
1422 1500
        %|<a href="##{anchor}" class="wiki-anchor">&para;</a></h1>|
1423
    assert_equal expected, textilizable(raw)
1501
    with_settings :text_formatting => 'textile' do
1502
      assert_equal expected, textilizable(raw)
1503
    end
1424 1504
  end
1425 1505

  
1426 1506
  def test_headings_in_wiki_single_page_export_should_be_prepended_with_page_title
......
1429 1509
    expected =
1430 1510
      %|<a name="Page_Title_Some-heading"></a>\n<h1 >Some heading| +
1431 1511
        %|<a href="#Page_Title_Some-heading" class="wiki-anchor">&para;</a></h1>|
1432
    assert_equal expected, textilizable(content, :text, :wiki_links => :anchor)
1512
    with_settings :text_formatting => 'textile' do
1513
      assert_equal expected, textilizable(content, :text, :wiki_links => :anchor)
1514
    end
1433 1515
  end
1434 1516

  
1435 1517
  def test_table_of_content
......
1491 1573
               '</ul>'
1492 1574

  
1493 1575
    @project = Project.find(1)
1494
    assert textilizable(raw).delete("\n").include?(expected)
1576
    with_settings :text_formatting => 'textile' do
1577
      assert textilizable(raw).delete("\n").include?(expected)
1578
    end
1495 1579
  end
1496 1580

  
1497 1581
  def test_table_of_content_should_generate_unique_anchors
......
1515 1599
                  '</li>' +
1516 1600
                '</ul>'
1517 1601
    @project = Project.find(1)
1518
    result = textilizable(raw).delete("\n")
1519
    assert_include expected, result
1520
    assert_include '<a name="Subtitle">', result
1521
    assert_include '<a name="Subtitle-2">', result
1602
    with_settings :text_formatting => 'textile' do
1603
      result = textilizable(raw).delete("\n")
1604
      assert_include expected, result
1605
      assert_include '<a name="Subtitle">', result
1606
      assert_include '<a name="Subtitle-2">', result
1607
    end
1522 1608
  end
1523 1609

  
1524 1610
  def test_table_of_content_should_contain_included_page_headings
......
1536 1622
               '<li><a href="#Child-page-1">Child page 1</a></li>' +
1537 1623
               '</ul>'
1538 1624
    @project = Project.find(1)
1539
    assert textilizable(raw).delete("\n").include?(expected)
1625
    with_settings :text_formatting => 'textile' do
1626
      assert textilizable(raw).delete("\n").include?(expected)
1627
    end
1540 1628
  end
1541 1629

  
1542 1630
  def test_toc_with_textile_formatting_should_be_parsed
......
1581 1669
    RAW
1582 1670
    @project = Project.find(1)
1583 1671
    set_language_if_valid 'en'
1584
    result =
1585
      textilizable(
1586
        raw,
1587
        :edit_section_links =>
1588
          {:controller => 'wiki', :action => 'edit',
1589
           :project_id => '1', :id => 'Test'}
1590
      ).delete("\n")
1591
    # heading that contains inline code
1592
    assert_match(
1593
      Regexp.new(
1594
        '<div class="contextual heading-2" title="Edit this section" id="section-4">' \
1595
        '<a class="icon-only icon-edit" href="/projects/1/wiki/Test/edit\?section=4">' \
1596
        'Edit this section' \
1597
        '</a></div>' \
1598
        '<a name="Subtitle-with-inline-code"></a>' \
1599
        '<h2 >Subtitle with ' \
1600
        '<code>inline code</code><a href="#Subtitle-with-inline-code" class="wiki-anchor">&para;</a>' \
1601
        '</h2>'
1602
      ),
1603
      result
1604
    )
1605
    # last heading
1606
    assert_match(
1607
      Regexp.new(
1608
        '<div class="contextual heading-2" title="Edit this section" id="section-5">' \
1609
        '<a class="icon-only icon-edit" href="/projects/1/wiki/Test/edit\?section=5">' \
1610
        'Edit this section' \
1611
        '</a></div>' \
1612
        '<a name="Subtitle-after-pre-tag"></a>' \
1613
        '<h2 >Subtitle after pre tag' \
1614
        '<a href="#Subtitle-after-pre-tag" class="wiki-anchor">&para;</a></h2>'
1615
      ),
1616
      result
1617
    )
1672
    with_settings :text_formatting => 'textile' do
1673
      result =
1674
        textilizable(
1675
          raw,
1676
          :edit_section_links =>
1677
            {:controller => 'wiki', :action => 'edit',
1678
            :project_id => '1', :id => 'Test'}
1679
        ).delete("\n")
1680
      # heading that contains inline code
1681
      assert_match(
1682
        Regexp.new(
1683
          '<div class="contextual heading-2" title="Edit this section" id="section-4">' \
1684
          '<a class="icon-only icon-edit" href="/projects/1/wiki/Test/edit\?section=4">' \
1685
          'Edit this section' \
1686
          '</a></div>' \
1687
          '<a name="Subtitle-with-inline-code"></a>' \
1688
          '<h2 >Subtitle with ' \
1689
          '<code>inline code</code><a href="#Subtitle-with-inline-code" class="wiki-anchor">&para;</a>' \
1690
          '</h2>'
1691
        ),
1692
        result
1693
      )
1694
      # last heading
1695
      assert_match(
1696
        Regexp.new(
1697
          '<div class="contextual heading-2" title="Edit this section" id="section-5">' \
1698
          '<a class="icon-only icon-edit" href="/projects/1/wiki/Test/edit\?section=5">' \
1699
          'Edit this section' \
1700
          '</a></div>' \
1701
          '<a name="Subtitle-after-pre-tag"></a>' \
1702
          '<h2 >Subtitle after pre tag' \
1703
          '<a href="#Subtitle-after-pre-tag" class="wiki-anchor">&para;</a></h2>'
1704
        ),
1705
        result
1706
      )
1707
    end
1618 1708
  end
1619 1709

  
1620 1710
  def test_default_formatter
......
1633 1723
  end
1634 1724

  
1635 1725
  def test_textilizable_with_formatting_set_to_true_should_format_text
1636
    assert_equal '<p><strong>text</strong></p>', textilizable("*text*", :formatting => true)
1726
    with_settings :text_formatting => 'textile' do
1727
      assert_equal '<p><strong>text</strong></p>', textilizable("*text*", :formatting => true)
1728
    end
1637 1729
  end
1638 1730

  
1639 1731
  def test_parse_redmine_links_should_handle_a_tag_without_attributes
test/integration/attachments_test.rb
90 90

  
91 91
    token = ajax_upload('myupload.jpg', 'JPEG content')
92 92

  
93
    post(
94
      '/issues/preview',
95
      :params => {
96
        :issue => {:tracker_id => 1, :project_id => 'ecookbook'},
97
        :text => 'Inline upload: !myupload.jpg!',
98
        :attachments => {
99
          '1' => {
100
            :filename => 'myupload.jpg',
101
            :description => 'My uploaded file',
102
            :token => token
93
    with_settings :text_formatting => 'textile' do
94
      post(
95
        '/issues/preview',
96
        :params => {
97
          :issue => {:tracker_id => 1, :project_id => 'ecookbook'},
98
          :text => 'Inline upload: !myupload.jpg!',
99
          :attachments => {
100
            '1' => {
101
              :filename => 'myupload.jpg',
102
              :description => 'My uploaded file',
103
              :token => token
104
            }
103 105
          }
104 106
        }
105
      }
106
    )
107
    assert_response :success
107
      )
108
      assert_response :success
108 109

  
109
    attachment_path = response.body.match(%r{<img src="(/attachments/download/\d+/myupload.jpg)"})[1]
110
    assert_not_nil token, "No attachment path found in response:\n#{response.body}"
110
      attachment_path = response.body.match(%r{<img src="(/attachments/download/\d+/myupload.jpg)"})[1]
111
      assert_not_nil token, "No attachment path found in response:\n#{response.body}"
111 112

  
112
    get attachment_path
113
    assert_response :success
114
    assert_equal 'JPEG content', response.body
113
      get attachment_path
114
      assert_response :success
115
      assert_equal 'JPEG content', response.body
116
    end
115 117
  end
116 118

  
117 119
  def test_upload_and_resubmit_after_validation_failure
test/unit/lib/redmine/field_format/field_format_test.rb
39 39
    field = IssueCustomField.new(:field_format => 'string', :text_formatting => 'full')
40 40
    custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "*foo*")
41 41

  
42
    assert_equal "*foo*", field.format.formatted_custom_value(self, custom_value, false)
43
    assert_include "<strong>foo</strong>", field.format.formatted_custom_value(self, custom_value, true)
42
    with_settings :text_formatting => 'textile' do
43
      assert_equal '*foo*', field.format.formatted_custom_value(self, custom_value, false)
44
      assert_include '<strong>foo</strong>', field.format.formatted_custom_value(self, custom_value, true)
45
    end
44 46
  end
45 47

  
46 48
  def test_text_field_with_text_formatting_disabled_should_not_format_text
......
55 57
    field = IssueCustomField.new(:field_format => 'text', :text_formatting => 'full')
56 58
    custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "*foo*\nbar")
57 59

  
58
    assert_equal "*foo*\nbar", field.format.formatted_custom_value(self, custom_value, false)
59
    assert_include "<strong>foo</strong>", field.format.formatted_custom_value(self, custom_value, true)
60
    with_settings :text_formatting => 'textile' do
61
      assert_equal "*foo*\nbar", field.format.formatted_custom_value(self, custom_value, false)
62
      assert_include '<strong>foo</strong>', field.format.formatted_custom_value(self, custom_value, true)
63
    end
60 64
  end
61 65

  
62 66
  def test_should_validate_url_pattern_with_safe_scheme
test/unit/lib/redmine/wiki_formatting/macros_test.rb
50 50
      end
51 51
    end
52 52

  
53
    assert_equal '<p>Foo: 0 () (Array)</p>', textilizable("{{foo}}")
54
    assert_equal '<p>Foo: 0 () (Array)</p>', textilizable("{{foo()}}")
55
    assert_equal '<p>Foo: 1 (arg1) (Array)</p>', textilizable("{{foo(arg1)}}")
56
    assert_equal '<p>Foo: 2 (arg1,arg2) (Array)</p>', textilizable("{{foo(arg1, arg2)}}")
53
    with_settings :text_formatting => 'textile' do
54
      assert_equal '<p>Foo: 0 () (Array)</p>', textilizable('{{foo}}')
55
      assert_equal '<p>Foo: 0 () (Array)</p>', textilizable('{{foo()}}')
56
      assert_equal '<p>Foo: 1 (arg1) (Array)</p>', textilizable('{{foo(arg1)}}')
57
      assert_equal '<p>Foo: 2 (arg1,arg2) (Array)</p>', textilizable('{{foo(arg1, arg2)}}')
58
    end
57 59
  end
58 60

  
59 61
  def test_macro_registration_parse_args_set_to_false_should_disable_arguments_parsing
......
63 65
      end
64 66
    end
65 67

  
66
    assert_equal '<p>Bar: (args, more args) (String)</p>', textilizable("{{bar(args, more args)}}")
67
    assert_equal '<p>Bar: () (String)</p>', textilizable("{{bar}}")
68
    assert_equal '<p>Bar: () (String)</p>', textilizable("{{bar()}}")
68
    with_settings :text_formatting => 'textile' do
69
      assert_equal '<p>Bar: (args, more args) (String)</p>', textilizable('{{bar(args, more args)}}')
70
      assert_equal '<p>Bar: () (String)</p>', textilizable('{{bar}}')
71
      assert_equal '<p>Bar: () (String)</p>', textilizable('{{bar()}}')
72
    end
69 73
  end
70 74

  
71 75
  def test_macro_registration_with_3_args_should_receive_text_argument
......
75 79
      end
76 80
    end
77 81

  
78
    assert_equal "<p>Baz: () (NilClass) ()</p>", textilizable("{{baz}}")
79
    assert_equal "<p>Baz: () (NilClass) ()</p>", textilizable("{{baz()}}")
80
    assert_equal "<p>Baz: () (String) (line1\nline2)</p>", textilizable("{{baz()\nline1\nline2\n}}")
81
    assert_equal "<p>Baz: (arg1,arg2) (String) (line1\nline2)</p>", textilizable("{{baz(arg1, arg2)\nline1\nline2\n}}")
82
    with_settings :text_formatting => 'textile' do
83
      assert_equal '<p>Baz: () (NilClass) ()</p>', textilizable('{{baz}}')
84
      assert_equal '<p>Baz: () (NilClass) ()</p>', textilizable('{{baz()}}')
85
      assert_equal "<p>Baz: () (String) (line1\nline2)</p>", textilizable("{{baz()\nline1\nline2\n}}")
86
      assert_equal "<p>Baz: (arg1,arg2) (String) (line1\nline2)</p>", textilizable("{{baz(arg1, arg2)\nline1\nline2\n}}")
87
    end
82 88
  end
83 89

  
84 90
  def test_macro_name_with_upper_case
85
    Redmine::WikiFormatting::Macros.macro(:UpperCase) {|obj, args| "Upper"}
86

  
87
    assert_equal "<p>Upper</p>", textilizable("{{UpperCase}}")
91
    with_settings :text_formatting => 'textile' do
92
      Redmine::WikiFormatting::Macros.macro(:UpperCase) {|obj, args| 'Upper'}
93
      assert_equal '<p>Upper</p>', textilizable('{{UpperCase}}')
94
    end
88 95
  end
89 96

  
90 97
  def test_multiple_macros_on_the_same_line
......
92 99
      args.any? ? "args: #{args.join(',')}" : "no args"
93 100
    end
94 101

  
95
    assert_equal '<p>no args no args</p>', textilizable("{{foo}} {{foo}}")
96
    assert_equal '<p>args: a,b no args</p>', textilizable("{{foo(a,b)}} {{foo}}")
97
    assert_equal '<p>args: a,b args: c,d</p>', textilizable("{{foo(a,b)}} {{foo(c,d)}}")
98
    assert_equal '<p>no args args: c,d</p>', textilizable("{{foo}} {{foo(c,d)}}")
102
    with_settings :text_formatting => 'textile' do
103
      assert_equal '<p>no args no args</p>', textilizable('{{foo}} {{foo}}')
104
      assert_equal '<p>args: a,b no args</p>', textilizable('{{foo(a,b)}} {{foo}}')
105
      assert_equal '<p>args: a,b args: c,d</p>', textilizable('{{foo(a,b)}} {{foo(c,d)}}')
106
      assert_equal '<p>no args args: c,d</p>', textilizable('{{foo}} {{foo(c,d)}}')
107
    end
99 108
  end
100 109

  
101 110
  def test_macro_should_receive_the_object_as_argument_when_with_object_and_attribute
102 111
    issue = Issue.find(1)
103 112
    issue.description = "{{hello_world}}"
104
    assert_equal(
105
      '<p>Hello world! Object: Issue, Called with no argument and no block of text.</p>',
106
      textilizable(issue, :description)
107
    )
113
    with_settings :text_formatting => 'textile' do
114
      assert_equal(
115
        '<p>Hello world! Object: Issue, Called with no argument and no block of text.</p>',
116
        textilizable(issue, :description)
117
      )
118
    end
108 119
  end
109 120

  
110 121
  def test_macro_should_receive_the_object_as_argument_when_called_with_object_option
111
    text = "{{hello_world}}"
112
    assert_equal(
113
      '<p>Hello world! Object: Issue, Called with no argument and no block of text.</p>',
114
      textilizable(text, :object => Issue.find(1))
115
    )
122
    with_settings :text_formatting => 'textile' do
123
      text = '{{hello_world}}'
124
      assert_equal(
125
        '<p>Hello world! Object: Issue, Called with no argument and no block of text.</p>',
126
        textilizable(text, :object => Issue.find(1))
127
      )
128
    end
116 129
  end
117 130

  
118 131
  def test_extract_macro_options_should_with_args
......
153 166
  end
154 167

  
155 168
  def test_exclamation_mark_should_not_run_macros
156
    text = "!{{hello_world}}"
157
    assert_equal '<p>{{hello_world}}</p>', textilizable(text)
169
    with_settings :text_formatting => 'textile' do
170
      text = '!{{hello_world}}'
171
      assert_equal '<p>{{hello_world}}</p>', textilizable(text)
172
    end
158 173
  end
159 174

  
160 175
  def test_exclamation_mark_should_escape_macros
161
    text = "!{{hello_world(<tag>)}}"
162
    assert_equal '<p>{{hello_world(&lt;tag&gt;)}}</p>', textilizable(text)
176
    with_settings :text_formatting => 'textile' do
177
      text = '!{{hello_world(<tag>)}}'
178
      assert_equal '<p>{{hello_world(&lt;tag&gt;)}}</p>', textilizable(text)
179
    end
163 180
  end
164 181

  
165 182
  def test_unknown_macros_should_not_be_replaced
166
    text = "{{unknown}}"
167
    assert_equal '<p>{{unknown}}</p>', textilizable(text)
183
    with_settings :text_formatting => 'textile' do
184
      text = '{{unknown}}'
185
      assert_equal '<p>{{unknown}}</p>', textilizable(text)
186
    end
168 187
  end
169 188

  
170 189
  def test_unknown_macros_should_parsed_as_text
171
    text = "{{unknown(*test*)}}"
172
    assert_equal '<p>{{unknown(<strong>test</strong>)}}</p>', textilizable(text)
190
    with_settings :text_formatting => 'textile' do
191
      text = '{{unknown(*test*)}}'
192
      assert_equal '<p>{{unknown(<strong>test</strong>)}}</p>', textilizable(text)
193
    end
173 194
  end
174 195

  
175 196
  def test_unknown_macros_should_be_escaped
176
    text = "{{unknown(<tag>)}}"
177
    assert_equal '<p>{{unknown(&lt;tag&gt;)}}</p>', textilizable(text)
197
    with_settings :text_formatting => 'textile' do
198
      text = '{{unknown(<tag>)}}'
199
      assert_equal '<p>{{unknown(&lt;tag&gt;)}}</p>', textilizable(text)
200
    end
178 201
  end
179 202

  
180 203
  def test_html_safe_macro_output_should_not_be_escaped
181
    Redmine::WikiFormatting::Macros.macro :safe_macro do |obj, args|
182
      "<tag>".html_safe
204
    with_settings :text_formatting => 'textile' do
205
      Redmine::WikiFormatting::Macros.macro :safe_macro do |obj, args|
206
        '<tag>'.html_safe
207
      end
208
      assert_equal '<p><tag></p>', textilizable('{{safe_macro}}')
183 209
    end
184
    assert_equal '<p><tag></p>', textilizable("{{safe_macro}}")
185 210
  end
186 211

  
187 212
  def test_macro_hello_world
......
220 245
  def test_macro_collapse
221 246
    text = "{{collapse\n*Collapsed* block of text\n}}"
222 247
    with_locale 'en' do
223
      result = textilizable(text)
248
      with_settings :text_formatting => 'textile' do
249
        result = textilizable(text)
224 250

  
225
      assert_select_in result, 'div.collapsed-text'
226
      assert_select_in result, 'strong', :text => 'Collapsed'
227
      assert_select_in result, 'a.collapsible.icon-collapsed', :text => 'Show'
228
      assert_select_in result, 'a.collapsible.icon-expanded', :text => 'Hide'
251
        assert_select_in result, 'div.collapsed-text'
252
        assert_select_in result, 'strong', :text => 'Collapsed'
253
        assert_select_in result, 'a.collapsible.icon-collapsed', :text => 'Show'
254
        assert_select_in result, 'a.collapsible.icon-expanded', :text => 'Hide'
255
      end
229 256
    end
230 257
  end
231 258

  
232 259
  def test_macro_collapse_with_one_arg
233 260
    text = "{{collapse(Example)\n*Collapsed* block of text\n}}"
234
    result = textilizable(text)
261
    with_settings :text_formatting => 'textile' do
262
      result = textilizable(text)
235 263

  
236
    assert_select_in result, 'div.collapsed-text'
237
    assert_select_in result, 'strong', :text => 'Collapsed'
238
    assert_select_in result, 'a.collapsible.icon-collapsed', :text => 'Example'
239
    assert_select_in result, 'a.collapsible.icon-expanded', :text => 'Example'
264
      assert_select_in result, 'div.collapsed-text'
265
      assert_select_in result, 'strong', :text => 'Collapsed'
266
      assert_select_in result, 'a.collapsible.icon-collapsed', :text => 'Example'
267
      assert_select_in result, 'a.collapsible.icon-expanded', :text => 'Example'
268
    end
240 269
  end
241 270

  
242 271
  def test_macro_collapse_with_two_args
243 272
    text = "{{collapse(Show example, Hide example)\n*Collapsed* block of text\n}}"
244
    result = textilizable(text)
273
    with_settings :text_formatting => 'textile' do
274
      result = textilizable(text)
245 275

  
246
    assert_select_in result, 'div.collapsed-text'
247
    assert_select_in result, 'strong', :text => 'Collapsed'
248
    assert_select_in result, 'a.collapsible.icon-collapsed', :text => 'Show example'
249
    assert_select_in result, 'a.collapsible.icon-expanded', :text => 'Hide example'
276
      assert_select_in result, 'div.collapsed-text'
277
      assert_select_in result, 'strong', :text => 'Collapsed'
278
      assert_select_in result, 'a.collapsible.icon-collapsed', :text => 'Show example'
279
      assert_select_in result, 'a.collapsible.icon-expanded', :text => 'Hide example'
280
    end
250 281
  end
251 282

  
252 283
  def test_macro_collapse_should_not_break_toc
......
264 295
    expected_toc =
265 296
      '<ul class="toc"><li><strong>Table of contents</strong></li>' \
266 297
      '<li><a href="#Title">Title</a><ul><li><a href="#Heading">Heading</a></li></ul></li></ul>'
267
    assert_include expected_toc, textilizable(text).gsub(/[\r\n]/, '')
298
    with_settings :text_formatting => 'textile' do
299
      assert_include expected_toc, textilizable(text).gsub(/[\r\n]/, '')
300
    end
268 301
  end
269 302

  
270 303
  def test_macro_child_pages
......
276 309
      "<li><a href=\"/projects/ecookbook/wiki/Child_2\">Child 2</a></li>\n" \
277 310
      "</ul>\n</p>"
278 311
    @project = Project.find(1)
279
    # child pages of the current wiki page
280
    assert_equal expected, textilizable("{{child_pages}}", :object => WikiPage.find(2).content)
281
    # child pages of another page
282
    assert_equal expected, textilizable("{{child_pages(Another_page)}}", :object => WikiPage.find(1).content)
283

  
284
    @project = Project.find(2)
285
    assert_equal expected, textilizable("{{child_pages(ecookbook:Another_page)}}", :object => WikiPage.find(1).content)
312
    with_settings :text_formatting => 'textile' do
313
      # child pages of the current wiki page
314
      assert_equal expected, textilizable('{{child_pages}}', :object => WikiPage.find(2).content)
315
      # child pages of another page
316
      assert_equal expected, textilizable('{{child_pages(Another_page)}}', :object => WikiPage.find(1).content)
317

  
318
      @project = Project.find(2)
319
      assert_equal expected, textilizable('{{child_pages(ecookbook:Another_page)}}', :object => WikiPage.find(1).content)
320
    end
286 321
  end
287 322

  
288 323
  def test_macro_child_pages_with_parent_option
......
297 332
      "</ul>\n</li>\n</ul>\n</p>"
298 333

  
299 334
    @project = Project.find(1)
300
    # child pages of the current wiki page
301
    assert_equal expected, textilizable("{{child_pages(parent=1)}}", :object => WikiPage.find(2).content)
302
    # child pages of another page
303
    assert_equal(
304
      expected,
305
      textilizable("{{child_pages(Another_page, parent=1)}}", :object => WikiPage.find(1).content)
306
    )
307
    @project = Project.find(2)
308
    assert_equal(
309
      expected,
310
      textilizable("{{child_pages(ecookbook:Another_page, parent=1)}}", :object => WikiPage.find(1).content)
311
    )
335
    with_settings :text_formatting => 'textile' do
336
      # child pages of the current wiki page
337
      assert_equal expected, textilizable('{{child_pages(parent=1)}}', :object => WikiPage.find(2).content)
338
      # child pages of another page
339
      assert_equal(
340
        expected,
341
        textilizable('{{child_pages(Another_page, parent=1)}}', :object => WikiPage.find(1).content)
342
      )
343
      @project = Project.find(2)
344
      assert_equal(
345
        expected,
346
        textilizable('{{child_pages(ecookbook:Another_page, parent=1)}}', :object => WikiPage.find(1).content)
347
      )
348
    end
312 349
  end
313 350

  
314 351
  def test_macro_child_pages_with_depth_option
......
318 355
        "<li><a href=\"/projects/ecookbook/wiki/Child_2\">Child 2</a></li>\n" \
319 356
        "</ul>\n</p>"
320 357
    @project = Project.find(1)
321
    assert_equal expected, textilizable("{{child_pages(depth=1)}}", :object => WikiPage.find(2).content)
358
    with_settings :text_formatting => 'textile' do
359
      assert_equal expected, textilizable("{{child_pages(depth=1)}}", :object => WikiPage.find(2).content)
360
    end
322 361
  end
323 362

  
324 363
  def test_macro_child_pages_without_wiki_page_should_fail
......
326 365
  end
327 366

  
328 367
  def test_macro_thumbnail
329
    link = link_to('<img alt="testfile.PNG" src="/attachments/thumbnail/17/200" />'.html_safe,
330
                   "/attachments/17",
331
                   :class => "thumbnail",
332
                   :title => "testfile.PNG")
333
    assert_equal "<p>#{link}</p>",
334
                 textilizable("{{thumbnail(testfile.png)}}", :object => Issue.find(14))
368
    with_settings :text_formatting => 'textile' do
369
      link = link_to('<img alt="testfile.PNG" src="/attachments/thumbnail/17/200" />'.html_safe,
370
                     '/attachments/17',
371
                     :class => 'thumbnail',
372
                     :title => 'testfile.PNG')
373
      assert_equal "<p>#{link}</p>",
374
                   textilizable('{{thumbnail(testfile.png)}}', :object => Issue.find(14))
375
    end
335 376
  end
336 377

  
337 378
  def test_macro_thumbnail_with_full_path
338
    link = link_to('<img alt="testfile.PNG" src="http://test.host/attachments/thumbnail/17/200" />'.html_safe,
339
                   "http://test.host/attachments/17",
340
                   :class => "thumbnail",
341
                   :title => "testfile.PNG")
... This diff was truncated because it exceeds the maximum size that can be displayed.
(2-2/2)