Ignore:
Timestamp:
09/15/09 06:36:40 (3 years ago)
Author:
MichaelTempest
Message:

Item1980: First, do no harm - copied from trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Release01x00/WysiwygPlugin/test/unit/WysiwygPlugin/TranslatorTests.pm

    r4434 r4931  
    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 
     41my $CANNOTWYSIWYG = 1 << 3;    # test that notWysiwygEditable returns true 
     42                               #   and make the ROUNDTRIP test expect failure 
    4143 
    4244# Note: ROUNDTRIP is *not* the same as the combination of 
    4345# HTML2TML and TML2HTML. The HTML and TML comparisons are both 
    44 # somewhat "flexible". This is necessry because, for example, 
     46# somewhat "flexible". This is necessary because, for example, 
    4547# the nature of whitespace in the TML may change. 
    4648# ROUNDTRIP tests are intended to isolate gradual degradation 
    4749# of the TML, where TML -> HTML -> not quite TML -> HTML 
    4850# -> even worse TML, ad nauseum 
     51# 
     52# CANNOTWYSIWYG should normally be used in conjunction with ROUNDTRIP 
     53# to ensure that notWysiwygEditable is consistent with this plugin's 
     54# ROUNDTRIP capabilities. 
     55# 
     56# CANNOTWYSIWYG and ROUNDTRIP used together document the failure cases, 
     57# i.e. they indicate TML that WysiwygPlugin cannot properly translate 
     58# to HTML and back. When WysiwygPlugin is modified to support these 
     59# cases, CANNOTWYSIWYG should be removed from each corresponding 
     60# test case and nonWysiwygEditable should be updated so that the TML 
     61# is "WysiwygEditable". 
     62# 
     63# Use CANNOTWYSIWYG without ROUNDTRIP *only* with an appropriate  
     64# explanation. For example:  
     65#   Can't ROUNDTRIP this TML because perl on the SMURF platform 
     66#   automagically replaces all instances of 'blue' with 'beautiful'. 
    4967 
    5068# Bit mask for selected test types 
    51 my $mask = $TML2HTML | $HTML2TML | $ROUNDTRIP; 
     69my $mask = $TML2HTML | $HTML2TML | $ROUNDTRIP | $CANNOTWYSIWYG; 
    5270 
    5371my $protecton  = '<span class="WYSIWYG_PROTECTED">'; 
     
    6482# Each testcase is a subhash with fields as follows: 
    6583# exec => $TML2HTML to test TML -> HTML, $HTML2TML to test HTML -> TML, 
    66 #   $ROUNDTRIP to test TML-> ->TML, all other bits are ignored. 
     84#   $ROUNDTRIP to test TML-> ->TML, $CANNOTWYSIWYG to test  
     85#   notWysiwygEditable, all other bits are ignored. 
    6786#   They may be OR'd togoether to perform multiple tests. 
    6887#   For example: $TML2HTML | $HTML2TML to test both 
     
    16311650BLAH 
    16321651        tml => "<sticky>Oranges</sticky>\n\n<sticky>Apples</sticky>" 
     1652    }, 
     1653    { 
     1654        exec => $ROUNDTRIP | $CANNOTWYSIWYG, # SMELL: Fix this case 
     1655        name => 'stickyInsideVerbatimItem1980', 
     1656        tml  => <<'GLUED', 
     1657<verbatim><sticky>banana</sticky></verbatim> 
     1658GLUED 
     1659        html => <<'BLAH', 
     1660<p> 
     1661<pre class="TMLverbatim">&lt;sticky&gt;banana&lt;/sticky&gt;</pre> 
     1662</p> 
     1663BLAH 
     1664    }, 
     1665    { 
     1666        exec => $ROUNDTRIP, 
     1667        name => 'literalInsideVerbatimItem1980', 
     1668        tml  => <<'GLUED', 
     1669<verbatim><literal><font color="blue"> *|B|* </font></literal></verbatim> 
     1670GLUED 
     1671    }, 
     1672    { 
     1673        exec => $ROUNDTRIP | $CANNOTWYSIWYG, 
     1674        name => 'verbatimInsideLiteralItem1980', 
     1675        tml  => <<'GLUED', 
     1676<literal><font color="blue"> *|B|*<verbatim>%H%</verbatim> </font></literal> 
     1677GLUED 
     1678    }, 
     1679    { 
     1680        exec => $TML2HTML | $ROUNDTRIP, 
     1681        name => 'verbatimInsideStickyItem1980', 
     1682        tml  => <<'GLUED', 
     1683<sticky><font color="blue"> *|B|*<verbatim>%H%</verbatim> </font></sticky> 
     1684GLUED 
     1685        html => <<'STUCK' 
     1686<p> 
     1687<div class="WYSIWYG_STICKY">&#60;verbatim&#62;&#60;font color="blue"&#62; *|B|* &#60;/font&#62;&#60;/verbatim&#62;</div> 
     1688</p> 
     1689STUCK 
     1690    }, 
     1691    { 
     1692        exec => $TML2HTML | $ROUNDTRIP, 
     1693        name => 'literalInsideSticky', 
     1694        tml  => <<'GLUED', 
     1695<sticky><literal><font color="blue"> *|B|* </font></literal></sticky> 
     1696GLUED 
     1697        html => <<'STUCK' 
     1698<p> 
     1699<div class="WYSIWYG_STICKY">&#60;literal&#62;&#60;font color="blue"&#62; *|B|* &#60;/font&#62;&#60;/literal&#62;</div> 
     1700</p> 
     1701STUCK 
     1702    }, 
     1703    { 
     1704        exec => $ROUNDTRIP | $CANNOTWYSIWYG, 
     1705        name => 'stickyInsideLiteral', 
     1706        tml  => <<'GLUED', 
     1707<literal><sticky><font color="blue"> *|B|* </font></sticky/></literal> 
     1708GLUED 
    16331709    }, 
    16341710    { 
     
    19532029            no strict 'refs'; 
    19542030            *$fn = sub { my $this = shift; $this->compareRoundTrip($datum) }; 
     2031            use strict 'refs'; 
     2032        } 
     2033        if ( ( $mask & $datum->{exec} ) & $CANNOTWYSIWYG ) { 
     2034            my $fn = 'TranslatorTests::testCANNOTWYSIWYG_' . $datum->{name}; 
     2035            no strict 'refs'; 
     2036            *$fn = sub { my $this = shift; $this->compareNotWysiwygEditable($datum) }; 
    19552037            use strict 'refs'; 
    19562038        } 
     
    20122094} 
    20132095 
     2096sub TML_HTMLconverterOptions 
     2097{ 
     2098    my $this = shift; 
     2099    return { 
     2100        web          => 'Current', 
     2101        topic        => 'TestTopic', 
     2102        convertImage => \&convertImage, 
     2103        rewriteURL   => \&Foswiki::Plugins::WysiwygPlugin::postConvertURL, 
     2104    }; 
     2105} 
     2106 
    20142107sub compareTML_HTML { 
    20152108    my ( $this, $args ) = @_; 
     
    20252118    $tml =~ s/%!page!%/$page/g; 
    20262119 
     2120    my $notEditable = Foswiki::Plugins::WysiwygPlugin::notWysiwygEditable( $tml ); 
     2121    $this->assert(!$notEditable, $notEditable); 
     2122 
    20272123    my $txer = new Foswiki::Plugins::WysiwygPlugin::TML2HTML(); 
    20282124    my $tx   = $txer->convert( 
    20292125        $tml, 
    2030         { 
    2031             web        => 'Current', 
    2032             topic      => 'TestTopic', 
    2033             getViewUrl => \&Foswiki::Plugins::WysiwygPlugin::getViewUrl, 
    2034             expandVarsInURL => 
    2035               \&Foswiki::Plugins::WysiwygPlugin::expandVarsInURL, 
    2036         } 
     2126        $this->TML_HTMLconverterOptions() 
    20372127    ); 
    20382128 
     
    20402130} 
    20412131 
    2042 sub compareRoundTrip { 
     2132sub compareNotWysiwygEditable { 
    20432133    my ( $this, $args ) = @_; 
     2134 
    20442135    my $page = 
    20452136      $this->{session}->getScriptUrl( 1, 'view', 'Current', 'TestTopic' ); 
    20462137    $page =~ s/\/Current\/TestTopic.*$//; 
     2138    my $html = $args->{html} || ''; 
     2139    $html =~ s/%!page!%/$page/g; 
     2140    my $finaltml = $args->{finaltml} || ''; 
     2141    $finaltml =~ s/%!page!%/$page/g; 
     2142    my $tml = $args->{tml} || ''; 
     2143    $tml =~ s/%!page!%/$page/g; 
     2144 
     2145    my $notEditable = Foswiki::Plugins::WysiwygPlugin::notWysiwygEditable( $tml, '' ); 
     2146    $this->assert($notEditable, "This TML should not be wysiwyg-editable: $tml"); 
     2147} 
     2148 
     2149sub compareRoundTrip { 
     2150    my ( $this, $args ) = @_; 
     2151 
     2152    my $page = 
     2153      $this->{session}->getScriptUrl( 1, 'view', 'Current', 'TestTopic' ); 
     2154    $page =~ s/\/Current\/TestTopic.*$//; 
    20472155 
    20482156    my $tml = $args->{tml} || ''; 
     
    20522160    my $html = $txer->convert( 
    20532161        $tml, 
    2054         { 
    2055             web        => 'Current', 
    2056             topic      => 'TestTopic', 
    2057             getViewUrl => \&Foswiki::Plugins::WysiwygPlugin::getViewUrl, 
    2058             expandVarsInURL => 
    2059               \&Foswiki::Plugins::WysiwygPlugin::expandVarsInURL, 
    2060         } 
     2162        $this->TML_HTMLconverterOptions() 
    20612163    ); 
    20622164 
     
    20642166    my $tx = $txer->convert( 
    20652167        $html, 
    2066         { 
    2067             web          => 'Current', 
    2068             topic        => 'TestTopic', 
    2069             convertImage => \&convertImage, 
    2070             rewriteURL   => \&Foswiki::Plugins::WysiwygPlugin::postConvertURL, 
    2071         } 
     2168        $this->HTML_TMLconverterOptions() 
    20722169    ); 
    20732170    my $finaltml = $args->{finaltml} || $tml; 
    20742171    $finaltml =~ s/%!page!%/$page/g; 
    2075     $this->_assert_tml_equals( $finaltml, $tx, $args->{name} ); 
     2172 
     2173    my $notEditable = Foswiki::Plugins::WysiwygPlugin::notWysiwygEditable( $tml, '' ); 
     2174    if ( ( $mask & $args->{exec} ) & $CANNOTWYSIWYG ) { 
     2175        $this->assert($notEditable, "This TML should not be wysiwyg-editable: $tml"); 
     2176        # Expect that roundtrip is not possible if notWysiwygEditable returns true. 
     2177        # notWysiwygEditable should not return false for anything that *can* be 
     2178        # roundtripped. 
     2179        $this->_assert_tml_not_equals( $finaltml, $tx, $args->{name} ); 
     2180    } 
     2181    else { 
     2182        $this->_assert_tml_equals( $finaltml, $tx, $args->{name} ); 
     2183        $this->assert(!$notEditable, "$args->{name} TML is wysiwyg-editable, but notWysiwygEditable() reports: $notEditable"); 
     2184    } 
     2185 
     2186} 
     2187 
     2188sub HTML_TMLconverterOptions 
     2189{ 
     2190    my $this = shift; 
     2191    return { 
     2192        web          => 'Current', 
     2193        topic        => 'TestTopic', 
     2194        convertImage => \&convertImage, 
     2195        rewriteURL   => \&Foswiki::Plugins::WysiwygPlugin::postConvertURL, 
     2196    }; 
    20762197} 
    20772198 
     
    20922213    my $tx   = $txer->convert( 
    20932214        $html, 
    2094         { 
    2095             web          => 'Current', 
    2096             topic        => 'TestTopic', 
    2097             convertImage => \&convertImage, 
    2098             rewriteURL   => \&Foswiki::Plugins::WysiwygPlugin::postConvertURL, 
    2099         } 
     2215        $this->HTML_TMLconverterOptions() 
    21002216    ); 
    21012217    $this->_assert_tml_equals( $finaltml, $tx, $args->{name} ); 
     
    21392255} 
    21402256 
     2257sub _assert_tml_not_equals { 
     2258    my ( $this, $expected, $actual, $name ) = @_; 
     2259    $expected ||= ''; 
     2260    $actual   ||= ''; 
     2261    $actual   =~ s/\n$//s; 
     2262    $expected =~ s/\n$//s; 
     2263    if ( $expected eq $actual ) { 
     2264        my $expl = 
     2265            "==$name== Actual TML unexpectedly correct, remove \$CANNOTWYSIWYG flag:\n" 
     2266          . encode($actual) 
     2267          . "\n==$name==\n"; 
     2268        $this->assert( 0, $expl . "\n" ); 
     2269    } 
     2270} 
     2271 
    21412272sub convertImage { 
    21422273    my $url = shift; 
Note: See TracChangeset for help on using the changeset viewer.