- Timestamp:
- 11/18/09 06:27:14 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WysiwygPlugin/test/unit/WysiwygPlugin/TranslatorTests.pm
r5503 r5573 36 36 # Bits for test type 37 37 # Fields in test records: 38 my $TML2HTML = 1 << 0;# test tml => html39 my $HTML2TML = 1 << 1;# test html => finaltml (default tml)40 my $ROUNDTRIP = 1 << 2;# test tml => => finaltml38 my $TML2HTML = 1 << 0; # test tml => html 39 my $HTML2TML = 1 << 1; # test html => finaltml (default tml) 40 my $ROUNDTRIP = 1 << 2; # test tml => => finaltml 41 41 my $CANNOTWYSIWYG = 1 << 3; # test that notWysiwygEditable returns true 42 42 # and make the ROUNDTRIP test expect failure … … 61 61 # is "WysiwygEditable". 62 62 # 63 # Use CANNOTWYSIWYG without ROUNDTRIP *only* with an appropriate 64 # explanation. For example: 63 # Use CANNOTWYSIWYG without ROUNDTRIP *only* with an appropriate 64 # explanation. For example: 65 65 # Can't ROUNDTRIP this TML because perl on the SMURF platform 66 66 # automagically replaces all instances of 'blue' with 'beautiful'. … … 82 82 # Each testcase is a subhash with fields as follows: 83 83 # exec => $TML2HTML to test TML -> HTML, $HTML2TML to test HTML -> TML, 84 # $ROUNDTRIP to test TML-> ->TML, $CANNOTWYSIWYG to test 84 # $ROUNDTRIP to test TML-> ->TML, $CANNOTWYSIWYG to test 85 85 # notWysiwygEditable, all other bits are ignored. 86 86 # They may be OR'd togoether to perform multiple tests. … … 410 410 <div align="center">TEST Centered text.</div> 411 411 HERE 412 tml => <<'HERE',412 tml => <<'HERE', 413 413 <center>Center Text</center><br /> <div style="text-align:center">TEST Centered text.</div> 414 414 … … 425 425 HERE 426 426 }, 427 428 429 427 430 428 { … … 1623 1621 }, 1624 1622 { 1623 exec => $TML2HTML | $ROUNDTRIP, 1624 name => 'RowSpan1', 1625 tml => <<EXPT, 1626 | A | B | 1627 | C | ^ | 1628 EXPT 1629 html => <<HEXPT, 1630 <table border="1" cellpadding="0" cellspacing="1"> 1631 <tr><td>A</td><td rowspan="2">B</td></tr> 1632 <tr><td>C</td></tr> 1633 </table> 1634 HEXPT 1635 }, 1636 { 1637 exec => $TML2HTML | $ROUNDTRIP, 1638 name => 'RowSpan2', 1639 tml => <<EXPT, 1640 | A | B | 1641 | ^ | C | 1642 EXPT 1643 html => <<HEXPT, 1644 <table border="1" cellpadding="0" cellspacing="1"> 1645 <tr><td rowspan="2">A</td><td>B</td></tr> 1646 <tr><td>C</td></tr> 1647 </table> 1648 HEXPT 1649 }, 1650 { 1651 exec => $TML2HTML | $ROUNDTRIP, 1652 name => 'RowSpan3', 1653 tml => <<EXPT, 1654 | A | B | X | 1655 | ^ | ^ | C | 1656 EXPT 1657 html => <<HEXPT, 1658 <table border="1" cellpadding="0" cellspacing="1"> 1659 <tr><td rowspan="2">A</td><td rowspan="2">B</td><td>X</td></tr> 1660 <tr><td>C</td></tr> 1661 </table> 1662 HEXPT 1663 }, 1664 { 1665 exec => $TML2HTML | $ROUNDTRIP, 1666 name => 'RowSpan4', 1667 tml => <<EXPT, 1668 | A | B | X | 1669 | ^ | ^ | C | 1670 | M | ^ | ^ | 1671 EXPT 1672 html => <<HEXPT, 1673 <table border="1" cellpadding="0" cellspacing="1"> 1674 <tr><td rowspan="2">A</td><td rowspan="3">B</td><td>X</td></tr> 1675 <tr><td rowspan="2">C</td></tr> 1676 <tr><td>M</td></tr> 1677 </table> 1678 HEXPT 1679 }, 1680 { 1681 exec => $TML2HTML | $ROUNDTRIP, 1682 name => 'RowSpan5', 1683 tml => <<EXPT, 1684 | A | B | X | 1685 | ^ | ^ | C | 1686 | M | ^ | 1687 EXPT 1688 html => <<HEXPT, 1689 <table border="1" cellpadding="0" cellspacing="1"> 1690 <tr><td rowspan="2">A</td><td rowspan="3">B</td><td>X</td></tr> 1691 <tr><td>C</td></tr> 1692 <tr><td>M</td></tr> 1693 </table> 1694 HEXPT 1695 DISABLEDfinaltml => <<FEXPT, 1696 | A | B | X | 1697 | ^ | ^ | C | 1698 | M | ^ | | 1699 FEXPT 1700 }, 1701 { 1702 exec => $TML2HTML | $ROUNDTRIP, 1703 name => 'mergedRowsAndColumnsCentre', 1704 tml => <<EXPT, 1705 | A1 | A2 | A3 | A4 | 1706 | B1 | X || B4 | 1707 | C1 | ^ | C4 | 1708 | D1 | D2 | D3 | D4 | 1709 EXPT 1710 html => <<HEXPT, 1711 <table border="1" cellpadding="0" cellspacing="1"> 1712 <tr><td>A1</td><td>A2</td><td>A3</td><td>A4</td></tr> 1713 <tr><td>B1</td><td rowspan="2" colspan="2">X</td><td>B4</td></tr> 1714 <tr><td>C1</td><td>C4</td></tr> 1715 <tr><td>D1</td><td>D2</td><td>D3</td><td>D4</td></tr> 1716 </table> 1717 HEXPT 1718 }, 1719 { 1720 exec => $TML2HTML | $ROUNDTRIP, 1721 name => 'mergedRowsAndColumnsTopLeft', 1722 tml => <<EXPT, 1723 | X || A3 | 1724 | ^ | B3 | 1725 | C1 | C2 | C3 | 1726 EXPT 1727 html => <<HEXPT, 1728 <table border="1" cellpadding="0" cellspacing="1"> 1729 <tr><td rowspan="2" colspan="2">X</td><td>A3</td></tr> 1730 <tr><td>B3</td></tr> 1731 <tr><td>C1</td><td>C2</td><td>C3</td></tr> 1732 </table> 1733 HEXPT 1734 }, 1735 { 1736 exec => $TML2HTML | $ROUNDTRIP, 1737 name => 'mergedRowsAndColumnsTopRight', 1738 tml => <<EXPT, 1739 | A1 | X || 1740 | B1 | ^ | 1741 | C1 | C2 | C3 | 1742 EXPT 1743 html => <<HEXPT, 1744 <table border="1" cellpadding="0" cellspacing="1"> 1745 <tr><td>A1</td><td rowspan="2" colspan="2">X</td></tr> 1746 <tr><td>B1</td></tr> 1747 <tr><td>C1</td><td>C2</td><td>C3</td></tr> 1748 </table> 1749 HEXPT 1750 }, 1751 { 1752 exec => $TML2HTML | $ROUNDTRIP, 1753 name => 'mergedRowsAndColumnsBottomLeft', 1754 tml => <<EXPT, 1755 | A1 | A2 | A3 | 1756 | X || B3 | 1757 | ^ | C3 | 1758 EXPT 1759 html => <<HEXPT, 1760 <table border="1" cellpadding="0" cellspacing="1"> 1761 <tr><td>A1</td><td>A2</td><td>A3</td></tr> 1762 <tr><td rowspan="2" colspan="2">X</td><td>B3</td></tr> 1763 <tr><td>C3</td></tr> 1764 </table> 1765 HEXPT 1766 }, 1767 { 1768 exec => $TML2HTML | $ROUNDTRIP, 1769 name => 'mergedRowsAndColumnsBottomRight', 1770 tml => <<EXPT, 1771 | A1 | A2 | A3 | 1772 | B1 | X || 1773 | C1 | ^ | 1774 EXPT 1775 html => <<HEXPT, 1776 <table border="1" cellpadding="0" cellspacing="1"> 1777 <tr><td>A1</td><td>A2</td><td>A3</td></tr> 1778 <tr><td>B1</td><td rowspan="2" colspan="2">X</td></tr> 1779 <tr><td>C1</td></tr> 1780 </table> 1781 HEXPT 1782 }, 1783 { 1784 exec => $TML2HTML | $ROUNDTRIP, 1785 name => 'notAlwaysRowSpan', 1786 tml => <<EXPT, 1787 | ^ | B | 1788 | ^ | <nop>^ | 1789 EXPT 1790 html => <<HEXPT, 1791 <table border="1" cellpadding="0" cellspacing="1"> 1792 <tr><td rowspan="2">^</td><td>B</td></tr> 1793 <tr><td>$protecton<nop>$protectoff^</td></tr> 1794 </table> 1795 HEXPT 1796 }, 1797 { 1625 1798 exec => $HTML2TML | $ROUNDTRIP, 1626 1799 name => 'collapse', … … 1805 1978 html => <<THERE, 1806 1979 <table cellspacing="1" cellpadding="0" border="1"> 1807 <tr><td><span class="WYSIWYG_LINK">[[LegacyTopic1]]</span></td><td> Main.SomeGuy</td></tr>1980 <tr><td><span class="WYSIWYG_LINK">[[LegacyTopic1]]</span></td><td><span class="WYSIWYG_LINK">Main.SomeGuy</span></td></tr> 1808 1981 </table> 1809 1982 <span class="WYSIWYG_PROTECTED"><br />%TABLESEP%</span> … … 1820 1993 html => <<THERE, 1821 1994 <table cellspacing="1" cellpadding="0" border="1"> 1822 <tr><td><span class="WYSIWYG_LINK">[[LegacyTopic1]]</span></td><td> Main.SomeGuy</td></tr>1995 <tr><td><span class="WYSIWYG_LINK">[[LegacyTopic1]]</span></td><td><span class="WYSIWYG_LINK">Main.SomeGuy</span></td></tr> 1823 1996 </table> 1824 1997 <span class="WYSIWYG_PROTECTED"><br />%SEARCH{"legacy" nonoise="on" format="| [[\$topic]] | [[\$wikiname]] |"}%</span> 1998 THERE 1999 }, 2000 { 2001 name => 'linkInTable', 2002 exec => $ROUNDTRIP | $TML2HTML, 2003 tml => <<HERE, 2004 | Main.SomeGuy | 2005 | - Main.SomeGuy - | 2006 Main.SomeGuy 2007 HERE 2008 html => <<THERE, 2009 <table cellspacing="1" cellpadding="0" border="1"> 2010 <tr><td><span class="WYSIWYG_LINK">Main.SomeGuy</span></td></tr> 2011 <tr><td> - <span class="WYSIWYG_LINK">Main.SomeGuy</span> - </td></tr> 2012 </table> 2013 <span class="WYSIWYG_LINK">Main.SomeGuy</span> 1825 2014 THERE 1826 2015 }, … … 2042 2231 name => "Item2222", 2043 2232 exec => $ROUNDTRIP | $CANNOTWYSIWYG, 2044 tml => '<!-- <sticky></sticky> -->',2233 tml => '<!-- <sticky></sticky> -->', 2045 2234 }, 2046 2235 ]; … … 2074 2263 my $fn = 'TranslatorTests::testCANNOTWYSIWYG_' . $datum->{name}; 2075 2264 no strict 'refs'; 2076 *$fn = sub { my $this = shift; $this->compareNotWysiwygEditable($datum) }; 2265 *$fn = 2266 sub { my $this = shift; $this->compareNotWysiwygEditable($datum) }; 2077 2267 use strict 'refs'; 2078 2268 } … … 2122 2312 } 2123 2313 $query->path_info("/Current/TestTopic"); 2124 $this->{session}->finish() if ( defined($this->{session}));2314 $this->{session}->finish() if ( defined( $this->{session} ) ); 2125 2315 $this->{session} = new Foswiki( undef, $query ); 2126 2316 $Foswiki::Plugins::SESSION = $this->{session}; … … 2135 2325 } 2136 2326 2137 sub TML_HTMLconverterOptions 2138 { 2327 sub TML_HTMLconverterOptions { 2139 2328 my $this = shift; 2140 2329 return { … … 2160 2349 $tml =~ s/%!page!%/$page/g; 2161 2350 2162 my $notEditable = Foswiki::Plugins::WysiwygPlugin::notWysiwygEditable( $tml);2163 $this->assert( !$notEditable, $notEditable);2351 my $notEditable = Foswiki::Plugins::WysiwygPlugin::notWysiwygEditable($tml); 2352 $this->assert( !$notEditable, $notEditable ); 2164 2353 2165 2354 my $txer = new Foswiki::Plugins::WysiwygPlugin::TML2HTML(); 2166 my $tx = $txer->convert( 2167 $tml, 2168 $this->TML_HTMLconverterOptions() 2169 ); 2355 my $tx = $txer->convert( $tml, $this->TML_HTMLconverterOptions() ); 2170 2356 2171 2357 $this->assert_html_equals( $html, $tx ); … … 2185 2371 $tml =~ s/%!page!%/$page/g; 2186 2372 2187 my $notEditable = Foswiki::Plugins::WysiwygPlugin::notWysiwygEditable( $tml, '' ); 2188 $this->assert($notEditable, "This TML should not be wysiwyg-editable: $tml"); 2373 my $notEditable = 2374 Foswiki::Plugins::WysiwygPlugin::notWysiwygEditable( $tml, '' ); 2375 $this->assert( $notEditable, 2376 "This TML should not be wysiwyg-editable: $tml" ); 2189 2377 } 2190 2378 … … 2200 2388 2201 2389 my $txer = new Foswiki::Plugins::WysiwygPlugin::TML2HTML(); 2202 # This conversion can throw an exception. 2390 2391 # This conversion can throw an exception. 2203 2392 # This might be expected if $args->{exec} also has $CANNOTWYSIWYG set 2204 my $html = eval { 2205 $txer->convert( 2206 $tml, 2207 $this->TML_HTMLconverterOptions() 2208 ); 2209 }; 2393 my $html = 2394 eval { $txer->convert( $tml, $this->TML_HTMLconverterOptions() ); }; 2210 2395 $html = $@ if $@; 2211 2396 2212 2397 $txer = new Foswiki::Plugins::WysiwygPlugin::HTML2TML(); 2213 my $tx = $txer->convert( 2214 $html, 2215 $this->HTML_TMLconverterOptions() 2216 ); 2398 my $tx = $txer->convert( $html, $this->HTML_TMLconverterOptions() ); 2217 2399 my $finaltml = $args->{finaltml} || $tml; 2218 2400 $finaltml =~ s/%!page!%/$page/g; 2219 2401 2220 my $notEditable = Foswiki::Plugins::WysiwygPlugin::notWysiwygEditable( $tml, '' ); 2402 my $notEditable = 2403 Foswiki::Plugins::WysiwygPlugin::notWysiwygEditable( $tml, '' ); 2221 2404 if ( ( $mask & $args->{exec} ) & $CANNOTWYSIWYG ) { 2222 $this->assert($notEditable, "This TML should not be wysiwyg-editable: $tml"); 2223 # Expect that roundtrip is not possible if notWysiwygEditable returns true. 2224 # notWysiwygEditable should not return false for anything that *can* be 2225 # roundtripped. 2405 $this->assert( $notEditable, 2406 "This TML should not be wysiwyg-editable: $tml" ); 2407 2408 # Expect that roundtrip is not possible if notWysiwygEditable returns true. 2409 # notWysiwygEditable should not return false for anything that *can* be 2410 # roundtripped. 2226 2411 $this->_assert_tml_not_equals( $finaltml, $tx, $args->{name} ); 2227 2412 } 2228 2413 else { 2229 2414 $this->_assert_tml_equals( $finaltml, $tx, $args->{name} ); 2230 $this->assert(!$notEditable, "$args->{name} TML is wysiwyg-editable, but notWysiwygEditable() reports: $notEditable"); 2415 $this->assert( !$notEditable, 2416 "$args->{name} TML is wysiwyg-editable, but notWysiwygEditable() reports: $notEditable" 2417 ); 2231 2418 } 2232 2419 2233 2420 } 2234 2421 2235 sub HTML_TMLconverterOptions 2236 { 2422 sub HTML_TMLconverterOptions { 2237 2423 my $this = shift; 2238 2424 return { … … 2258 2444 2259 2445 my $txer = new Foswiki::Plugins::WysiwygPlugin::HTML2TML(); 2260 my $tx = $txer->convert( 2261 $html, 2262 $this->HTML_TMLconverterOptions() 2263 ); 2446 my $tx = $txer->convert( $html, $this->HTML_TMLconverterOptions() ); 2264 2447 $this->_assert_tml_equals( $finaltml, $tx, $args->{name} ); 2265 2448 } … … 2310 2493 if ( $expected eq $actual ) { 2311 2494 my $expl = 2312 "==$name== Actual TML unexpectedly correct, remove \$CANNOTWYSIWYG flag:\n"2495 "==$name== Actual TML unexpectedly correct, remove \$CANNOTWYSIWYG flag:\n" 2313 2496 . encode($actual) 2314 2497 . "\n==$name==\n";
Note: See TracChangeset
for help on using the changeset viewer.
