Project

General

Profile

Patch #35952 » 0001-Explicitly-specify-text-formatting-in-the-test-suite.patch

Marius BĂLTEANU, 2021-10-03 21:28

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
......
2860 2862
  end
2861 2863

  
2862 2864
  def test_show_atom
2863
    get(
2864
      :show,
2865
      :params => {
2866
        :id => 2,
2867
        :format => 'atom'
2868
      }
2869
    )
2870
    assert_response :success
2871
    assert_equal 'application/atom+xml', response.media_type
2872
    # Inline image
2873
    assert_select(
2874
      'content',
2875
      :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
2876
    )
2865
    with_settings :text_formatting => 'textile' do
2866
      get(
2867
        :show,
2868
        :params => {
2869
          :id => 2,
2870
          :format => 'atom'
2871
        }
2872
      )
2873
      assert_response :success
2874
      assert_equal 'application/atom+xml', response.media_type
2875
      # Inline image
2876
      assert_select(
2877
        'content',
2878
        :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
2879
      )
2880
    end
2877 2881
  end
2878 2882

  
2879 2883
  def test_show_export_to_pdf
test/functional/projects_controller_test.rb
95 95
  end
96 96

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

  
104
    project = Project.find(1)
105
    assert_select 'table.projects' do
106
      assert_select 'tr[id=?]', 'project-1' do
107
        assert_select 'td.name a[href=?]', '/projects/ecookbook', :text => 'eCookbook'
108
        assert_select 'td.status', :text => 'active'
109
        assert_select 'td.short_description', :text => 'Recipes management application'
110
        assert_select 'td.homepage a.external', :text => 'http://ecookbook.somenet.foo/'
111
        assert_select 'td.identifier', :text => 'ecookbook'
112
        assert_select 'td.is_public', :text => 'Yes'
113
        assert_select 'td.created_on', :text => format_time(project.created_on)
114
        assert_select 'td.cf_3.list', :text => 'Stable'
115
      end
116
      assert_select 'tr[id=?]', 'project-4' do
117
        assert_select 'td.parent_id a[href=?]', '/projects/ecookbook', :text => 'eCookbook'
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'
119
        end
118 120
      end
119 121
    end
120 122
  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
......
47 49
  end
48 50

  
49 51
  def test_show_page_with_name
50
    get :show, :params => {:project_id => 1, :id => 'Another_page'}
51
    assert_response :success
52
    with_settings :text_formatting => 'textile' do
53
      get :show, :params => {:project_id => 1, :id => 'Another_page'}
54
      assert_response :success
52 55

  
53
    assert_select 'h1', :text => /Another page/
54
    # Included page with an inline image
55
    assert_select 'p', :text => /This is an inline image/
56
    assert_select 'img[src=?][alt=?]', '/attachments/download/3/logo.gif', 'This is a logo'
56
      assert_select 'h1', :text => /Another page/
57
      # Included page with an inline image
58
      assert_select 'p', :text => /This is an inline image/
59
      assert_select 'img[src=?][alt=?]', '/attachments/download/3/logo.gif', 'This is a logo'
60
    end
57 61
  end
58 62

  
59 63
  def test_show_old_version
......
114 118
  end
115 119

  
116 120
  def test_show_should_display_section_edit_links
117
    @request.session[:user_id] = 2
118
    get :show, :params => {:project_id => 1, :id => 'Page with sections'}
121
    with_settings :text_formatting => 'textile' do
122
      @request.session[:user_id] = 2
123
      get :show, :params => {:project_id => 1, :id => 'Page with sections'}
119 124

  
120
    assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=1', 0
121
    assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
122
    assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=3'
125
      assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=1', 0
126
      assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
127
      assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=3'
128
    end
123 129
  end
124 130

  
125 131
  def test_show_current_version_should_display_section_edit_links
126
    @request.session[:user_id] = 2
127
    get :show, :params => {:project_id => 1, :id => 'Page with sections', :version => 3}
132
    with_settings :text_formatting => 'textile' do
133
      @request.session[:user_id] = 2
134
      get :show, :params => {:project_id => 1, :id => 'Page with sections', :version => 3}
128 135

  
129
    assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
136
      assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
137
    end
130 138
  end
131 139

  
132 140
  def test_show_old_version_should_not_display_section_edit_links
......
320 328
  end
