Project

General

Profile

Feature #36294 ยป feature-36294.patch

Mizuki ISHIKAWA, 2021-12-09 02:29

View differences:

app/helpers/application_helper.rb
320 320
      image_tag(
321 321
        thumbnail_path(attachment),
322 322
        :srcset => "#{thumbnail_path(attachment, :size => thumbnail_size * 2)} 2x",
323
        :style => "max-width: #{thumbnail_size}px; max-height: #{thumbnail_size}px;"
323
        :style => "max-width: #{thumbnail_size}px; max-height: #{thumbnail_size}px;",
324
        :loading => "lazy"
324 325
      ),
325 326
      attachment_path(
326 327
        attachment
......
946 947
          if !desc.blank? && alttext.blank?
947 948
            alt = " title=\"#{desc}\" alt=\"#{desc}\""
948 949
          end
949
          "src=\"#{image_url}\"#{alt}"
950
          "src=\"#{image_url}\"#{alt} loading=\"lazy\""
950 951
        else
951 952
          m
952 953
        end
test/helpers/application_helper_test.rb
171 171
  def test_attached_images
172 172
    to_test = {
173 173
      'Inline image: !logo.gif!' =>
174
         'Inline image: <img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" />',
174
         'Inline image: <img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" loading="lazy" />',
175 175
      'Inline image: !logo.GIF!' =>
176
         'Inline image: <img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" />',
176
         'Inline image: <img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" loading="lazy" />',
177 177
      'No match: !ogo.gif!' => 'No match: <img src="ogo.gif" alt="" />',
178 178
      'No match: !ogo.GIF!' => 'No match: <img src="ogo.GIF" alt="" />',
179 179
      # link image
180 180
      '!logo.gif!:http://foo.bar/' =>
181
         '<a href="http://foo.bar/"><img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" /></a>',
181
         '<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 182
    }
183 183
    attachments = Attachment.all
184 184
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments)}
......
196 196
      !attached_on_journal.png!'
197 197
    RAW
198 198

  
199
    assert textilizable(raw, :object => journal).include?("<img src=\"/attachments/download/#{attachment_1.id}/attached_on_issue.png\" alt=\"\" />")
200
    assert textilizable(raw, :object => journal).include?("<img src=\"/attachments/download/#{attachment_2.id}/attached_on_journal.png\" alt=\"\" />")
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\" />")
201 201
  end
202 202

  
203 203
  def test_attached_images_with_textile_and_non_ascii_filename
......
208 208
    with_settings :text_formatting => 'textile' do
209 209
      to_test.each do |filename, result|
210 210
        attachment = Attachment.generate!(:filename => filename)
211
        assert_include %(<img src="/attachments/download/#{attachment.id}/#{result}" alt="" />),
211
        assert_include %(<img src="/attachments/download/#{attachment.id}/#{result}" alt="" loading="lazy" />),
212 212
                       textilizable("!#{filename}!", :attachments => [attachment])
213 213
      end
214 214
    end
......
224 224
    with_settings :text_formatting => 'markdown' do
225 225
      to_test.each do |filename, result|
226 226
        attachment = Attachment.generate!(:filename => filename)
227
        assert_include %(<img src="/attachments/download/#{attachment.id}/#{result}" alt="" />),
227
        assert_include %(<img src="/attachments/download/#{attachment.id}/#{result}" alt="" loading="lazy" />),
228 228
                       textilizable("![](#{filename})", :attachments => [attachment])
229 229
      end
230 230
    end
......
234 234
    attachment = Attachment.generate!(:filename => 'image@2x.png')
235 235
    assert_equal(
236 236
      %(<p><img src="/attachments/download/#{attachment.id}/image@2x.png" ) +
237
        %(srcset="/attachments/download/#{attachment.id}/image@2x.png 2x" alt="" /></p>),
237
        %(srcset="/attachments/download/#{attachment.id}/image@2x.png 2x" alt="" loading="lazy" /></p>),
238 238
      textilizable("!image@2x.png!", :attachments => [attachment])
239 239
    )
240 240
  end
......
286 286

  
287 287
    to_test = {
288 288
      'Inline image: !testtest.jpg!' =>
289
        'Inline image: <img src="/attachments/download/' + a1.id.to_s + '/testtest.JPG" alt="" />',
289
        'Inline image: <img src="/attachments/download/' + a1.id.to_s + '/testtest.JPG" alt="" loading="lazy" />',
290 290
      'Inline image: !testtest.jpeg!' =>
291
        'Inline image: <img src="/attachments/download/' + a2.id.to_s + '/testtest.jpeg" alt="" />',
291
        'Inline image: <img src="/attachments/download/' + a2.id.to_s + '/testtest.jpeg" alt="" loading="lazy" />',
292 292
      'Inline image: !testtest.jpe!' =>
293
        'Inline image: <img src="/attachments/download/' + a3.id.to_s + '/testtest.JPE" alt="" />',
293
        'Inline image: <img src="/attachments/download/' + a3.id.to_s + '/testtest.JPE" alt="" loading="lazy" />',
294 294
      'Inline image: !testtest.bmp!' =>
295
        'Inline image: <img src="/attachments/download/' + a4.id.to_s + '/Testtest.BMP" alt="" />',
295
        'Inline image: <img src="/attachments/download/' + a4.id.to_s + '/Testtest.BMP" alt="" loading="lazy" />',
296 296
    }
297 297

  
298 298
    attachments = [a1, a2, a3, a4]
......
315 315

  
316 316
    to_test = {
317 317
      'Inline image: !testfile.png!' =>
318
        'Inline image: <img src="/attachments/download/' + a2.id.to_s + '/testfile.PNG" alt="" />',
318
        'Inline image: <img src="/attachments/download/' + a2.id.to_s + '/testfile.PNG" alt="" loading="lazy" />',
319 319
      'Inline image: !Testfile.PNG!' =>
320
        'Inline image: <img src="/attachments/download/' + a2.id.to_s + '/testfile.PNG" alt="" />',
320
        'Inline image: <img src="/attachments/download/' + a2.id.to_s + '/testfile.PNG" alt="" loading="lazy" />',
321 321
    }
322 322
    attachments = [a1, a2]
323 323
    to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments)}
......
1794 1794
    a = Attachment.find(3)
1795 1795
    assert_select_in(
1796 1796
      thumbnail_tag(a),
1797
      'a[href=?][title=?] img[src=?]',
1797
      'a[href=?][title=?] img[src=?][loading="lazy"]',
1798 1798
      "/attachments/3", "logo.gif", "/attachments/thumbnail/3")
1799 1799
  end
1800 1800

  
test/unit/lib/redmine/wiki_formatting/common_mark/application_helper_test.rb
49 49
      with_settings :text_formatting => 'common_mark' do
50 50
        to_test.each do |filename, result|
51 51
          attachment = Attachment.generate!(:filename => filename)
52
          assert_include %(<img src="/attachments/download/#{attachment.id}/#{result}" alt="">), textilizable("![](#{filename})", :attachments => [attachment])
52
          assert_include %(<img src="/attachments/download/#{attachment.id}/#{result}" alt="" loading="lazy">), textilizable("![](#{filename})", :attachments => [attachment])
53 53
        end
54 54
      end
55 55
    end
    (1-1/1)