Making WordPress.org

Changeset 10181


Ignore:
Timestamp:
08/19/2020 04:16:47 AM (5 years ago)
Author:
tellyworth
Message:

Plugin dir: add test button for plugin reviewers.

See #5303.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-block-validator.php

    r10180 r10181  
    8484            } elseif ( $_POST && ! empty( $_POST['block-directory-edit'] ) ) {
    8585                self::handle_edit_form();
     86            } elseif ( $_POST && ! empty( $_POST['block-directory-test'] ) ) {
     87                self::handle_test();
    8688            }
    8789            ?>
     
    142144    }
    143145
     146    protected static function handle_test() {
     147        $post = get_post( intval( $_POST['plugin-id'] ) );
     148        if ( $post && wp_verify_nonce( $_POST['block-directory-nonce'], 'block-directory-test-' . $post->ID ) ) {
     149            if ( wp_cache_get( "plugin-e2e-test-{$post->ID}", 'plugin-test' ) ) {
     150                echo '<div class="notice notice-warning notice-alt"><p>' . __( 'Test already in progress.', 'wporg-plugins' ) . '</p></div>';
     151            } elseif ( current_user_can( 'edit_post', $post->ID ) || current_user_can( 'plugin_admin_edit', $post->ID ) ) {
     152                $result = Tools\Block_e2e::run( $post );
     153                if ( $result ) {
     154                    echo '<div class="notice notice-success notice-alt"><p>' . __( 'Test run started. Please check back in 10 minutes.', 'wporg-plugins' ) . '</p></div>';
     155                    wp_cache_add( "plugin-e2e-test-{$post->ID}", '1', 'plugin-test', 10 * MINUTE_IN_SECONDS );
     156                } else {
     157                    echo '<div class="notice notice-error notice-alt"><p>' . __( 'Unable to start a test run.', 'wporg-plugins' ) . '</p></div>';
     158                }
     159            }
     160        }
     161
     162        return self::validate_block( $post->post_name );
     163    }
     164
    144165    protected static function plugin_is_in_block_directory( $slug ) {
    145166        $plugin = Plugin_Directory::get_plugin_post( $slug );
     
    162183        echo '<input type="hidden" name="plugin-id" value="' . esc_attr( $plugin->ID ) . '" />';
    163184
     185        echo '<p>';
    164186        if ( self::plugin_is_in_block_directory( $plugin->post_name ) ) {
    165187            echo wp_nonce_field( 'block-directory-edit-' . $plugin->ID, 'block-directory-nonce' );
    166188            // translators: %s plugin title.
    167             echo '<p><button class="button button-secondary button-large" type="submit" name="block-directory-edit" value="remove">' . sprintf( __( 'Remove %s from Block Directory', 'wporg-plugins' ), $plugin->post_title ) . '</button></p>';
     189            echo '<button class="button button-secondary button-large" type="submit" name="block-directory-edit" value="remove">' . sprintf( __( 'Remove %s from Block Directory', 'wporg-plugins' ), $plugin->post_title ) . '</button>';
    168190        } else if ( ! $has_errors ) {
    169191            echo wp_nonce_field( 'block-directory-edit-' . $plugin->ID, 'block-directory-nonce' );
    170192            // translators: %s plugin title.
    171             echo '<p><button class="button button-primary button-large" type="submit" name="block-directory-edit" value="add">' . sprintf( __( 'Add %s to Block Directory', 'wporg-plugins' ), $plugin->post_title ) . '</button></p>';
    172         }
    173 
     193            echo '<button class="button button-primary button-large" type="submit" name="block-directory-edit" value="add">' . sprintf( __( 'Add %s to Block Directory', 'wporg-plugins' ), $plugin->post_title ) . '</button>';
     194        }
     195
     196        if ( current_user_can( 'edit_post', $post->ID ) ) {
     197            echo wp_nonce_field( 'block-directory-test-' . $plugin->ID, 'block-directory-nonce' );
     198            // translators: %s plugin title.
     199            $disabled = ( wp_cache_get( "plugin-e2e-test-{$plugin->ID}", 'plugin-test' ) ? ' disabled="disabled"' : '' );
     200            echo '<button class="button button-secondary button-large" type="submit" name="block-directory-test" value="test"' . $disabled . '>' . sprintf( __( 'Test %s', 'wporg-plugins' ), $plugin->post_title ) . '</button>';
     201        }
     202
     203        echo '</p>';
    174204        echo '</form>';
    175205    }
     
    271301                // Plugin reviewers etc
    272302                echo '<h3>' . __( 'Plugin Review Tools', 'wporg-plugins' ) . '</h3>';
     303
     304                $e2e_result = get_post_meta( $plugin->ID, 'e2e_success', true );
     305                if ( false !== $e2e_result ) {
     306                    echo '<h4>' . __( 'Test Results', 'wporg-plugins' ) . '</h4>';
     307                    if ( 'true' === $e2e_result ) {
     308                        echo "<div class='notice notice-info notice-alt'><p>\n";
     309                        echo __( 'Test passed.', 'wporg-plugins' );
     310                        echo "</p></div>\n";
     311                    } else {
     312                        echo "<div class='notice notice-error notice-alt'><p>\n";
     313                        echo sprintf( esc_html__( 'Test failed: %s', wporg-plugins ), '<code>' . esc_html( get_post_meta( $plugin->ID, 'e2e_error', true ) ) . '</code>' );
     314                        echo "</p></div>\n";
     315                    }
     316                }
     317
     318                if ( $image = get_post_meta( $plugin->ID, 'e2e_screenshotBlock', true ) ) {
     319                    echo '<div class="test-screenshot"><figure>';
     320                    echo '<img src="data:image/png;base64, ' . esc_attr( $image ) . '" />';
     321                    echo '<figcaption>Screenshot from last test run</figcaption>';
     322                    echo '</figure></div>';
     323                }
     324
    273325                echo '<ul>';
    274326                echo '<li><a href="' . get_edit_post_link( $plugin->ID ) . '">' . __( 'Edit plugin', 'wporg-plugins' ) . '</a></li>';
     
    277329
    278330                self::render_plugin_actions( $plugin, $has_errors );
     331
    279332            } elseif ( current_user_can( 'plugin_admin_edit', $plugin->ID ) ) {
    280333                // Plugin committers
Note: See TracChangeset for help on using the changeset viewer.