321 329

  
322 330
  def test_edit_section
323
    @request.session[:user_id] = 2
324
    get :edit, :params => {:project_id => 'ecookbook', :id => 'Page_with_sections', :section => 2}
331
    with_settings :text_formatting => 'textile' do
332
      @request.session[:user_id] = 2
333
      get :edit, :params => {:project_id => 'ecookbook', :id => 'Page_with_sections', :section => 2}
325 334

  
326
    assert_response :success
335
      assert_response :success
327 336

  
328
    page = WikiPage.find_by_title('Page_with_sections')
329
    section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
337
      page = WikiPage.find_by_title('Page_with_sections')
338
      section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
330 339

  
331
    assert_select 'textarea[name=?]', 'content[text]', :text => section
332
    assert_select 'input[name=section][type=hidden][value="2"]'
333
    assert_select 'input[name=section_hash][type=hidden][value=?]', hash
340
      assert_select 'textarea[name=?]', 'content[text]', :text => section
341
      assert_select 'input[name=section][type=hidden][value="2"]'
342
      assert_select 'input[name=section_hash][type=hidden][value=?]', hash
343
    end
334 344
  end
335 345

  
336 346
  def test_edit_invalid_section_should_respond_with_404
......
556 566
  end
557 567

  
558 568
  def test_update_section
559
    @request.session[:user_id] = 2
560
    page = WikiPage.find_by_title('Page_with_sections')
561
    section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
562
    text = page.content.text
563

  
564
    assert_no_difference 'WikiPage.count' do
565
      assert_no_difference 'WikiContent.count' do
566
        assert_difference 'WikiContentVersion.count' do
567
          put :update, :params => {
568
            :project_id => 1,
569
            :id => 'Page_with_sections',
570
            :content => {
571
              :text => "New section content",
572
              :version => 3
573
            },
574
            :section => 2,
575
            :section_hash => hash
576
          }
569
    with_settings :text_formatting => 'textile' do
570
      @request.session[:user_id] = 2
571
      page = WikiPage.find_by(title: 'Page_with_sections')
572
      section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
573
      text = page.content.text
574

  
575
      assert_no_difference 'WikiPage.count' do
576
        assert_no_difference 'WikiContent.count' do
577
          assert_difference 'WikiContentVersion.count' do
578
            put :update, :params => {
579
              :project_id => 1,
580
              :id => 'Page_with_sections',
581
              :content => {
582
                :text => 'New section content',
583
                :version => 3
584
              },
585
              :section => 2,
586
              :section_hash => hash
587
            }
588
          end
577 589
        end
578 590
      end
591
      assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2'
592
      assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, 'New section content'), page.reload.content.text
579 593
    end
580
    assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2'
581
    assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.reload.content.text
582 594
  end
583 595

  
584 596
  def test_update_section_should_allow_stale_page_update
585
    @request.session[:user_id] = 2
586
    page = WikiPage.find_by_title('Page_with_sections')
587
    section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
588
    text = page.content.text
589

  
590
    assert_no_difference 'WikiPage.count' do
591
      assert_no_difference 'WikiContent.count' do
592
        assert_difference 'WikiContentVersion.count' do
593
          put :update, :params => {
594
            :project_id => 1,
595
            :id => 'Page_with_sections',
596
            :content => {
597
              :text => "New section content",
598
              :version => 2 # Current version is 3
599
            },
600
            :section => 2,
601
            :section_hash => hash
602
          }
597
    with_settings :text_formatting => 'textile' do
598
      @request.session[:user_id] = 2
599
      page = WikiPage.find_by(title: 'Page_with_sections')
600
      section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
601
      text = page.content.text
602

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

  
612 626
  def test_update_section_should_not_allow_stale_section_update
......
636 650
  end
637 651

  
638 652
  def test_preview
639
    @request.session[:user_id] = 2
640
    post :preview, :params => {
641
      :project_id => 1,
642
      :id => 'CookBook_documentation',
643
      :content => {
644
        :comments => '',
645
        :text => 'this is a *previewed text*',
646
        :version => 3
647
      }
648
    }, :xhr => true
649
    assert_response :success
650
    assert_select 'strong', :text => /previewed text/
653
    with_settings :text_formatting => 'textile' do
654
      @request.session[:user_id] = 2
