<!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>[55903] trunk: Plugins: Display Auto-updates filters when the current view is "Must Use" or "Drop-in".</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 { white-space: pre-line; 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/55903">55903</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/55903","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>audrasjb</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2023-06-10 05:28:02 +0000 (Sat, 10 Jun 2023)</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'>Plugins: Display Auto-updates filters when the current view is "Must Use" or "Drop-in".

This changeset fixes a bug where the "Auto-updates Enabled/Disabled" filters were not showing when the current view is "Must Use" or "Drop-in".

Props NekoJonez, pbiron, costdev, audrasjb.
Fixes <a href="https://core.trac.wordpress.org/ticket/54309">#54309</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesclasswppluginslisttablephp">trunk/src/wp-admin/includes/class-wp-plugins-list-table.php</a></li>
<li><a href="#trunktestsphpunittestsadminwpPluginsListTablephp">trunk/tests/phpunit/tests/admin/wpPluginsListTable.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesclasswppluginslisttablephp"></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/includes/class-wp-plugins-list-table.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/class-wp-plugins-list-table.php       2023-06-09 15:06:17 UTC (rev 55902)
+++ trunk/src/wp-admin/includes/class-wp-plugins-list-table.php 2023-06-10 05:28:02 UTC (rev 55903)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -61,8 +61,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $this->show_autoupdates = wp_is_auto_update_enabled_for_type( 'plugin' )
</span><span class="cx" style="display: block; padding: 0 10px">                        && current_user_can( 'update_plugins' )
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        && ( ! is_multisite() || $this->screen->in_admin( 'network' ) )
-                       && ! in_array( $status, array( 'mustuse', 'dropins' ), true );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 && ( ! is_multisite() || $this->screen->in_admin( 'network' ) );
</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">@@ -463,7 +462,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'description' => __( 'Description' ),
</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 ( $this->show_autoupdates ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( $this->show_autoupdates && ! in_array( $status, array( 'mustuse', 'dropins' ), true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $columns['auto-updates'] = __( 'Automatic Updates' );
</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">@@ -1154,7 +1153,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        echo '</td>';
</span><span class="cx" style="display: block; padding: 0 10px">                                        break;
</span><span class="cx" style="display: block; padding: 0 10px">                                case 'auto-updates':
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        if ( ! $this->show_autoupdates ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 if ( ! $this->show_autoupdates || in_array( $status, array( 'mustuse', 'dropins' ), true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 break;
</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="trunktestsphpunittestsadminwpPluginsListTablephp"></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/admin/wpPluginsListTable.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/admin/wpPluginsListTable.php    2023-06-09 15:06:17 UTC (rev 55902)
+++ trunk/tests/phpunit/tests/admin/wpPluginsListTable.php      2023-06-10 05:28:02 UTC (rev 55903)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -11,6 +11,29 @@
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public $table = false;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        /**
+        * An admin user ID.
+        *
+        * @var int
+        */
+       private static $admin_id;
+
+       /**
+        * Creates an admin user before any tests run.
+        */
+       public static function set_up_before_class() {
+               parent::set_up_before_class();
+
+               self::$admin_id = self::factory()->user->create(
+                       array(
+                               'role'       => 'administrator',
+                               'user_login' => 'test_wp_plugins_list_table',
+                               'user_pass'  => 'password',
+                               'user_email' => 'testadmin@test.com',
+                       )
+               );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         public function set_up() {
</span><span class="cx" style="display: block; padding: 0 10px">                parent::set_up();
</span><span class="cx" style="display: block; padding: 0 10px">                $this->table = _get_list_table( 'WP_Plugins_List_Table', array( 'screen' => 'plugins' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -56,4 +79,178 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( $expected, $actual );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       /**
+        * Tests that WP_Plugins_List_Table::__construct() does not set
+        * the 'show_autoupdates' property to false for Must-Use and Drop-in
+        * plugins.
+        *
+        * The 'ms-excluded' group is added as $this->show_autoupdates is already set to false for multisite.
+        *
+        * @ticket 54309
+        * @group ms-excluded
+        *
+        * @covers WP_Plugins_List_Table::__construct()
+        *
+        * @dataProvider data_status_mustuse_and_dropins
+        *
+        * @param string $status The value for $_REQUEST['plugin_status'].
+        */
+       public function test_construct_should_not_set_show_autoupdates_to_false_for_mustuse_and_dropins( $status ) {
+               $original_status           = isset( $_REQUEST['plugin_status'] ) ? $_REQUEST['plugin_status'] : null;
+               $_REQUEST['plugin_status'] = $status;
+
+               // Enable plugin auto-updates.
+               add_filter( 'plugins_auto_update_enabled', '__return_true' );
+
+               // Use a user with the 'manage_plugins' capability.
+               wp_set_current_user( self::$admin_id );
+
+               $list_table       = new WP_Plugins_List_Table();
+               $show_autoupdates = new ReflectionProperty( $list_table, 'show_autoupdates' );
+
+               $show_autoupdates->setAccessible( true );
+               $actual = $show_autoupdates->getValue( $list_table );
+               $show_autoupdates->setAccessible( false );
+
+               $_REQUEST['plugin_status'] = $original_status;
+
+               $this->assertTrue( $actual );
+       }
+
+       /**
+        * Tests that WP_Plugins_List_Table::get_columns() does not add
+        * the auto-update column when not viewing Must-Use or Drop-in plugins.
+        *
+        * @ticket 54309
+        *
+        * @covers WP_Plugins_List_Table::get_columns
+        *
+        * @dataProvider data_status_mustuse_and_dropins
+        *
+        * @param string $test_status The value for the global $status variable.
+        */
+       public function test_get_columns_should_not_add_the_autoupdates_column_when_viewing_mustuse_or_dropins( $test_status ) {
+               global $status;
+
+               $original_status = $status;
+
+               // Enable plugin auto-updates.
+               add_filter( 'plugins_auto_update_enabled', '__return_true' );
+
+               // Use a user with the 'manage_plugins' capability.
+               wp_set_current_user( self::$admin_id );
+
+               $status = $test_status;
+               $actual = $this->table->get_columns();
+               $status = $original_status;
+
+               $this->assertArrayNotHasKey( 'auto-updates', $actual );
+       }
+
+       /**
+        * Tests that WP_Plugins_List_Table::get_columns() does not add
+        * the auto-update column when the 'plugins_auto_update_enabled'
+        * filter returns false.
+        *
+        * @ticket 54309
+        *
+        * @covers WP_Plugins_List_Table::get_columns
+        */
+       public function test_get_columns_should_not_add_the_autoupdates_column_when_plugin_auto_update_is_disabled() {
+               global $status;
+
+               $original_status = $status;
+
+               // Enable plugin auto-updates.
+               add_filter( 'plugins_auto_update_enabled', '__return_false' );
+
+               // Use a user with the 'manage_plugins' capability.
+               wp_set_current_user( self::$admin_id );
+
+               $status = 'all';
+               $actual = $this->table->get_columns();
+               $status = $original_status;
+
+               $this->assertArrayNotHasKey( 'auto-updates', $actual );
+       }
+
+       /**
+        * Tests that WP_Plugins_List_Table::single_row() does not output the
+        * 'Auto-updates' column for Must-Use or Drop-in plugins.
+        *
+        * @ticket 54309
+        *
+        * @covers WP_Plugins_List_Table::single_row
+        *
+        * @dataProvider data_status_mustuse_and_dropins
+        *
+        * @param string $test_status The value for the global $status variable.
+        */
+       public function test_single_row_should_not_add_the_autoupdates_column_for_mustuse_or_dropins( $test_status ) {
+               global $status;
+
+               $original_status = $status;
+
+               // Enable plugin auto-updates.
+               add_filter( 'plugins_auto_update_enabled', '__return_true' );
+
+               // Use a user with the 'manage_plugins' capability.
+               wp_set_current_user( self::$admin_id );
+
+               $column_info = array(
+                       array(
+                               'name'         => 'Plugin',
+                               'description'  => 'Description',
+                               'auto-updates' => 'Auto-updates',
+                       ),
+                       array(),
+                       array(),
+                       'name',
+               );
+
+               // Mock WP_Plugins_List_Table
+               $list_table_mock = $this->getMockBuilder( 'WP_Plugins_List_Table' )
+                       // Note: setMethods() is deprecated in PHPUnit 9, but still supported.
+                       ->setMethods( array( 'get_column_info' ) )
+                       ->getMock();
+
+               // Force the return value of the get_column_info() method.
+               $list_table_mock->expects( $this->once() )->method( 'get_column_info' )->willReturn( $column_info );
+
+               $single_row_args = array(
+                       'advanced-cache.php',
+                       array(
+                               'Name'        => 'Advanced caching plugin',
+                               'slug'        => 'advanced-cache',
+                               'Description' => 'An advanced caching plugin.',
+                               'Author'      => 'A plugin author',
+                               'Version'     => '1.0.0',
+                               'Author URI'  => 'http://example.org',
+                               'Text Domain' => 'advanced-cache',
+                       ),
+               );
+
+               $status = $test_status;
+               ob_start();
+               $list_table_mock->single_row( $single_row_args );
+               $actual = ob_get_clean();
+               $status = $original_status;
+
+               $this->assertIsString( $actual, 'Output was not captured.' );
+               $this->assertNotEmpty( $actual, 'The output string was empty.' );
+               $this->assertStringNotContainsString( 'column-auto-updates', $actual, 'The auto-updates column was output.' );
+       }
+
+       /**
+        * Data provider.
+        *
+        * @return array[]
+        */
+       public function data_status_mustuse_and_dropins() {
+               return array(
+                       'Must-Use' => array( 'mustuse' ),
+                       'Drop-ins' => array( 'dropins' ),
+               );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>

</body>
</html>