Chris@1296: # Redmine - project management software Chris@1296: # Copyright (C) 2006-2012 Jean-Philippe Lang Chris@1296: # Chris@1296: # This program is free software; you can redistribute it and/or Chris@1296: # modify it under the terms of the GNU General Public License Chris@1296: # as published by the Free Software Foundation; either version 2 Chris@1296: # of the License, or (at your option) any later version. Chris@1296: # Chris@1296: # This program is distributed in the hope that it will be useful, Chris@1296: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@1296: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@1296: # GNU General Public License for more details. Chris@1296: # Chris@1296: # You should have received a copy of the GNU General Public License Chris@1296: # along with this program; if not, write to the Free Software Chris@1296: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@1296: Chris@1296: require File.expand_path('../../../../../test_helper', __FILE__) Chris@1296: require 'digest/md5' Chris@1296: Chris@1296: class Redmine::WikiFormatting::TextileFormatterTest < ActionView::TestCase Chris@1296: Chris@1296: def setup Chris@1296: @formatter = Redmine::WikiFormatting::Textile::Formatter Chris@1296: end Chris@1296: Chris@1296: MODIFIERS = { Chris@1296: "*" => 'strong', # bold Chris@1296: "_" => 'em', # italic Chris@1296: "+" => 'ins', # underline Chris@1296: "-" => 'del', # deleted Chris@1296: "^" => 'sup', # superscript Chris@1296: "~" => 'sub' # subscript Chris@1296: } Chris@1296: Chris@1296: def test_modifiers Chris@1296: assert_html_output( Chris@1296: '*bold*' => 'bold', Chris@1296: 'before *bold*' => 'before bold', Chris@1296: '*bold* after' => 'bold after', Chris@1296: '*two words*' => 'two words', Chris@1296: '*two*words*' => 'two*words', Chris@1296: '*two * words*' => 'two * words', Chris@1296: '*two* *words*' => 'two words', Chris@1296: '*(two)* *(words)*' => '(two) (words)', Chris@1296: # with class Chris@1296: '*(foo)two words*' => 'two words' Chris@1296: ) Chris@1296: end Chris@1296: Chris@1296: def test_modifiers_combination Chris@1296: MODIFIERS.each do |m1, tag1| Chris@1296: MODIFIERS.each do |m2, tag2| Chris@1296: next if m1 == m2 Chris@1296: text = "#{m2}#{m1}Phrase modifiers#{m1}#{m2}" Chris@1296: html = "<#{tag2}><#{tag1}>Phrase modifiers" Chris@1296: assert_html_output text => html Chris@1296: end Chris@1296: end Chris@1296: end Chris@1296: Chris@1296: def test_styles Chris@1296: # single style Chris@1296: assert_html_output({ Chris@1296: 'p{color:red}. text' => '

text

', Chris@1296: 'p{color:red;}. text' => '

text

', Chris@1296: 'p{color: red}. text' => '

text

', Chris@1296: 'p{color:#f00}. text' => '

text

', Chris@1296: 'p{color:#ff0000}. text' => '

text

', Chris@1296: 'p{border:10px}. text' => '

text

', Chris@1296: 'p{border:10}. text' => '

text

', Chris@1296: 'p{border:10%}. text' => '

text

', Chris@1296: 'p{border:10em}. text' => '

text

', Chris@1296: 'p{border:1.5em}. text' => '

text

', Chris@1296: 'p{border-left:1px}. text' => '

text

', Chris@1296: 'p{border-right:1px}. text' => '

text

', Chris@1296: 'p{border-top:1px}. text' => '

text

', Chris@1296: 'p{border-bottom:1px}. text' => '

text

', Chris@1296: }, false) Chris@1296: Chris@1296: # multiple styles Chris@1296: assert_html_output({ Chris@1296: 'p{color:red; border-top:1px}. text' => '

text

', Chris@1296: 'p{color:red ; border-top:1px}. text' => '

text

', Chris@1296: 'p{color:red;border-top:1px}. text' => '

text

', Chris@1296: }, false) Chris@1296: Chris@1296: # styles with multiple values Chris@1296: assert_html_output({ Chris@1296: 'p{border:1px solid red;}. text' => '

text

', Chris@1296: 'p{border-top-left-radius: 10px 5px;}. text' => '

text

', Chris@1296: }, false) Chris@1296: end Chris@1296: Chris@1296: def test_invalid_styles_should_be_filtered Chris@1296: assert_html_output({ Chris@1296: 'p{invalid}. text' => '

text

', Chris@1296: 'p{invalid:red}. text' => '

text

', Chris@1296: 'p{color:(red)}. text' => '

text

', Chris@1296: 'p{color:red;invalid:blue}. text' => '

text

', Chris@1296: 'p{invalid:blue;color:red}. text' => '

text

', Chris@1296: 'p{color:"}. text' => '

p{color:"}. text

', Chris@1296: }, false) Chris@1296: end Chris@1296: Chris@1296: def test_inline_code Chris@1296: assert_html_output( Chris@1296: 'this is @some code@' => 'this is some code', Chris@1296: '@@' => '<Location /redmine>' Chris@1296: ) Chris@1296: end Chris@1296: Chris@1296: def test_nested_lists Chris@1296: raw = <<-RAW Chris@1296: # Item 1 Chris@1296: # Item 2 Chris@1296: ** Item 2a Chris@1296: ** Item 2b Chris@1296: # Item 3 Chris@1296: ** Item 3a Chris@1296: RAW Chris@1296: Chris@1296: expected = <<-EXPECTED Chris@1296:
    Chris@1296:
  1. Item 1
  2. Chris@1296:
  3. Item 2 Chris@1296:
      Chris@1296:
    • Item 2a
    • Chris@1296:
    • Item 2b
    • Chris@1296:
    Chris@1296:
  4. Chris@1296:
  5. Item 3 Chris@1296:
      Chris@1296:
    • Item 3a
    • Chris@1296:
    Chris@1296:
  6. Chris@1296:
Chris@1296: EXPECTED Chris@1296: Chris@1296: assert_equal expected.gsub(%r{\s+}, ''), to_html(raw).gsub(%r{\s+}, '') Chris@1296: end Chris@1296: Chris@1296: def test_escaping Chris@1296: assert_html_output( Chris@1296: 'this is a