655
      post :preview, :params => {
656
        :project_id => 1,
657
        :id => 'CookBook_documentation',
658
        :content => {
659
          :comments => '',
660
          :text => 'this is a *previewed text*',
661
          :version => 3
662
        }
663
      }, :xhr => true
664
      assert_response :success
665
      assert_select 'strong', :text => /previewed text/
666
    end
651 667
  end
652 668

  
653 669
  def test_preview_new_page
654
    @request.session[:user_id] = 2
655
    post :preview, :params => {
656
      :project_id => 1,
657
      :id => 'New page',
658
      :content => {
659
        :text => 'h1. New page',
660
        :comments => '',
661
        :version => 0
662
      }
663
    }, :xhr => true
664
    assert_response :success
665
    assert_select 'h1', :text => /New page/
670
    with_settings :text_formatting => 'textile' do
671
      @request.session[:user_id] = 2
672
      post :preview, :params => {
673
        :project_id => 1,
674
        :id => 'New page',
675
        :content => {
676
          :text => 'h1. New page',
677
          :comments => '',
678
          :version => 0
679
        }
680
      }, :xhr => true
681
      assert_response :success
682
      assert_select 'h1', :text => /New page/
683
    end
666 684
  end
667 685

  
668 686
  def test_history
......
1101 1119
  end
1102 1120

  
1103 1121
  def test_show_html
1104
    @request.session[:user_id] = 2
1105
    get :show, :params => {:project_id => 1, :format => 'html'}
1106
    assert_response :success
1122
    with_settings :text_formatting => 'textile' do
1123
      @request.session[:user_id] = 2
1124
      get :show, :params => {:project_id => 1, :format => 'html'}
1125
      assert_response :success
1107 1126

  
1108
    assert_equal 'text/html', @response.media_type
1109
    assert_equal 'attachment; filename="CookBook_documentation.html"',
1110
                 @response.headers['Content-Disposition']
1111
    assert_select 'h1', :text => /CookBook documentation/
1127
      assert_equal 'text/html', @response.media_type
1128
      assert_equal 'attachment; filename="CookBook_documentation.html"',
1129
                   @response.headers['Content-Disposition']
1130
      assert_select 'h1', :text => /CookBook documentation/
1131
    end
1112 1132
  end
1113 1133

  
1114 1134
  def test_show_versioned_html
1115
    @request.session[:user_id] = 2
1116
    get :show, :params => {:project_id => 1, :format => 'html', :version => 2}
1117
    assert_response :success
1135
    with_settings :text_formatting => 'textile' do
1136
      @request.session[:user_id] = 2
1137
      get :show, :params => {:project_id => 1, :format => 'html', :version => 2}
1138
      assert_response :success
1118 1139

  
1119
    assert_equal 'text/html', @response.media_type
1120
    assert_equal 'attachment; filename="CookBook_documentation.html"',
1121
                 @response.headers['Content-Disposition']
1122
    assert_select 'h1', :text => /CookBook documentation v2/
1140
      assert_equal 'text/html', @response.media_type
1141
      assert_equal 'attachment; filename="CookBook_documentation.html"',
1142
                  @response.headers['Content-Disposition']
1143
      assert_select 'h1', :text => /CookBook documentation v2/
1144
    end
1123 1145
  end
1124 1146

  
1125 1147
  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
......
151 157
        'with title <img src="http://foo.bar/image.jpg" title="This is a double-quoted &quot;title&quot;" ' \
152 158
          'alt="This is a double-quoted &quot;title&quot;" />',
153 159
    }
154
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
160
    with_settings :text_formatting => 'textile' do
161
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
162
    end
155 163
  end
156 164

  
157 165
  def test_inline_images_inside_tags
......
162 170

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

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

  
185 197
  def test_attached_images_with_textile_and_non_ascii_filename
......
214 226

  
215 227
  def test_attached_images_with_hires_naming
216 228
    attachment = Attachment.generate!(:filename => 'image@2x.png')
217
    assert_equal(
218
      %(<p><img src="/attachments/download/#{attachment.id}/image@2x.png" ) +
219
        %(srcset="/attachments/download/#{attachment.id}/image@2x.png 2x" alt="" /></p>),
220
      textilizable("!image@2x.png!", :attachments => [attachment])
221
    )
229
    with_settings :text_formatting => 'textile' do
