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