WordPress.org

Make WordPress Core

Ticket #21309: 21309-ut.diff

File 21309-ut.diff, 3.7 KB (added by ryan, 8 years ago)
  • tests/post/objects.php

     
    99                $id = $this->factory->post->create();
    1010
    1111                $post = get_post( $id );
    12 
     12                $this->assertInstanceOf( 'WP_Post', $post );
    1313                $this->assertEquals( $id, $post->ID );
     14                $this->assertTrue( isset( $post->ancestors ) );
     15                $this->assertEquals( array(), $post->ancestors );
    1416
    15                 $this->assertTrue( isset( $post->post_type ) );
     17                // Unset and then verify that the magic method fills the property again
     18                unset( $post->ancestors );
     19                $this->assertEquals( array(), $post->ancestors );
     20
     21                // Magic get should make meta accessible as properties
     22                add_post_meta( $id, 'test', 'test' );
     23                $this->assertEquals( 'test', get_post_meta( $id, 'test', true ) );
     24                $this->assertEquals( 'test', $post->test );
     25
     26                // Make sure meta does not eclipse true properties
     27                add_post_meta( $id, 'post_type', 'dummy' );
     28                $this->assertEquals( 'dummy', get_post_meta( $id, 'post_type', true ) );
    1629                $this->assertEquals( 'post', $post->post_type );
    1730
    18                 unset( $post->post_type );
    19                 $this->assertFalse( isset( $post->post_type ) );
     31                // Excercise the output argument
     32                $post = get_post( $id, ARRAY_A );
     33                $this->assertInternalType( 'array', $post );
     34                $this->assertEquals( 'post', $post[ 'post_type' ] );
     35
     36                $post = get_post( $id, ARRAY_N );
     37                $this->assertInternalType( 'array', $post );
     38                $this->assertFalse( isset( $post[ 'post_type' ] ) );
     39                $this->assertTrue( in_array( 'post', $post ) );
     40
     41                $post = get_post( $id );
     42                $post = get_post( $post, ARRAY_A );
     43                $this->assertInternalType( 'array', $post );
     44                $this->assertEquals( 'post', $post[ 'post_type' ] );
     45                $this->assertEquals( $id, $post[ 'ID' ] );
     46
     47                // Should default to OBJECT when given invalid output argument
     48                $post = get_post( $id, 'invalid-output-value' );
     49                $this->assertInstanceOf( 'WP_Post', $post );
     50                $this->assertEquals( $id, $post->ID );
    2051        }
    2152
     53        function test_get_post_ancestors() {
     54                $parent_id = $this->factory->post->create();
     55                $child_id = $this->factory->post->create();
     56                $grandchild_id = $this->factory->post->create();
     57                $updated = wp_update_post( array( 'ID' => $child_id, 'post_parent' => $parent_id ) );
     58                $this->assertEquals( $updated, $child_id );
     59                $updated = wp_update_post( array( 'ID' => $grandchild_id, 'post_parent' => $child_id ) );
     60                $this->assertEquals( $updated, $grandchild_id );
     61
     62                $this->assertEquals( array( $parent_id ), get_post( $child_id )->ancestors );
     63                $this->assertEquals( array( $parent_id ), get_post_ancestors( $child_id ) );
     64                $this->assertEquals( array( $parent_id ), get_post_ancestors( get_post( $child_id ) ) );
     65
     66                $this->assertEquals( array( $child_id, $parent_id ), get_post( $grandchild_id )->ancestors );
     67                $this->assertEquals( array( $child_id, $parent_id ), get_post_ancestors( $grandchild_id ) );
     68                $this->assertEquals( array( $child_id, $parent_id ), get_post_ancestors( get_post( $grandchild_id ) ) );
     69
     70                $this->assertEquals( array(), get_post( $parent_id )->ancestors );
     71                $this->assertEquals( array(), get_post_ancestors( $parent_id ) );
     72                $this->assertEquals( array(), get_post_ancestors( get_post( $parent_id ) ) );
     73        }
     74
    2275        function test_get_post_filter() {
    2376                $post = get_post( $this->factory->post->create( array(
    2477                        'post_title' => "Mary's home"
     
    3689                $raw_post = get_post( $display_post, OBJECT, 'raw' );
    3790                $this->assertEquals( 'raw', $raw_post->filter );
    3891                $this->assertNotEquals( esc_js( "Mary's home" ), $raw_post->post_title );
     92
     93                $raw_post->filter( 'js' );
     94                $this->assertEquals( 'js', $post->filter );
     95                $this->assertEquals( esc_js( "Mary's home" ), $raw_post->post_title );
    3996        }
    4097
    4198        function test_get_post_identity() {