230
      assert_equal(
231
        %(<p><img src="/attachments/download/#{attachment.id}/image@2x.png" ) +
232
          %(srcset="/attachments/download/#{attachment.id}/image@2x.png 2x" alt="" /></p>),
233
        textilizable('!image@2x.png!', :attachments => [attachment])
234
      )
235
    end
222 236
  end
223 237

  
224 238
  def test_attached_images_filename_extension
......
278 292
    }
279 293

  
280 294
    attachments = [a1, a2, a3, a4]
281
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments)}
295
    with_settings :text_formatting => 'textile' do
296
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments)}
297
    end
282 298
  end
283 299

  
284 300
  def test_attached_images_should_read_later
......
302 318
        'Inline image: <img src="/attachments/download/' + a2.id.to_s + '/testfile.PNG" alt="" />',
303 319
    }
304 320
    attachments = [a1, a2]
305
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments)}
321
    with_settings :text_formatting => 'textile' do
322
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments)}
323
    end
306 324
  ensure
307 325
    set_tmp_attachments_directory
308 326
  end
......
333 351
        '<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>',
334 352
      'This is an intern "link":/foo/bar-' => 'This is an intern <a href="/foo/bar-">link</a>'
335 353
    }
336
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
354
    with_settings :text_formatting => 'textile' do
355
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
356
    end
337 357
  end
338 358

  
339 359
  def test_textile_external_links_with_non_ascii_characters
......
341 361
      %|This is a "link":http://foo.bar/#{@russian_test}| =>
342 362
        %|This is a <a href="http://foo.bar/#{@russian_test}" class="external">link</a>|
343 363
    }
344
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
364
    with_settings :text_formatting => 'textile' do
365
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
366
    end
345 367
  end
346 368

  
347 369
  def test_redmine_links
......
530 552
      'user:foobar'                 => 'user:foobar',
531 553
    }
532 554
    @project = Project.find(1)
533
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"}
555
    with_settings :text_formatting => 'textile' do
556
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"}
557
    end
534 558
  end
535 559

  
536 560
  def test_link_to_note_within_the_same_page
537
    issue = Issue.find(1)
538
    assert_equal '<p><a href="#note-14">#note-14</a></p>', textilizable('#note-14', :object => issue)
561
    with_settings :text_formatting => 'textile' do
562
      issue = Issue.find(1)
563
      assert_equal '<p><a href="#note-14">#note-14</a></p>', textilizable('#note-14', :object => issue)
539 564

  
540
    journal = Journal.find(2)
541
    assert_equal '<p><a href="#note-2">#note-2</a></p>', textilizable('#note-2', :object => journal)
565
      journal = Journal.find(2)
566
      assert_equal '<p><a href="#note-2">#note-2</a></p>', textilizable('#note-2', :object => journal)
567
    end
542 568
  end
543 569

  
544 570
  def test_user_links_with_email_as_login_name_should_not_be_parsed_textile
......
584 610
  def test_should_not_parse_redmine_links_inside_link
585 611
    raw = "r1 should not be parsed in http://example.com/url-r1/"
586 612
    html = '<a class="external" href="http://example.com/url-r1/">http://example.com/url-r1/</a>'
587
    assert_match(
588
      %r{<p><a class="changeset".*>r1</a> should not be parsed in #{html}</p>},
589
      textilizable(raw, :project => Project.find(1))
590
    )
613
    with_settings :text_formatting => 'textile' do
614
      assert_match(
615
        %r{<p><a class="changeset".*>r1</a> should not be parsed in #{html}</p>},
616
        textilizable(raw, :project => Project.find(1))
617
      )
618
    end
591 619
  end
592 620

  
593 621
  def test_redmine_links_with_a_different_project_before_current_project
......
596 624
    @project = Project.find(3)
597 625
    result1 = link_to("1.4.4", "/versions/#{vp1.id}", :class => "version")
598 626
    result2 = link_to("1.4.4", "/versions/#{vp3.id}", :class => "version")
599
    assert_equal "<p>#{result1} #{result2}</p>",
600
                 textilizable("ecookbook:version:1.4.4 version:1.4.4")
627
    with_settings :text_formatting => 'textile' do
628
      assert_equal "<p>#{result1} #{result2}</p>",
629
                   textilizable('ecookbook:version:1.4.4 version:1.4.4')
630
    end
601 631
  end
602 632

  
603 633
  def test_escaped_redmine_links_should_not_be_parsed
......
614 644
      'source:/some/file'
615 645
    ]
616 646
    @project = Project.find(1)
617
    to_test.each {|text| assert_equal "<p>#{text}</p>", textilizable("!" + text), "#{text} failed"}
647
    with_settings :text_formatting => 'textile' do
648
      to_test.each {|text| assert_equal "<p>#{text}</p>", textilizable("!#{text}"), "#{text} failed"}
649
    end
618 650
  end
619 651

  
620 652
  def test_cross_project_redmine_links
......
648 680
      'invalid:source:/some/file'             => 'invalid:source:/some/file',
649 681
    }
