Skip to:
Content

BuddyPress.org

Changeset 9192


Ignore:
Timestamp:
11/26/2014 08:11:57 PM (12 years ago)
Author:
boonebgorges
Message:

More precise error checking in bp_sort_by_key().

In order to support sorting with a value of 0, we must use isset() to verify
the existence of a value.

See #6047.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-functions.php

    r9191 r9192  
    118118                }
    119119
    120                 if ( $values[0] && $values[1] ) {
     120                if ( isset( $values[0], $values[1] ) ) {
    121121                        if ( "num" === "' . $type . '" ) {
    122122                                $cmp = $values[0] - $values[1];
  • trunk/tests/phpunit/testcases/core/functions.php

    r9191 r9192  
    255255                $this->assertEquals( $expected, bp_sort_by_key( $items, 'value', 'num' ) );
    256256        }
     257
     258        /**
     259         * @group bp_sort_by_key
     260         */
     261        public function test_bp_sort_by_key_num_should_respect_0() {
     262                $items = array(
     263                        array(
     264                                'foo' => 'bar',
     265                                'value' => 2,
     266                        ),
     267                        array(
     268                                'foo' => 'bar',
     269                                'value' => 0,
     270                        ),
     271                        array(
     272                                'foo' => 'bar',
     273                                'value' => 4,
     274                        ),
     275                );
     276
     277                $expected = array(
     278                        array(
     279                                'foo' => 'bar',
     280                                'value' => 0,
     281                        ),
     282                        array(
     283                                'foo' => 'bar',
     284                                'value' => 2,
     285                        ),
     286                        array(
     287                                'foo' => 'bar',
     288                                'value' => 4,
     289                        ),
     290                );
     291
     292                $this->assertEquals( $expected, bp_sort_by_key( $items, 'value', 'num' ) );
     293        }
     294
    257295        /**
    258296         * @group bp_alpha_sort_by_key
Note: See TracChangeset for help on using the changeset viewer.