Project

General

Profile

Defect #43730 » 0002-add-tests-for-block-level-macro-content.diff

Alexander Meindl, 2026-07-28 18:00

View differences:

w/test/unit/lib/redmine/wiki_formatting/macros_test.rb
314 314
    end
315 315
  end
316 316

  
317
  BLOCK_LEVEL_CONTENT_IN_PARAGRAPH_RE =
318
    %r{<p(?:\s[^>]*)?>(?:(?!</p>).)*<(?:div|h[1-6]|hr|ol|pre|table|ul)[\s/>]}m
319

  
320
  def test_macro_returning_block_level_content_should_not_be_wrapped_in_paragraph
321
    text = <<~RAW
322
      {{collapse(Show example, Hide example)
323
      h2. Heading
324

  
325
      Some text
326
      }}
327
    RAW
328
    %w[textile common_mark].each do |format|
329
      with_settings :text_formatting => format do
330
        assert_no_match BLOCK_LEVEL_CONTENT_IN_PARAGRAPH_RE, textilizable(text)
331
      end
332
    end
333
  end
334

  
335
  def test_include_macro_should_not_be_wrapped_in_paragraph
336
    @project = Project.find(1)
337
    %w[textile common_mark].each do |format|
338
      with_settings :text_formatting => format do
339
        assert_no_match BLOCK_LEVEL_CONTENT_IN_PARAGRAPH_RE, textilizable('{{include(Another page)}}')
340
      end
341
    end
342
  end
343

  
344
  # Example 1 of #43730: text between collapses in the same paragraph
345
  def test_macro_multiple_collapse_with_text_between_should_not_generate_block_inside_p
346
    text = <<~RAW
347
      1 {{collapse(1)
348
      content 1
349
      }}
350
      2 {{collapse(2)
351
      content 2
352
      }}
353
      3 {{collapse(3)
354
      content 3
355
      }}
356
    RAW
357
    with_settings :text_formatting => 'textile' do
358
      assert_no_match BLOCK_LEVEL_CONTENT_IN_PARAGRAPH_RE, textilizable(text)
359
    end
360
  end
361

  
362
  # Example 2 of #43730: adjacent collapses with no text between
363
  def test_macro_multiple_collapse_adjacent_should_not_generate_block_inside_p
364
    text = <<~RAW
365
      {{collapse(1)
366
      content 1
367
      }}
368
      {{collapse(2)
369
      content 2
370
      }}
371
    RAW
372
    with_settings :text_formatting => 'textile' do
373
      assert_no_match BLOCK_LEVEL_CONTENT_IN_PARAGRAPH_RE, textilizable(text)
374
    end
375
  end
376

  
377
  # Example 3 of #43730: multiple groups of collapses separated by a blank line
378
  def test_macro_multiple_collapse_groups_should_not_generate_block_inside_p
379
    text = <<~RAW
380
      1 {{collapse(1)
381
      content 1
382
      }}
383
      2 {{collapse(2)
384
      content 2
385
      }}
386

  
387
      3 {{collapse(3)
388
      content 3
389
      }}
390
    RAW
391
    with_settings :text_formatting => 'textile' do
392
      assert_no_match BLOCK_LEVEL_CONTENT_IN_PARAGRAPH_RE, textilizable(text)
393
    end
394
  end
395

  
396
  def test_macro_returning_inline_content_should_keep_its_paragraph
397
    with_settings :text_formatting => 'textile' do
398
      assert_match %r{<p>Some text: <a}, textilizable('Some text: {{issue(1)}}')
399
    end
400
  end
401

  
402
  def test_text_without_macro_should_not_be_altered
403
    with_settings :text_formatting => 'textile' do
404
      assert_equal '<p>Some text</p>', textilizable('Some text').strip
405
    end
406
  end
407

  
317 408
  def test_macro_child_pages
318 409
    expected =
319 410
      "<p><ul class=\"pages-hierarchy\">\n" \
(14-14/15)