Make WordPress Core

Ticket #14424: 14424.7.diff

File 14424.7.diff, 5.7 KB (added by markjaquith, 11 years ago)

Add a test for get_importers() ordering

  • src/wp-admin/import.php

    foreach ( $popular_importers as $pop_importer => $pop_data ) { 
    7474if ( empty( $importers ) ) {
    7575        echo '<p>' . __('No importers are available.') . '</p>'; // TODO: make more helpful
    7676} else {
    77         uasort($importers, create_function('$a, $b', 'return strnatcasecmp($a[0], $b[0]);'));
     77        uasort( $importers, '_uasort_by_first_member' );
    7878?>
    7979<table class="widefat importers">
    8080
  • src/wp-admin/includes/import.php

     
    1515 */
    1616function get_importers() {
    1717        global $wp_importers;
    18         if ( is_array($wp_importers) )
    19                 uasort($wp_importers, create_function('$a, $b', 'return strcmp($a[0], $b[0]);'));
     18        if ( is_array( $wp_importers ) ) {
     19                uasort( $wp_importers, '_uasort_by_first_member' );
     20        }
    2021        return $wp_importers;
    2122}
    2223
    2324/**
     25 * Sorts a multidimensional array by first member of each top level member
     26 *
     27 * Used by uasort() as a callback, should not be used directly.
     28 *
     29 * @since 2.9.0
     30 * @access private
     31 *
     32 * @param array $a
     33 * @param array $b
     34 * @return int
     35 */
     36function _uasort_by_first_member( $a, $b ) {
     37        return strnatcasecmp( $a[0], $b[0] );
     38}
     39
     40/**
    2441 * Register importer for WordPress.
    2542 *
    2643 * @since 2.0.0
  • src/wp-admin/includes/media.php

    function media_upload_library_form($errors) { 
    22552255        if ( get_user_setting('uploader') )
    22562256                $form_class .= ' html-uploader';
    22572257
    2258         $_GET['paged'] = isset( $_GET['paged'] ) ? intval($_GET['paged']) : 0;
    2259         if ( $_GET['paged'] < 1 )
    2260                 $_GET['paged'] = 1;
    2261         $start = ( $_GET['paged'] - 1 ) * 10;
    2262         if ( $start < 1 )
    2263                 $start = 0;
    2264         add_filter( 'post_limits', create_function( '$a', "return 'LIMIT $start, 10';" ) );
     2258        $q = $_GET;
     2259        $q['posts_per_page'] = 10;
     2260        $q = isset( $q['paged'] ) ? intval( $q['paged'] ) : 0;
     2261        if ( $q['paged'] < 1 ) {
     2262                $q['paged'] = 1;
     2263        }
     2264        $q['offset'] = ( $q['paged'] - 1 ) * 10;
     2265        if ( $q['offset'] < 1 ) {
     2266                $q['offset'] = 0;
     2267        }
    22652268
    2266         list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
     2269        list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query( $q );
    22672270
    22682271?>
    22692272
  • src/wp-admin/includes/post.php

    function wp_edit_attachments_query( $q = false ) { 
    934934                unset($q['post_mime_type']);
    935935
    936936        if ( isset($q['detached']) )
    937                 add_filter('posts_where', '_edit_attachments_query_helper');
     937                $q['post_parent'] = 0;
    938938
    939939        wp( $q );
    940940
    941         if ( isset($q['detached']) )
    942                 remove_filter('posts_where', '_edit_attachments_query_helper');
    943 
    944941        return array($post_mime_types, $avail_post_mime_types);
    945942}
    946943
    947 function _edit_attachments_query_helper($where) {
    948         global $wpdb;
    949         return $where .= " AND {$wpdb->posts}.post_parent < 1";
    950 }
    951 
    952944/**
    953945 * Returns the list of classes to be used by a metabox
    954946 *
  • src/wp-includes/category-template.php

    function wp_generate_tag_cloud( $tags, $args = '' ) { 
    622622        );
    623623
    624624        if ( !isset( $args['topic_count_text_callback'] ) && isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) {
    625                 $body = 'return sprintf (
    626                         _n(' . var_export($args['single_text'], true) . ', ' . var_export($args['multiple_text'], true) . ', $count),
    627                         number_format_i18n( $count ));';
    628                 $args['topic_count_text_callback'] = create_function('$count', $body);
     625                $args['topic_count_text_callback'] = '_plugin_topic_count';
    629626        }
    630627
    631628        $args = wp_parse_args( $args, $defaults );
    function _wp_object_count_sort_cb( $a, $b ) { 
    725722        return ( $a->count > $b->count );
    726723}
    727724
     725/**
     726 * Default text for tooltip for tag links
     727 *
     728 * @since 3.9.0
     729 * @access private
     730 *
     731 * @param integer $count Number of posts with that tag.
     732 * @param object  $tag   Tag object.
     733 * @param array   $args  Arguments for the tag cloud.
     734 * @return string Text for the tooltip of a tag link.
     735 */
     736function _plugin_topic_count( $count, $tag, $args ) {
     737        return sprintf( 1 == $count? $args['single_text'] : $args['multiple_text'], number_format_i18n( $count ) );
     738}
     739
    728740//
    729741// Helper functions
    730742//
  • tests/phpunit/tests/import/import.php

    class Tests_Import_Import extends WP_Import_UnitTestCase { 
    222222                $this->assertEquals( 1, $comment_count->total_comments );
    223223        }
    224224
     225        function test_ordering_of_importers() {
     226                global $wp_importers;
     227                $_wp_importers = $wp_importers; // Preserve global state
     228                $wp_importers = array(
     229                        'xyz1' => array( 'xyz1' ),
     230                        'XYZ2' => array( 'XYZ2' ),
     231                        'abc2' => array( 'abc2' ),
     232                        'ABC1' => array( 'ABC1' ),
     233                        'def1' => array( 'def1' ),
     234                );
     235                $this->assertEquals( array(
     236                        'ABC1' => array( 'ABC1' ),
     237                        'abc2' => array( 'abc2' ),
     238                        'def1' => array( 'def1' ),
     239                        'xyz1' => array( 'xyz1' ),
     240                        'XYZ2' => array( 'XYZ2' ),
     241                ), get_importers() );
     242                $wp_importers = $_wp_importers; // Restore global state
     243        }
     244
    225245        // function test_menu_import
    226246}