- Timestamp:
- 09/15/09 06:36:40 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Release01x00/WysiwygPlugin/test/unit/WysiwygPlugin/TranslatorTests.pm
r4434 r4931 36 36 # Bits for test type 37 37 # 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 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 41 my $CANNOTWYSIWYG = 1 << 3; # test that notWysiwygEditable returns true 42 # and make the ROUNDTRIP test expect failure 41 43 42 44 # Note: ROUNDTRIP is *not* the same as the combination of 43 45 # HTML2TML and TML2HTML. The HTML and TML comparisons are both 44 # somewhat "flexible". This is necess ry because, for example,46 # somewhat "flexible". This is necessary because, for example, 45 47 # the nature of whitespace in the TML may change. 46 48 # ROUNDTRIP tests are intended to isolate gradual degradation 47 49 # of the TML, where TML -> HTML -> not quite TML -> HTML 48 50 # -> 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'. 49 67 50 68 # Bit mask for selected test types 51 my $mask = $TML2HTML | $HTML2TML | $ROUNDTRIP ;69 my $mask = $TML2HTML | $HTML2TML | $ROUNDTRIP | $CANNOTWYSIWYG; 52 70 53 71 my $protecton = '<span class="WYSIWYG_PROTECTED">'; … … 64 82 # Each testcase is a subhash with fields as follows: 65 83 # 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. 67 86 # They may be OR'd togoether to perform multiple tests. 68 87 # For example: $TML2HTML | $HTML2TML to test both … … 1631 1650 BLAH 1632 1651 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> 1658 GLUED 1659 html => <<'BLAH', 1660 <p> 1661 <pre class="TMLverbatim"><sticky>banana</sticky></pre> 1662 </p> 1663 BLAH 1664 }, 1665 { 1666 exec => $ROUNDTRIP, 1667 name => 'literalInsideVerbatimItem1980', 1668 tml => <<'GLUED', 1669 <verbatim><literal><font color="blue"> *|B|* </font></literal></verbatim> 1670 GLUED 1671 }, 1672 { 1673 exec => $ROUNDTRIP | $CANNOTWYSIWYG, 1674 name => 'verbatimInsideLiteralItem1980', 1675 tml => <<'GLUED', 1676 <literal><font color="blue"> *|B|*<verbatim>%H%</verbatim> </font></literal> 1677 GLUED 1678 }, 1679 { 1680 exec => $TML2HTML | $ROUNDTRIP, 1681 name => 'verbatimInsideStickyItem1980', 1682 tml => <<'GLUED', 1683 <sticky><font color="blue"> *|B|*<verbatim>%H%</verbatim> </font></sticky> 1684 GLUED 1685 html => <<'STUCK' 1686 <p> 1687 <div class="WYSIWYG_STICKY"><verbatim><font color="blue"> *|B|* </font></verbatim></div> 1688 </p> 1689 STUCK 1690 }, 1691 { 1692 exec => $TML2HTML | $ROUNDTRIP, 1693 name => 'literalInsideSticky', 1694 tml => <<'GLUED', 1695 <sticky><literal><font color="blue"> *|B|* </font></literal></sticky> 1696 GLUED 1697 html => <<'STUCK' 1698 <p> 1699 <div class="WYSIWYG_STICKY"><literal><font color="blue"> *|B|* </font></literal></div> 1700 </p> 1701 STUCK 1702 }, 1703 { 1704 exec => $ROUNDTRIP | $CANNOTWYSIWYG, 1705 name => 'stickyInsideLiteral', 1706 tml => <<'GLUED', 1707 <literal><sticky><font color="blue"> *|B|* </font></sticky/></literal> 1708 GLUED 1633 1709 }, 1634 1710 { … … 1953 2029 no strict 'refs'; 1954 2030 *$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) }; 1955 2037 use strict 'refs'; 1956 2038 } … … 2012 2094 } 2013 2095 2096 sub 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 2014 2107 sub compareTML_HTML { 2015 2108 my ( $this, $args ) = @_; … … 2025 2118 $tml =~ s/%!page!%/$page/g; 2026 2119 2120 my $notEditable = Foswiki::Plugins::WysiwygPlugin::notWysiwygEditable( $tml ); 2121 $this->assert(!$notEditable, $notEditable); 2122 2027 2123 my $txer = new Foswiki::Plugins::WysiwygPlugin::TML2HTML(); 2028 2124 my $tx = $txer->convert( 2029 2125 $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() 2037 2127 ); 2038 2128 … … 2040 2130 } 2041 2131 2042 sub compare RoundTrip{2132 sub compareNotWysiwygEditable { 2043 2133 my ( $this, $args ) = @_; 2134 2044 2135 my $page = 2045 2136 $this->{session}->getScriptUrl( 1, 'view', 'Current', 'TestTopic' ); 2046 2137 $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 2149 sub compareRoundTrip { 2150 my ( $this, $args ) = @_; 2151 2152 my $page = 2153 $this->{session}->getScriptUrl( 1, 'view', 'Current', 'TestTopic' ); 2154 $page =~ s/\/Current\/TestTopic.*$//; 2047 2155 2048 2156 my $tml = $args->{tml} || ''; … … 2052 2160 my $html = $txer->convert( 2053 2161 $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() 2061 2163 ); 2062 2164 … … 2064 2166 my $tx = $txer->convert( 2065 2167 $html, 2066 { 2067 web => 'Current', 2068 topic => 'TestTopic', 2069 convertImage => \&convertImage, 2070 rewriteURL => \&Foswiki::Plugins::WysiwygPlugin::postConvertURL, 2071 } 2168 $this->HTML_TMLconverterOptions() 2072 2169 ); 2073 2170 my $finaltml = $args->{finaltml} || $tml; 2074 2171 $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 2188 sub 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 }; 2076 2197 } 2077 2198 … … 2092 2213 my $tx = $txer->convert( 2093 2214 $html, 2094 { 2095 web => 'Current', 2096 topic => 'TestTopic', 2097 convertImage => \&convertImage, 2098 rewriteURL => \&Foswiki::Plugins::WysiwygPlugin::postConvertURL, 2099 } 2215 $this->HTML_TMLconverterOptions() 2100 2216 ); 2101 2217 $this->_assert_tml_equals( $finaltml, $tx, $args->{name} ); … … 2139 2255 } 2140 2256 2257 sub _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 2141 2272 sub convertImage { 2142 2273 my $url = shift;
Note: See TracChangeset
for help on using the changeset viewer.
