WordPress.org

Make WordPress Core

Changeset 410 in tests


Ignore:
Timestamp:
08/05/2011 08:39:57 PM (10 years ago)
Author:
ryan
Message:

wp_filter_object_list() tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_includes_functions.php

    r366 r410  
    249249}
    250250
     251/**
     252 * Test wp_filter_object_list(), wp_list_filter(), wp_list_pluck()
     253 */
     254class TestListFilter extends WPTestCase {
     255    var $object_list = array();
     256
     257    function setUp() {
     258        $this->object_list['foo'] = (object) array( 'name' => 'foo', 'field1' => true, 'field2' => true, 'field3' => true );
     259        $this->object_list['bar'] = (object) array( 'name' => 'bar', 'field1' => true, 'field2' => true, 'field3' => false );
     260        $this->object_list['baz'] = (object) array( 'name' => 'baz', 'field1' => true, 'field2' => false, 'field3' => false );     
     261    }
     262
     263    function test_filter_object_list_and() {
     264        $list = wp_filter_object_list( $this->object_list, array( 'field1' => true, 'field2' => true ), 'AND' );
     265        $this->assertEquals( 2, count( $list ) );
     266        $this->assertArrayHasKey( 'foo', $list );
     267        $this->assertArrayHasKey( 'bar', $list );
     268    }
     269
     270    function test_filter_object_list_or() {
     271        $list = wp_filter_object_list( $this->object_list, array( 'field1' => true, 'field2' => true ), 'OR' );
     272        $this->assertEquals( 3, count( $list ) );
     273        $this->assertArrayHasKey( 'foo', $list );
     274        $this->assertArrayHasKey( 'bar', $list );
     275        $this->assertArrayHasKey( 'baz', $list );
     276    }
     277
     278    function test_filter_object_list_not() {
     279        $list = wp_filter_object_list( $this->object_list, array( 'field2' => true, 'field3' => true ), 'NOT' );
     280        $this->assertEquals( 1, count( $list ) );
     281        $this->assertArrayHasKey( 'baz', $list );
     282    }
     283
     284    function test_filter_object_list_and_field() {
     285        $list = wp_filter_object_list( $this->object_list, array( 'field1' => true, 'field2' => true ), 'AND', 'name' );
     286        $this->assertEquals( 2, count( $list ) );
     287        $this->assertEquals( array( 'foo' => 'foo', 'bar' => 'bar' ) , $list );
     288    }
     289
     290    function test_filter_object_list_or_field() {
     291        $list = wp_filter_object_list( $this->object_list, array( 'field1' => true, 'field2' => true ), 'OR', 'name' );
     292        $this->assertEquals( 3, count( $list ) );
     293        $this->assertEquals( array( 'foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz' ) , $list );
     294    }
     295
     296    function test_filter_object_list_not_field() {
     297        $list = wp_filter_object_list( $this->object_list, array( 'field2' => true, 'field3' => true ), 'NOT', 'name' );
     298        $this->assertEquals( 1, count( $list ) );
     299        $this->assertEquals( array( 'baz' => 'baz' ) , $list );
     300    }
     301}
     302
    251303class TestHTTPFunctions extends WPTestCase {
    252304    function test_head_request() {
Note: See TracChangeset for help on using the changeset viewer.