650 682
    @project = Project.find(3)
651
    to_test.each do |text, result|
652
      assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"
683
    with_settings :text_formatting => 'textile' do
684
      to_test.each do |text, result|
685
        assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"
686
      end
653 687
    end
654 688
  end
655 689

  
......
658 692
    link = link_to("Test & Show.txt", "/versions/#{v.id}", :class => "version")
659 693

  
660 694
    @project = v.project
661
    assert_equal "<p>#{link}</p>", textilizable('version:"Test & Show.txt"')
695
    with_settings :text_formatting => 'textile' do
696
      assert_equal "<p>#{link}</p>", textilizable('version:"Test & Show.txt"')
697
    end
662 698
  end
663 699

  
664 700
  def test_link_to_issue_subject
......
748 784
    }
749 785

  
750 786
    @project = Project.find(1)
751
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"}
787
    with_settings :text_formatting => 'textile' do
788
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"}
789
    end
752 790
  end
753 791

  
754 792
  def test_cross_project_multiple_repositories_redmine_links
......
805 843
      'invalid:source:invalid|some/file'       => 'invalid:source:invalid|some/file',
806 844
    }
807 845
    @project = Project.find(3)
808
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"}
846
    with_settings :text_formatting => 'textile' do
847
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"}
848
    end
809 849
  end
810 850

  
811 851
  def test_redmine_links_git_commit
......
834 874
    to_test = {
835 875
      'commit:abcd' => changeset_link,
836 876
    }
837
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
877
    with_settings :text_formatting => 'textile' do
878
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
879
    end
838 880
  end
839 881

  
840 882
  # TODO: Bazaar commit id contains mail address, so it contains '@' and '_'.
......
877 919
      'r123' => changeset_link_rev,
878 920
      'commit:abcd' => changeset_link_commit,
879 921
    }
880
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
922
    with_settings :text_formatting => 'textile' do
923
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
924
    end
881 925
  end
882 926

  
883 927
  def test_attachment_links
884 928
    text = 'attachment:error281.txt'
885 929
    result = link_to("error281.txt", "/attachments/1",
886 930
                     :class => "attachment")
887
    assert_equal "<p>#{result}</p>",
888
                 textilizable(text,
889
                              :attachments => Issue.find(3).attachments),
890
                 "#{text} failed"
931
    with_settings :text_formatting => 'textile' do
932
      assert_equal "<p>#{result}</p>",
933
                  textilizable(text,
934
                                :attachments => Issue.find(3).attachments),
935
                  "#{text} failed"
936
    end
891 937
  end
892 938

  
893 939
  def test_attachment_link_should_link_to_latest_attachment
......
895 941
    a2 = Attachment.generate!(:filename => "test.txt")
896 942
    result = link_to("test.txt", "/attachments/#{a2.id}",
897 943
                     :class => "attachment")
898
    assert_equal "<p>#{result}</p>",
899
                 textilizable('attachment:test.txt', :attachments => [a1, a2])
944
    with_settings :text_formatting => 'textile' do
945
      assert_equal "<p>#{result}</p>",
946
                   textilizable('attachment:test.txt', :attachments => [a1, a2])
947
    end
900 948
  end
901 949

  
902 950
  def test_attachment_links_to_images_with_email_format_should_not_be_parsed
......
1012 1060
      '[[private-child:Wiki]]' => '[[private-child:Wiki]]',
1013 1061
    }
1014 1062
    @project = Project.find(1)
1015
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
1063
    with_settings :text_formatting => 'textile' do
1064
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
1065
    end
1016 1066
  end
1017 1067

  
1018 1068
  def test_wiki_links_with_special_characters_should_work_in_textile
......
1105 1155
                 :class => "wiki-page new"),
1106 1156
    }
1107 1157
    @project = Project.find(1)
