Ticket #16137: 16137_tests.2.diff

File 16137_tests.2.diff, 3.1 KB (added by ampt, 21 months ago)
  • wp-testcase/test_includes_functions.php

     
    255255        var $object_list = array(); 
    256256 
    257257        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 );           
     258                $this->object_list['foo'] = (object) array( 'name' => 'foo', 'field1' => true, 'field2' => true, 'field3' => true, 'field4' => array( 'red' ) ); 
     259                $this->object_list['bar'] = (object) array( 'name' => 'bar', 'field1' => true, 'field2' => true, 'field3' => false, 'field4' => array( 'green' ) ); 
     260                $this->object_list['baz'] = (object) array( 'name' => 'baz', 'field1' => true, 'field2' => false, 'field3' => false, 'field4' => array( 'blue' ) );              
    261261        } 
    262262 
    263263        function test_filter_object_list_and() { 
     
    298298                $this->assertEquals( 1, count( $list ) ); 
    299299                $this->assertEquals( array( 'baz' => 'baz' ) , $list ); 
    300300        } 
     301 
     302        function test_filter_object_list_nested_array_and() { 
     303                $list = wp_filter_object_list( $this->object_list, array( 'field4' => array( 'blue' ) ), 'AND' ); 
     304                $this->assertEquals( 1, count( $list ) ); 
     305                $this->assertArrayHasKey( 'baz', $list ); 
     306        } 
     307 
     308        function test_filter_object_list_nested_array_not() { 
     309                $list = wp_filter_object_list( $this->object_list, array( 'field4' => array( 'red' ) ), 'NOT' ); 
     310                $this->assertEquals( 2, count( $list ) ); 
     311                $this->assertArrayHasKey( 'bar', $list ); 
     312                $this->assertArrayHasKey( 'baz', $list ); 
     313        } 
     314 
     315        function test_filter_object_list_nested_array_or() { 
     316                $list = wp_filter_object_list( $this->object_list, array( 'field4' => array( 'blue' ) ), 'OR' ); 
     317                $this->assertEquals( 3, count( $list ) ); 
     318                $this->assertArrayHasKey( 'foo', $list ); 
     319                $this->assertArrayHasKey( 'bar', $list ); 
     320                $this->assertArrayHasKey( 'baz', $list ); 
     321        } 
     322 
     323        function test_filter_object_list_nested_array_and_field() { 
     324                $list = wp_filter_object_list( $this->object_list, array( 'field4' => array( 'blue' ) ), 'AND', 'name' ); 
     325                $this->assertEquals( 1, count( $list ) ); 
     326                $this->assertEquals( array( 'baz' => 'baz' ) , $list ); 
     327        } 
     328 
     329        function test_filter_object_list_nested_array_not_field() { 
     330                $list = wp_filter_object_list( $this->object_list, array( 'field4' => array( 'green' ) ), 'NOT', 'name' ); 
     331                $this->assertEquals( 2, count( $list ) ); 
     332                $this->assertEquals( array( 'foo' => 'foo', 'baz' => 'baz' ), $list ); 
     333        } 
     334 
     335        function test_filter_object_list_nested_array_or_field() { 
     336                $list = wp_filter_object_list( $this->object_list, array( 'field4' => array( 'blue' ) ), 'OR', 'name' ); 
     337                $this->assertEquals( 3, count( $list ) ); 
     338                $this->assertEquals( array( 'foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz' ), $list ); 
     339        } 
    301340} 
    302341 
    303342class TestHTTPFunctions extends WPTestCase {