', $output );
+ $this->assertStringContainsString( 'name="clear-recent-list"', $output, 'The button should be output.' );
+ $this->assertStringContainsString( 'value="Clear List"', $output );
+ $this->assertStringEndsWith( '
', $output );
+ }
+
+ /**
+ * Data provider.
+ *
+ * @return array[]
+ */
+ public static function data_tablenav_positions() {
+ return array(
+ 'top' => array( 'top' ),
+ 'bottom' => array( 'bottom' ),
+ );
+ }
+
+ /**
+ * Tests the description of the Must-Use plugins above the list only.
+ *
+ * @ticket 66552
+ *
+ * @covers WP_Plugins_List_Table::extra_tablenav
+ */
+ public function test_extra_tablenav_should_describe_the_mustuse_plugins_above_the_list() {
+ $this->set_global( 'status', 'mustuse' );
+
+ $top = $this->get_extra_tablenav( 'top' );
+ $bottom = $this->get_extra_tablenav( 'bottom' );
+
+ $this->assertSame(
+ 'Drop-ins are single files, found in the ' . str_replace( ABSPATH, '', WP_CONTENT_DIR ) . ' directory,', $top );
+ $this->assertSame( '
', $bottom, 'Nothing should be described below the list.' );
+ }
+
+ /**
+ * Tests the action of the button that clears the recently active plugins.
+ *
+ * @ticket 66552
+ *
+ * @covers WP_Plugins_List_Table::current_action
+ */
+ public function test_current_action_should_be_the_clear_button() {
+ $_POST['clear-recent-list'] = 'Clear List';
+ $_REQUEST['action'] = 'activate-selected';
+
+ try {
+ $this->assertSame( 'clear-recent-list', $this->table->current_action() );
+ } finally {
+ unset( $_POST['clear-recent-list'], $_REQUEST['action'] );
+ }
+ }
+
+ /**
+ * Tests the action of the bulk actions.
+ *
+ * @ticket 66552
+ *
+ * @covers WP_Plugins_List_Table::current_action
+ *
+ * @dataProvider data_current_action
+ *
+ * @param array $request The request.
+ * @param string|bool $expected The expected action.
+ */
+ public function test_current_action_should_use_the_bulk_action_of_the_request( array $request, $expected ) {
+ $original = $_REQUEST;
+
+ $_REQUEST = $request;
+
+ try {
+ $this->assertSame( $expected, $this->table->current_action() );
+ } finally {
+ $_REQUEST = $original;
+ }
+ }
+
+ /**
+ * Data provider.
+ *
+ * @return array[]
+ */
+ public static function data_current_action() {
+ return array(
+ 'an action' => array( array( 'action' => 'activate-selected' ), 'activate-selected' ),
+ 'no action' => array( array( 'action' => '-1' ), false ),
+ 'no request' => array( array(), false ),
+ 'a filter was applied' => array(
+ array(
+ 'action' => 'activate-selected',
+ 'filter_action' => 'Filter',
+ ),
+ false,
+ ),
+ );
+ }
+
+ /**
+ * Tests that a row is displayed for each plugin.
+ *
+ * @ticket 66552
+ *
+ * @covers WP_Plugins_List_Table::display_rows
+ */
+ public function test_display_rows_should_display_a_row_for_each_plugin() {
+ $this->set_global( 'status', 'all' );
+
+ $list_table = $this->getMockBuilder( 'WP_Plugins_List_Table' )
+ ->setConstructorArgs( array( array( 'screen' => 'plugins' ) ) )
+ ->setMethods( array( 'single_row' ) )
+ ->getMock();
+
+ $list_table->items = array(
+ 'one/one.php' => array( 'Name' => 'One' ),
+ 'two.php' => array( 'Name' => 'Two' ),
+ );
+
+ $list_table->expects( $this->exactly( 2 ) )
+ ->method( 'single_row' )
+ ->withConsecutive(
+ array( array( 'one/one.php', array( 'Name' => 'One' ) ) ),
+ array( array( 'two.php', array( 'Name' => 'Two' ) ) )
+ );
+
+ $list_table->display_rows();
+ }
+
+ /**
+ * Tests that the Must-Use plugins and the drop-ins are not displayed on the sites of a network.
+ *
+ * @ticket 66552
+ *
+ * @group ms-required
+ *
+ * @covers WP_Plugins_List_Table::display_rows
+ *
+ * @dataProvider data_status_mustuse_and_dropins
+ *
+ * @param string $status The plugin status.
+ */
+ public function test_display_rows_should_not_display_mustuse_plugins_and_dropins_on_a_site_of_a_network( $status ) {
+ $list_table = $this->getMockBuilder( 'WP_Plugins_List_Table' )
+ ->setConstructorArgs( array( array( 'screen' => 'plugins' ) ) )
+ ->setMethods( array( 'single_row' ) )
+ ->getMock();
+
+ // The constructor sets the status from the request.
+ $this->set_global( 'status', $status );
+
+ $list_table->items = array( 'one.php' => array( 'Name' => 'One' ) );
+
+ $list_table->expects( $this->never() )->method( 'single_row' );
+
+ $list_table->display_rows();
+ }
+
+ /**
+ * Tests the setting for the automatic updates of a plugin.
+ *
+ * The 'ms-excluded' group is added as the column is only shown in the network admin on multisite.
+ *
+ * @ticket 66552
+ *
+ * @group ms-excluded
+ *
+ * @covers WP_Plugins_List_Table::single_row
+ *
+ * @dataProvider data_autoupdate_settings
+ *
+ * @param array $plugin_data The data of the plugin.
+ * @param bool $enabled Whether the automatic updates of the plugin are on.
+ * @param string $label The expected label.
+ * @param string $action The expected action, or an empty string when there is no link.
+ */
+ public function test_single_row_should_output_the_setting_for_the_automatic_updates( array $plugin_data, $enabled, $label, $action ) {
+ add_filter( 'plugins_auto_update_enabled', '__return_true' );
+ wp_set_current_user( self::$admin_id );
+ $this->set_global( 'status', 'all' );
+ $this->set_global( 'page', 1 );
+ update_site_option( 'auto_update_plugins', $enabled ? array( 'auto/auto.php' ) : array() );
+
+ $output = $this->render_row( 'auto/auto.php', $plugin_data, array( 'auto-updates' => 'Automatic Updates' ) );
+
+ $this->assertStringContainsString( "
", $output );
+ $this->assertStringContainsString( '' . $label . '', $output );
+
+ if ( '' === $action ) {
+ $this->assertStringNotContainsString( 'toggle-auto-update', $output, 'There should be no link.' );
+ } else {
+ $this->assertStringContainsString( 'data-wp-action="' . $action . '"', $output );
+ $this->assertStringContainsString( 'plugin=auto%2Fauto.php', $output );
+ $this->assertStringContainsString( 'action=' . $action . '-auto-update', $output );
+ }
+ }
+
+ /**
+ * Data provider.
+ *
+ * @return array[]
+ */
+ public static function data_autoupdate_settings() {
+ return array(
+ 'forced on' => array( array( 'auto-update-forced' => true ), false, 'Auto-updates enabled', '' ),
+ 'forced off' => array( array( 'auto-update-forced' => false ), true, 'Auto-updates disabled', '' ),
+ 'not supported' => array( array(), true, '', '' ),
+ 'supported and enabled' => array( array( 'update-supported' => true ), true, 'Disable auto-updates', 'disable' ),
+ 'supported and not on' => array( array( 'update-supported' => true ), false, 'Enable auto-updates', 'enable' ),
+ );
+ }
+
+ /**
+ * Tests that the time of the next update is shown for a plugin with an update that updates automatically.
+ *
+ * @ticket 66552
+ *
+ * @group ms-excluded
+ *
+ * @covers WP_Plugins_List_Table::single_row
+ *
+ * @dataProvider data_autoupdate_time
+ *
+ * @param bool $enabled Whether the automatic updates of the plugin are on.
+ * @param string $time_class The expected class of the message.
+ */
+ public function test_single_row_should_show_the_auto_update_message_only_when_updates_are_on( $enabled, $time_class ) {
+ add_filter( 'plugins_auto_update_enabled', '__return_true' );
+ wp_set_current_user( self::$admin_id );
+ $this->set_global( 'status', 'all' );
+ $this->set_global( 'page', 1 );
+ update_site_option( 'auto_update_plugins', $enabled ? array( 'auto/auto.php' ) : array() );
+
+ $output = $this->render_row(
+ 'auto/auto.php',
+ array(
+ 'update' => true,
+ 'update-supported' => true,
+ ),
+ array( 'auto-updates' => 'Automatic Updates' )
+ );
+
+ $this->assertStringContainsString( '', $output );
+ }
+
+ /**
+ * Data provider.
+ *
+ * @return array[]
+ */
+ public static function data_autoupdate_time() {
+ return array(
+ 'on' => array( true, '' ),
+ 'off' => array( false, ' hidden' ),
+ );
+ }
+
+ /**
+ * Tests that the setting for the automatic updates can be filtered, and that its column can be hidden.
+ *
+ * @ticket 66552
+ *
+ * @group ms-excluded
+ *
+ * @covers WP_Plugins_List_Table::single_row
+ */
+ public function test_single_row_should_filter_the_setting_for_the_automatic_updates_and_hide_the_column() {
+ add_filter( 'plugins_auto_update_enabled', '__return_true' );
+ wp_set_current_user( self::$admin_id );
+ $this->set_global( 'status', 'all' );
+ $this->set_global( 'page', 1 );
+
+ $filter = new MockAction();
+ add_filter( 'plugin_auto_update_setting_html', array( $filter, 'filter' ), 10, 3 );
+ add_filter(
+ 'plugin_auto_update_setting_html',
+ static function () {
+ return ' Custom setting';
+ },
+ 11
+ );
+
+ $output = $this->render_row( 'auto/auto.php', array( 'update-supported' => true ), array( 'auto-updates' => 'Automatic Updates' ), array( 'auto-updates' ) );
+ $args = $filter->get_args();
+
+ $this->assertStringContainsString( " Custom setting", $output, 'The setting should be replaced, in a hidden column.' );
+ $this->assertStringContainsString( 'notice notice-error notice-alt inline hidden', $output, 'A hidden notice should be output for errors.' );
+ $this->assertStringContainsString( 'toggle-auto-update', $args[0][0], 'The filter should receive the setting.' );
+ $this->assertSame( 'auto/auto.php', $args[0][1], 'The filter should receive the plugin file.' );
+ $this->assertSame( 'Row Plugin', $args[0][2]['Name'], 'The filter should receive the plugin data.' );
+ }
+
+ /**
+ * Tests that a column that is not one of the plugin columns is filled by an action.
+ *
+ * @ticket 66552
+ *
+ * @covers WP_Plugins_List_Table::single_row
+ */
+ public function test_single_row_should_let_an_action_fill_a_custom_column() {
+ $this->set_global( 'status', 'all' );
+ $this->set_global( 'page', 1 );
+
+ $action = new MockAction();
+ add_action( 'manage_plugins_custom_column', array( $action, 'action' ), 10, 3 );
+ add_action(
+ 'manage_plugins_custom_column',
+ static function ( $column_name ) {
+ echo 'Value of ' . $column_name;
+ }
+ );
+
+ $output = $this->render_row(
+ 'hello.php',
+ array(),
+ array(
+ 'name' => 'Plugin',
+ 'custom' => 'Custom',
+ 'hidden' => 'Hidden',
+ ),
+ array( 'hidden' )
+ );
+
+ $args = $action->get_args();
+
+ $this->assertStringContainsString( " | Value of custom | ", $output, 'The column should be filled by the action.' );
+ $this->assertStringContainsString( " Value of hidden | ", $output, 'A hidden column should be hidden.' );
+ $this->assertSame( array( 'custom', 'hello.php' ), array_slice( $args[0], 0, 2 ), 'The action should receive the column and the plugin file.' );
+ $this->assertSame( 'Row Plugin', $args[0][2]['Name'], 'The action should receive the plugin data.' );
+ }
+
+ /**
+ * Tests the row of a drop-in that is always active.
+ *
+ * @ticket 66552
+ *
+ * @covers WP_Plugins_List_Table::single_row
+ */
+ public function test_single_row_should_describe_a_dropin_that_is_always_active() {
+ $this->set_global( 'status', 'dropins' );
+ $this->set_global( 'page', 1 );
+
+ $output = $this->render_row(
+ 'db.php',
+ array(
+ 'Name' => 'Custom Database',
+ 'Description' => 'My database class.',
+ ),
+ array(
+ 'name' => 'Plugin',
+ 'description' => 'Description',
+ )
+ );
+
+ $this->assertStringContainsString( 'db.php Custom Database', $output, 'The file and the name should be output.' );
+ $this->assertStringContainsString( ' Custom database class. My database class. ', $output, 'The description of the drop-in should be output.' );
+ $this->assertStringContainsString( 'class="active', $output, 'The drop-in should be active.' );
+ $this->assertStringNotContainsString( 'Inactive:', $output );
+ }
+
+ /**
+ * Tests the row of a drop-in that needs a constant that is not defined.
+ *
+ * @ticket 66552
+ *
+ * @covers WP_Plugins_List_Table::single_row
+ */
+ public function test_single_row_should_describe_a_dropin_that_needs_a_constant_as_inactive() {
+ if ( defined( 'WP_CACHE' ) && WP_CACHE ) {
+ $this->markTestSkipped( 'The constant WP_CACHE is defined.' );
+ }
+
+ $this->set_global( 'status', 'dropins' );
+ $this->set_global( 'page', 1 );
+
+ $output = $this->render_row(
+ 'advanced-cache.php',
+ array( 'Name' => 'advanced-cache.php' ),
+ array(
+ 'name' => 'Plugin',
+ 'description' => 'Description',
+ )
+ );
+
+ $this->assertStringNotContainsString( 'advanced-cache.php ', $output, 'The name should not be repeated.' );
+ $this->assertStringContainsString( 'Advanced caching plugin. Inactive:', $output, 'The drop-in should be inactive.' );
+ $this->assertStringContainsString( " define('WP_CACHE', true);", $output, 'The constant should be output.' );
+ $this->assertStringContainsString( 'class="inactive', $output, 'The drop-in should be inactive.' );
+ }
+
+ /**
+ * Tests the message for a plugin that is not compatible, by what the user can update.
+ *
+ * Updating PHP needs the capability to update WordPress, so a filter separates them.
+ *
+ * @ticket 66552
+ *
+ * @covers WP_Plugins_List_Table::single_row
+ *
+ * @dataProvider data_incompatible_message
+ *
+ * @param bool $can_update_core Whether the user can update WordPress.
+ * @param bool $can_update_php Whether the user can learn about updating PHP.
+ * @param string[] $expected The strings that the message should contain.
+ * @param string[] $unexpected The strings that the message should not contain.
+ */
+ public function test_single_row_should_explain_that_a_plugin_is_not_compatible( $can_update_core, $can_update_php, array $expected, array $unexpected ) {
+ wp_set_current_user( self::$admin_id );
+
+ add_filter(
+ 'map_meta_cap',
+ static function ( $caps, $cap ) use ( $can_update_core, $can_update_php ) {
+ if ( 'update_core' === $cap ) {
+ return $can_update_core ? array( 'exist' ) : array( 'do_not_allow' );
+ }
+
+ if ( 'update_php' === $cap ) {
+ return $can_update_php ? array( 'exist' ) : array( 'do_not_allow' );
+ }
+
+ return $caps;
+ },
+ 10,
+ 2
+ );
+
+ $this->set_global( 'status', 'all' );
+ $this->set_global( 'page', 1 );
+
+ $output = $this->render_row(
+ 'hello.php',
+ array(
+ 'RequiresPHP' => '99.0',
+ 'RequiresWP' => '99.0',
+ )
+ );
+
+ $this->assertStringContainsString( ' | Please update WordPress, and then .' ),
+ array(),
+ ),
+ 'WordPress only' => array(
+ true,
+ false,
+ array( '/update-core.php">Please update WordPress.' ),
+ array( 'pdating PHP' ),
+ ),
+ 'PHP only' => array(
+ false,
+ true,
+ array( 'Learn more about updating PHP.' ),
+ array( 'Please update WordPress' ),
+ ),
+ 'neither' => array(
+ false,
+ false,
+ array(),
+ array( 'Please update WordPress', 'pdating PHP' ),
+ ),
+ );
+ }
}
| |