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 ) ); |
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 ); |
| 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 | |