1108
    to_test.each do |text, result|
1109
      assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :local)
1158
    with_settings :text_formatting => 'textile' do
1159
      to_test.each do |text, result|
1160
        assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :local)
1161
      end
1110 1162
    end
1111 1163
  end
1112 1164

  
......
1165 1217
                 :class => "wiki-page new"),
1166 1218
    }
1167 1219
    @project = Project.find(1)
1168
    to_test.each do |text, result|
1169
      assert_equal "<p>#{result}</p>",
1170
                   textilizable(WikiContent.new(:text => text, :page => page), :text)
1220
    with_settings :text_formatting => 'textile' do
1221
      to_test.each do |text, result|
1222
        assert_equal "<p>#{result}</p>",
1223
                     textilizable(WikiContent.new(:text => text, :page => page), :text)
1224
      end
1171 1225
    end
1172 1226
  end
1173 1227

  
......
1209 1263
                  :class => "wiki-page new"),
1210 1264
    }
1211 1265
    @project = Project.find(1)
1212
    to_test.each do |text, result|
1213
      assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :anchor)
1266
    with_settings :text_formatting => 'textile' do
1267
      to_test.each do |text, result|
1268
        assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :anchor)
1269
      end
1214 1270
    end
1215 1271
  end
1216 1272

  
......
1235 1291
      '<pre><code class=""onmouseover="alert(1)">text</code></pre>' => '<pre><code>text</code></pre>',
1236 1292
      '<pre class=""onmouseover="alert(1)">text</pre>' => '<pre>text</pre>',
1237 1293
    }
1238
    to_test.each {|text, result| assert_equal result, textilizable(text)}
1294
    with_settings :text_formatting => 'textile' do
1295
      to_test.each {|text, result| assert_equal result, textilizable(text)}
1296
    end
1239 1297
  end
1240 1298

  
1241 1299
  def test_allowed_html_tags
......
1244 1302
      "<notextile>no *textile* formatting</notextile>" => "no *textile* formatting",
1245 1303
      "<notextile>this is <tag>a tag</tag></notextile>" => "this is &lt;tag&gt;a tag&lt;/tag&gt;"
1246 1304
    }
1247
    to_test.each {|text, result| assert_equal result, textilizable(text)}
1305
    with_settings :text_formatting => 'textile' do
1306
      to_test.each {|text, result| assert_equal result, textilizable(text)}
1307
    end
1248 1308
  end
1249 1309

  
1250 1310
  def test_pre_tags
......
1264 1324
      </pre>
1265 1325
      <p>After</p>
1266 1326
    EXPECTED
1267
    assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
1327
    with_settings :text_formatting => 'textile' do
1328
      assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
1329
    end
1268 1330
  end
1269 1331

  
1270 1332
  def test_pre_content_should_not_parse_wiki_and_redmine_links
......
1296 1358
      </pre>
1297 1359
    EXPECTED
1298 1360
    @project = Project.find(1)
1299
    assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
1361
    with_settings :text_formatting => 'textile' do
1362
      assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
1363
    end
1300 1364
  end
1301 1365

  
1302 1366
  def test_non_closing_pre_blocks_should_be_closed
......
1308 1372
      </code></pre>
1309 1373
    EXPECTED
1310 1374
    @project = Project.find(1)
1311
    assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
1375
    with_settings :text_formatting => 'textile' do
1376
      assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
1377
    end
1312 1378
  end
1313 1379

  
1314 1380
  def test_unbalanced_closing_pre_tag_should_not_error
......
1327 1393
    expected = <<~EXPECTED
1328 1394
      <pre><code class="ECMA_script syntaxhl"><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>
1329 1395
    EXPECTED
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_syntax_highlight_ampersand_in_textile
......
1364 1432
               "<td>#{link2}</td>" +
1365 1433
               "</tr><tr><td>Cell 21</td><td>#{link3}</td></tr>"
1366 1434
    @project = Project.find(1)
1367
    assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '')
1435
    with_settings :text_formatting => 'textile' do
1436
      assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '')
1437
    end
1368 1438
  end
1369 1439

  
1370 1440
  def test_text_formatting
......
1377 1447
      'a *H* umane *W* eb *T* ext *G* enerator' =>
1378 1448
        'a <strong>H</strong> umane <strong>W</strong> eb <strong>T</strong> ext <strong>G</strong> enerator',
