<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[41132] trunk: Widgets: Rename Text widget's `legacy` mode to non-`visual` mode, restore boolean `filter` prop, and improve compatibility for `widget_text` filters applied in Custom HTML widget.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/41132">41132</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/41132","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>westonruter</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2017-07-24 22:45:55 +0000 (Mon, 24 Jul 2017)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Widgets: Rename Text widget's `legacy` mode to non-`visual` mode, restore boolean `filter` prop, and improve compatibility for `widget_text` filters applied in Custom HTML widget.

Props westonruter, obenland, timmydcrawford for testing.
Amends <a href="https://core.trac.wordpress.org/changeset/41050">[41050]</a>.
See <a href="https://core.trac.wordpress.org/ticket/35243">#35243</a>, <a href="https://core.trac.wordpress.org/ticket/40951">#40951</a>, <a href="https://core.trac.wordpress.org/ticket/40907">#40907</a>.
Fixes <a href="https://core.trac.wordpress.org/ticket/41394">#41394</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminjswidgetstextwidgetsjs">trunk/src/wp-admin/js/widgets/text-widgets.js</a></li>
<li><a href="#trunksrcwpincludeswidgetsclasswpwidgetcustomhtmlphp">trunk/src/wp-includes/widgets/class-wp-widget-custom-html.php</a></li>
<li><a href="#trunksrcwpincludeswidgetsclasswpwidgettextphp">trunk/src/wp-includes/widgets/class-wp-widget-text.php</a></li>
<li><a href="#trunktestsphpunittestswidgetscustomhtmlwidgetphp">trunk/tests/phpunit/tests/widgets/custom-html-widget.php</a></li>
<li><a href="#trunktestsphpunittestswidgetstextwidgetphp">trunk/tests/phpunit/tests/widgets/text-widget.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminjswidgetstextwidgetsjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/js/widgets/text-widgets.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/js/widgets/text-widgets.js     2017-07-24 22:40:12 UTC (rev 41131)
+++ trunk/src/wp-admin/js/widgets/text-widgets.js       2017-07-24 22:45:55 UTC (rev 41132)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -368,7 +368,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Bypass using TinyMCE when widget is in legacy mode.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( widgetForm.find( '.legacy' ).length > 0 ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( ! widgetForm.find( '.visual' ).val() ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         return;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -429,7 +429,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Bypass using TinyMCE when widget is in legacy mode.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( widgetForm.find( '.legacy' ).length > 0 ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( ! widgetForm.find( '.visual' ).val() ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         return;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunksrcwpincludeswidgetsclasswpwidgetcustomhtmlphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/widgets/class-wp-widget-custom-html.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/widgets/class-wp-widget-custom-html.php     2017-07-24 22:40:12 UTC (rev 41131)
+++ trunk/src/wp-includes/widgets/class-wp-widget-custom-html.php       2017-07-24 22:45:55 UTC (rev 41132)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -61,8 +61,16 @@
</span><span class="cx" style="display: block; padding: 0 10px">                /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
</span><span class="cx" style="display: block; padding: 0 10px">                $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                // Prepare instance data that looks like a normal Text widget.
+               $simulated_text_widget_instance = array_merge( $instance, array(
+                       'text' => isset( $instance['content'] ) ? $instance['content'] : '',
+                       'filter' => false, // Because wpautop is not applied.
+                       'visual' => false, // Because it wasn't created in TinyMCE.
+               ) );
+               unset( $simulated_text_widget_instance['content'] ); // Was moved to 'text' prop.
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 /** This filter is documented in wp-includes/widgets/class-wp-widget-text.php */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $content = apply_filters( 'widget_text', $instance['content'], $instance, $this );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $content = apply_filters( 'widget_text', $instance['content'], $simulated_text_widget_instance, $this );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                /**
</span><span class="cx" style="display: block; padding: 0 10px">                 * Filters the content of the Custom HTML widget.
</span></span></pre></div>
<a id="trunksrcwpincludeswidgetsclasswpwidgettextphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/widgets/class-wp-widget-text.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/widgets/class-wp-widget-text.php    2017-07-24 22:40:12 UTC (rev 41131)
+++ trunk/src/wp-includes/widgets/class-wp-widget-text.php      2017-07-24 22:45:55 UTC (rev 41132)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -79,12 +79,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function is_legacy_instance( $instance ) {
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // If the widget has been updated while in legacy mode, it stays in legacy mode.
-               if ( ! empty( $instance['legacy'] ) ) {
-                       return true;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Legacy mode when not in visual mode.
+               if ( isset( $instance['visual'] ) ) {
+                       return ! $instance['visual'];
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // If the widget has been added/updated in 4.8 then filter prop is 'content' and it is no longer legacy.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Or, the widget has been added/updated in 4.8.0 then filter prop is 'content' and it is no longer legacy.
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( isset( $instance['filter'] ) && 'content' === $instance['filter'] ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return false;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -193,8 +193,17 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $text = ! empty( $instance['text'] ) ? $instance['text'] : '';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $is_visual_text_widget = ( isset( $instance['filter'] ) && 'content' === $instance['filter'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $is_visual_text_widget = ( ! empty( $instance['visual'] ) && ! empty( $instance['filter'] ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                // In 4.8.0 only, visual Text widgets get filter=content, without visual prop; upgrade instance props just-in-time.
+               if ( ! $is_visual_text_widget ) {
+                       $is_visual_text_widget = ( isset( $instance['filter'] ) && 'content' === $instance['filter'] );
+               }
+               if ( $is_visual_text_widget ) {
+                       $instance['filter'] = true;
+                       $instance['visual'] = true;
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 /*
</span><span class="cx" style="display: block; padding: 0 10px">                 * Just-in-time temporarily upgrade Visual Text widget shortcode handling
</span><span class="cx" style="display: block; padding: 0 10px">                 * (with support added by plugin) from the widget_text filter to
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -221,25 +230,23 @@
</span><span class="cx" style="display: block; padding: 0 10px">                 */
</span><span class="cx" style="display: block; padding: 0 10px">                $text = apply_filters( 'widget_text', $text, $instance, $this );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( isset( $instance['filter'] ) ) {
-                       if ( 'content' === $instance['filter'] ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( $is_visual_text_widget ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                /**
-                                * Filters the content of the Text widget to apply changes expected from the visual (TinyMCE) editor.
-                                *
-                                * By default a subset of the_content filters are applied, including wpautop and wptexturize.
-                                *
-                                * @since 4.8.0
-                                *
-                                * @param string         $text     The widget content.
-                                * @param array          $instance Array of settings for the current widget.
-                                * @param WP_Widget_Text $this     Current Text widget instance.
-                                */
-                               $text = apply_filters( 'widget_text_content', $text, $instance, $this );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 /**
+                        * Filters the content of the Text widget to apply changes expected from the visual (TinyMCE) editor.
+                        *
+                        * By default a subset of the_content filters are applied, including wpautop and wptexturize.
+                        *
+                        * @since 4.8.0
+                        *
+                        * @param string         $text     The widget content.
+                        * @param array          $instance Array of settings for the current widget.
+                        * @param WP_Widget_Text $this     Current Text widget instance.
+                        */
+                       $text = apply_filters( 'widget_text_content', $text, $instance, $this );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        } elseif ( $instance['filter'] ) {
-                               $text = wpautop( $text ); // Back-compat for instances prior to 4.8.
-                       }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         } elseif ( ! empty( $instance['filter'] ) ) {
+                       $text = wpautop( $text ); // Back-compat for instances prior to 4.8.
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Undo temporary upgrade of the plugin-supplied shortcode handling.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -271,7 +278,15 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return array Settings to save or bool false to cancel saving.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function update( $new_instance, $old_instance ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $new_instance = wp_parse_args( $new_instance, array(
+                       'title' => '',
+                       'text' => '',
+                       'filter' => false, // For back-compat.
+                       'visual' => null, // Must be explicitly defined.
+               ) );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $instance = $old_instance;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $instance['title'] = sanitize_text_field( $new_instance['title'] );
</span><span class="cx" style="display: block; padding: 0 10px">                if ( current_user_can( 'unfiltered_html' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $instance['text'] = $new_instance['text'];
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -279,22 +294,25 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $instance['text'] = wp_kses_post( $new_instance['text'] );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                /*
-                * If the Text widget is in legacy mode, then a hidden input will indicate this
-                * and the new content value for the filter prop will by bypassed. Otherwise,
-                * re-use legacy 'filter' (wpautop) property to now indicate content filters will always apply.
-                * Prior to 4.8, this is a boolean value used to indicate whether or not wpautop should be
-                * applied. By re-using this property, downgrading WordPress from 4.8 to 4.7 will ensure
-                * that the content for Text widgets created with TinyMCE will continue to get wpautop.
-                */
-               if ( isset( $new_instance['legacy'] ) || isset( $old_instance['legacy'] ) || ( isset( $new_instance['filter'] ) && 'content' !== $new_instance['filter'] ) ) {
-                       $instance['filter'] = ! empty( $new_instance['filter'] );
-                       $instance['legacy'] = true;
-               } else {
-                       $instance['filter'] = 'content';
-                       unset( $instance['legacy'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $instance['filter'] = ! empty( $new_instance['filter'] );
+
+               // Upgrade 4.8.0 format.
+               if ( isset( $old_instance['filter'] ) && 'content' === $old_instance['filter'] ) {
+                       $instance['visual'] = true;
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                if ( 'content' === $new_instance['filter'] ) {
+                       $instance['visual'] = true;
+               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                if ( isset( $new_instance['visual'] ) ) {
+                       $instance['visual'] = ! empty( $new_instance['visual'] );
+               }
+
+               // Filter is always true in visual mode.
+               if ( ! empty( $instance['visual'] ) ) {
+                       $instance['filter'] = true;
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 return $instance;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -333,8 +351,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                <?php if ( ! $this->is_legacy_instance( $instance ) ) : ?>
</span><span class="cx" style="display: block; padding: 0 10px">                        <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" class="title" type="hidden" value="<?php echo esc_attr( $instance['title'] ); ?>">
</span><span class="cx" style="display: block; padding: 0 10px">                        <input id="<?php echo $this->get_field_id( 'text' ); ?>" name="<?php echo $this->get_field_name( 'text' ); ?>" class="text" type="hidden" value="<?php echo esc_attr( $instance['text'] ); ?>">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        <input id="<?php echo $this->get_field_id( 'filter' ); ?>" name="<?php echo $this->get_field_name( 'filter' ); ?>" class="filter" type="hidden" value="on">
+                       <input id="<?php echo $this->get_field_id( 'visual' ); ?>" name="<?php echo $this->get_field_name( 'visual' ); ?>" class="visual" type="hidden" value="on">
</ins><span class="cx" style="display: block; padding: 0 10px">                 <?php else : ?>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        <input name="<?php echo $this->get_field_name( 'legacy' ); ?>" type="hidden" class="legacy" value="true">
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 <input id="<?php echo $this->get_field_id( 'visual' ); ?>" name="<?php echo $this->get_field_name( 'visual' ); ?>" class="visual" type="hidden" value="">
</ins><span class="cx" style="display: block; padding: 0 10px">                         <p>
</span><span class="cx" style="display: block; padding: 0 10px">                                <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
</span><span class="cx" style="display: block; padding: 0 10px">                                <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>"/>
</span></span></pre></div>
<a id="trunktestsphpunittestswidgetscustomhtmlwidgetphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/widgets/custom-html-widget.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/widgets/custom-html-widget.php  2017-07-24 22:40:12 UTC (rev 41131)
+++ trunk/tests/phpunit/tests/widgets/custom-html-widget.php    2017-07-24 22:45:55 UTC (rev 41132)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -59,6 +59,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'content' => $content,
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                // Convert Custom HTML widget instance into Text widget instance data.
+               $text_widget_instance = array_merge( $instance, array(
+                       'text' => $instance['content'],
+                       'filter' => false,
+                       'visual' => false,
+               ) );
+               unset( $text_widget_instance['content'] );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 update_option( 'use_balanceTags', 0 );
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter( 'widget_custom_html_content', array( $this, 'filter_widget_custom_html_content' ), 5, 3 );
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter( 'widget_text', array( $this, 'filter_widget_text' ), 10, 3 );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -75,11 +83,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertNotContains( '<p>', $output );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertNotContains( '<br>', $output );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertNotContains( '</u>', $output );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( $instance, $this->widget_text_args[1] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertEquals( $text_widget_instance, $this->widget_text_args[1] );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertEquals( $instance, $this->widget_custom_html_content_args[1] );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( $widget, $this->widget_text_args[2] );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( $widget, $this->widget_custom_html_content_args[2] );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                remove_filter( 'widget_custom_html_content', array( $this, 'filter_widget_custom_html_content' ), 5, 3 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         remove_filter( 'widget_custom_html_content', array( $this, 'filter_widget_custom_html_content' ), 5 );
</ins><span class="cx" style="display: block; padding: 0 10px">                 remove_filter( 'widget_text', array( $this, 'filter_widget_text' ), 10 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                update_option( 'use_balanceTags', 1 );
</span></span></pre></div>
<a id="trunktestsphpunittestswidgetstextwidgetphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/widgets/text-widget.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/widgets/text-widget.php 2017-07-24 22:40:12 UTC (rev 41131)
+++ trunk/tests/phpunit/tests/widgets/text-widget.php   2017-07-24 22:45:55 UTC (rev 41132)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -82,17 +82,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'before_widget' => '<section>',
</span><span class="cx" style="display: block; padding: 0 10px">                        'after_widget'  => "</section>\n",
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               add_filter( 'widget_text_content', array( $this, 'filter_widget_text_content' ), 5, 3 );
+               add_filter( 'widget_text', array( $this, 'filter_widget_text' ), 5, 3 );
+
+               // Test with filter=false, implicit legacy mode.
+               $this->widget_text_content_args = null;
+               ob_start();
</ins><span class="cx" style="display: block; padding: 0 10px">                 $instance = array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'title'  => 'Foo',
</span><span class="cx" style="display: block; padding: 0 10px">                        'text'   => $text,
</span><span class="cx" style="display: block; padding: 0 10px">                        'filter' => false,
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-               add_filter( 'widget_text_content', array( $this, 'filter_widget_text_content' ), 5, 3 );
-               add_filter( 'widget_text', array( $this, 'filter_widget_text' ), 5, 3 );
-
-               // Test with filter=false.
-               ob_start();
</del><span class="cx" style="display: block; padding: 0 10px">                 $widget->widget( $args, $instance );
</span><span class="cx" style="display: block; padding: 0 10px">                $output = ob_get_clean();
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertNotContains( '<p>', $output );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -102,8 +103,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertContains( '[filter:widget_text]', $output );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertNotContains( '[filter:widget_text_content]', $output );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // Test with filter=true.
-               $instance['filter'] = true;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Test with filter=true, implicit legacy mode.
+               $this->widget_text_content_args = null;
+               $instance = array(
+                       'title'  => 'Foo',
+                       'text'   => $text,
+                       'filter' => true,
+               );
</ins><span class="cx" style="display: block; padding: 0 10px">                 ob_start();
</span><span class="cx" style="display: block; padding: 0 10px">                $widget->widget( $args, $instance );
</span><span class="cx" style="display: block; padding: 0 10px">                $output = ob_get_clean();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -117,22 +123,97 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertContains( '[filter:widget_text]', $output );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertNotContains( '[filter:widget_text_content]', $output );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // Test with filter=content, the upgraded widget.
-               $instance['filter'] = 'content';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Test with filter=content, the upgraded widget, in 4.8.0 only.
+               $this->widget_text_content_args = null;
+               $instance = array(
+                       'title'  => 'Foo',
+                       'text'   => $text,
+                       'filter' => 'content',
+               );
+               $expected_instance = array_merge( $instance, array(
+                       'filter' => true,
+                       'visual' => true,
+               ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                 ob_start();
</span><span class="cx" style="display: block; padding: 0 10px">                $widget->widget( $args, $instance );
</span><span class="cx" style="display: block; padding: 0 10px">                $output = ob_get_clean();
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertContains( '<p>', $output );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertContains( '<br />', $output );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertCount( 3, $this->widget_text_args );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( $instance['text'], $this->widget_text_args[0] );
-               $this->assertEquals( $instance, $this->widget_text_args[1] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertEquals( $expected_instance['text'], $this->widget_text_args[0] );
+               $this->assertEquals( $expected_instance, $this->widget_text_args[1] );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertEquals( $widget, $this->widget_text_args[2] );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertCount( 3, $this->widget_text_content_args );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( $instance['text'] . '[filter:widget_text]', $this->widget_text_content_args[0] );
-               $this->assertEquals( $instance, $this->widget_text_content_args[1] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertEquals( $expected_instance['text'] . '[filter:widget_text]', $this->widget_text_content_args[0] );
+               $this->assertEquals( $expected_instance, $this->widget_text_content_args[1] );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertEquals( $widget, $this->widget_text_content_args[2] );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertContains( wpautop( $instance['text'] . '[filter:widget_text][filter:widget_text_content]' ), $output );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertContains( wpautop( $expected_instance['text'] . '[filter:widget_text][filter:widget_text_content]' ), $output );
+
+               // Test with filter=true&visual=true, the upgraded widget, in 4.8.1 and above.
+               $this->widget_text_content_args = null;
+               $instance = array(
+                       'title'  => 'Foo',
+                       'text'   => $text,
+                       'filter' => true,
+                       'visual' => true,
+               );
+               $expected_instance = $instance;
+               ob_start();
+               $widget->widget( $args, $instance );
+               $output = ob_get_clean();
+               $this->assertContains( '<p>', $output );
+               $this->assertContains( '<br />', $output );
+               $this->assertCount( 3, $this->widget_text_args );
+               $this->assertEquals( $expected_instance['text'], $this->widget_text_args[0] );
+               $this->assertEquals( $expected_instance, $this->widget_text_args[1] );
+               $this->assertEquals( $widget, $this->widget_text_args[2] );
+               $this->assertCount( 3, $this->widget_text_content_args );
+               $this->assertEquals( $expected_instance['text'] . '[filter:widget_text]', $this->widget_text_content_args[0] );
+               $this->assertEquals( $expected_instance, $this->widget_text_content_args[1] );
+               $this->assertEquals( $widget, $this->widget_text_content_args[2] );
+               $this->assertContains( wpautop( $expected_instance['text'] . '[filter:widget_text][filter:widget_text_content]' ), $output );
+
+               // Test with filter=true&visual=true, the upgraded widget, in 4.8.1 and above.
+               $this->widget_text_content_args = null;
+               $instance = array(
+                       'title'  => 'Foo',
+                       'text'   => $text,
+                       'filter' => true,
+                       'visual' => false,
+               );
+               $expected_instance = $instance;
+               ob_start();
+               $widget->widget( $args, $instance );
+               $output = ob_get_clean();
+               $this->assertContains( '<p>', $output );
+               $this->assertContains( '<br />', $output );
+               $this->assertCount( 3, $this->widget_text_args );
+               $this->assertEquals( $expected_instance['text'], $this->widget_text_args[0] );
+               $this->assertEquals( $expected_instance, $this->widget_text_args[1] );
+               $this->assertEquals( $widget, $this->widget_text_args[2] );
+               $this->assertNull( $this->widget_text_content_args );
+               $this->assertContains( wpautop( $expected_instance['text'] . '[filter:widget_text]' ), $output );
+
+               // Test with filter=false&visual=false, the upgraded widget, in 4.8.1 and above.
+               $this->widget_text_content_args = null;
+               $instance = array(
+                       'title'  => 'Foo',
+                       'text'   => $text,
+                       'filter' => false,
+                       'visual' => false,
+               );
+               $expected_instance = $instance;
+               ob_start();
+               $widget->widget( $args, $instance );
+               $output = ob_get_clean();
+               $this->assertNotContains( '<p>', $output );
+               $this->assertNotContains( '<br />', $output );
+               $this->assertCount( 3, $this->widget_text_args );
+               $this->assertEquals( $expected_instance['text'], $this->widget_text_args[0] );
+               $this->assertEquals( $expected_instance, $this->widget_text_args[1] );
+               $this->assertEquals( $widget, $this->widget_text_args[2] );
+               $this->assertNull( $this->widget_text_content_args );
+               $this->assertContains( $expected_instance['text'] . '[filter:widget_text]', $output );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -250,14 +331,19 @@
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $instance = array_merge( $base_instance, array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'legacy' => true,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'visual' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertTrue( $widget->is_legacy_instance( $instance ), 'Legacy when legacy prop is present.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertTrue( $widget->is_legacy_instance( $instance ), 'Legacy when visual=false prop is present.' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $instance = array_merge( $base_instance, array(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'visual' => true,
+               ) );
+               $this->assertFalse( $widget->is_legacy_instance( $instance ), 'Not legacy when visual=true prop is present.' );
+
+               $instance = array_merge( $base_instance, array(
</ins><span class="cx" style="display: block; padding: 0 10px">                         'filter' => 'content',
</span><span class="cx" style="display: block; padding: 0 10px">                ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertFalse( $widget->is_legacy_instance( $instance ), 'Not legacy when filter is explicitly content.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertFalse( $widget->is_legacy_instance( $instance ), 'Not legacy when filter is explicitly content (in WP 4.8.0 only).' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $instance = array_merge( $base_instance, array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'text' => '',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -364,13 +450,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'title' => 'Title',
</span><span class="cx" style="display: block; padding: 0 10px">                        'text' => 'Text',
</span><span class="cx" style="display: block; padding: 0 10px">                        'filter' => false,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'legacy' => true,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'visual' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertTrue( $widget->is_legacy_instance( $instance ) );
</span><span class="cx" style="display: block; padding: 0 10px">                ob_start();
</span><span class="cx" style="display: block; padding: 0 10px">                $widget->form( $instance );
</span><span class="cx" style="display: block; padding: 0 10px">                $form = ob_get_clean();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertContains( 'class="legacy"', $form );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertContains( 'class="visual" type="hidden" value=""', $form );
+               $this->assertNotContains( 'class="visual" type="hidden" value="1"', $form );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $instance = array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'title' => 'Title',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -381,7 +468,33 @@
</span><span class="cx" style="display: block; padding: 0 10px">                ob_start();
</span><span class="cx" style="display: block; padding: 0 10px">                $widget->form( $instance );
</span><span class="cx" style="display: block; padding: 0 10px">                $form = ob_get_clean();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNotContains( 'class="legacy"', $form );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertContains( 'class="visual" type="hidden" value="1"', $form );
+               $this->assertNotContains( 'class="visual" type="hidden" value=""', $form );
+
+               $instance = array(
+                       'title' => 'Title',
+                       'text' => 'Text',
+                       'filter' => true,
+               );
+               $this->assertFalse( $widget->is_legacy_instance( $instance ) );
+               ob_start();
+               $widget->form( $instance );
+               $form = ob_get_clean();
+               $this->assertContains( 'class="visual" type="hidden" value="1"', $form );
+               $this->assertNotContains( 'class="visual" type="hidden" value=""', $form );
+
+               $instance = array(
+                       'title' => 'Title',
+                       'text' => 'Text',
+                       'filter' => true,
+                       'visual' => true,
+               );
+               $this->assertFalse( $widget->is_legacy_instance( $instance ) );
+               ob_start();
+               $widget->form( $instance );
+               $form = ob_get_clean();
+               $this->assertContains( 'class="visual" type="hidden" value="1"', $form );
+               $this->assertNotContains( 'class="visual" type="hidden" value=""', $form );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -394,30 +507,30 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $instance = array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'title' => "The\nTitle",
</span><span class="cx" style="display: block; padding: 0 10px">                        'text'  => "The\n\nText",
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'filter' => 'content',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'filter' => true,
+                       'visual' => true,
</ins><span class="cx" style="display: block; padding: 0 10px">                 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                wp_set_current_user( $this->factory()->user->create( array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'role' => 'administrator',
</span><span class="cx" style="display: block; padding: 0 10px">                ) ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // Should return valid instance in legacy mode since filter=false and there are line breaks.
</del><span class="cx" style="display: block; padding: 0 10px">                 $expected = array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'title'  => sanitize_text_field( $instance['title'] ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'text'   => $instance['text'],
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'filter' => 'content',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'filter' => true,
+                       'visual' => true,
</ins><span class="cx" style="display: block; padding: 0 10px">                 );
</span><span class="cx" style="display: block; padding: 0 10px">                $result = $widget->update( $instance, array() );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $expected, $result );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertTrue( ! empty( $expected['filter'] ), 'Expected filter prop to be truthy, to handle case where 4.8 is downgraded to 4.7.' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // Make sure KSES is applying as expected.
</del><span class="cx" style="display: block; padding: 0 10px">                 add_filter( 'map_meta_cap', array( $this, 'grant_unfiltered_html_cap' ), 10, 2 );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertTrue( current_user_can( 'unfiltered_html' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                $instance['text'] = '<script>alert( "Howdy!" );</script>';
</span><span class="cx" style="display: block; padding: 0 10px">                $expected['text'] = $instance['text'];
</span><span class="cx" style="display: block; padding: 0 10px">                $result = $widget->update( $instance, array() );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( $expected, $result );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertEquals( $expected, $result, 'KSES should apply as expected.' );
</ins><span class="cx" style="display: block; padding: 0 10px">                 remove_filter( 'map_meta_cap', array( $this, 'grant_unfiltered_html_cap' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter( 'map_meta_cap', array( $this, 'revoke_unfiltered_html_cap' ), 10, 2 );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -425,7 +538,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $instance['text'] = '<script>alert( "Howdy!" );</script>';
</span><span class="cx" style="display: block; padding: 0 10px">                $expected['text'] = wp_kses_post( $instance['text'] );
</span><span class="cx" style="display: block; padding: 0 10px">                $result = $widget->update( $instance, array() );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( $expected, $result );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertEquals( $expected, $result, 'KSES should not apply since user can unfiltered_html.' );
</ins><span class="cx" style="display: block; padding: 0 10px">                 remove_filter( 'map_meta_cap', array( $this, 'revoke_unfiltered_html_cap' ), 10 );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -437,48 +550,150 @@
</span><span class="cx" style="display: block; padding: 0 10px">        function test_update_legacy() {
</span><span class="cx" style="display: block; padding: 0 10px">                $widget = new WP_Widget_Text();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // Updating a widget with explicit filter=true persists with legacy mode.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // --
</ins><span class="cx" style="display: block; padding: 0 10px">                 $instance = array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'title' => 'Legacy',
</span><span class="cx" style="display: block; padding: 0 10px">                        'text' => 'Text',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'filter' => false,
+               );
+               $result = $widget->update( $instance, array() );
+               $this->assertEquals( $instance, $result, 'Updating a widget without visual prop and explicit filter=false leaves visual prop absent' );
+
+               // --
+               $instance = array(
+                       'title' => 'Legacy',
+                       'text' => 'Text',
</ins><span class="cx" style="display: block; padding: 0 10px">                         'filter' => true,
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="cx" style="display: block; padding: 0 10px">                $result = $widget->update( $instance, array() );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->assertEquals( $instance, $result, 'Updating a widget without visual prop and explicit filter=true leaves legacy prop absent.' );
+
+               // --
+               $instance = array(
+                       'title' => 'Legacy',
+                       'text' => 'Text',
+                       'visual' => true,
+               );
+               $old_instance = array_merge( $instance, array(
+                       'filter' => false,
+               ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $expected = array_merge( $instance, array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'legacy' => true,
</del><span class="cx" style="display: block; padding: 0 10px">                         'filter' => true,
</span><span class="cx" style="display: block; padding: 0 10px">                ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( $expected, $result );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $result = $widget->update( $instance, $old_instance );
+               $this->assertEquals( $expected, $result, 'Updating a pre-existing widget with visual mode forces filter to be true.' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // Updating a widget with explicit filter=false persists with legacy mode.
-               $instance['filter'] = false;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // --
+               $instance = array(
+                       'title' => 'Legacy',
+                       'text' => 'Text',
+                       'filter' => true,
+               );
+               $old_instance = array_merge( $instance, array(
+                       'visual' => true,
+               ) );
+               $result = $widget->update( $instance, $old_instance );
+               $expected = array_merge( $instance, array(
+                       'visual' => true,
+               ) );
+               $this->assertEquals( $expected, $result, 'Updating a pre-existing visual widget retains visual mode when updated.' );
+
+               // --
+               $instance = array(
+                       'title' => 'Legacy',
+                       'text' => 'Text',
+               );
+               $old_instance = array_merge( $instance, array(
+                       'visual' => true,
+               ) );
+               $result = $widget->update( $instance, $old_instance );
+               $expected = array_merge( $instance, array(
+                       'visual' => true,
+                       'filter' => true,
+               ) );
+               $this->assertEquals( $expected, $result, 'Updating a pre-existing visual widget retains visual=true and supplies missing filter=true.' );
+
+               // --
+               $instance = array(
+                       'title' => 'Legacy',
+                       'text' => 'Text',
+                       'visual' => true,
+               );
+               $expected = array_merge( $instance, array(
+                       'filter' => true,
+               ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $result = $widget->update( $instance, array() );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->assertEquals( $expected, $result, 'Updating a widget with explicit visual=true and absent filter prop causes filter to be set to true.' );
+
+               // --
+               $instance = array(
+                       'title' => 'Legacy',
+                       'text' => 'Text',
+                       'visual' => false,
+               );
+               $result = $widget->update( $instance, array() );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $expected = array_merge( $instance, array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'legacy' => true,
</del><span class="cx" style="display: block; padding: 0 10px">                         'filter' => false,
</span><span class="cx" style="display: block; padding: 0 10px">                ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( $expected, $result );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertEquals( $expected, $result, 'Updating a widget in legacy mode results in filter=false as if checkbox not checked.' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // Updating a widget in legacy form results in filter=false when checkbox not checked.
-               $instance['filter'] = true;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // --
+               $instance = array(
+                       'title' => 'Title',
+                       'text' => 'Text',
+                       'filter' => false,
+               );
+               $old_instance = array_merge( $instance, array(
+                       'visual' => false,
+                       'filter' => true,
+               ) );
+               $result = $widget->update( $instance, $old_instance );
+               $expected = array_merge( $instance, array(
+                       'visual' => false,
+                       'filter' => false,
+               ) );
+               $this->assertEquals( $expected, $result, 'Updating a widget that previously had legacy form results in filter allowed to be false.' );
+
+               // --
+               $instance = array(
+                       'title' => 'Title',
+                       'text' => 'Text',
+                       'filter' => 'content',
+               );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $result = $widget->update( $instance, array() );
</span><span class="cx" style="display: block; padding: 0 10px">                $expected = array_merge( $instance, array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'legacy' => true,
</del><span class="cx" style="display: block; padding: 0 10px">                         'filter' => true,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'visual' => true,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( $expected, $result );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertEquals( $expected, $result, 'Updating a widget that had \'content\' as its filter value persists non-legacy mode. This only existed in WP 4.8.0.' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // Updating a widget that previously had legacy form results in filter persisting.
-               unset( $instance['legacy'] );
-               $instance['filter'] = true;
-               $result = $widget->update( $instance, array(
-                       'legacy' => true,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // --
+               $instance = array(
+                       'title' => 'Title',
+                       'text' => 'Text',
+               );
+               $old_instance = array_merge( $instance, array(
+                       'filter' => 'content',
</ins><span class="cx" style="display: block; padding: 0 10px">                 ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $result = $widget->update( $instance, $old_instance );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $expected = array_merge( $instance, array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'legacy' => true,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'visual' => true,
</ins><span class="cx" style="display: block; padding: 0 10px">                         'filter' => true,
</span><span class="cx" style="display: block; padding: 0 10px">                ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( $expected, $result );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertEquals( $expected, $result, 'Updating a pre-existing widget with the filter=content prop in WP 4.8.0 upgrades to filter=true&visual=true.' );
+
+               // --
+               $instance = array(
+                       'title' => 'Title',
+                       'text' => 'Text',
+                       'filter' => 'content',
+               );
+               $result = $widget->update( $instance, array() );
+               $expected = array_merge( $instance, array(
+                       'filter' => true,
+                       'visual' => true,
+               ) );
+               $this->assertEquals( $expected, $result, 'Updating a widget with filter=content (from WP 4.8.0) upgrades to filter=true&visual=true.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span></span></pre>
</div>
</div>

</body>
</html>