Ignore:
Timestamp:
11/18/09 06:27:14 (3 years ago)
Author:
MichaelTempest
Message:

Item2369: Add rowspan support to the WYSIWYG editor
This also fixed a bug in how Web.WikiWord links are rendered, if the link is the only text in the table cell.

Tables are no longer "normalised" when converting from HTML to TML by appending |'s so that every row has the same number of |'s. The logic to do so when supporting rowspans is complex (read: likely to be buggy) and the "normalisation" feature is seldom used (it only had any effect if the HTML has a table with a hole in it.) Taking out the normalisation does not result in loss of content.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/WysiwygPlugin/test/unit/WysiwygPlugin/TranslatorTests.pm

    r5503 r5573  
    3636# Bits for test type 
    3737# Fields in test records: 
    38 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 
     38my $TML2HTML      = 1 << 0;    # test tml => html 
     39my $HTML2TML      = 1 << 1;    # test html => finaltml (default tml) 
     40my $ROUNDTRIP     = 1 << 2;    # test tml => => finaltml 
    4141my $CANNOTWYSIWYG = 1 << 3;    # test that notWysiwygEditable returns true 
    4242                               #   and make the ROUNDTRIP test expect failure 
     
    6161# is "WysiwygEditable". 
    6262# 
    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: 
    6565#   Can't ROUNDTRIP this TML because perl on the SMURF platform 
    6666#   automagically replaces all instances of 'blue' with 'beautiful'. 
     
    8282# Each testcase is a subhash with fields as follows: 
    8383# 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 
    8585#   notWysiwygEditable, all other bits are ignored. 
    8686#   They may be OR'd togoether to perform multiple tests. 
     
    410410<div align="center">TEST Centered text.</div> 
    411411HERE 
    412         tml  => <<'HERE', 
     412        tml => <<'HERE', 
    413413<center>Center Text</center><br /> <div style="text-align:center">TEST Centered text.</div>  
    414414 
     
    425425HERE 
    426426    }, 
    427  
    428  
    429427 
    430428    { 
     
    16231621    }, 
    16241622    { 
     1623        exec => $TML2HTML | $ROUNDTRIP, 
     1624        name => 'RowSpan1', 
     1625        tml  => <<EXPT, 
     1626| A | B | 
     1627| C | ^ | 
     1628EXPT 
     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> 
     1634HEXPT 
     1635    }, 
     1636    { 
     1637        exec => $TML2HTML | $ROUNDTRIP, 
     1638        name => 'RowSpan2', 
     1639        tml  => <<EXPT, 
     1640| A | B | 
     1641| ^ | C | 
     1642EXPT 
     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> 
     1648HEXPT 
     1649    }, 
     1650    { 
     1651        exec => $TML2HTML | $ROUNDTRIP, 
     1652        name => 'RowSpan3', 
     1653        tml  => <<EXPT, 
     1654| A | B | X | 
     1655| ^ | ^ | C | 
     1656EXPT 
     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> 
     1662HEXPT 
     1663    }, 
     1664    { 
     1665        exec => $TML2HTML | $ROUNDTRIP, 
     1666        name => 'RowSpan4', 
     1667        tml  => <<EXPT, 
     1668| A | B | X | 
     1669| ^ | ^ | C | 
     1670| M | ^ | ^ | 
     1671EXPT 
     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> 
     1678HEXPT 
     1679    }, 
     1680    { 
     1681        exec => $TML2HTML | $ROUNDTRIP, 
     1682        name => 'RowSpan5', 
     1683        tml  => <<EXPT, 
     1684| A | B | X | 
     1685| ^ | ^ | C | 
     1686| M | ^ | 
     1687EXPT 
     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> 
     1694HEXPT 
     1695        DISABLEDfinaltml => <<FEXPT, 
     1696| A | B | X | 
     1697| ^ | ^ | C | 
     1698| M | ^ | | 
     1699FEXPT 
     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 | 
     1709EXPT 
     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> 
     1717HEXPT 
     1718    }, 
     1719    { 
     1720        exec => $TML2HTML | $ROUNDTRIP, 
     1721        name => 'mergedRowsAndColumnsTopLeft', 
     1722        tml  => <<EXPT, 
     1723| X || A3 | 
     1724| ^ | B3 | 
     1725| C1 | C2 | C3 | 
     1726EXPT 
     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> 
     1733HEXPT 
     1734    }, 
     1735    { 
     1736        exec => $TML2HTML | $ROUNDTRIP, 
     1737        name => 'mergedRowsAndColumnsTopRight', 
     1738        tml  => <<EXPT, 
     1739| A1 | X || 
     1740| B1 | ^ | 
     1741| C1 | C2 | C3 | 
     1742EXPT 
     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> 
     1749HEXPT 
     1750    }, 
     1751    { 
     1752        exec => $TML2HTML | $ROUNDTRIP, 
     1753        name => 'mergedRowsAndColumnsBottomLeft', 
     1754        tml  => <<EXPT, 
     1755| A1 | A2 | A3 | 
     1756| X || B3 | 
     1757| ^ | C3 | 
     1758EXPT 
     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> 
     1765HEXPT 
     1766    }, 
     1767    { 
     1768        exec => $TML2HTML | $ROUNDTRIP, 
     1769        name => 'mergedRowsAndColumnsBottomRight', 
     1770        tml  => <<EXPT, 
     1771| A1 | A2 | A3 | 
     1772| B1 | X || 
     1773| C1 | ^ | 
     1774EXPT 
     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> 
     1781HEXPT 
     1782    }, 
     1783    { 
     1784        exec => $TML2HTML | $ROUNDTRIP, 
     1785        name => 'notAlwaysRowSpan', 
     1786        tml  => <<EXPT, 
     1787| ^ | B | 
     1788| ^ | <nop>^ | 
     1789EXPT 
     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&lt;nop&gt;$protectoff^</td></tr> 
     1794</table> 
     1795HEXPT 
     1796    }, 
     1797    { 
    16251798        exec => $HTML2TML | $ROUNDTRIP, 
    16261799        name => 'collapse', 
     
    18051978        html => <<THERE, 
    18061979<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> 
    18081981</table> 
    18091982<span class="WYSIWYG_PROTECTED"><br />%TABLESEP%</span> 
     
    18201993        html => <<THERE, 
    18211994<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> 
    18231996</table> 
    18241997<span class="WYSIWYG_PROTECTED"><br />%SEARCH{"legacy" nonoise="on" format="| [[\$topic]] | [[\$wikiname]] |"}%</span> 
     1998THERE 
     1999    }, 
     2000    { 
     2001        name => 'linkInTable', 
     2002        exec => $ROUNDTRIP | $TML2HTML, 
     2003        tml  => <<HERE, 
     2004| Main.SomeGuy | 
     2005| - Main.SomeGuy - | 
     2006Main.SomeGuy 
     2007HERE 
     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> 
    18252014THERE 
    18262015    }, 
     
    20422231        name => "Item2222", 
    20432232        exec => $ROUNDTRIP | $CANNOTWYSIWYG, 
    2044         tml => '<!-- <sticky></sticky> -->', 
     2233        tml  => '<!-- <sticky></sticky> -->', 
    20452234    }, 
    20462235]; 
     
    20742263            my $fn = 'TranslatorTests::testCANNOTWYSIWYG_' . $datum->{name}; 
    20752264            no strict 'refs'; 
    2076             *$fn = sub { my $this = shift; $this->compareNotWysiwygEditable($datum) }; 
     2265            *$fn = 
     2266              sub { my $this = shift; $this->compareNotWysiwygEditable($datum) }; 
    20772267            use strict 'refs'; 
    20782268        } 
     
    21222312    } 
    21232313    $query->path_info("/Current/TestTopic"); 
    2124     $this->{session}->finish() if (defined($this->{session})); 
     2314    $this->{session}->finish() if ( defined( $this->{session} ) ); 
    21252315    $this->{session} = new Foswiki( undef, $query ); 
    21262316    $Foswiki::Plugins::SESSION = $this->{session}; 
     
    21352325} 
    21362326 
    2137 sub TML_HTMLconverterOptions 
    2138 { 
     2327sub TML_HTMLconverterOptions { 
    21392328    my $this = shift; 
    21402329    return { 
     
    21602349    $tml =~ s/%!page!%/$page/g; 
    21612350 
    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 ); 
    21642353 
    21652354    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() ); 
    21702356 
    21712357    $this->assert_html_equals( $html, $tx ); 
     
    21852371    $tml =~ s/%!page!%/$page/g; 
    21862372 
    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" ); 
    21892377} 
    21902378 
     
    22002388 
    22012389    my $txer = new Foswiki::Plugins::WysiwygPlugin::TML2HTML(); 
    2202     # This conversion can throw an exception.  
     2390 
     2391    # This conversion can throw an exception. 
    22032392    # 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() ); }; 
    22102395    $html = $@ if $@; 
    22112396 
    22122397    $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() ); 
    22172399    my $finaltml = $args->{finaltml} || $tml; 
    22182400    $finaltml =~ s/%!page!%/$page/g; 
    22192401 
    2220     my $notEditable = Foswiki::Plugins::WysiwygPlugin::notWysiwygEditable( $tml, '' ); 
     2402    my $notEditable = 
     2403      Foswiki::Plugins::WysiwygPlugin::notWysiwygEditable( $tml, '' ); 
    22212404    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. 
    22262411        $this->_assert_tml_not_equals( $finaltml, $tx, $args->{name} ); 
    22272412    } 
    22282413    else { 
    22292414        $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        ); 
    22312418    } 
    22322419 
    22332420} 
    22342421 
    2235 sub HTML_TMLconverterOptions 
    2236 { 
     2422sub HTML_TMLconverterOptions { 
    22372423    my $this = shift; 
    22382424    return { 
     
    22582444 
    22592445    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() ); 
    22642447    $this->_assert_tml_equals( $finaltml, $tx, $args->{name} ); 
    22652448} 
     
    23102493    if ( $expected eq $actual ) { 
    23112494        my $expl = 
    2312             "==$name== Actual TML unexpectedly correct, remove \$CANNOTWYSIWYG flag:\n" 
     2495"==$name== Actual TML unexpectedly correct, remove \$CANNOTWYSIWYG flag:\n" 
    23132496          . encode($actual) 
    23142497          . "\n==$name==\n"; 
Note: See TracChangeset for help on using the changeset viewer.