1379 1449
    }
1380
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
1450
    with_settings :text_formatting => 'textile' do
1451
      to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
1452
    end
1381 1453
  end
1382 1454

  
1383 1455
  def test_wiki_horizontal_rule
1384
    assert_equal '<hr />', textilizable('---')
1385
    assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---')
1456
    with_settings :text_formatting => 'textile' do
1457
      assert_equal '<hr />', textilizable('---')
1458
      assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---')
1459
    end
1386 1460
  end
1387 1461

  
1388 1462
  def test_headings
......
1390 1464
    expected =
1391 1465
      %|<a name="Some-heading"></a>\n<h1 >Some heading| +
1392 1466
        %|<a href="#Some-heading" class="wiki-anchor">&para;</a></h1>|
1393
    assert_equal expected, textilizable(raw)
1467
    with_settings :text_formatting => 'textile' do
1468
      assert_equal expected, textilizable(raw)
1469
    end
1394 1470
  end
1395 1471

  
1396 1472
  def test_headings_with_special_chars
......
1401 1477
    expected =
1402 1478
      %|<a name="#{anchor}"></a>\n<h1 >Some heading related to version 0.5| +
1403 1479
        %|<a href="##{anchor}" class="wiki-anchor">&para;</a></h1>|
1404
    assert_equal expected, textilizable(raw)
1480
    with_settings :text_formatting => 'textile' do
1481
      assert_equal expected, textilizable(raw)
1482
    end
1405 1483
  end
1406 1484

  
1407 1485
  def test_headings_in_wiki_single_page_export_should_be_prepended_with_page_title
......
1410 1488
    expected =
1411 1489
      %|<a name="Page_Title_Some-heading"></a>\n<h1 >Some heading| +
1412 1490
        %|<a href="#Page_Title_Some-heading" class="wiki-anchor">&para;</a></h1>|
1413
    assert_equal expected, textilizable(content, :text, :wiki_links => :anchor)
1491
    with_settings :text_formatting => 'textile' do
1492
      assert_equal expected, textilizable(content, :text, :wiki_links => :anchor)
1493
    end
1414 1494
  end
1415 1495

  
1416 1496
  def test_table_of_content
......
1472 1552
               '</ul>'
1473 1553

  
1474 1554
    @project = Project.find(1)
1475
    assert textilizable(raw).delete("\n").include?(expected)
1555
    with_settings :text_formatting => 'textile' do
1556
      assert textilizable(raw).delete("\n").include?(expected)
1557
    end
1476 1558
  end
1477 1559

  
1478 1560
  def test_table_of_content_should_generate_unique_anchors
......
1496 1578
                  '</li>' +
1497 1579
                '</ul>'
1498 1580
    @project = Project.find(1)
1499
    result = textilizable(raw).delete("\n")
1500
    assert_include expected, result
1501
    assert_include '<a name="Subtitle">', result
1502
    assert_include '<a name="Subtitle-2">', result
1581
    with_settings :text_formatting => 'textile' do
1582
      result = textilizable(raw).delete("\n")
1583
      assert_include expected, result
1584
      assert_include '<a name="Subtitle">', result
1585
      assert_include '<a name="Subtitle-2">', result
1586
    end
1503 1587
  end
1504 1588

  
1505 1589
  def test_table_of_content_should_contain_included_page_headings
......
1517 1601
               '<li><a href="#Child-page-1">Child page 1</a></li>' +
1518 1602
               '</ul>'
1519 1603
    @project = Project.find(1)
1520
    assert textilizable(raw).delete("\n").include?(expected)
1604
    with_settings :text_formatting => 'textile' do
1605
      assert textilizable(raw).delete("\n").include?(expected)
1606
    end
1521 1607
  end
1522 1608

  
1523 1609
  def test_toc_with_textile_formatting_should_be_parsed
......
1562 1648
    RAW
1563 1649
    @project = Project.find(1)
1564 1650
    set_language_if_valid 'en'
1565
    result =
1566
      textilizable(
1567
        raw,
1568
        :edit_section_links =>
1569
          {:controller => 'wiki', :action => 'edit',
1570
           :project_id => '1', :id => 'Test'}
1571
      ).delete("\n")
1572
    # heading that contains inline code
