Skip to content

Commit

Permalink
Change method name from filtered_by to CMB2_Boxes::filter_by, and add…
Browse files Browse the repository at this point in the history
… unit test
  • Loading branch information
jtsternberg committed Dec 23, 2017
1 parent 95de60d commit c62c689
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions includes/CMB2_Boxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static function get_by( $property, $compare = 'nocompare' ) {
* @param mixed $to_ignore The value to ignore.
* @return CMB2[] Array of matching cmb2 instances.
*/
public static function filtered_by( $property, $to_ignore = null ) {
public static function filter_by( $property, $to_ignore = null ) {
$boxes = array();

foreach ( self::$cmb2_instances as $cmb_id => $cmb ) {
Expand All @@ -133,7 +133,7 @@ public static function filtered_by( $property, $to_ignore = null ) {
* @return CMB2[] Array of matching cmb2 instances.
*/
public static function get_by_property( $property, $to_ignore = null ) {
_deprecated_function( __METHOD__, '2.4.0', 'CMB2_Boxes::filtered_by()' );
return self::filtered_by( $property );
_deprecated_function( __METHOD__, '2.4.0', 'CMB2_Boxes::filter_by()' );
return self::filter_by( $property );
}
}
8 changes: 8 additions & 0 deletions tests/test-cmb-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,14 @@ public function test_boxes_get_by() {
$this->assertSame( 1, count( $boxes ) );
}

public function test_boxes_filter_by() {
$all = CMB2_Boxes::get_all();
$with = CMB2_Boxes::get_by( 'classes', 'custom-class another-class' );
$boxes = CMB2_Boxes::filter_by( 'classes', 'custom-class another-class' );
$this->assertContainsOnlyInstancesOf( 'CMB2', $boxes );
$this->assertSame( count( $all ) - count( $with ), count( $boxes ) );
}

public function test_boxes_get() {
new Test_CMB2_Object( $this->metabox_array2 );

Expand Down

0 comments on commit c62c689

Please sign in to comment.