1573
    assert_match(
1574
      Regexp.new(
1575
        '<div class="contextual heading-2" title="Edit this section" id="section-4">' \
1576
        '<a class="icon-only icon-edit" href="/projects/1/wiki/Test/edit\?section=4">' \
1577
        'Edit this section' \
1578
        '</a></div>' \
1579
        '<a name="Subtitle-with-inline-code"></a>' \
1580
        '<h2 >Subtitle with ' \
1581
        '<code>inline code</code><a href="#Subtitle-with-inline-code" class="wiki-anchor">&para;</a>' \
1582
        '</h2>'
1583
      ),
1584
      result
1585
    )
1586
    # last heading
1587
    assert_match(
1588
      Regexp.new(
1589
        '<div class="contextual heading-2" title="Edit this section" id="section-5">' \
1590
        '<a class="icon-only icon-edit" href="/projects/1/wiki/Test/edit\?section=5">' \
1591
        'Edit this section' \
1592
        '</a></div>' \
1593
        '<a name="Subtitle-after-pre-tag"></a>' \
1594
        '<h2 >Subtitle after pre tag' \
1595
        '<a href="#Subtitle-after-pre-tag" class="wiki-anchor">&para;</a></h2>'
1596
      ),
1597
      result
1598
    )
1651
    with_settings :text_formatting => 'textile' do
1652
      result =
1653
        textilizable(
1654
          raw,
1655
          :edit_section_links =>
1656
            {:controller => 'wiki', :action => 'edit',
1657
            :project_id => '1', :id => 'Test'}
1658
        ).delete("\n")
1659
      # heading that contains inline code
1660
      assert_match(
1661
        Regexp.new(
1662
          '<div class="contextual heading-2" title="Edit this section" id="section-4">' \
1663
          '<a class="icon-only icon-edit" href="/projects/1/wiki/Test/edit\?section=4">' \
1664
          'Edit this section' \
1665
          '</a></div>' \
1666
          '<a name="Subtitle-with-inline-code"></a>' \
1667
          '<h2 >Subtitle with ' \
1668
          '<code>inline code</code><a href="#Subtitle-with-inline-code" class="wiki-anchor">&para;</a>' \
1669
          '</h2>'
1670
        ),
1671
        result
1672
      )
1673
      # last heading
1674
      assert_match(
1675
        Regexp.new(
1676
          '<div class="contextual heading-2" title="Edit this section" id="section-5">' \
1677
          '<a class="icon-only icon-edit" href="/projects/1/wiki/Test/edit\?section=5">' \
1678
          'Edit this section' \
1679
          '</a></div>' \
1680
          '<a name="Subtitle-after-pre-tag"></a>' \
1681
          '<h2 >Subtitle after pre tag' \
1682
          '<a href="#Subtitle-after-pre-tag" class="wiki-anchor">&para;</a></h2>'
1683
        ),
1684
        result
1685
      )
1686
    end
1599 1687
  end
1600 1688

  
1601 1689
  def test_default_formatter
......
1614 1702
  end
1615 1703

  
1616 1704
  def test_textilizable_with_formatting_set_to_true_should_format_text
1617
    assert_equal '<p><strong>text</strong></p>', textilizable("*text*", :formatting => true)
1705
    with_settings :text_formatting => 'textile' do
1706
      assert_equal '<p><strong>text</strong></p>', textilizable("*text*", :formatting => true)
1707
    end
1618 1708
  end
1619 1709

  
1620 1710
  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-expended', :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-expended', :text => 'Hide'
255
      end
229 256
    end
230 257
  end
231 258

  
232 259
  def test_macro_collapse_with_one_arg
233
    text = "{{collapse(Example)\n*Collapsed* block of text\n}}"
234
    result = textilizable(text)
260
    with_settings :text_formatting => 'textile' do
261
      text = "{{collapse(Example)\n*Collapsed* block of text\n}}"
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-expended', :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-expended', :text => 'Example'
268
    end
240 269
  end
241 270

  
242 271
  def test_macro_collapse_with_two_args
243
    text = "{{collapse(Show example, Hide example)\n*Collapsed* block of text\n}}"
244
    result = textilizable(text)
272
    with_settings :text_formatting => 'textile' do
273
      text = "{{collapse(Show example, Hide example)\n*Collapsed* block of text\n}}"
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-expended', :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-expended', :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

  
... This diff was truncated because it exceeds the maximum size that can be displayed.
(1-1/2)